Search in sources :

Example 46 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq by apache.

the class OrderMsgRebalanceIT method testFourConsuemrBalance.

@Test
public void testFourConsuemrBalance() {
    int msgSize = 20;
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, "*", new RMQOrderListener());
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic, "*", new RMQOrderListener());
    RMQNormalConsumer consumer3 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic, "*", new RMQOrderListener());
    RMQNormalConsumer consumer4 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic, "*", new RMQOrderListener());
    TestUtils.waitForSeconds(waitTime);
    List<MessageQueue> mqs = producer.getMessageQueue();
    MessageQueueMsg mqMsgs = new MessageQueueMsg(mqs, msgSize);
    producer.send(mqMsgs.getMsgsWithMQ());
    boolean recvAll = MQWait.waitConsumeAll(consumeTime, producer.getAllMsgBody(), consumer1.getListener(), consumer2.getListener(), consumer3.getListener(), consumer4.getListener());
    assertThat(recvAll).isEqualTo(true);
    boolean balance = VerifyUtils.verifyBalance(producer.getAllMsgBody().size(), VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer1.getListener().getAllUndupMsgBody()).size(), VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer2.getListener().getAllUndupMsgBody()).size(), VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer3.getListener().getAllUndupMsgBody()).size(), VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer4.getListener().getAllUndupMsgBody()).size());
    logger.info(String.format("consumer1:%s;consumer2:%s;consumer3:%s,consumer4:%s", consumer1.getListener().getAllMsgBody().size(), consumer2.getListener().getAllMsgBody().size(), consumer3.getListener().getAllMsgBody().size(), consumer4.getListener().getAllMsgBody().size()));
    assertThat(balance).isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer1.getListener()).getMsgs())).isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer2.getListener()).getMsgs())).isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer3.getListener()).getMsgs())).isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer4.getListener()).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 47 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq by apache.

the class OrderMsgWithTagIT method testTwoConsumerSubTag.

@Test
public void testTwoConsumerSubTag() {
    int msgSize = 10;
    String tag1 = "jueyin_tag_1";
    String tag2 = "jueyin_tag_2";
    RMQNormalConsumer consumer1 = getConsumer(nsAddr, topic, tag1, new RMQOrderListener("consumer1"));
    RMQNormalConsumer consumer2 = getConsumer(nsAddr, topic, tag2, new RMQOrderListener("consumer2"));
    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(), consumer1.getListener(), consumer2.getListener());
    assertThat(recvAll).isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer1.getListener()).getMsgs())).isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer2.getListener()).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 48 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq by apache.

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.getListener());
    assertThat(recvAll).isEqualTo(true);
    assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer.getListener()).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 49 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq by apache.

the class BaseConf method getConsumer.

public static RMQNormalConsumer getConsumer(String nsAddr, String consumerGroup, String topic, String subExpression, AbstractListener listener, boolean useTLS) {
    RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(nsAddr, consumerGroup, topic, subExpression, listener, useTLS);
    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 50 with RMQNormalConsumer

use of org.apache.rocketmq.test.client.rmq.RMQNormalConsumer in project rocketmq by apache.

the class NormalMsgStaticBalanceIT method testTwoConsumersBalance.

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