Search in sources :

Example 1 with MessagingQos

use of io.joynr.messaging.MessagingQos 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);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MulticastPublication(joynr.MulticastPublication) MutableMessage(joynr.MutableMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 2 with MessagingQos

use of io.joynr.messaging.MessagingQos 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);
}
Also used : Semaphore(java.util.concurrent.Semaphore) Mockito.anyString(org.mockito.Mockito.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) MutableMessage(joynr.MutableMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) Reply(joynr.Reply) Test(org.junit.Test)

Example 3 with MessagingQos

use of io.joynr.messaging.MessagingQos 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 MessagingQos

use of io.joynr.messaging.MessagingQos in project joynr by bmwcarit.

the class DefaultJoynrRuntimeFactoryTest method testJoynrMessageProcessorUsed.

@Test
public void testJoynrMessageProcessorUsed() throws Exception {
    createFixture();
    Injector injector = fixture.getInjector();
    MutableMessageFactory messageFactory = injector.getInstance(MutableMessageFactory.class);
    MutableMessage request = messageFactory.createRequest("from", "to", new Request("name", new Object[0], new Class[0]), new MessagingQos());
    assertEquals("test", request.getCustomHeaders().get("test"));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MutableMessageFactory(io.joynr.dispatching.MutableMessageFactory) MutableMessage(joynr.MutableMessage) Injector(com.google.inject.Injector) Request(joynr.Request) Test(org.junit.Test)

Example 5 with MessagingQos

use of io.joynr.messaging.MessagingQos in project joynr by bmwcarit.

the class GpsConsumerApplication method run.

@Override
public void run() {
    DiscoveryQos discoveryQos = new DiscoveryQos();
    // As soon as the arbitration QoS is set on the proxy builder, discovery of suitable providers
    // is triggered. If the discovery process does not find matching providers within the
    // arbitration timeout duration it will be terminated and you will get an arbitration exception.
    discoveryQos.setDiscoveryTimeoutMs(10000);
    // Provider entries in the global capabilities directory are cached locally. Discovery will
    // consider entries in this cache valid if they are younger as the max age of cached
    // providers as defined in the QoS. All valid entries will be processed by the arbitrator when searching
    // for and arbitrating the "best" matching provider.
    // NOTE: Valid cache entries might prevent triggering a lookup in the global capabilities
    // directory. Therefore, not all providers registered with the global capabilities
    // directory might be taken into account during arbitration.
    discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
    // The discovery process outputs a list of matching providers. The arbitration strategy then
    // chooses one or more of them to be used by the proxy.
    discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
    // The provider will maintain at least a minimum interval idle time in milliseconds between
    // successive notifications, even if on-change notifications are enabled and the value changes more
    // often. This prevents the consumer from being flooded by updated values. The filtering happens on
    // the provider's side, thus also preventing excessive network traffic.
    int minInterval_ms = 0;
    // The provider will send notifications every maximum interval in milliseconds, even if the value didn't
    // change. It will send notifications more often if on-change notifications are enabled,
    // the value changes more often, and the minimum interval QoS does not prevent it. The maximum interval
    // can thus be seen as a sort of heart beat.
    int maxInterval_ms = 10000;
    // The provider will send notifications until the end date is reached. The consumer will not receive any
    // notifications (neither value notifications nor missed publication notifications) after
    // this date.
    long validity_ms = 60000;
    // If no notification was received within the last alert interval, a missed publication
    // notification will be raised.
    int alertAfterInterval_ms = 20000;
    // Notification messages will be sent with this time-to-live. If a notification message can not be
    // delivered within its TTL, it will be deleted from the system.
    // NOTE: If a notification message is not delivered due to an expired TTL, it might raise a
    // missed publication notification (depending on the value of the alert interval QoS).
    int publicationTtl_ms = 5000;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos();
    subscriptionQos.setMinIntervalMs(minInterval_ms).setMaxIntervalMs(maxInterval_ms).setValidityMs(validity_ms);
    subscriptionQos.setAlertAfterIntervalMs(alertAfterInterval_ms).setPublicationTtlMs(publicationTtl_ms);
    ProxyBuilder<GpsProxy> proxyBuilder = runtime.getProxyBuilder(providerDomain, GpsProxy.class);
    // reading an attribute value
    gpsProxy = proxyBuilder.setMessagingQos(new MessagingQos()).setDiscoveryQos(discoveryQos).build();
    subscriptionFuture = gpsProxy.subscribeToLocation(new AttributeSubscriptionAdapter<GpsLocation>() {

        @Override
        public void onReceive(GpsLocation value) {
            LOG.info(PRINT_BORDER + "SUBSCRIPTION: location: " + value + PRINT_BORDER);
        }

        @Override
        public void onError(JoynrRuntimeException error) {
            LOG.info(PRINT_BORDER + "SUBSCRIPTION: location, publication missed " + PRINT_BORDER);
        }
    }, subscriptionQos);
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) GpsProxy(joynr.vehicle.GpsProxy) AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) GpsLocation(joynr.types.Localisation.GpsLocation) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Aggregations

MessagingQos (io.joynr.messaging.MessagingQos)55 Test (org.junit.Test)23 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)19 MutableMessage (joynr.MutableMessage)15 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)11 Matchers.anyString (org.mockito.Matchers.anyString)11 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)9 SubscriptionRequest (joynr.SubscriptionRequest)9 Before (org.junit.Before)8 Properties (java.util.Properties)6 ImmutableMessage (joynr.ImmutableMessage)6 Request (joynr.Request)6 Injector (com.google.inject.Injector)5 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)5 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)5 joynr.tests.testProxy (joynr.tests.testProxy)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 AbstractModule (com.google.inject.AbstractModule)4 IOException (java.io.IOException)4 OneWayRequest (joynr.OneWayRequest)4