Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
4f7e8312
R
Rocketmq
项目概览
小五666\n哈哈
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4f7e8312
编写于
5月 26, 2021
作者:
斜
斜阳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ISSUE #2708] Fix unit test
上级
707d1b85
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
60 addition
and
36 deletion
+60
-36
client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumerTest.java
...e/rocketmq/client/consumer/DefaultMQPushConsumerTest.java
+60
-36
未找到文件。
client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumerTest.java
浏览文件 @
4f7e8312
...
...
@@ -16,17 +16,6 @@
*/
package
org.apache.rocketmq.client.consumer
;
import
java.io.ByteArrayOutputStream
;
import
java.net.InetSocketAddress
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicReference
;
import
org.apache.commons.lang3.reflect.FieldUtils
;
import
org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext
;
import
org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus
;
...
...
@@ -48,6 +37,7 @@ import org.apache.rocketmq.client.impl.consumer.PullMessageService;
import
org.apache.rocketmq.client.impl.consumer.PullRequest
;
import
org.apache.rocketmq.client.impl.consumer.PullResultExt
;
import
org.apache.rocketmq.client.impl.consumer.RebalanceImpl
;
import
org.apache.rocketmq.client.impl.consumer.RebalancePushImpl
;
import
org.apache.rocketmq.client.impl.factory.MQClientInstance
;
import
org.apache.rocketmq.common.message.MessageClientExt
;
import
org.apache.rocketmq.common.message.MessageDecoder
;
...
...
@@ -66,6 +56,18 @@ import org.mockito.invocation.InvocationOnMock;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.stubbing.Answer
;
import
java.io.ByteArrayOutputStream
;
import
java.net.InetSocketAddress
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicReference
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Fail
.
failBecauseExceptionWasNotThrown
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
...
...
@@ -74,6 +76,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
ArgumentMatchers
.
nullable
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
when
;
...
...
@@ -87,6 +90,7 @@ public class DefaultMQPushConsumerTest {
@Mock
private
MQClientAPIImpl
mQClientAPIImpl
;
private
RebalanceImpl
rebalanceImpl
;
private
RebalancePushImpl
rebalancePushImpl
;
private
DefaultMQPushConsumer
pushConsumer
;
@Before
...
...
@@ -105,7 +109,7 @@ public class DefaultMQPushConsumerTest {
messageClientExt
.
setTopic
(
topic
);
messageClientExt
.
setQueueId
(
0
);
messageClientExt
.
setMsgId
(
"123"
);
messageClientExt
.
setBody
(
new
byte
[]
{
'a'
});
messageClientExt
.
setBody
(
new
byte
[]
{
'a'
});
messageClientExt
.
setOffsetMsgId
(
"234"
);
messageClientExt
.
setBornHost
(
new
InetSocketAddress
(
8080
));
messageClientExt
.
setStoreHost
(
new
InetSocketAddress
(
8080
));
...
...
@@ -130,6 +134,7 @@ public class DefaultMQPushConsumerTest {
});
DefaultMQPushConsumerImpl
pushConsumerImpl
=
pushConsumer
.
getDefaultMQPushConsumerImpl
();
rebalancePushImpl
=
spy
(
new
RebalancePushImpl
(
pushConsumer
.
getDefaultMQPushConsumerImpl
()));
// suppress updateTopicRouteInfoFromNameServer
pushConsumer
.
changeInstanceNameToPID
();
...
...
@@ -142,7 +147,8 @@ public class DefaultMQPushConsumerTest {
doReturn
(
new
FindBrokerResult
(
"127.0.0.1:10911"
,
false
)).
when
(
mQClientFactory
).
findBrokerAddressInSubscribe
(
anyString
(),
anyLong
(),
anyBoolean
());
rebalanceImpl
=
spy
(
pushConsumerImpl
.
getRebalanceImpl
());
doReturn
(
123L
).
when
(
rebalanceImpl
).
computePullFromWhere
(
any
(
MessageQueue
.
class
));
// doReturn(123L).when(rebalancePushImpl).computePullFromWhere(any(MessageQueue.class));
doReturn
(
123L
).
when
(
rebalanceImpl
).
computePullFromWhereWithException
(
any
(
MessageQueue
.
class
));
FieldUtils
.
writeDeclaredField
(
pushConsumerImpl
,
"rebalanceImpl"
,
rebalanceImpl
,
true
);
Set
<
MessageQueue
>
messageQueueSet
=
new
HashSet
<
MessageQueue
>();
...
...
@@ -183,7 +189,7 @@ public class DefaultMQPushConsumerTest {
MessageExt
msg
=
messageAtomic
.
get
();
assertThat
(
msg
).
isNotNull
();
assertThat
(
msg
.
getTopic
()).
isEqualTo
(
topic
);
assertThat
(
msg
.
getBody
()).
isEqualTo
(
new
byte
[]
{
'a'
});
assertThat
(
msg
.
getBody
()).
isEqualTo
(
new
byte
[]{
'a'
});
}
@Test
...
...
@@ -210,7 +216,7 @@ public class DefaultMQPushConsumerTest {
MessageExt
msg
=
messageAtomic
.
get
();
assertThat
(
msg
).
isNotNull
();
assertThat
(
msg
.
getTopic
()).
isEqualTo
(
topic
);
assertThat
(
msg
.
getBody
()).
isEqualTo
(
new
byte
[]
{
'a'
});
assertThat
(
msg
.
getBody
()).
isEqualTo
(
new
byte
[]{
'a'
});
}
@Test
...
...
@@ -320,4 +326,22 @@ public class DefaultMQPushConsumerTest {
}
return
new
PullResultExt
(
pullStatus
,
requestHeader
.
getQueueOffset
()
+
messageExtList
.
size
(),
123
,
2048
,
messageExtList
,
0
,
outputStream
.
toByteArray
());
}
@Test
public
void
testPullMessage_ExceptionOccursWhenComputePullFromWhere
()
throws
MQClientException
{
doThrow
(
MQClientException
.
class
).
when
(
rebalancePushImpl
).
computePullFromWhereWithException
(
any
(
MessageQueue
.
class
));
final
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
1
);
final
MessageExt
[]
messageExts
=
new
MessageExt
[
1
];
pushConsumer
.
getDefaultMQPushConsumerImpl
().
setConsumeMessageService
(
new
ConsumeMessageConcurrentlyService
(
pushConsumer
.
getDefaultMQPushConsumerImpl
(),
(
msgs
,
context
)
->
{
messageExts
[
0
]
=
msgs
.
get
(
0
);
return
null
;
}));
pushConsumer
.
getDefaultMQPushConsumerImpl
().
setConsumeOrderly
(
true
);
PullMessageService
pullMessageService
=
mQClientFactory
.
getPullMessageService
();
pullMessageService
.
executePullRequestImmediately
(
createPullRequest
());
assertThat
(
messageExts
[
0
]).
isNull
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录