Java Code Examples for org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener

The following examples show how to use org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener. These examples are extracted from open source projects. 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
@Test
public void testTwoConsumerSubTag() {
    int msgSize = 20;
    String tag = "jueyin_tag";

    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, topic, tag,
        new RMQNormalListener());
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr,
        consumer1.getConsumerGroup(), topic, tag, new RMQNormalListener());
    TestUtils.waitForSeconds(waitTime);

    producer.send(tag, msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size());

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    consumer2.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer2.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 2
@Test
public void testConsumerStartWithInterval() {
    int msgSize = 100;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();

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

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 3
Source Project: rocketmq-4.3.0   Source File: DynamicAddConsumerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddTwoConsumer() {
    int msgSize = 100;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListener());

    MQAsyncProducer asyncDefaultMQProducer = new MQAsyncProducer(producer, msgSize, 100);
    asyncDefaultMQProducer.start();
    TestUtils.waitForSeconds(waitTime);

    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());
    RMQNormalConsumer consumer3 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());

    asyncDefaultMQProducer.waitSendAll(waitTime * 6);

    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListener(),
        consumer2.getListener(), consumer3.getListener());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener(), consumer3.getListener());
    assertThat(recvAll).isEqualTo(true);
}
 
Example 4
Source Project: rocketmq-read   Source File: MulTagSubIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNoMatch() {
    String tags[] = {"jueyin1", "jueyin2", "jueyin3"};
    String subExpress = "no_match";
    int msgSize = 10;

    TagMessage tagMessage = new TagMessage(tags, topic, msgSize);
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress,
        new RMQNormalListener());

    producer.send(tagMessage.getMixedTagMessages());
    Assert.assertEquals("Not all sent succeeded", msgSize * tags.length,
        producer.getAllUndupMsgBody().size());

    TestUtils.waitForSeconds(5);

    assertThat(VerifyUtils
        .getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())
        .size()).isEqualTo(0);
}
 
Example 5
Source Project: DDMQ   Source File: BroadCastNormalMsgTwoDiffGroupRecvIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStartDiffSameGroupConsumer() {
    int msgSize = 16;

    String group1 = initConsumerGroup();
    String group2 = initConsumerGroup();
    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, group1, topic, "*",
        new RMQNormalListener(group1 + "_1"));
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr, group2, topic, "*",
        new RMQNormalListener(group2 + "_2"));
    TestUtils.waitForSeconds(waitTime);

    producer.send(msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size());

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    consumer2.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer2.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 6
Source Project: DDMQ   Source File: BroadCastNormalMsgRecvFailIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStartTwoConsumerAndOneConsumerFail() {
    int msgSize = 16;

    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, topic, "*",
        new RMQNormalListener());
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr,
        consumer1.getConsumerGroup(), topic, "*",
        new RMQNormalListener(ConsumeConcurrentlyStatus.RECONSUME_LATER));

    producer.send(msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size());

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 7
Source Project: DDMQ   Source File: BroadCastTwoConsumerSubDiffTagIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoConsumerSubDiffTag() {
    int msgSize = 40;
    String tag = "jueyin_tag";

    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, topic, "*",
        new RMQNormalListener());
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr,
        consumer1.getConsumerGroup(), topic, tag, new RMQNormalListener());
    TestUtils.waitForSeconds(waitTime);

    producer.send(tag, msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size());

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    consumer2.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer2.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 8
Source Project: rocketmq-read   Source File: MulConsumerMulTopicIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumeWithDiffTag() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    String tag = "jueyin_tag";
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic1, "*", new RMQNormalListener());
    consumer1.subscribe(topic2, tag);
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic1,
        "*", new RMQNormalListener());
    consumer2.subscribe(topic2, tag);

    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag));
    Assert.assertEquals("Not all sent succeeded", msgSize * 2, producer.getAllUndupMsgBody().size());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener());
    assertThat(recvAll).isEqualTo(true);
}
 
Example 9
Source Project: DDMQ   Source File: BroadCastTwoConsumerSubTagIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoConsumerSubTag() {
    int msgSize = 20;
    String tag = "jueyin_tag";

    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, topic, tag,
        new RMQNormalListener());
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr,
        consumer1.getConsumerGroup(), topic, tag, new RMQNormalListener());
    TestUtils.waitForSeconds(waitTime);

    producer.send(tag, msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size());

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    consumer2.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer2.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 10
Source Project: DDMQ   Source File: NormalMsgStaticBalanceIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoConsumersBalance() {
    int msgSize = 400;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());
    TestUtils.waitForSeconds(waitTime);

    producer.send(msgSize);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener());
    assertThat(recvAll).isEqualTo(true);

    boolean balance = VerifyUtils.verifyBalance(msgSize,
        VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
            consumer1.getListener().getAllUndupMsgBody()).size(),
        VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
            consumer2.getListener().getAllUndupMsgBody()).size());
    assertThat(balance).isEqualTo(true);
}
 
