Search in sources :

Example 6 with FailureAction

use of io.joynr.messaging.FailureAction in project joynr by bmwcarit.

the class CcMessageRouterTest method testNoMessageDuplicationForMulticastForMultipleAddressesWithErrorFromStub.

@Test
public void testNoMessageDuplicationForMulticastForMultipleAddressesWithErrorFromStub() throws Exception {
    ChannelAddress receiverAddress1 = new ChannelAddress("http://testUrl", "channelId1");
    ChannelAddress receiverAddress2 = new ChannelAddress("http://testUrl", "channelId2");
    prepareMulticastForMultipleAddresses(receiverAddress1, receiverAddress2);
    ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    doAnswer(new Answer<Void>() {

        private int callCount = 0;

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            FailureAction failureAction = invocation.getArgumentAt(2, FailureAction.class);
            if (callCount < 2) {
                callCount++;
                failureAction.execute(new JoynrDelayMessageException(10, "first retry"));
            } else {
                failureAction.execute(new JoynrMessageNotSentException("do not retry twice"));
            }
            return null;
        }
    }).when(messagingStubMock).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    messageRouter.route(immutableMessage);
    Thread.sleep(1000);
    verify(messagingStubMock, times(4)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    verify(middlewareMessagingStubFactoryMock, times(2)).create(receiverAddress1);
    verify(middlewareMessagingStubFactoryMock, times(2)).create(receiverAddress2);
}
Also used : FailureAction(io.joynr.messaging.FailureAction) SuccessAction(io.joynr.messaging.SuccessAction) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) Test(org.junit.Test)

Aggregations

FailureAction (io.joynr.messaging.FailureAction)6 JoynrDelayMessageException (io.joynr.exceptions.JoynrDelayMessageException)3 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)3 SuccessAction (io.joynr.messaging.SuccessAction)3 ImmutableMessage (joynr.ImmutableMessage)3 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)2 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)2 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 JoynrShutdownException (io.joynr.exceptions.JoynrShutdownException)1 MessagingQos (io.joynr.messaging.MessagingQos)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Semaphore (java.util.concurrent.Semaphore)1 OneWayRequest (joynr.OneWayRequest)1 Address (joynr.system.RoutingTypes.Address)1