Java Code Examples for org.apache.rocketmq.test.util.TestUtils#waitForMonment()

The following examples show how to use org.apache.rocketmq.test.util.TestUtils#waitForMonment() . 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: BaseConf.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static String initTopic() {
    long startTime = System.currentTimeMillis();
    String topic = MQRandomUtils.getRandomTopic();
    boolean createResult = false;
    while (true) {
        createResult = MQAdmin.createTopic(nsAddr, clusterName, topic, 8);
        if (createResult) {
            break;
        } else if (System.currentTimeMillis() - startTime > topicCreateTime) {
            Assert.fail(String.format("topic[%s] is created failed after:%d ms", topic,
                System.currentTimeMillis() - startTime));
            break;
        } else {
            TestUtils.waitForMonment(500);
            continue;
        }
    }

    return topic;
}
 
Example 2
Source File: QueryMsgByIdIT.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryMsg() {
    int msgSize = 20;
    producer.send(msgSize);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    Assert.assertEquals("Not all are consumed", 0, VerifyUtils.verify(producer.getAllMsgBody(),
        consumer.getListner().getAllMsgBody()));

    MessageExt recvMsg = (MessageExt) consumer.getListner().getFirstMsg();
    MessageExt queryMsg = null;
    try {
        TestUtils.waitForMonment(3000);
        queryMsg = producer.getProducer().viewMessage(((MessageClientExt) recvMsg).getOffsetMsgId());
    } catch (Exception e) {
    }

    assertThat(queryMsg).isNotNull();
    assertThat(new String(queryMsg.getBody())).isEqualTo(new String(recvMsg.getBody()));
}
 
Example 3
Source File: QueryMsgByKeyIT.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryMsg() {
    int msgSize = 20;
    String key = "jueyin";
    long begin = System.currentTimeMillis();
    List<Object> msgs = MQMessageFactory.getKeyMsg(topic, key, msgSize);
    producer.send(msgs);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());

    List<MessageExt> queryMsgs = null;
    try {
        TestUtils.waitForMonment(500 * 3);
        queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 5000,
            System.currentTimeMillis() + 5000).getMessageList();
    } catch (Exception e) {
    }

    assertThat(queryMsgs).isNotNull();
    assertThat(queryMsgs.size()).isEqualTo(msgSize);
}
 
Example 4
Source File: TagMessageWithSameGroupConsumerIT.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumerStartWithInterval() {
    String tag = "jueyin";
    int msgSize = 100;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();

    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag,
        new RMQNormalListner(originMsgDCName, msgBodyDCName));
    producer.send(tag, msgSize, 100);
    TestUtils.waitForMonment(5);
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), tag,
        new RMQNormalListner(originMsgDCName, msgBodyDCName));
    TestUtils.waitForMonment(5);

    consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListner().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 5
Source File: TagMessageWithSameGroupConsumerIT.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumerStartTwoAndCrashOnsAfterWhile() {
    String tag = "jueyin";
    int msgSize = 100;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();

    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag,
        new RMQNormalListner(originMsgDCName, msgBodyDCName));
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), tag,
        new RMQNormalListner(originMsgDCName, msgBodyDCName));

    producer.send(tag, msgSize, 100);
    TestUtils.waitForMonment(5);
    consumer2.shutdown();
    mqClients.remove(1);
    TestUtils.waitForMonment(5);

    consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListner().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 6
Source File: BaseConf.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public static String initTopic() {
    long startTime = System.currentTimeMillis();
    String topic = MQRandomUtils.getRandomTopic();
    boolean createResult = false;
    while (true) {
        createResult = MQAdmin.createTopic(nsAddr, clusterName, topic, 8);
        if (createResult) {
            break;
        } else if (System.currentTimeMillis() - startTime > topicCreateTime) {
            Assert.fail(String.format("topic[%s] is created failed after:%d ms", topic,
                System.currentTimeMillis() - startTime));
            break;
        } else {
            TestUtils.waitForMonment(500);
            continue;
        }
    }

    return topic;
}
 
Example 7
Source File: QueryMsgByIdIT.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryMsg() {
    int msgSize = 20;
    producer.send(msgSize);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    Assert.assertEquals("Not all are consumed", 0, VerifyUtils.verify(producer.getAllMsgBody(),
        consumer.getListner().getAllMsgBody()));

    MessageExt recvMsg = (MessageExt) consumer.getListner().getFirstMsg();
    MessageExt queryMsg = null;
    try {
        TestUtils.waitForMonment(3000);
        queryMsg = producer.getProducer().viewMessage(((MessageClientExt) recvMsg).getOffsetMsgId());
    } catch (Exception e) {
    }

    assertThat(queryMsg).isNotNull();
    assertThat(new String(queryMsg.getBody())).isEqualTo(new String(recvMsg.getBody()));
}
 
