Java Code Examples for org.apache.rocketmq.client.producer.SendResult#setSendStatus()

The following examples show how to use org.apache.rocketmq.client.producer.SendResult#setSendStatus() . 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: SendMessageCommandTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws MQClientException, RemotingException, InterruptedException, MQBrokerException, NoSuchFieldException, IllegalAccessException {

    DefaultMQProducer defaultMQProducer = mock(DefaultMQProducer.class);
    SendResult sendResult = new SendResult();
    sendResult.setMessageQueue(new MessageQueue());
    sendResult.getMessageQueue().setBrokerName("broker1");
    sendResult.getMessageQueue().setQueueId(1);
    sendResult.setSendStatus(SendStatus.SEND_OK);
    sendResult.setMsgId("fgwejigherughwueyutyu4t4343t43");

    when(defaultMQProducer.send(any(Message.class))).thenReturn(sendResult);
    when(defaultMQProducer.send(any(Message.class), any(MessageQueue.class))).thenReturn(sendResult);

    Field producerField = SendMessageCommand.class.getDeclaredField("producer");
    producerField.setAccessible(true);
    producerField.set(sendMessageCommand, defaultMQProducer);
}
 
Example 2
Source File: SendMessageCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws MQClientException, RemotingException, InterruptedException, MQBrokerException, NoSuchFieldException, IllegalAccessException {

    DefaultMQProducer defaultMQProducer = mock(DefaultMQProducer.class);
    SendResult sendResult = new SendResult();
    sendResult.setMessageQueue(new MessageQueue());
    sendResult.getMessageQueue().setBrokerName("broker1");
    sendResult.getMessageQueue().setQueueId(1);
    sendResult.setSendStatus(SendStatus.SEND_OK);
    sendResult.setMsgId("fgwejigherughwueyutyu4t4343t43");

    when(defaultMQProducer.send(any(Message.class))).thenReturn(sendResult);
    when(defaultMQProducer.send(any(Message.class), any(MessageQueue.class))).thenReturn(sendResult);

    Field producerField = SendMessageCommand.class.getDeclaredField("producer");
    producerField.setAccessible(true);
    producerField.set(sendMessageCommand, defaultMQProducer);
}
 
Example 3
Source File: SendMessageCommandTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws MQClientException, RemotingException, InterruptedException, MQBrokerException, NoSuchFieldException, IllegalAccessException {

    DefaultMQProducer defaultMQProducer = mock(DefaultMQProducer.class);
    SendResult sendResult = new SendResult();
    sendResult.setMessageQueue(new MessageQueue());
    sendResult.getMessageQueue().setBrokerName("broker1");
    sendResult.getMessageQueue().setQueueId(1);
    sendResult.setSendStatus(SendStatus.SEND_OK);
    sendResult.setMsgId("fgwejigherughwueyutyu4t4343t43");

    when(defaultMQProducer.send(any(Message.class))).thenReturn(sendResult);
    when(defaultMQProducer.send(any(Message.class), any(MessageQueue.class))).thenReturn(sendResult);

    Field producerField = SendMessageCommand.class.getDeclaredField("producer");
    producerField.setAccessible(true);
    producerField.set(sendMessageCommand, defaultMQProducer);
}
 
Example 4
Source File: ProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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.");
    }
}
 
Example 5
Source File: DefaultMQConsumerWithTraceTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private SendResult createSendResult(SendStatus sendStatus) {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("123");
    sendResult.setOffsetMsgId("123");
    sendResult.setQueueOffset(456);
    sendResult.setSendStatus(sendStatus);
    sendResult.setRegionId("HZ");
    return sendResult;
}
 
Example 6
Source File: DefaultMQProducerWithTraceTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private SendResult createSendResult(SendStatus sendStatus) {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("123");
    sendResult.setOffsetMsgId("123");
    sendResult.setQueueOffset(456);
    sendResult.setSendStatus(sendStatus);
    sendResult.setRegionId("HZ");
    return sendResult;
}
 
