Search in sources :

Example 41 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BroadCastTwoConsumerFilterIT method testTwoConsumerFilter.

@Test
public void testTwoConsumerFilter() {
    int msgSize = 40;
    String tag1 = "jueyin_tag_1";
    String tag2 = "jueyin_tag_2";
    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, topic, tag1, new RMQNormalListner());
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr, consumer1.getConsumerGroup(), topic, tag1, new RMQNormalListner());
    TestUtils.waitForSeconds(waitTime);
    producer.send(tag2, msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size());
    producer.clearMsg();
    producer.send(tag1, msgSize);
    consumer1.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    consumer2.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer1.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer2.getListner().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQBroadCastConsumer(org.apache.rocketmq.test.client.rmq.RMQBroadCastConsumer) Test(org.junit.Test)

Example 42 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DynamicAddConsumerIT method testAddTwoConsumer.

@Test
public void testAddTwoConsumer() {
    int msgSize = 100;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListner());
    MQAsyncProducer asyncDefaultMQProducer = new MQAsyncProducer(producer, msgSize, 100);
    asyncDefaultMQProducer.start();
    TestUtils.waitForSeconds(waitTime);
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic, "*", new RMQNormalListner());
    RMQNormalConsumer consumer3 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic, "*", new RMQNormalListner());
    asyncDefaultMQProducer.waitSendAll(waitTime * 6);
    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner(), consumer3.getListner());
    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner(), consumer3.getListner());
    assertThat(recvAll).isEqualTo(true);
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) MQAsyncProducer(org.apache.rocketmq.test.client.mq.MQAsyncProducer) Test(org.junit.Test)

Example 43 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DynamicAddConsumerIT method testAddOneConsumer.

@Test
public void testAddOneConsumer() {
    int msgSize = 100;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListner());
    MQAsyncProducer asyncDefaultMQProducer = new MQAsyncProducer(producer, msgSize, 100);
    asyncDefaultMQProducer.start();
    TestUtils.waitForSeconds(waitTime);
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic, "*", new RMQNormalListner());
    asyncDefaultMQProducer.waitSendAll(waitTime * 6);
    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner());
    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListner(), consumer2.getListner());
    assertThat(recvAll).isEqualTo(true);
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) MQAsyncProducer(org.apache.rocketmq.test.client.mq.MQAsyncProducer) Test(org.junit.Test)

Example 44 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class SqlFilterIT method testFilterConsumer.

@Test
public void testFilterConsumer() throws Exception {
    int msgSize = 16;
    String group = initConsumerGroup();
    MessageSelector selector = MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))");
    RMQSqlConsumer consumer = ConsumerFactory.getRMQSqlConsumer(nsAddr, group, topic, selector, new RMQNormalListner(group + "_1"));
    Thread.sleep(3000);
    producer.send("TagA", msgSize);
    producer.send("TagB", msgSize);
    producer.send("TagC", msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumer.getListner().waitForMessageConsume(msgSize * 2, consumeTime);
    assertThat(producer.getAllMsgBody()).containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody()));
    assertThat(consumer.getListner().getAllMsgBody().size()).isEqualTo(msgSize * 2);
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQSqlConsumer(org.apache.rocketmq.test.client.rmq.RMQSqlConsumer) MessageSelector(org.apache.rocketmq.client.consumer.MessageSelector) Test(org.junit.Test)

Example 45 with RMQNormalListner

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class TagMessageWith1ConsumerIT method testSubTagWithKindsOfMessage.

@Test
public void testSubTagWithKindsOfMessage() {
    String tag1 = null;
    String tag2 = "jueyin";
    String subExpress = tag2;
    int msgSize = 10;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress, new RMQNormalListner());
    List<Object> tag1Msgs = MQMessageFactory.getRMQMessage(tag1, topic, msgSize);
    List<Object> tag2Msgs = MQMessageFactory.getRMQMessage(tag2, topic, msgSize);
    producer.send(tag1Msgs);
    producer.send(tag2Msgs);
    producer.send(10);
    Assert.assertEquals("Not all are sent", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumer.getListner().waitForMessageConsume(MQMessageFactory.getMessageBody(tag2Msgs), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody())).containsExactlyElementsIn(MQMessageFactory.getMessageBody(tag2Msgs));
}
Also used : RMQNormalListner(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) Test(org.junit.Test)

Aggregations

RMQNormalListner (org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListner)54 Test (org.junit.Test)54 RMQNormalConsumer (org.apache.rocketmq.test.client.rmq.RMQNormalConsumer)44 RMQBroadCastConsumer (org.apache.rocketmq.test.client.rmq.RMQBroadCastConsumer)9 MQAsyncProducer (org.apache.rocketmq.test.client.mq.MQAsyncProducer)6 TagMessage (org.apache.rocketmq.test.factory.TagMessage)6 Message (org.apache.rocketmq.common.message.Message)4 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)4 MessageQueueSelector (org.apache.rocketmq.client.producer.MessageQueueSelector)2 MessageSelector (org.apache.rocketmq.client.consumer.MessageSelector)1 RMQSqlConsumer (org.apache.rocketmq.test.client.rmq.RMQSqlConsumer)1