org.apache.rocketmq.srvutil.ServerUtil Java Examples

The following examples show how to use org.apache.rocketmq.srvutil.ServerUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsumeMessageCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #2
Source File: UpdateTopicSubCommandTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute() {
    UpdateTopicSubCommand cmd = new UpdateTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {
        "-b 127.0.0.1:10911",
        "-c default-cluster",
        "-t unit-test",
        "-r 8",
        "-w 8",
        "-p 6",
        "-o false",
        "-u false",
        "-s false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('b').trim()).isEqualTo("127.0.0.1:10911");
    assertThat(commandLine.getOptionValue('c').trim()).isEqualTo("default-cluster");
    assertThat(commandLine.getOptionValue('r').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('w').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('p').trim()).isEqualTo("6");
    assertThat(commandLine.getOptionValue('o').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('u').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("false");
}
 
Example #3
Source File: QueryMsgByUniqueKeySubCommandTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute() throws SubCommandException {

    System.setProperty("rocketmq.namesrv.addr", "127.0.0.1:9876");

    QueryMsgByUniqueKeySubCommand cmd = new QueryMsgByUniqueKeySubCommand();
    String[] args = new String[]{"-t myTopicTest", "-i 0A3A54F7BF7D18B4AAC28A3FA2CF0000"};
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin ", args, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);

    args = new String[]{"-t myTopicTest", "-i 0A3A54F7BF7D18B4AAC28A3FA2CF0000", "-g producerGroupName", "-d clientId"};
    commandLine = ServerUtil.parseCmdLine("mqadmin ", args, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);

}
 
Example #4
Source File: SendMessageCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute() throws SubCommandException {
    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","-p 'send message test'","-c tagA","-k order-16546745756"};
    CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + sendMessageCommand.commandName(), subargs, sendMessageCommand.buildCommandlineOptions(options), new PosixParser());
    sendMessageCommand.execute(commandLine, options, null);

    subargs = new String[] {"-t mytopic","-p 'send message test'","-c tagA","-k order-16546745756","-b brokera","-i 1"};
    commandLine = ServerUtil.parseCmdLine("mqadmin " + sendMessageCommand.commandName(), subargs, sendMessageCommand.buildCommandlineOptions(options), new PosixParser());
    sendMessageCommand.execute(commandLine, options, null);
    System.setOut(out);
    String s = new String(bos.toByteArray());
    Assert.assertTrue(s.contains("SEND_OK"));
}
 
Example #5
Source File: DeleteTopicSubCommand.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        String topic = commandLine.getOptionValue('t').trim();

        if (commandLine.hasOption('c')) {
            String clusterName = commandLine.getOptionValue('c').trim();

            adminExt.start();
            deleteTopic(adminExt, clusterName, topic);
            return;
        }

        ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        adminExt.shutdown();
    }
}
 
Example #6
Source File: DeleteTopicSubCommand.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        String topic = commandLine.getOptionValue('t').trim();

        if (commandLine.hasOption('c')) {
            String clusterName = commandLine.getOptionValue('c').trim();

            adminExt.start();
            deleteTopic(adminExt, clusterName, topic);
            return;
        }

        ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        adminExt.shutdown();
    }
}
 
Example #7
Source File: DeleteTopicSubCommand.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        String topic = commandLine.getOptionValue('t').trim();

        if (commandLine.hasOption('c')) {
            String clusterName = commandLine.getOptionValue('c').trim();

            adminExt.start();
            deleteTopic(adminExt, clusterName, topic);
            return;
        }

        ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        adminExt.shutdown();
    }
}
 
Example #8
Source File: SendMessageCommandTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute() throws SubCommandException {
    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","-p 'send message test'","-c tagA","-k order-16546745756"};
    CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + sendMessageCommand.commandName(), subargs, sendMessageCommand.buildCommandlineOptions(options), new PosixParser());
    sendMessageCommand.execute(commandLine, options, null);

    subargs = new String[] {"-t mytopic","-p 'send message test'","-c tagA","-k order-16546745756","-b brokera","-i 1"};
    commandLine = ServerUtil.parseCmdLine("mqadmin " + sendMessageCommand.commandName(), subargs, sendMessageCommand.buildCommandlineOptions(options), new PosixParser());
    sendMessageCommand.execute(commandLine, options, null);
    System.setOut(out);
    String s = new String(bos.toByteArray());
    Assert.assertTrue(s.contains("SEND_OK"));
}
 