Example 7
Source File: ProducerImplTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@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.createBytesMessage("HELLO_TOPIC", new byte[] {'a'}));
        failBecauseExceptionWasNotThrown(OMSRuntimeException.class);
    } catch (Exception e) {
        assertThat(e).hasMessageContaining("Send message to RocketMQ broker failed.");
    }
}
 
Example 8
Source File: ProducerImplTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_OK() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("TestMsgID");
    sendResult.setSendStatus(SendStatus.SEND_OK);
    when(rocketmqProducer.send(any(Message.class), anyLong())).thenReturn(sendResult);
    io.openmessaging.producer.SendResult omsResult =
        producer.send(producer.createBytesMessage("HELLO_TOPIC", new byte[] {'a'}));

    assertThat(omsResult.messageId()).isEqualTo("TestMsgID");
}
 
Example 9
Source File: SequenceProducerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 10
Source File: ProducerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@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.");
    }
}
 
Example 11
Source File: ProducerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_OK() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("TestMsgID");
    sendResult.setSendStatus(SendStatus.SEND_OK);
    when(rocketmqProducer.send(any(Message.class), anyLong())).thenReturn(sendResult);
    io.openmessaging.SendResult omsResult =
        producer.send(producer.createBytesMessageToTopic("HELLO_TOPIC", new byte[] {'a'}));

    assertThat(omsResult.messageId()).isEqualTo("TestMsgID");
}
 
Example 12
Source File: SequenceProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 13
Source File: ProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_OK() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("TestMsgID");
    sendResult.setSendStatus(SendStatus.SEND_OK);
    when(rocketmqProducer.send(any(Message.class), anyLong())).thenReturn(sendResult);
    io.openmessaging.SendResult omsResult =
        producer.send(producer.createBytesMessageToTopic("HELLO_TOPIC", new byte[] {'a'}));

    assertThat(omsResult.messageId()).isEqualTo("TestMsgID");
}
 
Example 14
Source File: ProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_OK() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("TestMsgID");
    sendResult.setSendStatus(SendStatus.SEND_OK);
    when(rocketmqProducer.send(any(Message.class), anyLong())).thenReturn(sendResult);
    io.openmessaging.SendResult omsResult =
        producer.send(producer.createBytesMessageToTopic("HELLO_TOPIC", new byte[] {'a'}));

    assertThat(omsResult.messageId()).isEqualTo("TestMsgID");
}
 
Example 15
Source File: ProducerImplTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@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.createBytesMessage("HELLO_TOPIC", new byte[] {'a'}));
        failBecauseExceptionWasNotThrown(OMSRuntimeException.class);
    } catch (Exception e) {
        assertThat(e).hasMessageContaining("Send message to RocketMQ broker failed.");
    }
}
 
Example 16
Source File: ProducerImplTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_OK() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("TestMsgID");
    sendResult.setSendStatus(SendStatus.SEND_OK);
    when(rocketmqProducer.send(any(Message.class), anyLong())).thenReturn(sendResult);
    io.openmessaging.producer.SendResult omsResult =
        producer.send(producer.createBytesMessage("HELLO_TOPIC", new byte[] {'a'}));

    assertThat(omsResult.messageId()).isEqualTo("TestMsgID");
}
 
Example 17
Source File: ProducerImplTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@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.createBytesMessage("HELLO_TOPIC", new byte[] {'a'}));
        failBecauseExceptionWasNotThrown(OMSRuntimeException.class);
    } catch (Exception e) {
        assertThat(e).hasMessageContaining("Send message to RocketMQ broker failed.");
    }
}
 
Example 18
Source File: ProducerImplTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_OK() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("TestMsgID");
    sendResult.setSendStatus(SendStatus.SEND_OK);
    when(rocketmqProducer.send(any(Message.class), anyLong())).thenReturn(sendResult);
    io.openmessaging.producer.SendResult omsResult =
        producer.send(producer.createBytesMessage("HELLO_TOPIC", new byte[] {'a'}));

    assertThat(omsResult.messageId()).isEqualTo("TestMsgID");
}
 
Example 19
Source File: SequenceProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 20
Source File: ProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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.");
    }
}