io.openmessaging.exception.OMSRuntimeException Java Examples

The following examples show how to use io.openmessaging.exception.OMSRuntimeException. 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: AbstractOMSProducer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
OMSRuntimeException checkProducerException(String topic, String msgId, Throwable e) {
    if (e instanceof MQClientException) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof RemotingTimeoutException) {
                return new OMSTimeOutException("-1", String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s",
                    this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e);
            } else if (e.getCause() instanceof MQBrokerException || e.getCause() instanceof RemotingConnectException) {
                MQBrokerException brokerException = (MQBrokerException) e.getCause();
                return new OMSRuntimeException("-1", String.format("Received a broker exception, Topic=%s, msgId=%s, %s",
                    topic, msgId, brokerException.getErrorMessage()), e);
            }
        }
        // Exception thrown by local.
        else {
            MQClientException clientException = (MQClientException) e;
            if (-1 == clientException.getResponseCode()) {
                return new OMSRuntimeException("-1", String.format("Topic does not exist, Topic=%s, msgId=%s",
                    topic, msgId), e);
            } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) {
                return new OMSMessageFormatException("-1", String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s",
                    topic, msgId), e);
            }
        }
    }
    return new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.", e);
}
 
Example #2
Source File: AbstractServiceLifecycle.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
@Override
public ServiceLifeState currentState() {
    ServiceState serviceState = super.getServiceState();
    switch (serviceState) {
        case WILL_START:
            return ServiceLifeState.INITIALIZED;
        case STARTING:
            return ServiceLifeState.STARTING;
        case STARTED:
        case START_FAILED:
            return ServiceLifeState.STARTED;
        case WILL_STOP:
        case STOPPING:
            return ServiceLifeState.STOPPING;
        case STOPPED:
            return ServiceLifeState.STOPPED;
        default:
            throw new OMSRuntimeException(JoyQueueCode.CN_UNKNOWN_ERROR.getCode(),
                    String.format("service state error, current: %s", serviceState));
    }
}
 
Example #3
Source File: ProducerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
}
 
Example #4
Source File: AbstractOMSProducer.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    if ("true".equalsIgnoreCase(System.getenv("OMS_RMQ_DIRECT_NAME_SRV"))) {
        String accessPoints = clientConfig.getAccessPoints();
        if (accessPoints == null || accessPoints.isEmpty()) {
            throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
        }

        this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    }

    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    this.rocketmqProducer.setLanguage(LanguageCode.OMS);
    properties.put(OMSBuiltinKeys.PRODUCER_ID, producerId);
}
 
Example #5
Source File: AbstractOMSProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOmsOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    properties.put(PropertyKeys.PRODUCER_ID, producerId);
}
 
Example #6
Source File: ProducerImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
    }
}
 
Example #7
Source File: ProducerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
    }
}
 
Example #8
Source File: AbstractOMSProducer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOmsOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    properties.put(PropertyKeys.PRODUCER_ID, producerId);
}
 
Example #9
Source File: ExceptionConverter.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
public static OMSRuntimeException convertRuntimeException(Throwable cause) {
    if (cause instanceof OMSRuntimeException) {
        return (OMSRuntimeException) cause;
    } else if (cause instanceof IllegalArgumentException) {
        return new OMSRuntimeException(JoyQueueCode.CN_PARAM_ERROR.getCode(), cause.getMessage(), cause);
    } else if (cause instanceof ClientException) {
        ClientException clientException = (ClientException) cause;
        if (clientException.getCause() instanceof TransportException.RequestTimeoutException) {
            return new OMSTimeOutException(JoyQueueCode.CN_REQUEST_TIMEOUT.getCode(), clientException.getMessage(), cause);
        }
        JoyQueueCode joyQueueCode = JoyQueueCode.valueOf(clientException.getCode());
        if (joyQueueCode.equals(JoyQueueCode.FW_TOPIC_NOT_EXIST) || joyQueueCode.equals(JoyQueueCode.FW_PRODUCER_NOT_EXISTS)) {
            return new OMSSecurityException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        return new OMSRuntimeException(((ClientException) cause).getCode(), cause.getMessage(), cause);
    } else {
        return new OMSRuntimeException(JoyQueueCode.CN_UNKNOWN_ERROR.getCode(), JoyQueueCode.CN_UNKNOWN_ERROR.getMessage(), cause);
    }
}
 
Example #10
Source File: ProducerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
}
 
