Search in sources :

Example 1 with JoynrPropertiesModule

use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.

the class TtlUpliftTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException {
    fromParticipantId = "sender";
    toParticipantId = "receiver";
    cleanupScheduler = new ScheduledThreadPoolExecutor(1);
    cleanupSchedulerSpy = Mockito.spy(cleanupScheduler);
    Module defaultModule = Modules.override(new JoynrPropertiesModule(new Properties())).with(new JsonMessageSerializerModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(NO_TTL_UPLIFT);
            requestStaticInjection(Request.class);
            Multibinder<JoynrMessageProcessor> joynrMessageProcessorMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
            joynrMessageProcessorMultibinder.addBinding().toInstance(new JoynrMessageProcessor() {

                @Override
                public MutableMessage processOutgoing(MutableMessage joynrMessage) {
                    return joynrMessage;
                }

                @Override
                public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
                    return joynrMessage;
                }
            });
            bind(PublicationManager.class).to(PublicationManagerImpl.class);
            bind(SubscriptionRequestStorage.class).toInstance(Mockito.mock(FileSubscriptionRequestStorage.class));
            bind(AttributePollInterpreter.class).toInstance(attributePollInterpreter);
            bind(Dispatcher.class).toInstance(dispatcher);
            bind(ProviderDirectory.class).toInstance(providerDirectory);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(JoynrInjectionConstants.JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupSchedulerSpy);
        }
    });
    Injector injector = Guice.createInjector(defaultModule);
    messageFactory = injector.getInstance(MutableMessageFactory.class);
    Module ttlUpliftModule = Modules.override(defaultModule).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(TTL_UPLIFT_MS);
        }
    });
    Injector injectorWithTtlUplift = Guice.createInjector(ttlUpliftModule);
    messageFactoryWithTtlUplift = injectorWithTtlUplift.getInstance(MutableMessageFactory.class);
    requestCaller = new RequestCallerFactory().create(provider);
    when(providerContainer.getProviderProxy()).thenReturn(requestCaller.getProxy());
    when(providerContainer.getSubscriptionPublisher()).thenReturn(subscriptionPublisher);
    Deferred<String> valueToPublishDeferred = new Deferred<String>();
    valueToPublishDeferred.resolve(valueToPublish);
    Promise<Deferred<String>> valueToPublishPromise = new Promise<Deferred<String>>(valueToPublishDeferred);
    doReturn(valueToPublishPromise).when(attributePollInterpreter).execute(any(ProviderContainer.class), any(Method.class));
    Module subcriptionUpliftModule = Modules.override(defaultModule).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(SUBSCRIPTION_UPLIFT_MS);
        }
    });
    Injector injectorWithPublicationUplift = Guice.createInjector(subcriptionUpliftModule);
    publicationManager = (PublicationManagerImpl) injector.getInstance(PublicationManager.class);
    publicationManagerWithTtlUplift = (PublicationManagerImpl) injectorWithPublicationUplift.getInstance(PublicationManager.class);
    payload = "payload";
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
    messagingQos = new MessagingQos(TTL);
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Deferred(io.joynr.provider.Deferred) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Properties(java.util.Properties) MessagingQos(io.joynr.messaging.MessagingQos) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) Injector(com.google.inject.Injector) PublicationManagerImpl(io.joynr.dispatching.subscription.PublicationManagerImpl) ProviderContainer(io.joynr.provider.ProviderContainer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) Request(joynr.Request) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) Promise(io.joynr.provider.Promise) ImmutableMessage(joynr.ImmutableMessage) Matchers.anyLong(org.mockito.Matchers.anyLong) Module(com.google.inject.Module) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 2 with JoynrPropertiesModule

use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.

the class ParticipantIdStorageTest method setUp.

