use of joynr.system.RoutingTypes.Address 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.system.RoutingTypes.Address 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);
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class CcMessageRouterTest method setUp.
@Before
public void setUp() throws Exception {
when(middlewareMessagingStubFactoryMock.create(any(ChannelAddress.class))).thenReturn(messagingStubMock);
AbstractModule mockModule = new AbstractModule() {
private Long msgRetryIntervalMs = 10L;
// message runnables + cleanup thread
private int numberOfThreads = maximumParallelSends + 1;
private long routingTableGracePeriodMs = 30000;
private long routingTableCleanupIntervalMs = 60000;
@Override
protected void configure() {
bind(MessageRouter.class).to(CcMessageRouter.class);
bind(RoutingTable.class).toInstance(routingTable);
bind(AddressManager.class).toInstance(addressManager);
bind(MulticastReceiverRegistry.class).toInstance(multicastReceiverRegistry);
bind(ShutdownNotifier.class).toInstance(shutdownNotifier);
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_SEND_MSG_RETRY_INTERVAL_MS)).toInstance(msgRetryIntervalMs);
bind(Integer.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_MESSAGING_MAXIMUM_PARALLEL_SENDS)).toInstance(maximumParallelSends);
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_ROUTING_TABLE_GRACE_PERIOD_MS)).toInstance(routingTableGracePeriodMs);
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_ROUTING_TABLE_CLEANUP_INTERVAL_MS)).toInstance(routingTableCleanupIntervalMs);
bindConstant().annotatedWith(Names.named(ClusterControllerRuntimeModule.PROPERTY_ACCESSCONTROL_ENABLE)).to(false);
bind(AccessController.class).toInstance(Mockito.mock(AccessController.class));
bind(StatusReceiver.class).toInstance(statusReceiver);
MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
}, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
messagingStubFactory.addBinding(ChannelAddress.class).toInstance(middlewareMessagingStubFactoryMock);
MapBinder<Class<? extends Address>, IMessagingSkeleton> messagingSkeletonFactory;
messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<IMessagingSkeleton>() {
}, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
messagingSkeletonFactory.addBinding(ChannelAddress.class).toInstance(messagingSkeletonMock);
Multibinder.newSetBinder(binder(), new TypeLiteral<MulticastAddressCalculator>() {
});
}
@Provides
@Named(MessageRouter.SCHEDULEDTHREADPOOL)
ScheduledExecutorService provideMessageSchedulerThreadPoolExecutor() {
ThreadFactory schedulerNamedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.MessageScheduler-scheduler-%d").build();
ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(numberOfThreads, schedulerNamedThreadFactory);
scheduler.setKeepAliveTime(100, TimeUnit.SECONDS);
scheduler.allowCoreThreadTimeOut(true);
return scheduler;
}
};
testModule = Modules.override(mockModule).with(new TestGlobalAddressModule());
Injector injector = Guice.createInjector(testModule);
messageRouter = injector.getInstance(MessageRouter.class);
ObjectMapper objectMapper = new ObjectMapper();
messageFactory = new MutableMessageFactory(objectMapper, new HashSet<JoynrMessageProcessor>());
// toParticipantId is globally visible
final boolean isGloballyVisible = true;
final long expiryDateMs = Long.MAX_VALUE;
final boolean isSticky = true;
final boolean allowUpdate = false;
routingTable.put(toParticipantId, channelAddress, isGloballyVisible, expiryDateMs, isSticky, allowUpdate);
Request request = new Request("noMethod", new Object[] {}, new String[] {}, "requestReplyId");
joynrMessage = messageFactory.createRequest(fromParticipantId, toParticipantId, request, new MessagingQos());
joynrMessage.setLocalMessage(true);
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method registerIncomingEndpoints.
private void registerIncomingEndpoints(Collection<GlobalDiscoveryEntry> caps) {
for (GlobalDiscoveryEntry ce : caps) {
// TODO when are entries purged from the messagingEndpointDirectory?
if (ce.getParticipantId() != null && ce.getAddress() != null) {
Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(ce);
final boolean isGloballyVisible = (ce.getQos().getScope() == ProviderScope.GLOBAL);
final boolean isSticky = false;
final long expiryDateMs = Long.MAX_VALUE;
// Always trust the discovery directory.
final boolean allowUpdate = true;
messageRouter.addNextHop(ce.getParticipantId(), address, isGloballyVisible, expiryDateMs, isSticky, allowUpdate);
}
}
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class JeeJoynrIntegrationModule method configure.
@Override
protected void configure() {
bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(scheduledExecutorService);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JoynrInjectionConstants.JOYNR_SCHEDULER_CLEANUP)).toInstance(scheduledExecutorService);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(LocalCapabilitiesDirectory.JOYNR_SCHEDULER_CAPABILITIES_FRESHNESS)).toInstance(scheduledExecutorService);
bind(ExecutorService.class).toInstance(scheduledExecutorService);
MapBinder<Class<? extends Address>, IMessagingSkeleton> messagingSkeletonFactory;
messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<IMessagingSkeleton>() {
}, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
}, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
Multibinder.newSetBinder(binder(), JoynrMessageProcessor.class);
install(new JeeHttpMessagingModule(messagingSkeletonFactory, messagingStubFactory));
install(new HttpBridgeEndpointRegistryClientModule());
install(new JeeMqttMessageSendingModule(messagingSkeletonFactory, messagingStubFactory));
}
Aggregations