Search in sources :

Example 31 with RMQNormalListener

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener in project rocketmq by apache.

the class TagMessageWith1ConsumerIT method testSubNullWithKindsOfMessage.

@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());
}
Also used : RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Example 32 with RMQNormalListener

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener in project rocketmq by apache.

the class TagMessageWithMulConsumerIT method testTwoConsumerOneMatchOneOtherMatchAll.

@Test
public void testTwoConsumerOneMatchOneOtherMatchAll() {
    String[] tags = { "jueyin1", "jueyin2" };
    String sub1 = String.format("%s||%s", tags[0], tags[1]);
    String sub2 = String.format("%s|| noExist", tags[0]);
    int msgSize = 10;
    TagMessage tagMessage = new TagMessage(tags, topic, msgSize);
    RMQNormalConsumer consumerTag1 = getConsumer(nsAddr, topic, sub1, new RMQNormalListener());
    RMQNormalConsumer consumerTag2 = getConsumer(nsAddr, topic, sub2, new RMQNormalListener());
    List<Object> tagMsgs = tagMessage.getMixedTagMessages();
    producer.send(tagMsgs);
    Assert.assertEquals("Not all are sent", msgSize * tags.length, producer.getAllUndupMsgBody().size());
    consumerTag1.getListener().waitForMessageConsume(tagMessage.getMessageBodyByTag(tags), consumeTime);
    consumerTag2.getListener().waitForMessageConsume(tagMessage.getMessageBodyByTag(tags[0]), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerTag1.getListener().getAllMsgBody())).containsExactlyElementsIn(tagMessage.getAllTagMessageBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerTag2.getListener().getAllMsgBody())).containsExactlyElementsIn(tagMessage.getMessageBodyByTag(tags[0]));
}
Also used : RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) TagMessage(org.apache.rocketmq.test.factory.TagMessage) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Example 33 with RMQNormalListener

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener in project rocketmq by apache.

the class TagMessageWithMulConsumerIT method testSendMessagesWithTwoTag.

@Test
public void testSendMessagesWithTwoTag() {
    String[] tags = { "jueyin1", "jueyin2" };
    int msgSize = 10;
    TagMessage tagMessage = new TagMessage(tags, topic, msgSize);
    RMQNormalConsumer consumerTag1 = getConsumer(nsAddr, topic, tags[0], new RMQNormalListener());
    RMQNormalConsumer consumerTag2 = getConsumer(nsAddr, topic, tags[1], new RMQNormalListener());
    List<Object> tagMsgs = tagMessage.getMixedTagMessages();
    producer.send(tagMsgs);
    Assert.assertEquals("Not all are sent", msgSize * tags.length, producer.getAllUndupMsgBody().size());
    consumerTag1.getListener().waitForMessageConsume(tagMessage.getMessageBodyByTag(tags[0]), consumeTime);
    consumerTag2.getListener().waitForMessageConsume(tagMessage.getMessageBodyByTag(tags[1]), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerTag1.getListener().getAllMsgBody())).containsExactlyElementsIn(tagMessage.getMessageBodyByTag(tags[0]));
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerTag2.getListener().getAllMsgBody())).containsExactlyElementsIn(tagMessage.getMessageBodyByTag(tags[1]));
}
Also used : RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) TagMessage(org.apache.rocketmq.test.factory.TagMessage) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Example 34 with RMQNormalListener

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener in project rocketmq by apache.

the class TagMessageWithMulConsumerIT method testSendTwoTag.

@Test
public void testSendTwoTag() {
    String tag1 = "jueyin1";
    String tag2 = "jueyin2";
    int msgSize = 10;
    RMQNormalConsumer consumerTag1 = getConsumer(nsAddr, topic, tag1, new RMQNormalListener());
    RMQNormalConsumer consumerTag2 = getConsumer(nsAddr, topic, tag2, new RMQNormalListener());
    List<Object> tag1Msgs = MQMessageFactory.getRMQMessage(tag1, topic, msgSize);
    producer.send(tag1Msgs);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
    List<Object> tag2Msgs = MQMessageFactory.getRMQMessage(tag2, topic, msgSize);
    producer.send(tag2Msgs);
    Assert.assertEquals("Not all are sent", msgSize * 2, producer.getAllUndupMsgBody().size());
    consumerTag1.getListener().waitForMessageConsume(MQMessageFactory.getMessageBody(tag1Msgs), consumeTime);
    consumerTag2.getListener().waitForMessageConsume(MQMessageFactory.getMessageBody(tag2Msgs), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerTag1.getListener().getAllMsgBody())).containsExactlyElementsIn(MQMessageFactory.getMessageBody(tag1Msgs));
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerTag2.getListener().getAllMsgBody())).containsExactlyElementsIn(MQMessageFactory.getMessageBody(tag2Msgs));
}
Also used : RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Example 35 with RMQNormalListener

use of org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener in project rocketmq by apache.

the class TagMessageWithMulConsumerIT method testSubKindsOf.

@Test
public void testSubKindsOf() {
    String[] tags = { "jueyin1", "jueyin2" };
    String sub1 = String.format("%s||%s", tags[0], tags[1]);
    String sub2 = String.format("%s|| noExist", tags[0]);
    String sub3 = tags[0];
    String sub4 = "*";
    int msgSize = 10;
    RMQNormalConsumer consumerSubTwoMatchAll = getConsumer(nsAddr, topic, sub1, new RMQNormalListener());
    RMQNormalConsumer consumerSubTwoMachieOne = getConsumer(nsAddr, topic, sub2, new RMQNormalListener());
    RMQNormalConsumer consumerSubTag1 = getConsumer(nsAddr, topic, sub3, new RMQNormalListener());
    RMQNormalConsumer consumerSubAll = getConsumer(nsAddr, topic, sub4, new RMQNormalListener());
    producer.send(msgSize);
    Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
    Collection<Object> msgsWithNoTag = producer.getMsgBodysCopy();
    TagMessage tagMessage = new TagMessage(tags, topic, msgSize);
    List<Object> tagMsgs = tagMessage.getMixedTagMessages();
    producer.send(tagMsgs);
    Assert.assertEquals("Not all are sent", msgSize * 3, producer.getAllUndupMsgBody().size());
    consumerSubTwoMatchAll.getListener().waitForMessageConsume(tagMessage.getMessageBodyByTag(tags), consumeTime);
    consumerSubTwoMachieOne.getListener().waitForMessageConsume(tagMessage.getMessageBodyByTag(tags[0]), consumeTime);
    consumerSubTag1.getListener().waitForMessageConsume(tagMessage.getMessageBodyByTag(tags[0]), consumeTime);
    consumerSubAll.getListener().waitForMessageConsume(MQMessageFactory.getMessage(msgsWithNoTag, tagMessage.getAllTagMessageBody()), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerSubTwoMatchAll.getListener().getAllMsgBody())).containsExactlyElementsIn(tagMessage.getAllTagMessageBody());
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerSubTwoMachieOne.getListener().getAllMsgBody())).containsExactlyElementsIn(tagMessage.getMessageBodyByTag(tags[0]));
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerSubTag1.getListener().getAllMsgBody())).containsExactlyElementsIn(tagMessage.getMessageBodyByTag(tags[0]));
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumerSubAll.getListener().getAllMsgBody())).containsExactlyElementsIn(MQMessageFactory.getMessage(msgsWithNoTag, tagMessage.getAllTagMessageBody()));
}
Also used : RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) TagMessage(org.apache.rocketmq.test.factory.TagMessage) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Aggregations

RMQNormalListener (org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener)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