@Before
public void setUp() {
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(GlobalDiscoveryEntry.class).annotatedWith(Names.named(MessagingPropertyKeys.CAPABILITIES_DIRECTORY_DISCOVERY_ENTRY)).toInstance(capabilitiesDirectoryEntry);
            bind(GlobalDiscoveryEntry.class).annotatedWith(Names.named(MessagingPropertyKeys.DOMAIN_ACCESS_CONTROLLER_DISCOVERY_ENTRY)).toInstance(domainAccessControllerEntry);
            bind(ParticipantIdStorage.class).to(PropertiesFileParticipantIdStorage.class);
        }
    }, new JoynrPropertiesModule(new Properties()));
    storage = injector.getInstance(ParticipantIdStorage.class);
}
Also used : Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Properties(java.util.Properties) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 3 with JoynrPropertiesModule

use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.

the class MqttPahoClientTest method mqttClientTestResubscriptionWithCleanRestartEnabled.

@Test
public void mqttClientTestResubscriptionWithCleanRestartEnabled() throws Exception {
    properties.put(MqttModule.PROPERTY_KEY_MQTT_BROKER_URI, "tcp://localhost:1883");
    injector = Guice.createInjector(new MqttPahoModule(), new JoynrPropertiesModule(properties), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MessageRouter.class).toInstance(mockMessageRouter);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(Executors.newScheduledThreadPool(10));
            bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
        }
    });
    ownTopic = injector.getInstance((Key.get(MqttAddress.class, Names.named(MqttModule.PROPERTY_MQTT_GLOBAL_ADDRESS))));
    ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
    MqttClientIdProvider mqttClientIdProvider = injector.getInstance(MqttClientIdProvider.class);
    String clientId = mqttClientIdProvider.getClientId();
    String brokerUri = "tcp://localhost:1883";
    int reconnectSleepMs = 100;
    int keepAliveTimerSec = 60;
    int connectionTimeoutSec = 60;
    int timeToWaitMs = -1;
    int maxMsgsInflight = 100;
    int maxMsgSizeBytes = 0;
    boolean cleanSession = true;
    MqttClient mqttClient = new MqttClient(brokerUri, clientId, new MemoryPersistence(), scheduledExecutorService);
    joynrMqttClient = new MqttPahoClient(mqttClient, reconnectSleepMs, keepAliveTimerSec, connectionTimeoutSec, timeToWaitMs, maxMsgsInflight, maxMsgSizeBytes, cleanSession, "", "", "", "", mock(MqttStatusReceiver.class));
    joynrMqttClient.start();
    joynrMqttClient.setMessageListener(mockReceiver);
    joynrMqttClient.subscribe(ownTopic.getTopic());
    // manually call disconnect and connectionLost
    mqttClient.disconnect(500);
    MqttException exeption = new MqttException(MqttException.REASON_CODE_CLIENT_TIMEOUT);
    MqttPahoClient mqttPahoClient = (MqttPahoClient) joynrMqttClient;
    mqttPahoClient.connectionLost(exeption);
    joynrMqttClientPublishAndVerifyReceivedMessage(serializedMessage);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MemoryPersistence(org.eclipse.paho.client.mqttv3.persist.MemoryPersistence) MessageRouter(io.joynr.messaging.routing.MessageRouter) MqttClientIdProvider(io.joynr.messaging.mqtt.MqttClientIdProvider) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) AbstractModule(com.google.inject.AbstractModule) JoynrMqttClient(io.joynr.messaging.mqtt.JoynrMqttClient) MqttClient(org.eclipse.paho.client.mqttv3.MqttClient) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) MqttException(org.eclipse.paho.client.mqttv3.MqttException) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Test(org.junit.Test)

Example 4 with JoynrPropertiesModule

use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.

the class MqttPahoClientTest method createMqttClientInternal.

