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

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

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