use of io.joynr.messaging.AbstractMiddlewareMessagingStubFactory in project joynr by bmwcarit.
the class CcMessageRouterTest method setUp.
@Before
public void setUp() throws Exception {
when(middlewareMessagingStubFactoryMock.create(any(ChannelAddress.class))).thenReturn(messagingStubMock);
AbstractModule mockModule = new AbstractModule() {
private Long msgRetryIntervalMs = 10L;
// message runnables + cleanup thread
private int numberOfThreads = maximumParallelSends + 1;
private long routingTableGracePeriodMs = 30000;
private long routingTableCleanupIntervalMs = 60000;
@Override
protected void configure() {
bind(MessageRouter.class).to(CcMessageRouter.class);
bind(RoutingTable.class).toInstance(routingTable);
bind(AddressManager.class).toInstance(addressManager);
bind(MulticastReceiverRegistry.class).toInstance(multicastReceiverRegistry);
bind(ShutdownNotifier.class).toInstance(shutdownNotifier);
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_SEND_MSG_RETRY_INTERVAL_MS)).toInstance(msgRetryIntervalMs);
bind(Integer.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_MESSAGING_MAXIMUM_PARALLEL_SENDS)).toInstance(maximumParallelSends);
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_ROUTING_TABLE_GRACE_PERIOD_MS)).toInstance(routingTableGracePeriodMs);
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_ROUTING_TABLE_CLEANUP_INTERVAL_MS)).toInstance(routingTableCleanupIntervalMs);
bindConstant().annotatedWith(Names.named(ClusterControllerRuntimeModule.PROPERTY_ACCESSCONTROL_ENABLE)).to(false);
bind(AccessController.class).toInstance(Mockito.mock(AccessController.class));
bind(StatusReceiver.class).toInstance(statusReceiver);
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(ChannelAddress.class).toInstance(middlewareMessagingStubFactoryMock);
MapBinder<Class<? extends Address>, IMessagingSkeleton> messagingSkeletonFactory;
messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<IMessagingSkeleton>() {
}, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
messagingSkeletonFactory.addBinding(ChannelAddress.class).toInstance(messagingSkeletonMock);
Multibinder.newSetBinder(binder(), new TypeLiteral<MulticastAddressCalculator>() {
});
}
@Provides
@Named(MessageRouter.SCHEDULEDTHREADPOOL)
ScheduledExecutorService provideMessageSchedulerThreadPoolExecutor() {
ThreadFactory schedulerNamedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.MessageScheduler-scheduler-%d").build();
ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(numberOfThreads, schedulerNamedThreadFactory);
scheduler.setKeepAliveTime(100, TimeUnit.SECONDS);
scheduler.allowCoreThreadTimeOut(true);
return scheduler;
}
};
testModule = Modules.override(mockModule).with(new TestGlobalAddressModule());
Injector injector = Guice.createInjector(testModule);
messageRouter = injector.getInstance(MessageRouter.class);
ObjectMapper objectMapper = new ObjectMapper();
messageFactory = new MutableMessageFactory(objectMapper, new HashSet<JoynrMessageProcessor>());
// toParticipantId is globally visible
final boolean isGloballyVisible = true;
final long expiryDateMs = Long.MAX_VALUE;
final boolean isSticky = true;
final boolean allowUpdate = false;
routingTable.put(toParticipantId, channelAddress, isGloballyVisible, expiryDateMs, isSticky, allowUpdate);
Request request = new Request("noMethod", new Object[] {}, new String[] {}, "requestReplyId");
joynrMessage = messageFactory.createRequest(fromParticipantId, toParticipantId, request, new MessagingQos());
joynrMessage.setLocalMessage(true);
}
use of io.joynr.messaging.AbstractMiddlewareMessagingStubFactory in project joynr by bmwcarit.
the class JeeJoynrIntegrationModule method configure.
@Override
protected void configure() {
bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(scheduledExecutorService);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JoynrInjectionConstants.JOYNR_SCHEDULER_CLEANUP)).toInstance(scheduledExecutorService);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(LocalCapabilitiesDirectory.JOYNR_SCHEDULER_CAPABILITIES_FRESHNESS)).toInstance(scheduledExecutorService);
bind(ExecutorService.class).toInstance(scheduledExecutorService);
MapBinder<Class<? extends Address>, IMessagingSkeleton> messagingSkeletonFactory;
messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<IMessagingSkeleton>() {
}, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
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));
Multibinder.newSetBinder(binder(), JoynrMessageProcessor.class);
install(new JeeHttpMessagingModule(messagingSkeletonFactory, messagingStubFactory));
install(new HttpBridgeEndpointRegistryClientModule());
install(new JeeMqttMessageSendingModule(messagingSkeletonFactory, messagingStubFactory));
}
use of io.joynr.messaging.AbstractMiddlewareMessagingStubFactory 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);
}
Aggregations