Search in sources :

Example 1 with Address

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));
}
Also used : FailureAction(io.joynr.messaging.FailureAction) Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) SuccessAction(io.joynr.messaging.SuccessAction) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 2 with Address

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

Example 3 with Address

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);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) IMessagingSkeleton(io.joynr.messaging.IMessagingSkeleton) Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CcMessageRouter(io.joynr.messaging.routing.CcMessageRouter) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) StatusReceiver(io.joynr.statusmetrics.StatusReceiver) MessagingQos(io.joynr.messaging.MessagingQos) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ShutdownNotifier(io.joynr.runtime.ShutdownNotifier) Request(joynr.Request) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) AbstractModule(com.google.inject.AbstractModule) AbstractMiddlewareMessagingStubFactory(io.joynr.messaging.AbstractMiddlewareMessagingStubFactory) AccessController(io.joynr.accesscontrol.AccessController) MutableMessageFactory(io.joynr.dispatching.MutableMessageFactory) IMessagingStub(io.joynr.messaging.IMessagingStub) Before(org.junit.Before)

Example 4 with Address

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);
        }
    }
}
Also used : Address(joynr.system.RoutingTypes.Address) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry)

Example 5 with Address

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));
}
Also used : AbstractMiddlewareMessagingStubFactory(io.joynr.messaging.AbstractMiddlewareMessagingStubFactory) JeeHttpMessagingModule(io.joynr.jeeintegration.messaging.JeeHttpMessagingModule) IMessagingSkeleton(io.joynr.messaging.IMessagingSkeleton) Address(joynr.system.RoutingTypes.Address) TypeLiteral(com.google.inject.TypeLiteral) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) JeeMqttMessageSendingModule(io.joynr.jeeintegration.messaging.JeeMqttMessageSendingModule) IMessagingStub(io.joynr.messaging.IMessagingStub) HttpBridgeEndpointRegistryClientModule(io.joynr.jeeintegration.httpbridge.HttpBridgeEndpointRegistryClientModule)

Aggregations

Address (joynr.system.RoutingTypes.Address)43 Test (org.junit.Test)21 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)15 MqttAddress (joynr.system.RoutingTypes.MqttAddress)13 ProviderQos (joynr.types.ProviderQos)9 Version (joynr.types.Version)9 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 TypeLiteral (com.google.inject.TypeLiteral)5 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)5 AbstractModule (com.google.inject.AbstractModule)4 HashSet (java.util.HashSet)4 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)4 DiscoveryException (io.joynr.exceptions.DiscoveryException)3 AbstractMiddlewareMessagingStubFactory (io.joynr.messaging.AbstractMiddlewareMessagingStubFactory)3 IMessagingSkeleton (io.joynr.messaging.IMessagingSkeleton)3 IMessagingStub (io.joynr.messaging.IMessagingStub)3 CcMessageRouter (io.joynr.messaging.routing.CcMessageRouter)3 ArrayList (java.util.ArrayList)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2