use of io.joynr.context.JoynrMessageScopeModule in project joynr by bmwcarit.
the class RequestReplyManagerTest method setUp.
@Before
public void setUp() throws NoSuchMethodException, SecurityException, JsonGenerationException, IOException {
requestCallerFactory = new RequestCallerFactory();
testOneWayRecipientParticipantId = "testOneWayRecipientParticipantId";
testOneWayRecipientDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
testOneWayRecipientDiscoveryEntry.setParticipantId(testOneWayRecipientParticipantId);
testOneWayRecipientDiscoveryEntries = Sets.newHashSet(testOneWayRecipientDiscoveryEntry);
testMessageResponderParticipantId = "testMessageResponderParticipantId";
testMessageResponderDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
testMessageResponderDiscoveryEntry.setParticipantId(testMessageResponderParticipantId);
testSenderParticipantId = "testSenderParticipantId";
testResponderUnregisteredParticipantId = "testResponderUnregisteredParticipantId";
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new JoynrMessageScopeModule());
bind(MessageSender.class).toInstance(messageSenderMock);
bind(MessageRouter.class).toInstance(messageRouterMock);
bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
requestStaticInjection(RpcUtils.class, Request.class, JoynrMessagingConnectorFactory.class);
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.Cleanup-%d").build();
ScheduledExecutorService cleanupExecutor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupExecutor);
Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
});
}
});
objectMapper = injector.getInstance(ObjectMapper.class);
objectMapper.registerSubtypes(Request.class, OneWayRequest.class);
requestReplyManager = injector.getInstance(RequestReplyManager.class);
providerDirectory = injector.getInstance(ProviderDirectory.class);
replyCallerDirectory = injector.getInstance(ReplyCallerDirectory.class);
requestReplyManager = injector.getInstance(RequestReplyManager.class);
// dispatcher.addListener(testOneWayRecipientParticipantId, testListener);
// jsonRequestString1 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
// + payload1 + "\"}}";
// jsonRequestString2 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
// + payload2 + "\"}}";
Object[] params1 = new Object[] { payload1 };
Object[] params2 = new Object[] { payload2 };
// MethodMetaInformation methodMetaInformation = new
// MethodMetaInformation(TestRequestCaller.class.getMethod("respond", new Class[]{ Object.class }));
Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
request1 = new Request(method.getName(), params1, method.getParameterTypes());
request2 = new Request(method.getName(), params2, method.getParameterTypes());
request3 = new Request("unknownMethodName", params2, method.getParameterTypes());
Method fireAndForgetMethod = TestOneWayRecipient.class.getMethod("fireAndForgetMethod", new Class[] { String.class });
oneWay1 = new OneWayRequest(fireAndForgetMethod.getName(), new Object[] { payload1 }, fireAndForgetMethod.getParameterTypes());
}
use of io.joynr.context.JoynrMessageScopeModule in project joynr by bmwcarit.
the class RpcStubbingTest method setUp.
@Before
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_PARAM_DEREF", justification = "NPE in test would fail test")
public void setUp() throws JoynrCommunicationException, JoynrSendBufferFullException, JsonGenerationException, JsonMappingException, IOException, JoynrMessageNotSentException {
Deferred<GpsLocation> deferredGpsLocation = new Deferred<GpsLocation>();
deferredGpsLocation.resolve(gpsValue);
when(testMock.returnsGpsLocation()).thenReturn(new Promise<Deferred<GpsLocation>>(deferredGpsLocation));
Deferred<List<GpsLocation>> deferredGpsLocationList = new Deferred<List<GpsLocation>>();
deferredGpsLocationList.resolve(gpsList);
when(testMock.returnsGpsLocationList()).thenReturn(new Promise<Deferred<List<GpsLocation>>>(deferredGpsLocationList));
DeferredVoid deferredVoid = new DeferredVoid();
deferredVoid.resolve();
when(testMock.noParamsNoReturnValue()).thenReturn(new Promise<DeferredVoid>(deferredVoid));
when(testMock.takesTwoSimpleParams(any(Integer.class), any(String.class))).thenReturn(new Promise<DeferredVoid>(deferredVoid));
fromParticipantId = UUID.randomUUID().toString();
toParticipantId = UUID.randomUUID().toString();
toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
// required to inject static members of JoynMessagingConnectorFactory
injector = Guice.createInjector(new JoynrPropertiesModule(PropertyLoader.loadProperties(MessagingPropertyKeys.DEFAULT_MESSAGING_PROPERTIES_FILE)), new JsonMessageSerializerModule(), new AbstractModule() {
@Override
protected void configure() {
requestStaticInjection(RpcUtils.class);
install(new JoynrMessageScopeModule());
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(InProcessAddress.class).to(InProcessMessagingStubFactory.class);
}
});
final RequestInterpreter requestInterpreter = injector.getInstance(RequestInterpreter.class);
final RequestCallerFactory requestCallerFactory = injector.getInstance(RequestCallerFactory.class);
when(requestReplyManager.sendSyncRequest(eq(fromParticipantId), eq(toDiscoveryEntry), any(Request.class), any(SynchronizedReplyCaller.class), eq(messagingQos))).thenAnswer(new Answer<Reply>() {
@Override
public Reply answer(InvocationOnMock invocation) throws Throwable {
RequestCaller requestCaller = requestCallerFactory.create(testMock);
Object[] args = invocation.getArguments();
Request request = null;
for (Object arg : args) {
if (arg instanceof Request) {
request = (Request) arg;
break;
}
}
final Future<Reply> future = new Future<Reply>();
ProviderCallback<Reply> callback = new ProviderCallback<Reply>() {
@Override
public void onSuccess(Reply result) {
future.onSuccess(result);
}
@Override
public void onFailure(JoynrException error) {
future.onFailure(error);
}
};
requestInterpreter.execute(callback, requestCaller, request);
return future.get();
}
});
JoynrMessagingConnectorFactory joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(requestReplyManager, replyCallerDirectory, subscriptionManager);
connector = joynrMessagingConnectorFactory.create(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), messagingQos);
}
use of io.joynr.context.JoynrMessageScopeModule in project joynr by bmwcarit.
the class AbstractRuntimeModule method configure.
@Override
protected void configure() {
requestStaticInjection(CapabilityUtils.class, RpcUtils.class, ArbitratorFactory.class, JoynrDelayMessageException.class, JoynrAppenderManagerFactory.class);
install(new JsonMessageSerializerModule());
install(new FactoryModuleBuilder().implement(ProxyInvocationHandler.class, ProxyInvocationHandlerImpl.class).build(ProxyInvocationHandlerFactory.class));
install(new JoynrMessageScopeModule());
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(InProcessAddress.class).to(InProcessMessagingStubFactory.class);
messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<IMessagingSkeleton>() {
}, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
messagingSkeletonFactory.addBinding(InProcessAddress.class).to(InProcessLibjoynrMessagingSkeleton.class);
// other address types must be added to the Multibinder to support global addressing. Created here to make
// sure the Set exists, even if empty.
Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() {
}, Names.named(GlobalAddressProvider.GLOBAL_ADDRESS_PROVIDER));
Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() {
}, Names.named(ReplyToAddressProvider.REPLY_TO_ADDRESS_PROVIDER));
multicastAddressCalculators = Multibinder.newSetBinder(binder(), new TypeLiteral<MulticastAddressCalculator>() {
});
bind(ProxyBuilderFactory.class).to(ProxyBuilderFactoryImpl.class);
bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
bind(SubscriptionManager.class).to(SubscriptionManagerImpl.class);
bind(PublicationManager.class).to(PublicationManagerImpl.class);
bind(Dispatcher.class).to(DispatcherImpl.class);
bind(LocalDiscoveryAggregator.class).in(Singleton.class);
bind(DiscoveryAsync.class).to(LocalDiscoveryAggregator.class);
bind(CapabilitiesRegistrar.class).to(CapabilitiesRegistrarImpl.class);
bind(ParticipantIdStorage.class).to(PropertiesFileParticipantIdStorage.class);
bind(SubscriptionRequestStorage.class).to(FileSubscriptionRequestStorage.class);
bind(MessagingSettings.class).to(ConfigurableMessagingSettings.class);
bind(RoutingTable.class).to(RoutingTableImpl.class).asEagerSingleton();
bind(MulticastReceiverRegistry.class).to(InMemoryMulticastReceiverRegistry.class).asEagerSingleton();
bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toProvider(DefaultScheduledExecutorServiceProvider.class);
bind(StatusReceiver.class).to(DefaultStatusReceiver.class);
install(new StaticCapabilitiesProvisioningModule());
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toProvider(DefaultScheduledExecutorServiceProvider.class);
Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
});
}
Aggregations