use of io.joynr.messaging.JoynrMessageProcessor in project joynr by bmwcarit.
the class DefaultJoynrRuntimeFactoryTest method testJoynrMessageProcessorAdded.
@Test
public void testJoynrMessageProcessorAdded() throws Exception {
createFixture();
Injector injector = fixture.getInjector();
List<Binding<JoynrMessageProcessor>> bindings = injector.findBindingsByType(new TypeLiteral<JoynrMessageProcessor>() {
});
assertEquals(1, bindings.size());
}
use of io.joynr.messaging.JoynrMessageProcessor in project joynr by bmwcarit.
the class MqttMessagingSkeletonTest method testJoynrMessageProcessorIsCalled.
@Test
public void testJoynrMessageProcessorIsCalled() throws Exception {
JoynrMessageProcessor processorMock = mock(JoynrMessageProcessor.class);
when(processorMock.processIncoming(any(ImmutableMessage.class))).then(returnsFirstArg());
subject = new MqttMessagingSkeleton(ownAddress, maxIncomingMqttRequests, messageRouter, mqttClientFactory, mqttTopicPrefixProvider, new NoOpRawMessagingPreprocessor(), Sets.newHashSet(processorMock), mqttStatusReceiver);
ImmutableMessage rqMessage = createTestRequestMessage();
subject.transmit(rqMessage.getSerializedMessage(), failIfCalledAction);
ArgumentCaptor<ImmutableMessage> argCaptor = ArgumentCaptor.forClass(ImmutableMessage.class);
verify(processorMock).processIncoming(argCaptor.capture());
Assert.assertArrayEquals(rqMessage.getSerializedMessage(), argCaptor.getValue().getSerializedMessage());
}
use of io.joynr.messaging.JoynrMessageProcessor 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.messaging.JoynrMessageProcessor 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.messaging.JoynrMessageProcessor in project joynr by bmwcarit.
the class WebSocketMessagingSkeleton method transmit.
@Override
public void transmit(byte[] serializedMessage, FailureAction failureAction) {
try {
ImmutableMessage message = new ImmutableMessage(serializedMessage);
LOG.debug("<<< INCOMING <<< {}", message);
if (messageProcessors != null) {
for (JoynrMessageProcessor processor : messageProcessors) {
message = processor.processIncoming(message);
}
}
if (Message.VALUE_MESSAGE_TYPE_MULTICAST.equals(message.getType()) && this.isMainTransport()) {
message.setReceivedFromGlobal(true);
}
messageRouter.route(message);
} catch (Exception error) {
failureAction.execute(error);
}
}
Aggregations