Example 8
Source File: QueryMsgByKeyIT.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryMsg() {
    int msgSize = 20;
    String key = "jueyin";
    long begin = System.currentTimeMillis();
    List<Object> msgs = MQMessageFactory.getKeyMsg(topic, key, msgSize);
    producer.send(msgs);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());

    List<MessageExt> queryMsgs = null;
    try {
        TestUtils.waitForMonment(500 * 3);
        queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 5000,
            System.currentTimeMillis() + 5000).getMessageList();
    } catch (Exception e) {
    }

    assertThat(queryMsgs).isNotNull();
    assertThat(queryMsgs.size()).isEqualTo(msgSize);
}
 
Example 9
Source File: TagMessageWithSameGroupConsumerIT.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumerStartWithInterval() {
    String tag = "jueyin";
    int msgSize = 100;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();

    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag,
        new RMQNormalListner(originMsgDCName, msgBodyDCName));
    producer.send(tag, msgSize, 100);
    TestUtils.waitForMonment(5);
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), tag,
        new RMQNormalListner(originMsgDCName, msgBodyDCName));
    TestUtils.waitForMonment(5);

    consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListner().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 10
Source File: TagMessageWithSameGroupConsumerIT.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumerStartTwoAndCrashOnsAfterWhile() {
    String tag = "jueyin";
    int msgSize = 100;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();

    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag,
        new RMQNormalListner(originMsgDCName, msgBodyDCName));
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), tag,
        new RMQNormalListner(originMsgDCName, msgBodyDCName));

    producer.send(tag, msgSize, 100);
    TestUtils.waitForMonment(5);
    consumer2.shutdown();
    mqClients.remove(1);
    TestUtils.waitForMonment(5);

    consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListner().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 11
Source File: QueryMsgByKeyIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryMax() {
    int msgSize = 500;
    int max = 64 * brokerNum;
    String key = "jueyin";
    long begin = System.currentTimeMillis();
    List<Object> msgs = MQMessageFactory.getKeyMsg(topic, key, msgSize);
    producer.send(msgs);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());

    List<MessageExt> queryMsgs = null;
    try {
        queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 15000,
            System.currentTimeMillis() + 15000).getMessageList();

        int i = 3;
        while (queryMsgs == null || queryMsgs.size() != brokerNum) {
            i--;
            queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 15000,
                System.currentTimeMillis() + 15000).getMessageList();
            TestUtils.waitForMonment(1000);

            if (i == 0 || (queryMsgs != null && queryMsgs.size() == max)) {
                break;
            }
        }
    } catch (Exception e) {
    }

    assertThat(queryMsgs).isNotNull();
    assertThat(queryMsgs.size()).isEqualTo(max);
}
 
Example 12
Source File: AsyncSendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdBigThanQueueNum() throws Exception {
    int queueId = 100;
    sendFail = false;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (!sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMonment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(true);
}
 
Example 13
Source File: AsyncSendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdSmallZero() throws Exception {
    int queueId = -100;
    sendFail = true;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            sendFail = false;
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMonment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}
 
Example 14
Source File: QueryMsgByKeyIT.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryMax() {
    int msgSize = 500;
    int max = 64 * brokerNum;
    String key = "jueyin";
    long begin = System.currentTimeMillis();
    List<Object> msgs = MQMessageFactory.getKeyMsg(topic, key, msgSize);
    producer.send(msgs);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());

    List<MessageExt> queryMsgs = null;
    try {
        queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 15000,
            System.currentTimeMillis() + 15000).getMessageList();

        int i = 3;
        while (queryMsgs == null || queryMsgs.size() != brokerNum) {
            i--;
            queryMsgs = producer.getProducer().queryMessage(topic, key, msgSize, begin - 15000,
                System.currentTimeMillis() + 15000).getMessageList();
            TestUtils.waitForMonment(1000);

            if (i == 0 || (queryMsgs != null && queryMsgs.size() == max)) {
                break;
            }
        }
    } catch (Exception e) {
    }

    assertThat(queryMsgs).isNotNull();
    assertThat(queryMsgs.size()).isEqualTo(max);
}
 
Example 15
Source File: AsyncSendExceptionIT.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdBigThanQueueNum() throws Exception {
    int queueId = 100;
    sendFail = false;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (!sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMonment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(true);
}
 
Example 16
Source File: AsyncSendExceptionIT.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdSmallZero() throws Exception {
    int queueId = -100;
    sendFail = true;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            sendFail = false;
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMonment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}