use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class ProducerImplTest method testSend_Not_OK.
@Test
public void testSend_Not_OK() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
SendResult sendResult = new SendResult();
sendResult.setSendStatus(SendStatus.FLUSH_DISK_TIMEOUT);
when(rocketmqProducer.send(any(Message.class), anyLong())).thenReturn(sendResult);
try {
producer.send(producer.createBytesMessageToTopic("HELLO_TOPIC", new byte[] { 'a' }));
failBecauseExceptionWasNotThrown(OMSRuntimeException.class);
} catch (Exception e) {
assertThat(e).hasMessageContaining("Send message to RocketMQ broker failed.");
}
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class SequenceProducerImplTest method testSend_WithCommit.
@Test
public void testSend_WithCommit() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
SendResult sendResult = new SendResult();
sendResult.setMsgId("TestMsgID");
sendResult.setSendStatus(SendStatus.SEND_OK);
when(rocketmqProducer.send(ArgumentMatchers.<Message>anyList())).thenReturn(sendResult);
when(rocketmqProducer.getMaxMessageSize()).thenReturn(1024);
final BytesMessage message = producer.createBytesMessageToTopic("HELLO_TOPIC", new byte[] { 'a' });
producer.send(message);
producer.commit();
assertThat(message.headers().getString(MessageHeader.MESSAGE_ID)).isEqualTo("TestMsgID");
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class AsyncSendExceptionIT method testQueueIdBigThanQueueNum.
@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);
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class AsyncSendExceptionIT method testQueueIdSmallZero.
@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);
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class BatchSendIT method testBatchSend_ViewMessage.
@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)]);
}
}
Aggregations