Search in sources :

Example 61 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testDelayWithoutExponentialBackoffLimit.

@Test
public void testDelayWithoutExponentialBackoffLimit() throws Exception {
    // test idea is that on average more than sendMsgRetryIntervalMs ms are needed.
    // -> at least one run exists that takes longer than sendMsgRetryIntervalMs
    // -> exponential backoff for the retry interval is active
    final long routingDuration = 1000;
    final long sendMsgRetryIntervalMs = 20;
    final long expectedAverageIntervalMs = 50;
    final long maxruns = routingDuration / expectedAverageIntervalMs;
    Module testMaxRetryCountModule = Modules.override(testModule).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_SEND_MSG_RETRY_INTERVAL_MS)).toInstance(sendMsgRetryIntervalMs);
        }
    });
    Injector injector4 = Guice.createInjector(testMaxRetryCountModule);
    MessageRouter messageRouterWithHighRetryInterval = injector4.getInstance(MessageRouter.class);
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            invocation.getArgumentAt(1, FailureAction.class).execute(new Exception());
            return null;
        }
    }).when(messagingStubMock).transmit(any(ImmutableMessage.class), any(SuccessAction.class), any(FailureAction.class));
    joynrMessage.setTtlMs(ExpiryDate.fromRelativeTtl(100000000).getValue());
    joynrMessage.setTtlAbsolute(true);
    ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    messageRouterWithHighRetryInterval.route(immutableMessage);
    Thread.sleep(routingDuration);
    // make sure that the stub is called at least few times
    // but not too often which means that the average retry interval
    // is much higher then initially set in sendMsgRetryIntervalMs
    verify(messagingStubMock, Mockito.atLeast(5)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    verify(messagingStubMock, Mockito.atMost((int) maxruns)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
}
Also used : FailureAction(io.joynr.messaging.FailureAction) CcMessageRouter(io.joynr.messaging.routing.CcMessageRouter) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) AbstractModule(com.google.inject.AbstractModule) SuccessAction(io.joynr.messaging.SuccessAction) Injector(com.google.inject.Injector) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) Module(com.google.inject.Module) ClusterControllerRuntimeModule(io.joynr.runtime.ClusterControllerRuntimeModule) TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 62 with ImmutableMessage

use of joynr.ImmutableMessage 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)

Example 63 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testMessageProcessedListenerOnlyCalledOnceForMulticast.

@Test
public void testMessageProcessedListenerOnlyCalledOnceForMulticast() throws Exception {
    final Semaphore semaphore = new Semaphore(-1);
    ChannelAddress receiverAddress1 = new ChannelAddress("http://testUrl", "channelId1");
    ChannelAddress receiverAddress2 = new ChannelAddress("http://testUrl", "channelId2");
    prepareMulticastForMultipleAddresses(receiverAddress1, receiverAddress2);
    final ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    final MessageProcessedListener mockMessageProcessedListener = mock(MessageProcessedListener.class);
    messageRouter.registerMessageProcessedListener(mockMessageProcessedListener);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            verify(mockMessageProcessedListener, times(0)).messageProcessed(eq(immutableMessage.getId()));
            invocation.getArgumentAt(1, SuccessAction.class).execute();
            semaphore.release();
            return null;
        }
    }).when(messagingStubMock).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    messageRouter.route(immutableMessage);
    semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
    verify(messagingStubMock, times(2)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    verify(mockMessageProcessedListener).messageProcessed(eq(immutableMessage.getId()));
}
Also used : SuccessAction(io.joynr.messaging.SuccessAction) FailureAction(io.joynr.messaging.FailureAction) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Aggregations

ImmutableMessage (joynr.ImmutableMessage)63 Test (org.junit.Test)42 Response (com.jayway.restassured.response.Response)12 FailureAction (io.joynr.messaging.FailureAction)11 SuccessAction (io.joynr.messaging.SuccessAction)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 EncodingException (io.joynr.smrf.EncodingException)9 MutableMessage (joynr.MutableMessage)9 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)8 UnsuppportedVersionException (io.joynr.smrf.UnsuppportedVersionException)8 Semaphore (java.util.concurrent.Semaphore)7 JoynrDelayMessageException (io.joynr.exceptions.JoynrDelayMessageException)6 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)6 MessagingQos (io.joynr.messaging.MessagingQos)6 Ignore (org.junit.Ignore)6 AbstractModule (com.google.inject.AbstractModule)5 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)5 Injector (com.google.inject.Injector)4 Module (com.google.inject.Module)4 CcMessageRouter (io.joynr.messaging.routing.CcMessageRouter)4