Example #9
Source File: TopicStatusSubCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    TopicStatusSubCommand cmd = new TopicStatusSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
}
 
Example #10
Source File: WipeWritePermSubCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    WipeWritePermSubCommand cmd = new WipeWritePermSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b default-broker"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #11
Source File: GetNamesrvConfigCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() throws SubCommandException {
    GetNamesrvConfigCommand cmd = new GetNamesrvConfigCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #12
Source File: ConsumerOffsetManager.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void decode(String jsonString) {
    if (jsonString != null) {
        ConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, ConsumerOffsetManager.class);
        if (obj != null) {
            ServerUtil.updateMap(this.offsetTable, obj.offsetTable);
        }
    }
}
 
Example #13
Source File: ResetOffsetByTimeOldCommandTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    ResetOffsetByTimeOldCommand cmd = new ResetOffsetByTimeOldCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-s 1412131213231", "-f false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('g').trim()).isEqualTo("default-group");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("1412131213231");
}
 
Example #14
Source File: GetNamesrvConfigCommandTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() throws SubCommandException {
    GetNamesrvConfigCommand cmd = new GetNamesrvConfigCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #15
Source File: BrokerStatusSubCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    BrokerStatusSubCommand cmd = new BrokerStatusSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-c default-cluster"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #16
Source File: ResetOffsetByTimeCommandTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ResetOffsetByTimeCommand cmd = new ResetOffsetByTimeCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-s 1412131213231", "-f false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #17
Source File: ConsumerProgressSubCommandTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ConsumerProgressSubCommand cmd = new ConsumerProgressSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #18
Source File: TopicStatusSubCommandTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    TopicStatusSubCommand cmd = new TopicStatusSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
}
 
Example #19
Source File: ResetOffsetByTimeOldCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    ResetOffsetByTimeOldCommand cmd = new ResetOffsetByTimeOldCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-s 1412131213231", "-f false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('g').trim()).isEqualTo("default-group");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("1412131213231");
}
 
Example #20
Source File: CleanUnusedTopicCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    CleanUnusedTopicCommand cmd = new CleanUnusedTopicCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-c default-cluster"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #21
Source File: CleanUnusedTopicCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    CleanUnusedTopicCommand cmd = new CleanUnusedTopicCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-c default-cluster"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #22
Source File: DeleteTopicSubCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    DeleteTopicSubCommand cmd = new DeleteTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-t unit-test", "-c default-cluster"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue("c").trim()).isEqualTo("default-cluster");
}
 
Example #23
Source File: ProducerConnectionSubCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    ProducerConnectionSubCommand cmd = new ProducerConnectionSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-producer-group", "-t unit-test"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #24
Source File: SendMsgStatusCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    SendMsgStatusCommand cmd = new SendMsgStatusCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-s 1024 -c 10"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    //cmd.execute(commandLine, options, null);
}
 
Example #25
Source File: GetBrokerConfigCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    GetBrokerConfigCommand cmd = new GetBrokerConfigCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-c default-cluster"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #26
Source File: QueryConsumeQueueCommand.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    QueryConsumeQueueCommand cmd = new QueryConsumeQueueCommand();

    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[]{"-t TopicTest", "-q 0", "-i 6447", "-b 100.81.165.119:10911"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options),
            new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #27
Source File: ResetOffsetByTimeCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testExecute() throws SubCommandException {
    ResetOffsetByTimeCommand cmd = new ResetOffsetByTimeCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-s 1412131213231", "-f false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #28
Source File: WipeWritePermSubCommandTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    WipeWritePermSubCommand cmd = new WipeWritePermSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b default-broker"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    cmd.execute(commandLine, options, null);
}
 
Example #29
Source File: ResetOffsetByTimeOldCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    ResetOffsetByTimeOldCommand cmd = new ResetOffsetByTimeOldCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-g default-group", "-t unit-test", "-s 1412131213231", "-f false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('g').trim()).isEqualTo("default-group");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("1412131213231");
}
 
Example #30
Source File: SendMsgStatusCommandTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() {
    SendMsgStatusCommand cmd = new SendMsgStatusCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {"-b 127.0.0.1:10911", "-s 1024 -c 10"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    //cmd.execute(commandLine, options, null);
}