org.apache.rocketmq.test.factory.ProducerFactory Java Examples

The following examples show how to use org.apache.rocketmq.test.factory.ProducerFactory. 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
Source File: BatchSendIT.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #2
Source File: BatchSendIT.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #3
Source File: BatchSendIT.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #4
Source File: BatchSendIT.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #5
Source File: BatchSendIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #6
Source File: AsyncSendExceptionIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdBigThanQueueNum() throws Exception {
    int queueId = 100;
    sendFail = false;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (!sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(true);
}
 
Example #7
Source File: AsyncSendExceptionIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test(expected = java.lang.NullPointerException.class)
public void testSendMQNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueue messageQueue = null;
    producer.send(msg, messageQueue, SendCallBackFactory.getSendCallBack());
}
 
Example #8
Source File: OneWaySendExceptionIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test(expected = java.lang.NullPointerException.class)
public void testSendMQNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueue messageQueue = null;
    producer.sendOneway(msg, messageQueue);
}
 
Example #9
Source File: OneWaySendExceptionIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSendSelectorNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueueSelector selector = null;
    producer.sendOneway(msg, selector, 100);
}
 
Example #10
Source File: OneWaySendExceptionIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSelectorThrowsException() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    producer.sendOneway(msg, new MessageQueueSelector() {
        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            String str = null;
            return list.get(str.length());
        }
    }, null);
}
 
Example #11
Source File: AsyncSendExceptionIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdSmallZero() throws Exception {
    int queueId = -100;
    sendFail = true;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            sendFail = false;
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}
 
Example #12
Source File: AsyncSendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test(expected = java.lang.NullPointerException.class)
public void testSendMQNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueue messageQueue = null;
    producer.send(msg, messageQueue, SendCallBackFactory.getSendCallBack());
}
 
Example #13
Source File: AsyncSendExceptionIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSelectorThrowsException() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    producer.send(msg, new MessageQueueSelector() {
        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            String str = null;
            return list.get(str.length());
        }
    }, null, SendCallBackFactory.getSendCallBack());
}
 
Example #14
Source File: AsyncSendExceptionIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSendSelectorNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueueSelector selector = null;
    producer.send(msg, selector, 100, SendCallBackFactory.getSendCallBack());
}
 
Example #15
Source File: AsyncSendExceptionIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendCallBackNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendCallback sendCallback = null;
    producer.send(msg, sendCallback);
}
 
Example #16
Source File: OneWaySendExceptionIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test(expected = java.lang.NullPointerException.class)
public void testSendMQNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueue messageQueue = null;
    producer.sendOneway(msg, messageQueue);
}
 
Example #17
Source File: OneWaySendExceptionIT.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSendSelectorNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueueSelector selector = null;
    producer.sendOneway(msg, selector, 100);
}
 
Example #18
Source File: AsyncSendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSelectorThrowsException() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    producer.send(msg, new MessageQueueSelector() {
        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            String str = null;
            return list.get(str.length());
        }
    }, null, SendCallBackFactory.getSendCallBack());
}
 
Example #19
Source File: AsyncSendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSendSelectorNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueueSelector selector = null;
    producer.send(msg, selector, 100, SendCallBackFactory.getSendCallBack());
}
 
Example #20
Source File: AsyncSendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdSmallZero() throws Exception {
    int queueId = -100;
    sendFail = true;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            sendFail = false;
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMonment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}
 
Example #21
Source File: AsyncSendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendCallBackNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendCallback sendCallback = null;
    producer.send(msg, sendCallback);
}
 
Example #22
Source File: OneWaySendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSelectorThrowsException() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    producer.sendOneway(msg, new MessageQueueSelector() {
        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            String str = null;
            return list.get(str.length());
        }
    }, null);
}
 
Example #23
Source File: OneWaySendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSendSelectorNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueueSelector selector = null;
    producer.sendOneway(msg, selector, 100);
}
 
Example #24
Source File: OneWaySendExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test(expected = java.lang.NullPointerException.class)
public void testSendMQNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueue messageQueue = null;
    producer.sendOneway(msg, messageQueue);
}
 
Example #25
Source File: AsyncSendExceptionIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test(expected = java.lang.NullPointerException.class)
public void testSendMQNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueue messageQueue = null;
    producer.send(msg, messageQueue, SendCallBackFactory.getSendCallBack());
}
 
Example #26
Source File: AsyncSendExceptionIT.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSendSelectorNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueueSelector selector = null;
    producer.send(msg, selector, 100, SendCallBackFactory.getSendCallBack());
}
 
Example #27
Source File: AsyncSendExceptionIT.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdSmallZero() throws Exception {
    int queueId = -100;
    sendFail = true;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            sendFail = false;
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMoment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(false);
}
 
Example #28
Source File: AsyncSendExceptionIT.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueIdBigThanQueueNum() throws Exception {
    int queueId = 100;
    sendFail = false;
    MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);

    producer.send(msg, mq, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
        }

        @Override
        public void onException(Throwable throwable) {
            sendFail = true;
        }
    });

    int checkNum = 50;
    while (!sendFail && checkNum > 0) {
        checkNum--;
        TestUtils.waitForMonment(100);
    }
    producer.shutdown();
    assertThat(sendFail).isEqualTo(true);
}
 
Example #29
Source File: AsyncSendExceptionIT.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testSelectorThrowsException() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    producer.send(msg, new MessageQueueSelector() {
        @Override
        public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
            String str = null;
            return list.get(str.length());
        }
    }, null, SendCallBackFactory.getSendCallBack());
}
 
Example #30
Source File: AsyncSendExceptionIT.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendSelectorNull() throws Exception {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    MessageQueueSelector selector = null;
    producer.send(msg, selector, 100, SendCallBackFactory.getSendCallBack());
}