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

The following examples show how to use org.apache.rocketmq.test.util.TestUtils#waitForMoment() . 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: QueryMsgByIdIT.java    From DDMQ 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.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    Assert.assertEquals("Not all are consumed", 0, VerifyUtils.verify(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()));

    MessageExt recvMsg = (MessageExt) consumer.getListener().getFirstMsg();
    MessageExt queryMsg = null;
    try {
        TestUtils.waitForMoment(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 2
Source File: QueryMsgByKeyIT.java    From DDMQ 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.waitForMoment(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 3
Source File: QueryMsgByKeyIT.java    From DDMQ 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.waitForMoment(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: QueryMsgByKeyIT.java    From rocketmq-read 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.waitForMoment(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 5
Source File: QueryMsgByIdIT.java    From rocketmq-read 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.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    Assert.assertEquals("Not all are consumed", 0, VerifyUtils.verify(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()));

    MessageExt recvMsg = (MessageExt) consumer.getListener().getFirstMsg();
    MessageExt queryMsg = null;
    try {
        TestUtils.waitForMoment(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 6
Source File: IntegrationTestBase.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public static boolean initTopic(String topic, String nsAddr, String clusterName, int queueNumbers) {
    long startTime = System.currentTimeMillis();
    boolean createResult;

    while (true) {
        createResult = MQAdmin.createTopic(nsAddr, clusterName, topic, queueNumbers);
        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.waitForMoment(500);
            continue;
        }
    }

    return createResult;
}
 
Example 7
Source File: TagMessageWithSameGroupConsumerIT.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumerStartTwoAndCrashOneAfterWhile() {
    int msgSize = 100;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();

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

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

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 8
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static boolean initTopic(String topic, String nsAddr, String clusterName, int queueNumbers) {
    long startTime = System.currentTimeMillis();
    boolean createResult;

    while (true) {
        createResult = MQAdmin.createTopic(nsAddr, clusterName, topic, queueNumbers);
        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.waitForMoment(500);
            continue;
        }
    }

    return createResult;
}
 
Example 9
Source File: QueryMsgByIdIT.java    From rocketmq-4.3.0 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.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    Assert.assertEquals("Not all are consumed", 0, VerifyUtils.verify(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()));

    MessageExt recvMsg = (MessageExt) consumer.getListener().getFirstMsg();
    MessageExt queryMsg = null;
    try {
        TestUtils.waitForMoment(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 10
Source File: QueryMsgByIdIT.java    From rocketmq-all-4.1.0-incubating 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.waitForMoment(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 11
Source File: TagMessageWithSameGroupConsumerIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumerStartTwoAndCrashOneAfterWhile() {
    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.waitForMoment(5);
    consumer2.shutdown();
    mqClients.remove(1);
    TestUtils.waitForMoment(5);

    consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListner().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 12
Source File: QueryMsgByKeyIT.java    From rocketmq-read 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.waitForMoment(1000);

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

    assertThat(queryMsgs).isNotNull();
    assertThat(queryMsgs.size()).isEqualTo(max);
}
 
Example 13
Source File: AsyncSendExceptionIT.java    From rocketmq-read 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.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}
 
Example 14
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.waitForMoment(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 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.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}
 
Example 16
Source File: AsyncSendExceptionIT.java    From rocketmq-all-4.1.0-incubating 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.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(true);
}
 
Example 17
Source File: AsyncSendExceptionIT.java    From rocketmq-all-4.1.0-incubating 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.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}
 
Example 18
Source File: AsyncSendExceptionIT.java    From DDMQ 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.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}
 
Example 19
Source File: AsyncSendExceptionIT.java    From DDMQ 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.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(true);
}
 
Example 20
Source File: AsyncSendExceptionIT.java    From DDMQ 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.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(true);
}