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));
}
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));
}
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");
}
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));
}
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);
}
Aggregations