Example 11
Source Project: rocketmq-read   Source File: TagMessageWith1ConsumerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSubNullWithKindsOfMessage() {
    String tag1 = null;
    String tag2 = "jueyin";
    String subExpress = null;
    int msgSize = 10;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress,
        new RMQNormalListener());

    List<Object> tag1Msgs = MQMessageFactory.getRMQMessage(tag1, topic, msgSize);
    List<Object> tag2Msgs = MQMessageFactory.getRMQMessage(tag2, topic, msgSize);

    producer.send(tag1Msgs);
    producer.send(tag2Msgs);
    Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 12
@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 13
Source Project: rocketmq-4.3.0   Source File: OneConsumerMulTopicIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSynSendMessage() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic1, "*", new RMQNormalListener());
    consumer.subscribe(topic2, "*");

    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize));

    Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 14
@Test
public void testStartTwoConsumerAndOneConsumerFail() {
    int msgSize = 16;

    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, topic, "*",
        new RMQNormalListener());
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr,
        consumer1.getConsumerGroup(), topic, "*",
        new RMQNormalListener(ConsumeConcurrentlyStatus.RECONSUME_LATER));

    producer.send(msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size());

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 15
Source Project: DDMQ   Source File: MulTagSubIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSubThreeTabAndMatchTwo() {
    String tags[] = {"jueyin1", "jueyin2", "jueyin3"};
    String subExpress = String.format("%s||%s", tags[0], tags[1]);
    int msgSize = 10;

    TagMessage tagMessage = new TagMessage(tags, topic, msgSize);
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress,
        new RMQNormalListener());

    producer.send(tagMessage.getMixedTagMessages());
    Assert.assertEquals("Not all sent succeeded", msgSize * tags.length,
        producer.getAllUndupMsgBody().size());

    consumer.getListener().waitForMessageConsume(
        tagMessage.getMessageBodyByTag(tags[0], tags[1]), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody())).containsExactlyElementsIn(
        tagMessage.getMessageBodyByTag(tags[0], tags[1]));
}
 
Example 16
Source Project: DDMQ   Source File: TagMessageWithSameGroupConsumerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoConsumerWithSameGroup() {
    int msgSize = 20;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag,
        new RMQNormalListener(originMsgDCName, msgBodyDCName));
    getConsumer(nsAddr, consumer1.getConsumerGroup(), tag,
        new RMQNormalListener(originMsgDCName, msgBodyDCName));
    producer.send(tag, msgSize);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 17
Source Project: rocketmq-read   Source File: SqlFilterIT.java    License: Apache License 2.0 6 votes vote down vote up
@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 RMQNormalListener(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.getListener().waitForMessageConsume(msgSize * 2, consumeTime);
    assertThat(producer.getAllMsgBody())
        .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
            consumer.getListener().getAllMsgBody()));

    assertThat(consumer.getListener().getAllMsgBody().size()).isEqualTo(msgSize * 2);
}
 
Example 18
Source Project: rocketmq-4.3.0   Source File: OneConsumerMulTopicIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumeWithDiffTag() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    String tag = "jueyin_tag";
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic1, "*", new RMQNormalListener());
    consumer.subscribe(topic2, tag);

    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag));

    Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 19
@Test
public void testTwoConsumerWithSameGroup() {
    int msgSize = 20;
    String originMsgDCName = RandomUtils.getStringByUUID();
    String msgBodyDCName = RandomUtils.getStringByUUID();
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag,
        new RMQNormalListener(originMsgDCName, msgBodyDCName));
    getConsumer(nsAddr, consumer1.getConsumerGroup(), tag,
        new RMQNormalListener(originMsgDCName, msgBodyDCName));
    producer.send(tag, msgSize);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 20
Source Project: rocketmq-4.3.0   Source File: DynamicAddConsumerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddOneConsumer() {
    int msgSize = 100;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListener());

    MQAsyncProducer asyncDefaultMQProducer = new MQAsyncProducer(producer, msgSize, 100);
    asyncDefaultMQProducer.start();
    TestUtils.waitForSeconds(waitTime);

    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());

    asyncDefaultMQProducer.waitSendAll(waitTime * 6);

    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListener(),
        consumer2.getListener());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener());
    assertThat(recvAll).isEqualTo(true);
}
 
Example 21
Source Project: rocketmq-read   Source File: DynamicAddAndCrashIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddOneConsumerAndCrashAfterWhile() {
    int msgSize = 150;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListener());

    MQAsyncProducer asyncDefaultMQProducer = new MQAsyncProducer(producer, msgSize, 100);
    asyncDefaultMQProducer.start();
    TestUtils.waitForSeconds(waitTime);

    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());
    TestUtils.waitForSeconds(waitTime);
    consumer2.shutdown();

    asyncDefaultMQProducer.waitSendAll(waitTime * 6);

    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListener(),
        consumer2.getListener());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener());
    assertThat(recvAll).isEqualTo(true);
}
 
