Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
raphaelmichael
Rocketmq
提交
3f7dda3c
R
Rocketmq
项目概览
raphaelmichael
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
2
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,发现更多精彩内容 >>
提交
3f7dda3c
编写于
7月 23, 2018
作者:
X
XiaoZYang
提交者:
von gosling
7月 23, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ISSUE #377] FIX Admin subcommand consumeMessage should quit when catching an exception (#378)
上级
bc0c04bf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
13 deletion
+58
-13
tools/src/main/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommand.java
...rocketmq/tools/command/message/ConsumeMessageCommand.java
+1
-0
tools/src/test/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommandTest.java
...etmq/tools/command/message/ConsumeMessageCommandTest.java
+57
-13
未找到文件。
tools/src/main/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommand.java
浏览文件 @
3f7dda3c
...
...
@@ -207,6 +207,7 @@ public class ConsumeMessageCommand implements SubCommand {
pullResult
=
defaultMQPullConsumer
.
pull
(
mq
,
"*"
,
offset
,
(
int
)(
maxOffset
-
offset
+
1
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
;
}
if
(
pullResult
!=
null
)
{
offset
=
pullResult
.
getNextBeginOffset
();
...
...
tools/src/test/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommandTest.java
浏览文件 @
3f7dda3c
...
...
@@ -16,6 +16,13 @@
*/
package
org.apache.rocketmq.tools.command.message
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.Options
;
import
org.apache.commons.cli.PosixParser
;
...
...
@@ -34,14 +41,6 @@ import org.junit.Assert;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyInt
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
...
...
@@ -54,14 +53,14 @@ public class ConsumeMessageCommandTest {
@BeforeClass
public
static
void
init
()
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
,
NoSuchFieldException
,
IllegalAccessException
{
NoSuchFieldException
,
IllegalAccessException
{
consumeMessageCommand
=
new
ConsumeMessageCommand
();
DefaultMQPullConsumer
defaultMQPullConsumer
=
mock
(
DefaultMQPullConsumer
.
class
);
MessageExt
msg
=
new
MessageExt
();
msg
.
setBody
(
new
byte
[]{
'a'
});
msg
.
setBody
(
new
byte
[]
{
'a'
});
List
<
MessageExt
>
msgFoundList
=
new
ArrayList
<>();
msgFoundList
.
add
(
msg
);
final
PullResult
pullResult
=
new
PullResult
(
PullStatus
.
FOUND
,
2
,
0
,
1
,
msgFoundList
);
final
PullResult
pullResult
=
new
PullResult
(
PullStatus
.
FOUND
,
2
,
0
,
1
,
msgFoundList
);
when
(
defaultMQPullConsumer
.
pull
(
any
(
MessageQueue
.
class
),
anyString
(),
anyLong
(),
anyInt
())).
thenReturn
(
pullResult
);
when
(
defaultMQPullConsumer
.
minOffset
(
any
(
MessageQueue
.
class
))).
thenReturn
(
Long
.
valueOf
(
0
));
...
...
@@ -73,8 +72,9 @@ public class ConsumeMessageCommandTest {
Field
producerField
=
ConsumeMessageCommand
.
class
.
getDeclaredField
(
"defaultMQPullConsumer"
);
producerField
.
setAccessible
(
true
);
producerField
.
set
(
consumeMessageCommand
,
defaultMQPullConsumer
);
producerField
.
set
(
consumeMessageCommand
,
defaultMQPullConsumer
);
}
@AfterClass
public
static
void
terminate
()
{
}
...
...
@@ -102,11 +102,55 @@ public class ConsumeMessageCommandTest {
System
.
setOut
(
new
PrintStream
(
bos
));
Options
options
=
ServerUtil
.
buildCommandlineOptions
(
new
Options
());
String
[]
subargs
=
new
String
[]
{
"-t mytopic"
,
"-b localhost"
,
"-i 0"
,
"-n localhost:9876"
};
String
[]
subargs
=
new
String
[]
{
"-t mytopic"
,
"-b localhost"
,
"-i 0"
,
"-n localhost:9876"
};
CommandLine
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqadmin "
+
consumeMessageCommand
.
commandName
(),
subargs
,
consumeMessageCommand
.
buildCommandlineOptions
(
options
),
new
PosixParser
());
consumeMessageCommand
.
execute
(
commandLine
,
options
,
null
);
System
.
setOut
(
out
);
String
s
=
new
String
(
bos
.
toByteArray
());
Assert
.
assertTrue
(
s
.
contains
(
"Consume ok"
));
}
@Test
public
void
testExecuteDefaultWhenPullMessageByQueueGotException
()
throws
SubCommandException
,
InterruptedException
,
RemotingException
,
MQClientException
,
MQBrokerException
,
NoSuchFieldException
,
IllegalAccessException
{
DefaultMQPullConsumer
defaultMQPullConsumer
=
mock
(
DefaultMQPullConsumer
.
class
);
when
(
defaultMQPullConsumer
.
pull
(
any
(
MessageQueue
.
class
),
anyString
(),
anyLong
(),
anyInt
())).
thenThrow
(
Exception
.
class
);
Field
producerField
=
ConsumeMessageCommand
.
class
.
getDeclaredField
(
"defaultMQPullConsumer"
);
producerField
.
setAccessible
(
true
);
producerField
.
set
(
consumeMessageCommand
,
defaultMQPullConsumer
);
PrintStream
out
=
System
.
out
;
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
System
.
setOut
(
new
PrintStream
(
bos
));
Options
options
=
ServerUtil
.
buildCommandlineOptions
(
new
Options
());
String
[]
subargs
=
new
String
[]
{
"-t topic-not-existu"
,
"-n localhost:9876"
};
CommandLine
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqadmin "
+
consumeMessageCommand
.
commandName
(),
subargs
,
consumeMessageCommand
.
buildCommandlineOptions
(
options
),
new
PosixParser
());
consumeMessageCommand
.
execute
(
commandLine
,
options
,
null
);
System
.
setOut
(
out
);
String
s
=
new
String
(
bos
.
toByteArray
());
Assert
.
assertTrue
(!
s
.
contains
(
"Consume ok"
));
}
@Test
public
void
testExecuteByConditionWhenPullMessageByQueueGotException
()
throws
IllegalAccessException
,
InterruptedException
,
RemotingException
,
MQClientException
,
MQBrokerException
,
NoSuchFieldException
,
SubCommandException
{
DefaultMQPullConsumer
defaultMQPullConsumer
=
mock
(
DefaultMQPullConsumer
.
class
);
when
(
defaultMQPullConsumer
.
pull
(
any
(
MessageQueue
.
class
),
anyString
(),
anyLong
(),
anyInt
())).
thenThrow
(
Exception
.
class
);
Field
producerField
=
ConsumeMessageCommand
.
class
.
getDeclaredField
(
"defaultMQPullConsumer"
);
producerField
.
setAccessible
(
true
);
producerField
.
set
(
consumeMessageCommand
,
defaultMQPullConsumer
);
PrintStream
out
=
System
.
out
;
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
System
.
setOut
(
new
PrintStream
(
bos
));
Options
options
=
ServerUtil
.
buildCommandlineOptions
(
new
Options
());
String
[]
subargs
=
new
String
[]
{
"-t mytopic"
,
"-b localhost"
,
"-i 0"
,
"-n localhost:9876"
};
CommandLine
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqadmin "
+
consumeMessageCommand
.
commandName
(),
subargs
,
consumeMessageCommand
.
buildCommandlineOptions
(
options
),
new
PosixParser
());
consumeMessageCommand
.
execute
(
commandLine
,
options
,
null
);
System
.
setOut
(
out
);
String
s
=
new
String
(
bos
.
toByteArray
());
Assert
.
assertTrue
(!
s
.
contains
(
"Consume ok"
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录