use of io.joynr.messaging.mqtt.MqttClientIdProvider in project joynr by bmwcarit.
the class DefaultJoynrRuntimeFactoryTest method createFixture.
@SuppressWarnings("unchecked")
private void createFixture(Instance<Properties> joynrProperties, Instance<String> joynrLocalDomain) throws Exception {
Instance<RawMessagingPreprocessor> rawMessageProcessor = mock(Instance.class);
when(rawMessageProcessor.get()).thenReturn(new NoOpRawMessagingPreprocessor());
BeanManager beanManager = mock(BeanManager.class);
Bean<JoynrMessageProcessor> bean = mock(Bean.class);
when(bean.create(Mockito.any())).thenReturn(new JoynrMessageProcessorTest());
when(beanManager.getBeans(Mockito.<Type>eq(JoynrMessageProcessor.class), Mockito.<Annotation>any())).thenReturn(Sets.newHashSet(bean));
final String mqttClientId = "someTestMqttClientId";
MqttClientIdProvider mqttClientIdProvider = mock(MqttClientIdProvider.class);
when(mqttClientIdProvider.getClientId()).thenReturn(mqttClientId);
Instance<MqttClientIdProvider> mqttClientIdProviderInstance = mock(Instance.class);
when(mqttClientIdProviderInstance.get()).thenReturn(mqttClientIdProvider);
fixture = new DefaultJoynrRuntimeFactory(joynrProperties, joynrLocalDomain, rawMessageProcessor, mqttClientIdProviderInstance, beanManager, mock(StatusReceiver.class), mock(MqttStatusReceiver.class));
scheduledExecutorService = mock(ScheduledExecutorService.class);
Field executorField = DefaultJoynrRuntimeFactory.class.getDeclaredField("scheduledExecutorService");
executorField.setAccessible(true);
executorField.set(fixture, scheduledExecutorService);
}
use of io.joynr.messaging.mqtt.MqttClientIdProvider 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);
}
Aggregations