Example 22
Source Project: DDMQ   Source File: TagMessageWith1ConsumerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSubTagWithKindsOfMessage() {
    String tag1 = null;
    String tag2 = "jueyin";
    String subExpress = tag2;
    int msgSize = 10;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, subExpress,
        new RMQNormalListener());

    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.getListener().waitForMessageConsume(MQMessageFactory.getMessageBody(tag2Msgs),
        consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(MQMessageFactory.getMessageBody(tag2Msgs));
}
 
Example 23
@Test
public void testTwoConsumerSubDiffTag() {
    int msgSize = 40;
    String tag = "jueyin_tag";

    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, topic, "*",
        new RMQNormalListener());
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr,
        consumer1.getConsumerGroup(), topic, tag, new RMQNormalListener());
    TestUtils.waitForSeconds(waitTime);

    producer.send(tag, msgSize);
    Assert.assertEquals("Not all sent succeeded", msgSize, producer.getAllUndupMsgBody().size());

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    consumer2.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer2.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 24
Source Project: rocketmq-4.3.0   Source File: OneConsumerMulTopicIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumeWithDiffTagAndFilter() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    String tag1 = "jueyin_tag_1";
    String tag2 = "jueyin_tag_2";
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic1, "*", new RMQNormalListener());
    consumer.subscribe(topic2, tag1);

    producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag2));
    producer.clearMsg();
    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize, tag1));

    Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 25
Source Project: DDMQ   Source File: DynamicAddConsumerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddTwoConsumer() {
    int msgSize = 100;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListener());

    MQAsyncProducer asyncDefaultMQProducer = new MQAsyncProducer(producer, msgSize, 100);
    asyncDefaultMQProducer.start();
    TestUtils.waitForSeconds(waitTime);

    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());
    RMQNormalConsumer consumer3 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());

    asyncDefaultMQProducer.waitSendAll(waitTime * 6);

    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListener(),
        consumer2.getListener(), consumer3.getListener());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener(), consumer3.getListener());
    assertThat(recvAll).isEqualTo(true);
}
 
Example 26
@Test
public void testStartTwoSameGroupConsumer() {
    int msgSize = 16;

    String group = initConsumerGroup();
    RMQBroadCastConsumer consumer1 = getBroadCastConsumer(nsAddr, group, topic, "*",
        new RMQNormalListener(group + "_1"));
    RMQBroadCastConsumer consumer2 = getBroadCastConsumer(nsAddr,
        consumer1.getConsumerGroup(), topic, "*", new RMQNormalListener(group + "_2"));
    TestUtils.waitForSeconds(waitTime);

    producer.send(msgSize);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());

    consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    consumer2.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer1.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer2.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}
 
Example 27
Source Project: DDMQ   Source File: DynamicCrashConsumerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddTwoConsumer() {
    int msgSize = 100;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());
    RMQNormalConsumer consumer3 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());

    MQAsyncProducer asyncDefaultMQProducer = new MQAsyncProducer(producer, msgSize, 100);
    asyncDefaultMQProducer.start();
    TestUtils.waitForSeconds(waitTime);

    consumer2.shutdown();
    consumer3.shutdown();

    asyncDefaultMQProducer.waitSendAll(waitTime * 6);

    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListener(),
        consumer2.getListener(), consumer3.getListener());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener(), consumer3.getListener());
    assertThat(recvAll).isEqualTo(true);
}
 
Example 28
Source Project: rocketmq-read   Source File: DynamicCrashConsumerIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddTwoConsumer() {
    int msgSize = 100;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());
    RMQNormalConsumer consumer3 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic,
        "*", new RMQNormalListener());

    MQAsyncProducer asyncDefaultMQProducer = new MQAsyncProducer(producer, msgSize, 100);
    asyncDefaultMQProducer.start();
    TestUtils.waitForSeconds(waitTime);

    consumer2.shutdown();
    consumer3.shutdown();

    asyncDefaultMQProducer.waitSendAll(waitTime * 6);

    MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListener(),
        consumer2.getListener(), consumer3.getListener());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener(), consumer3.getListener());
    assertThat(recvAll).isEqualTo(true);
}
 
Example 29
Source Project: DDMQ   Source File: MulConsumerMulTopicIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSynSendMessage() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic1, "*", new RMQNormalListener());
    consumer1.subscribe(topic2, "*");
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic1,
        "*", new RMQNormalListener());
    consumer2.subscribe(topic2, "*");

    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize));
    Assert.assertEquals("Not all sent succeeded", msgSize * 2, producer.getAllUndupMsgBody().size());

    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(),
        consumer1.getListener(), consumer2.getListener());
    assertThat(recvAll).isEqualTo(true);
}
 
Example 30
Source Project: rocketmq-read   Source File: OneConsumerMulTopicIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSynSendMessage() {
    int msgSize = 10;
    String topic1 = initTopic();
    String topic2 = initTopic();
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic1, "*", new RMQNormalListener());
    consumer.subscribe(topic2, "*");

    producer.send(MQMessageFactory.getMsg(topic1, msgSize));
    producer.send(MQMessageFactory.getMsg(topic2, msgSize));

    Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size());
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(),
        consumer.getListener().getAllMsgBody()))
        .containsExactlyElementsIn(producer.getAllMsgBody());
}