Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
普通程序员一名
spring-framework
提交
6ffeee3e
S
spring-framework
项目概览
普通程序员一名
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6ffeee3e
编写于
3月 12, 2021
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Basic integration tests with various listener container settings
See gh-26442
上级
1b458aea
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
120 addition
and
0 deletion
+120
-0
spring-jms/spring-jms.gradle
spring-jms/spring-jms.gradle
+1
-0
spring-jms/src/test/java/org/springframework/jms/listener/MessageListenerContainerIntegrationTests.java
...ms/listener/MessageListenerContainerIntegrationTests.java
+119
-0
未找到文件。
spring-jms/spring-jms.gradle
浏览文件 @
6ffeee3e
...
...
@@ -14,5 +14,6 @@ dependencies {
optional
(
"com.fasterxml.jackson.core:jackson-databind"
)
testCompile
(
testFixtures
(
project
(
":spring-beans"
)))
testCompile
(
testFixtures
(
project
(
":spring-tx"
)))
testCompile
(
"org.apache.activemq:activemq-broker"
)
testImplementation
(
"javax.jms:javax.jms-api"
)
}
spring-jms/src/test/java/org/springframework/jms/listener/MessageListenerContainerIntegrationTests.java
0 → 100644
浏览文件 @
6ffeee3e
/*
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.jms.listener
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.concurrent.CopyOnWriteArraySet
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
javax.jms.JMSException
;
import
javax.jms.Session
;
import
javax.jms.TextMessage
;
import
org.apache.activemq.ActiveMQConnectionFactory
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.jms.core.JmsTemplate
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* @author Juergen Hoeller
* @since 5.3.5
*/
public
class
MessageListenerContainerIntegrationTests
{
@Test
public
void
simpleMessageListenerContainer
()
throws
InterruptedException
{
SimpleMessageListenerContainer
mlc
=
new
SimpleMessageListenerContainer
();
testMessageListenerContainer
(
mlc
);
}
@Test
public
void
defaultMessageListenerContainer
()
throws
InterruptedException
{
DefaultMessageListenerContainer
mlc
=
new
DefaultMessageListenerContainer
();
testMessageListenerContainer
(
mlc
);
}
@Test
public
void
defaultMessageListenerContainerWithMaxMessagesPerTask
()
throws
InterruptedException
{
DefaultMessageListenerContainer
mlc
=
new
DefaultMessageListenerContainer
();
mlc
.
setConcurrentConsumers
(
1
);
mlc
.
setMaxConcurrentConsumers
(
2
);
mlc
.
setMaxMessagesPerTask
(
1
);
testMessageListenerContainer
(
mlc
);
}
@Test
public
void
defaultMessageListenerContainerWithIdleReceivesPerTaskLimit
()
throws
InterruptedException
{
DefaultMessageListenerContainer
mlc
=
new
DefaultMessageListenerContainer
();
mlc
.
setConcurrentConsumers
(
1
);
mlc
.
setMaxConcurrentConsumers
(
2
);
mlc
.
setIdleReceivesPerTaskLimit
(
1
);
testMessageListenerContainer
(
mlc
);
}
private
void
testMessageListenerContainer
(
AbstractMessageListenerContainer
mlc
)
throws
InterruptedException
{
ActiveMQConnectionFactory
aqcf
=
new
ActiveMQConnectionFactory
(
"vm://localhost?broker.persistent=false"
);
TestMessageListener
tml
=
new
TestMessageListener
();
mlc
.
setConnectionFactory
(
aqcf
);
mlc
.
setMessageListener
(
tml
);
mlc
.
setDestinationName
(
"test"
);
mlc
.
afterPropertiesSet
();
mlc
.
start
();
JmsTemplate
jt
=
new
JmsTemplate
(
aqcf
);
jt
.
setDefaultDestinationName
(
"test"
);
Set
<
String
>
messages
=
new
HashSet
<>();
messages
.
add
(
"text1"
);
messages
.
add
(
"text2"
);
for
(
String
message
:
messages
)
{
jt
.
convertAndSend
(
message
);
}
assertThat
(
tml
.
result
()).
isEqualTo
(
messages
);
mlc
.
destroy
();
}
private
static
class
TestMessageListener
implements
SessionAwareMessageListener
<
TextMessage
>
{
private
final
CountDownLatch
latch
=
new
CountDownLatch
(
2
);
private
final
Set
<
String
>
messages
=
new
CopyOnWriteArraySet
<>();
@Override
public
void
onMessage
(
TextMessage
message
,
Session
session
)
throws
JMSException
{
this
.
messages
.
add
(
message
.
getText
());
this
.
latch
.
countDown
();
}
public
Set
<
String
>
result
()
throws
InterruptedException
{
assertThat
(
this
.
latch
.
await
(
5
,
TimeUnit
.
SECONDS
)).
isTrue
();
return
this
.
messages
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录