Search in sources :

Example 1 with JoynrRuntimeException

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);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MulticastPublication(joynr.MulticastPublication) MutableMessage(joynr.MutableMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 2 with JoynrRuntimeException

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);
}
Also used : Semaphore(java.util.concurrent.Semaphore) Mockito.anyString(org.mockito.Mockito.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) MutableMessage(joynr.MutableMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) Reply(joynr.Reply) Test(org.junit.Test)

Example 3 with JoynrRuntimeException

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;
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) Future(io.joynr.proxy.Future) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) CheckForNull(javax.annotation.CheckForNull)

Example 4 with JoynrRuntimeException

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);
}
Also used : JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 5 with JoynrRuntimeException

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);
        }
    }
}
Also used : MqttException(org.eclipse.paho.client.mqttv3.MqttException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) URISyntaxException(java.net.URISyntaxException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MqttException(org.eclipse.paho.client.mqttv3.MqttException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) MqttSecurityException(org.eclipse.paho.client.mqttv3.MqttSecurityException)

Aggregations

JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)76 Test (org.junit.Test)41 ApplicationException (joynr.exceptions.ApplicationException)18 joynr.tests.testProxy (joynr.tests.testProxy)16 MessagingQos (io.joynr.messaging.MessagingQos)14 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)13 Callback (io.joynr.proxy.Callback)9 Future (io.joynr.proxy.Future)9 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)9 IOException (java.io.IOException)8 Semaphore (java.util.concurrent.Semaphore)8 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 JoynrException (io.joynr.exceptions.JoynrException)7 DeferredVoid (io.joynr.provider.DeferredVoid)7 HashSet (java.util.HashSet)7 ProviderQos (joynr.types.ProviderQos)7 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)5 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)5