private JoynrMqttClient createMqttClientInternal(final MqttStatusReceiver mqttStatusReceiver) {
    injector = Guice.createInjector(override(new MqttPahoModule()).with(new AbstractModule() {

        @Override
        protected void configure() {
            if (mqttStatusReceiver != null) {
                bind(MqttStatusReceiver.class).toInstance(mqttStatusReceiver);
            }
        }
    }), new JoynrPropertiesModule(properties), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MessageRouter.class).toInstance(mockMessageRouter);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(Executors.newScheduledThreadPool(10));
            bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
        }
    });
    // create a new Factory because the factory caches its client.
    mqttClientFactory = injector.getInstance(MqttClientFactory.class);
    JoynrMqttClient client = mqttClientFactory.create();
    client.setMessageListener(mockReceiver);
    return client;
}
Also used : JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) MessageRouter(io.joynr.messaging.routing.MessageRouter) MqttClientFactory(io.joynr.messaging.mqtt.MqttClientFactory) JoynrMqttClient(io.joynr.messaging.mqtt.JoynrMqttClient) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) AbstractModule(com.google.inject.AbstractModule)

Example 5 with JoynrPropertiesModule

use of io.joynr.common.JoynrPropertiesModule in project joynr by bmwcarit.

the class DefaultMqttClientIdProviderTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    Properties properties = PropertyLoader.loadProperties(MessagingPropertyKeys.DEFAULT_MESSAGING_PROPERTIES_FILE);
    Module testModule = Modules.override(new MqttPahoModule()).with(new AbstractModule() {

        @Override
        protected void configure() {
            Multibinder.newSetBinder(binder(), JoynrMessageProcessor.class);
            bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
            bind(MessageRouter.class).toInstance(mockMessageRouter);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(Executors.newScheduledThreadPool(10));
        }
    });
    properties.put(MessagingPropertyKeys.RECEIVERID, shortReceiverId);
    Injector injectorWithShortReceiverId = Guice.createInjector(testModule, new JoynrPropertiesModule(properties));
    clientIdProviderWithShortReceiverId = injectorWithShortReceiverId.getInstance(MqttClientIdProvider.class);
    properties.put(MessagingPropertyKeys.RECEIVERID, longReceiverId);
    Injector injectorWithLongReceiverId = Guice.createInjector(testModule, new JoynrPropertiesModule(properties));
    clientIdProviderWithLongReceiverId = injectorWithLongReceiverId.getInstance(MqttClientIdProvider.class);
    properties.put(MessagingPropertyKeys.RECEIVERID, standardReceiverId);
    Injector injectorWithoutClientIdPrefix = Guice.createInjector(testModule, new JoynrPropertiesModule(properties));
    clientIdProviderWithoutClientIdPrefix = injectorWithoutClientIdPrefix.getInstance(MqttClientIdProvider.class);
    properties.put(MqttModule.PROPERTY_KEY_MQTT_CLIENT_ID_PREFIX, clientIdPrefix);
    Injector injectorWithClientIdPrefix = Guice.createInjector(testModule, new JoynrPropertiesModule(properties));
    clientIdProviderWithClientIdPrefix = injectorWithClientIdPrefix.getInstance(MqttClientIdProvider.class);
}
Also used : NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Properties(java.util.Properties) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) Module(com.google.inject.Module) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) AbstractModule(com.google.inject.AbstractModule) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Aggregations

AbstractModule (com.google.inject.AbstractModule)13 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)13 Injector (com.google.inject.Injector)10 Properties (java.util.Properties)10 Before (org.junit.Before)10 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)6 TypeLiteral (com.google.inject.TypeLiteral)5 JsonMessageSerializerModule (io.joynr.messaging.JsonMessageSerializerModule)4 NoOpRawMessagingPreprocessor (io.joynr.messaging.NoOpRawMessagingPreprocessor)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Module (com.google.inject.Module)3 Singleton (com.google.inject.Singleton)3 MessagingQos (io.joynr.messaging.MessagingQos)3 Request (joynr.Request)3 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)3 RequestConfig (org.apache.http.client.config.RequestConfig)3 Multibinder (com.google.inject.multibindings.Multibinder)2 AtmosphereMessagingModule (io.joynr.messaging.AtmosphereMessagingModule)2 MessagingTestModule (io.joynr.messaging.MessagingTestModule)2 RawMessagingPreprocessor (io.joynr.messaging.RawMessagingPreprocessor)2