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