Example #11
Source File: ExceptionConverter.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
public static OMSRuntimeException convertProduceException(Throwable cause) {
    if (cause instanceof ClientException) {
        ClientException clientException = (ClientException) cause;
        if (clientException.getCause() instanceof TransportException.RequestTimeoutException) {
            return new OMSTimeOutException(JoyQueueCode.CN_REQUEST_TIMEOUT.getCode(), clientException.getMessage(), cause);
        }
        JoyQueueCode joyQueueCode = JoyQueueCode.valueOf(clientException.getCode());
        if (joyQueueCode.equals(JoyQueueCode.FW_TOPIC_NOT_EXIST) || joyQueueCode.equals(JoyQueueCode.FW_PRODUCER_NOT_EXISTS)) {
            return new OMSSecurityException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        if (joyQueueCode.equals(JoyQueueCode.CN_PARAM_ERROR)) {
            return new OMSMessageFormatException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        if (joyQueueCode.equals(JoyQueueCode.CN_SERVICE_NOT_AVAILABLE)) {
            return new OMSDestinationException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        return new OMSRuntimeException(clientException.getCode(), clientException.getMessage(), cause);
    } else {
        return convertRuntimeException(cause);
    }
}
 
Example #12
Source File: ExceptionConverter.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
public static OMSRuntimeException convertConsumeException(Throwable cause) {
    if (cause instanceof ClientException) {
        ClientException clientException = (ClientException) cause;
        if (clientException.getCause() instanceof TransportException.RequestTimeoutException) {
            return new OMSTimeOutException(JoyQueueCode.CN_REQUEST_TIMEOUT.getCode(), clientException.getMessage(), cause);
        }
        JoyQueueCode joyQueueCode = JoyQueueCode.valueOf(clientException.getCode());
        if (joyQueueCode.equals(JoyQueueCode.FW_TOPIC_NOT_EXIST) || joyQueueCode.equals(JoyQueueCode.FW_CONSUMER_NOT_EXISTS)) {
            return new OMSSecurityException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        if (joyQueueCode.equals(JoyQueueCode.CN_SERVICE_NOT_AVAILABLE)) {
            return new OMSDestinationException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        return new OMSRuntimeException(((ClientException) cause).getCode(), cause.getMessage(), cause);
    } else {
        return convertRuntimeException(cause);
    }
}
 
Example #13
Source File: AbstractOMSProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
AbstractOMSProducer(final KeyValue properties) {
    this.properties = properties;
    this.rocketmqProducer = new DefaultMQProducer();
    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqProducer.setNamesrvAddr(accessPoints.replace(',', ';'));
    this.rocketmqProducer.setProducerGroup(clientConfig.getRmqProducerGroup());

    String producerId = buildInstanceName();
    this.rocketmqProducer.setSendMsgTimeout(clientConfig.getOmsOperationTimeout());
    this.rocketmqProducer.setInstanceName(producerId);
    this.rocketmqProducer.setMaxMessageSize(1024 * 1024 * 4);
    properties.put(PropertyKeys.PRODUCER_ID, producerId);
}
 
Example #14
Source File: ProducerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
}
 
Example #15
Source File: AbstractOMSProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
OMSRuntimeException checkProducerException(String topic, String msgId, Throwable e) {
    if (e instanceof MQClientException) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof RemotingTimeoutException) {
                return new OMSTimeOutException("-1", String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s",
                    this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e);
            } else if (e.getCause() instanceof MQBrokerException || e.getCause() instanceof RemotingConnectException) {
                MQBrokerException brokerException = (MQBrokerException) e.getCause();
                return new OMSRuntimeException("-1", String.format("Received a broker exception, Topic=%s, msgId=%s, %s",
                    topic, msgId, brokerException.getErrorMessage()), e);
            }
        }
        // Exception thrown by local.
        else {
            MQClientException clientException = (MQClientException) e;
            if (-1 == clientException.getResponseCode()) {
                return new OMSRuntimeException("-1", String.format("Topic does not exist, Topic=%s, msgId=%s",
                    topic, msgId), e);
            } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) {
                return new OMSMessageFormatException("-1", String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s",
                    topic, msgId), e);
            }
        }
    }
    return new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.", e);
}
 
Example #16
Source File: DefaultPromiseTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testGet_WithTimeout() throws Exception {
    try {
        promise.get(100);
        failBecauseExceptionWasNotThrown(OMSRuntimeException.class);
    } catch (OMSRuntimeException e) {
        assertThat(e).hasMessageContaining("Get request result is timeout or interrupted");
    }
}
 
Example #17
Source File: MessageListenerReflectAdapter.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceived(Message message, Context context) {
    try {
        method.invoke(instance, message, context);
    } catch (Exception e) {
        throw new OMSRuntimeException(-1, e.getMessage(), e);
    }
}
 
Example #18
Source File: DefaultPromiseTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void getThrowable() throws Exception {
    assertThat(promise.getThrowable()).isNull();
    Throwable exception = new OMSRuntimeException("-1", "Test Error");
    promise.setFailure(exception);
    assertThat(promise.getThrowable()).isEqualTo(exception);
}
 
