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