use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class CcMessageRouterTest method testMulticastMessageIsDroppedIfNoAddressIsFound.
@Test
public void testMulticastMessageIsDroppedIfNoAddressIsFound() throws Exception {
final Semaphore semaphore = new Semaphore(0);
final MulticastPublication multicastPublication = new MulticastPublication(new JoynrRuntimeException("Test Exception"), "multicastId");
final MutableMessage mutableMessage = messageFactory.createMulticast("fromParticipantId", multicastPublication, new MessagingQos());
final ImmutableMessage immutableMessage = mutableMessage.getImmutableMessage();
MessageProcessedListener mockMsgProcessedListener = Mockito.mock(MessageProcessedListener.class);
messageRouter.registerMessageProcessedListener(mockMsgProcessedListener);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
semaphore.release();
return null;
}
}).when(mockMsgProcessedListener).messageProcessed(anyString());
messageRouter.route(immutableMessage);
semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
verify(mockMsgProcessedListener).messageProcessed(immutableMessage.getId());
verifyNoMoreInteractions(messagingStubMock);
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class CcMessageRouterTest method testNotRoutableReplyDropped.
@Test
public void testNotRoutableReplyDropped() throws Exception {
final Semaphore semaphore = new Semaphore(0);
final String unknownParticipantId = "unknown_participant_id";
final String requestReplyId = "some_request_reply_id";
final Reply reply = new Reply(requestReplyId, new JoynrRuntimeException("TestException"));
final MutableMessage mutableMessage = messageFactory.createReply(fromParticipantId, unknownParticipantId, reply, new MessagingQos());
final ImmutableMessage immutableMessage = mutableMessage.getImmutableMessage();
MessageProcessedListener mockMsgProcessedListener = Mockito.mock(MessageProcessedListener.class);
messageRouter.registerMessageProcessedListener(mockMsgProcessedListener);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
semaphore.release();
return null;
}
}).when(mockMsgProcessedListener).messageProcessed(anyString());
messageRouter.route(immutableMessage);
semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
verify(mockMsgProcessedListener).messageProcessed(immutableMessage.getId());
verifyNoMoreInteractions(messagingStubMock);
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method lookup.
@Override
@CheckForNull
public DiscoveryEntryWithMetaInfo lookup(String participantId, DiscoveryQos discoveryQos) {
final Future<DiscoveryEntryWithMetaInfo> lookupFuture = new Future<>();
lookup(participantId, discoveryQos, new CapabilityCallback() {
@Override
public void processCapabilityReceived(DiscoveryEntryWithMetaInfo capability) {
lookupFuture.onSuccess(capability);
}
@Override
public void onError(Throwable e) {
lookupFuture.onFailure(new JoynrRuntimeException(e));
}
});
DiscoveryEntryWithMetaInfo retrievedCapabilitiyEntry = null;
try {
retrievedCapabilitiyEntry = lookupFuture.get();
} catch (InterruptedException e1) {
logger.error("interrupted while retrieving capability entry by participant ID", e1);
} catch (ApplicationException e1) {
// should not be reachable since ApplicationExceptions are not used internally
logger.error("ApplicationException while retrieving capability entry by participant ID", e1);
}
return retrievedCapabilitiyEntry;
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class MqttMessagingStubTest method testFailureActionCalled.
@Test
public void testFailureActionCalled() {
when(joynrMessage.getEffort()).thenReturn(String.valueOf(MessagingQosEffort.NORMAL));
JoynrRuntimeException exception = new JoynrRuntimeException("testException");
doThrow(exception).when(mqttClient).publishMessage(anyString(), any(byte[].class), anyInt());
subject.transmit(joynrMessage, successAction, failureAction);
Mockito.verify(failureAction).execute(exception);
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class MqttPahoClient method subscribe.
@Override
public void subscribe(String topic) {
boolean subscribed = false;
while (!subscribed && !shutdown.get()) {
logger.debug("MQTT subscribing to: {}", topic);
try {
synchronized (subscribedTopics) {
if (!subscribedTopics.contains(topic)) {
mqttClient.subscribe(topic);
subscribedTopics.add(topic);
}
subscribed = true;
}
} catch (MqttException mqttError) {
logger.debug("MQTT subscribe to {} failed: {}. Error code {}", topic, mqttError.getMessage(), mqttError.getReasonCode(), mqttError);
switch(mqttError.getReasonCode()) {
case MqttException.REASON_CODE_CLIENT_EXCEPTION:
case MqttException.REASON_CODE_BROKER_UNAVAILABLE:
case MqttException.REASON_CODE_CLIENT_TIMEOUT:
case MqttException.REASON_CODE_CONNECT_IN_PROGRESS:
case MqttException.REASON_CODE_MAX_INFLIGHT:
case MqttException.REASON_CODE_NO_MESSAGE_IDS_AVAILABLE:
case MqttException.REASON_CODE_SERVER_CONNECT_ERROR:
case MqttException.REASON_CODE_SUBSCRIBE_FAILED:
case MqttException.REASON_CODE_UNEXPECTED_ERROR:
case MqttException.REASON_CODE_WRITE_TIMEOUT:
case MqttException.REASON_CODE_CONNECTION_LOST:
case MqttException.REASON_CODE_CLIENT_NOT_CONNECTED:
case MqttException.REASON_CODE_CLIENT_DISCONNECTING:
try {
Thread.sleep(reconnectSleepMs);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
continue;
default:
throw new JoynrIllegalStateException("Unexpected exception while subscribing to " + topic + ", error: " + mqttError);
}
} catch (Exception e) {
throw new JoynrRuntimeException("Unable to start MqttPahoClient", e);
}
}
}
Aggregations