use of joynr.Request in project joynr by bmwcarit.
the class ConnectorTest method syncMethodCallCallsRequestReplyManagerWithCorrectArguments.
@Test
public void syncMethodCallCallsRequestReplyManagerWithCorrectArguments() {
ConnectorInvocationHandler connector = createConnector();
assertNotNull(connector);
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
try {
Method method = TestSyncInterface.class.getDeclaredMethod("methodWithoutParameters");
when(requestReplyManager.sendSyncRequest(any(String.class), any(DiscoveryEntryWithMetaInfo.class), any(Request.class), any(SynchronizedReplyCaller.class), any(MessagingQos.class))).thenReturn(new Reply());
connector.executeSyncMethod(method, new Object[] {});
verify(requestReplyManager, times(1)).sendSyncRequest(eq(fromParticipantId), eq(toDiscoveryEntry), requestCaptor.capture(), isA(SynchronizedReplyCaller.class), eq(qosSettings));
Request actualRequest = requestCaptor.getValue();
Request expectedRequest = new Request(method.getName(), new Object[] {}, new String[] {}, actualRequest.getRequestReplyId());
assertEquals(expectedRequest, actualRequest);
} catch (Exception e) {
fail("Unexpected exception from sync method call: " + e);
}
}
use of joynr.Request in project joynr by bmwcarit.
the class ConnectorTest method asyncMethodCallCallsRequestReplyManagerWithCorrectArguments.
@Test
public void asyncMethodCallCallsRequestReplyManagerWithCorrectArguments() {
ConnectorInvocationHandler connector = createConnector();
assertNotNull(connector);
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
Future<Void> future = new Future<Void>();
try {
Method method = TestAsyncInterface.class.getDeclaredMethod("methodWithoutParameters", Callback.class);
connector.executeAsyncMethod(method, new Object[] { voidCallback }, future);
verify(requestReplyManager, times(1)).sendRequest(eq(fromParticipantId), eq(toDiscoveryEntry), requestCaptor.capture(), eq(qosSettings));
Request actualRequest = requestCaptor.getValue();
Request expectedRequest = new Request(method.getName(), new Object[] {}, new String[] {}, actualRequest.getRequestReplyId());
assertEquals(expectedRequest, actualRequest);
} catch (Exception e) {
fail("Unexpected exception from async method call: " + e);
}
}
use of joynr.Request 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 joynr.Request in project joynr by bmwcarit.
the class MutableMessageFactoryTest method testMessageProcessorUsed.
@Test
public void testMessageProcessorUsed() {
MutableMessage message = mutableMessageFactory.createRequest("from", "to", new Request("name", new Object[0], new Class[0]), new MessagingQos());
assertNotNull(message.getCustomHeaders().get("test"));
assertEquals("test", message.getCustomHeaders().get("test"));
}
use of joynr.Request 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());
}
Aggregations