提交 8c59640d 编写于 作者: H hdchen 提交者: dinglei

[RIP-10] modify test case of BrokerConsumeStatusSubCommand (#983)

上级 26878e9c
......@@ -36,6 +36,24 @@ import org.apache.rocketmq.tools.command.SubCommandException;
public class BrokerConsumeStatsSubCommad implements SubCommand {
private DefaultMQAdminExt defaultMQAdminExt;
private DefaultMQAdminExt createMQAdminExt(RPCHook rpcHook) throws SubCommandException {
if (this.defaultMQAdminExt != null) {
return defaultMQAdminExt;
} else {
defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
defaultMQAdminExt.start();
}
catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
}
return defaultMQAdminExt;
}
}
@Override
public String commandName() {
return "brokerConsumeStats";
......@@ -69,10 +87,9 @@ public class BrokerConsumeStatsSubCommad implements SubCommand {
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
defaultMQAdminExt.start();
defaultMQAdminExt = createMQAdminExt(rpcHook);
String brokerAddr = commandLine.getOptionValue('b').trim();
boolean isOrder = false;
long timeoutMillis = 50000;
......
......@@ -49,6 +49,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class BrokerConsumeStatsSubCommadTest {
private static BrokerConsumeStatsSubCommad cmd = new BrokerConsumeStatsSubCommad();
private static DefaultMQAdminExt defaultMQAdminExt;
private static DefaultMQAdminExtImpl defaultMQAdminExtImpl;
private static MQClientInstance mqClientInstance = MQClientManager.getInstance().getAndCreateMQClientInstance(new ClientConfig());
......@@ -81,10 +84,13 @@ public class BrokerConsumeStatsSubCommadTest {
public static void terminate() {
}
@Ignore
@Test
public void testExecute() throws SubCommandException {
BrokerConsumeStatsSubCommad cmd = new BrokerConsumeStatsSubCommad();
public void testExecute() throws SubCommandException, IllegalAccessException, NoSuchFieldException {
Field field = BrokerConsumeStatsSubCommad.class.getDeclaredField("defaultMQAdminExt");
field.setAccessible(true);
field.set(cmd, defaultMQAdminExt);
Options options = ServerUtil.buildCommandlineOptions(new Options());
String[] subargs = new String[] {"-b 127.0.0.1:10911", "-t 3000", "-l 5", "-o true"};
final CommandLine commandLine =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册