Search in sources :

Example 6 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testScheduleMessageOk.

@Test
public void testScheduleMessageOk() throws Exception {
    joynrMessage.setTtlMs(ExpiryDate.fromRelativeTtl(100000000).getValue());
    joynrMessage.setTtlAbsolute(true);
    ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    messageRouter.route(immutableMessage);
    Thread.sleep(1000);
    verify(middlewareMessagingStubFactoryMock).create(eq(channelAddress));
    verify(messagingStubMock).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
}
Also used : SuccessAction(io.joynr.messaging.SuccessAction) FailureAction(io.joynr.messaging.FailureAction) ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 7 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testRetryWithoutMaxRetryCount.

@Test
public void testRetryWithoutMaxRetryCount() throws Exception {
    ImmutableMessage immutableMessage = retryRoutingWith1msDelay(messageRouter, 200);
    verify(messagingStubMock, Mockito.atLeast(10)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
}
Also used : SuccessAction(io.joynr.messaging.SuccessAction) FailureAction(io.joynr.messaging.FailureAction) ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 8 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testScheduleExpiredMessageFails.

@Test
public void testScheduleExpiredMessageFails() throws Exception {
    joynrMessage.setTtlMs(ExpiryDate.fromRelativeTtl(1).getValue());
    joynrMessage.setTtlAbsolute(true);
    ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    Thread.sleep(5);
    try {
        messageRouter.route(immutableMessage);
    } catch (JoynrMessageNotSentException e) {
        verify(middlewareMessagingStubFactoryMock, never()).create(any(ChannelAddress.class));
        return;
    }
    fail("scheduling an expired message should throw");
}
Also used : ImmutableMessage(joynr.ImmutableMessage) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) Test(org.junit.Test)

Example 9 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testDelayWithExponentialBackoffLimit.

@Test
public void testDelayWithExponentialBackoffLimit() throws Exception {
    final long routingDuration = 1000;
    final long sendMsgRetryIntervalMs = 50;
    final long maxDelayMs = 70;
    final long toleranceMs = 20;
    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);
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_MAX_DELAY_WITH_EXPONENTIAL_BACKOFF_MS)).toInstance(maxDelayMs);
        }
    });
    Injector injector3 = Guice.createInjector(testMaxRetryCountModule);
    MessageRouter messageRouterWithMaxExponentialBackoff = injector3.getInstance(MessageRouter.class);
    Mockito.doAnswer(new Answer<Object>() {

        private long previousInvocationTimeMs = -1;

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (previousInvocationTimeMs == -1) {
                // firstRun
                previousInvocationTimeMs = System.currentTimeMillis();
            } else {
                long now = System.currentTimeMillis();
                assertThat(now - previousInvocationTimeMs, lessThan(maxDelayMs + toleranceMs));
                previousInvocationTimeMs = now;
            }
            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();
    messageRouterWithMaxExponentialBackoff.route(immutableMessage);
    Thread.sleep(routingDuration);
    // test that the mock is called multiple times which means that
    // the assert inside is multiple times correct
    verify(messagingStubMock, Mockito.atLeast(10)).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 10 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testScheduleMessage.

public void testScheduleMessage() throws InterruptedException {
    final DelayQueue<DelayableImmutableMessage> messageQueue = spy(new DelayQueue<DelayableImmutableMessage>());
    Module messageQueueSpyModule = Modules.override(testModule).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(new TypeLiteral<DelayQueue<DelayableImmutableMessage>>() {
            }).toInstance(messageQueue);
        }
    });
    messageRouter = Guice.createInjector(messageQueueSpyModule).getInstance(MessageRouter.class);
    Address address = new Address();
    ImmutableMessage message = Mockito.mock(ImmutableMessage.class);
    when(message.isTtlAbsolute()).thenReturn(true);
    when(message.getTtlMs()).thenReturn(ExpiryDate.fromRelativeTtl(60000L).getValue());
    when(message.getRecipient()).thenReturn("to");
    when(routingTable.get("to")).thenReturn(address);
    messageRouter.route(message);
    ArgumentCaptor<DelayableImmutableMessage> passedDelaybleMessage = ArgumentCaptor.forClass(DelayableImmutableMessage.class);
    verify(messageQueue, atLeast(1)).put(passedDelaybleMessage.capture());
    assertEquals(message, passedDelaybleMessage.getAllValues().get(0).getMessage());
    assertTrue(passedDelaybleMessage.getAllValues().get(0).getDelay(TimeUnit.MILLISECONDS) <= 0);
}
Also used : Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CcMessageRouter(io.joynr.messaging.routing.CcMessageRouter) ImmutableMessage(joynr.ImmutableMessage) Module(com.google.inject.Module) ClusterControllerRuntimeModule(io.joynr.runtime.ClusterControllerRuntimeModule) TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) AbstractModule(com.google.inject.AbstractModule) DelayQueue(java.util.concurrent.DelayQueue) AbstractModule(com.google.inject.AbstractModule)

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