Search in sources :

Example 1 with RMQNormalListener

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

the class AsyncSendWithMessageQueueSelectorIT method testSendWithSelector.

@Test
public void testSendWithSelector() {
    int msgSize = 20;
    final int queueId = 0;
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
    producer.asyncSend(msgSize, new MessageQueueSelector() {

        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            for (MessageQueue mq : list) {
                if (mq.getQueueId() == queueId && mq.getBrokerName().equals(broker1Name)) {
                    return mq;
                }
            }
            return list.get(0);
        }
    });
    producer.waitForResponse(5 * 1000);
    assertThat(producer.getSuccessMsgCount()).isEqualTo(msgSize);
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    VerifyUtils.verifyMessageQueueId(queueId, consumer.getListener().getAllOriginMsg());
    producer.clearMsg();
    consumer.clearMsg();
    producer.getSuccessSendResult().clear();
    producer.asyncSend(msgSize, new MessageQueueSelector() {

        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            for (MessageQueue mq : list) {
                if (mq.getQueueId() == queueId && mq.getBrokerName().equals(broker2Name)) {
                    return mq;
                }
            }
            return list.get(8);
        }
    });
    producer.waitForResponse(5 * 1000);
    assertThat(producer.getSuccessMsgCount()).isEqualTo(msgSize);
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    assertThat(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())).containsExactlyElementsIn(producer.getAllMsgBody());
    VerifyUtils.verifyMessageQueueId(queueId, consumer.getListener().getAllOriginMsg());
}
Also used : MessageQueueSelector(org.apache.rocketmq.client.producer.MessageQueueSelector) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) Message(org.apache.rocketmq.common.message.Message) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Example 2 with RMQNormalListener

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

the class MessageUserPropIT method testSendEnglishUserProp.

/**
 * @since version3.4.6
 */
@Test
public void testSendEnglishUserProp() {
    Message msg = MessageFactory.getRandomMessage(topic);
    String msgKey = "jueyinKey";
    String msgValue = "jueyinValue";
    msg.putUserProperty(msgKey, msgValue);
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
    producer.send(msg, null);
    assertThat(producer.getAllMsgBody().size()).isEqualTo(1);
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    Message sendMsg = (Message) producer.getFirstMsg();
    Message recvMsg = (Message) consumer.getListener().getFirstMsg();
    assertThat(recvMsg.getUserProperty(msgKey)).isEqualTo(sendMsg.getUserProperty(msgKey));
}
Also used : Message(org.apache.rocketmq.common.message.Message) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Example 3 with RMQNormalListener

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

the class MessageUserPropIT method testSendChinaUserProp.

/**
 * @since version3.4.6
 */
@Test
public void testSendChinaUserProp() {
    Message msg = MessageFactory.getRandomMessage(topic);
    String msgKey = "jueyinKey";
    String msgValue = "jueyinzhi";
    msg.putUserProperty(msgKey, msgValue);
    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
    producer.send(msg, null);
    assertThat(producer.getAllMsgBody().size()).isEqualTo(1);
    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
    Message sendMsg = (Message) producer.getFirstMsg();
    Message recvMsg = (Message) consumer.getListener().getFirstMsg();
    assertThat(recvMsg.getUserProperty(msgKey)).isEqualTo(sendMsg.getUserProperty(msgKey));
}
Also used : Message(org.apache.rocketmq.common.message.Message) RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Example 4 with RMQNormalListener

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

the class DynamicAddAndCrashIT method testAddTwoConsumerAndCrashAfterWhile.

@Test
public void testAddTwoConsumerAndCrashAfterWhile() {
    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());
    RMQNormalConsumer consumer3 = getConsumer(nsAddr, consumer1.getConsumerGroup(), topic, "*", new RMQNormalListener());
    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);
}
Also used : RMQNormalConsumer(org.apache.rocketmq.test.client.rmq.RMQNormalConsumer) MQAsyncProducer(org.apache.rocketmq.test.client.mq.MQAsyncProducer) RMQNormalListener(org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener) Test(org.junit.Test)

Example 5 with RMQNormalListener

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

the class DynamicAddConsumerIT method testAddTwoConsumer.

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