use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class CcMessageRouterTest method testFailedTransmitDoesNotLeadToThreadStarvation.
@Test(timeout = 3000)
public void testFailedTransmitDoesNotLeadToThreadStarvation() throws Exception {
final int MESSAGE_LOAD = 10;
ImmutableMessage failingMessage = mock(ImmutableMessage.class);
when(failingMessage.isTtlAbsolute()).thenReturn(true);
when(failingMessage.getTtlMs()).thenReturn(ExpiryDate.fromRelativeTtl(1000L).getValue());
when(failingMessage.getRecipient()).thenReturn("to");
when(routingTable.get("to")).thenReturn(channelAddress);
Set<Address> addressSet = new HashSet<>();
addressSet.add(channelAddress);
Mockito.doReturn(addressSet).when(addressManager).getAddresses(failingMessage);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertEquals(invocation.getArguments().length, 3);
FailureAction failureAction = (FailureAction) invocation.getArguments()[2];
failureAction.execute(new Exception("Some error"));
return null;
}
}).when(messagingStubMock).transmit(eq(failingMessage), any(SuccessAction.class), any(FailureAction.class));
for (int i = 0; i < MESSAGE_LOAD; i++) {
messageRouter.route(failingMessage);
}
Thread.sleep(2000);
verify(messagingStubMock, atLeast(MESSAGE_LOAD * 3)).transmit(eq(failingMessage), any(SuccessAction.class), any(FailureAction.class));
ImmutableMessage anotherMessage = mock(ImmutableMessage.class);
when(anotherMessage.isTtlAbsolute()).thenReturn(true);
when(anotherMessage.getTtlMs()).thenReturn(ExpiryDate.fromRelativeTtl(1000L).getValue());
when(anotherMessage.getRecipient()).thenReturn("to");
Mockito.doReturn(addressSet).when(addressManager).getAddresses(anotherMessage);
final Semaphore semaphore = new Semaphore(0);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertEquals(invocation.getArguments().length, 3);
SuccessAction successAction = (SuccessAction) invocation.getArguments()[1];
successAction.execute();
semaphore.release();
return null;
}
}).when(messagingStubMock).transmit(eq(anotherMessage), any(SuccessAction.class), any(FailureAction.class));
messageRouter.route(anotherMessage);
assertTrue(semaphore.tryAcquire(100, TimeUnit.MILLISECONDS));
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class CcMessageRouterTest method testMulticastMessageIsDroppedIfNoAddressIsFound.
@Test
public void testMulticastMessageIsDroppedIfNoAddressIsFound() throws Exception {
final Semaphore semaphore = new Semaphore(0);
final MulticastPublication multicastPublication = new MulticastPublication(new JoynrRuntimeException("Test Exception"), "multicastId");
final MutableMessage mutableMessage = messageFactory.createMulticast("fromParticipantId", multicastPublication, new MessagingQos());
final ImmutableMessage immutableMessage = mutableMessage.getImmutableMessage();
MessageProcessedListener mockMsgProcessedListener = Mockito.mock(MessageProcessedListener.class);
messageRouter.registerMessageProcessedListener(mockMsgProcessedListener);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
semaphore.release();
return null;
}
}).when(mockMsgProcessedListener).messageProcessed(anyString());
messageRouter.route(immutableMessage);
semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
verify(mockMsgProcessedListener).messageProcessed(immutableMessage.getId());
verifyNoMoreInteractions(messagingStubMock);
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class CcMessageRouterTest method testMessageProcessedListenerCalledOnSuccess.
@Test
public void testMessageProcessedListenerCalledOnSuccess() throws Exception {
final Semaphore semaphore = new Semaphore(0);
joynrMessage.setTtlMs(ExpiryDate.fromRelativeTtl(100000000).getValue());
joynrMessage.setTtlAbsolute(true);
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(any(ImmutableMessage.class), any(SuccessAction.class), any(FailureAction.class));
messageRouter.route(immutableMessage);
semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
verify(mockMessageProcessedListener).messageProcessed(eq(immutableMessage.getId()));
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class CcMessageRouterTest method testNotRoutableReplyDropped.
@Test
public void testNotRoutableReplyDropped() throws Exception {
final Semaphore semaphore = new Semaphore(0);
final String unknownParticipantId = "unknown_participant_id";
final String requestReplyId = "some_request_reply_id";
final Reply reply = new Reply(requestReplyId, new JoynrRuntimeException("TestException"));
final MutableMessage mutableMessage = messageFactory.createReply(fromParticipantId, unknownParticipantId, reply, new MessagingQos());
final ImmutableMessage immutableMessage = mutableMessage.getImmutableMessage();
MessageProcessedListener mockMsgProcessedListener = Mockito.mock(MessageProcessedListener.class);
messageRouter.registerMessageProcessedListener(mockMsgProcessedListener);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
semaphore.release();
return null;
}
}).when(mockMsgProcessedListener).messageProcessed(anyString());
messageRouter.route(immutableMessage);
semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
verify(mockMsgProcessedListener).messageProcessed(immutableMessage.getId());
verifyNoMoreInteractions(messagingStubMock);
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class CcMessageRouterTest method testRetryForNoParticipantFound.
@Test
public void testRetryForNoParticipantFound() throws Exception {
joynrMessage.setTtlMs(ExpiryDate.fromRelativeTtl(100000).getValue());
joynrMessage.setTtlAbsolute(true);
joynrMessage.setRecipient("I don't exist");
ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
messageRouter.route(immutableMessage);
Thread.sleep(100);
verify(routingTable, atLeast(2)).containsKey("I don't exist");
verify(addressManager, atLeast(2)).getAddresses(immutableMessage);
}
Aggregations