Example #19
Source File: AbstractOMSProducer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void startup() {
    if (!started) {
        try {
            this.rocketmqProducer.start();
        } catch (MQClientException e) {
            throw new OMSRuntimeException("-1", e);
        }
    }
    this.started = true;
}
 
Example #20
Source File: DefaultPromiseTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void getThrowable() throws Exception {
    assertThat(promise.getThrowable()).isNull();
    Throwable exception = new OMSRuntimeException("-1", "Test Error");
    promise.setFailure(exception);
    assertThat(promise.getThrowable()).isEqualTo(exception);
}
 
Example #21
Source File: PullConsumerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public PullConsumerImpl(final String queueName, final KeyValue properties) {
    this.properties = properties;
    this.targetQueueName = queueName;

    this.clientConfig = BeanUtils.populate(properties, ClientConfig.class);

    String consumerGroup = clientConfig.getRmqConsumerGroup();
    if (null == consumerGroup || consumerGroup.isEmpty()) {
        throw new OMSRuntimeException("-1", "Consumer Group is necessary for RocketMQ, please set it.");
    }
    pullConsumerScheduleService = new MQPullConsumerScheduleService(consumerGroup);

    this.rocketmqPullConsumer = pullConsumerScheduleService.getDefaultMQPullConsumer();

    String accessPoints = clientConfig.getOmsAccessPoints();
    if (accessPoints == null || accessPoints.isEmpty()) {
        throw new OMSRuntimeException("-1", "OMS AccessPoints is null or empty.");
    }
    this.rocketmqPullConsumer.setNamesrvAddr(accessPoints.replace(',', ';'));

    this.rocketmqPullConsumer.setConsumerGroup(consumerGroup);

    int maxReDeliveryTimes = clientConfig.getRmqMaxRedeliveryTimes();
    this.rocketmqPullConsumer.setMaxReconsumeTimes(maxReDeliveryTimes);

    String consumerId = OMSUtil.buildInstanceName();
    this.rocketmqPullConsumer.setInstanceName(consumerId);
    properties.put(PropertyKeys.CONSUMER_ID, consumerId);

    this.localMessageCache = new LocalMessageCache(this.rocketmqPullConsumer, clientConfig);
}
 
Example #22
Source File: ProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_WithException() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    when(rocketmqProducer.send(any(Message.class), anyLong())).thenThrow(MQClientException.class);
    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 #23
Source File: BatchMessageListenerReflectAdapter.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceived(List<Message> batchMessage, Context context) {
    try {
        method.invoke(instance, batchMessage, context);
    } catch (Exception e) {
        throw new OMSRuntimeException(-1, e.getMessage(), e);
    }
}
 
Example #24
Source File: PullConsumerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void startup() {
    if (!started) {
        try {
            registerPullTaskCallback();
            this.pullConsumerScheduleService.start();
            this.localMessageCache.startup();
        } catch (MQClientException e) {
            throw new OMSRuntimeException("-1", e);
        }
    }
    this.started = true;
}
 
Example #25
Source File: DefaultPromiseTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddListener_WithException() throws Exception {
    final Throwable exception = new OMSRuntimeException("-1", "Test Error");
    promise.addListener(new FutureListener<String>() {
        @Override
        public void operationComplete(Future<String> future) {
            assertThat(promise.getThrowable()).isEqualTo(exception);
        }
    });
    promise.setFailure(exception);
}
 
Example #26
Source File: DefaultPromiseTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddListener_WithException_ListenerAfterSet() throws Exception {
    final Throwable exception = new OMSRuntimeException("-1", "Test Error");
    promise.setFailure(exception);
    promise.addListener(new FutureListener<String>() {
        @Override
        public void operationComplete(Future<String> future) {
            assertThat(promise.getThrowable()).isEqualTo(exception);
        }
    });
}
 
Example #27
Source File: DefaultPromiseTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testGet_WithTimeout() throws Exception {
    try {
        promise.get(100);
        failBecauseExceptionWasNotThrown(OMSRuntimeException.class);
    } catch (OMSRuntimeException e) {
        assertThat(e).hasMessageContaining("Get request result is timeout or interrupted");
    }
}
 
Example #28
Source File: ProducerImplTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_WithException() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    when(rocketmqProducer.send(any(Message.class), anyLong())).thenThrow(MQClientException.class);
    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 #29
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 #30
Source File: DefaultPromise.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
private V getValueOrThrowable() {
    if (exception != null) {
        Throwable e = exception.getCause() != null ? exception.getCause() : exception;
        throw new OMSRuntimeException("-1", e);
    }
    notifyListeners();
    return result;
}