Search in sources :

Example 1 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class OneWaySendIT method testOneWaySendWithOnlyMsgAsParam.

@Test
public void testOneWaySendWithOnlyMsgAsParam() {
    int msgSize = 20;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListner());
    producer.sendOneWay(msgSize);
    producer.waitForResponse(5 * 1000);
    assertThat(producer.getAllMsgBody().size()).isEqualTo(msgSize);
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Example 2 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class OrderMsgWithTagIT method testConsumeTwoTag.

@Test
public void testConsumeTwoTag() {
    int msgSize = 10;
    String tag1 = "jueyin_tag_1";
    String tag2 = "jueyin_tag_2";
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, String.format("%s||%s", tag1, tag2), new RMQOrderListener());
    List<MessageQueue> mqs = producer.getMessageQueue();
    MessageQueueMsg mqMsgs = new MessageQueueMsg(mqs, msgSize, tag1);
    producer.send(mqMsgs.getMsgsWithMQ());
    mqMsgs = new MessageQueueMsg(mqs, msgSize, tag2);
    producer.send(mqMsgs.getMsgsWithMQ());
    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer.getListner());
    assertThat(recvAll).isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer.getListner()).getMsgs())).isEqualTo(true);
}
Also used : RMQOrderListener(org.apache.rocketmq.test.listener.rmq.order.RMQOrderListener) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) MessageQueueMsg(org.apache.rocketmq.test.message.MessageQueueMsg) Test(org.junit.Test)

Example 3 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class OrderMsgWithTagIT method testOrderMsgWithTagSubAll.

@Test
public void testOrderMsgWithTagSubAll() {
    int msgSize = 10;
    String tag = "jueyin_tag";
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQOrderListener());
    List<MessageQueue> mqs = producer.getMessageQueue();
    MessageQueueMsg mqMsgs = new MessageQueueMsg(mqs, msgSize, tag);
    producer.send(mqMsgs.getMsgsWithMQ());
    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(mqMsgs.getMsgBodys());
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer.getListner()).getMsgs())).isEqualTo(true);
}
Also used : RMQOrderListener(org.apache.rocketmq.test.listener.rmq.order.RMQOrderListener) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) MessageQueueMsg(org.apache.rocketmq.test.message.MessageQueueMsg) Test(org.junit.Test)

Example 4 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BaseConf method getConsumer.

public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic, String subExpression, AbstractListener listner) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup, topic, subExpression, listner);
    if (debug) {
        consumer.setDebug();
    }
    mqClients.add(consumer);
    log.info(String.format("consumer[%s] start,topic[%s],subExpression[%s]", consumerGroup, topic, subExpression));
    return consumer;
}
Also used : RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer)

Example 5 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class NormalMsgDynamicBalanceIT method testTwoConsumerAndCrashOne.

@Test
public void testTwoConsumerAndCrashOne() {
    int msgSize = 400;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListner());
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic, "*", new RMQNormalListner());
    producer.send(msgSize);
    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner());
    consumer2.shutdown();
    producer.send(msgSize);
    Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size());
    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner());
    assertThat(recvAll).isEqualTo(true);
    boolean balance = VerifyUtils.verifyBalance(msgSize, VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer1.getListner().getAllUndupMsgBody()).size() - msgSize, VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer2.getListner().getAllUndupMsgBody()).size());
    assertThat(balance).isEqualTo(true);
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Aggregations

RMQNormalConsumer (org.apache.rocketmq.test.client.rmq.RMQNormalConsumer)111 Test (org.junit.Test)106 RMQNormalListener (org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener)44 RMQNormalListner (org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner)44 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)26 RMQOrderListener (org.apache.rocketmq.test.listener.rmq.order.RMQOrderListener)18 MessageQueueMsg (org.apache.rocketmq.test.message.MessageQueueMsg)18 MQAsyncProducer (org.apache.rocketmq.test.client.mq.MQAsyncProducer)12 TagMessage (org.apache.rocketmq.test.factory.TagMessage)12 Message (org.apache.rocketmq.common.message.Message)8 MessageQueueSelector (org.apache.rocketmq.client.producer.MessageQueueSelector)4