use of joynr.Reply in project joynr by bmwcarit.
the class CcMessageRouterTest method testNotRoutableReplyDropped.
@Test
public void testNotRoutableReplyDropped() throws Exception {
final Semaphore semaphore = new Semaphore(0);
final String unknownParticipantId = "unknown_participant_id";
final String requestReplyId = "some_request_reply_id";
final Reply reply = new Reply(requestReplyId, new JoynrRuntimeException("TestException"));
final MutableMessage mutableMessage = messageFactory.createReply(fromParticipantId, unknownParticipantId, reply, new MessagingQos());
final ImmutableMessage immutableMessage = mutableMessage.getImmutableMessage();
MessageProcessedListener mockMsgProcessedListener = Mockito.mock(MessageProcessedListener.class);
messageRouter.registerMessageProcessedListener(mockMsgProcessedListener);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
semaphore.release();
return null;
}
}).when(mockMsgProcessedListener).messageProcessed(anyString());
messageRouter.route(immutableMessage);
semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
verify(mockMsgProcessedListener).messageProcessed(immutableMessage.getId());
verifyNoMoreInteractions(messagingStubMock);
}
use of joynr.Reply in project joynr by bmwcarit.
the class JoynrMessagingConnectorInvocationHandler method executeSyncMethod.
@CheckForNull
@Override
public Object executeSyncMethod(Method method, Object[] args) throws ApplicationException {
// TODO does a method with 0 args pass in an empty args array, or null for args?
if (method == null) {
throw new IllegalArgumentException("Method cannot be null");
}
if (toDiscoveryEntries.size() > 1) {
throw new JoynrIllegalStateException("You can't execute sync methods for multiple participants.");
}
if (toDiscoveryEntries.isEmpty()) {
throw new JoynrIllegalStateException("You must have exactly one participant to be able to execute a sync method.");
}
MethodMetaInformation methodMetaInformation = JoynrMessagingConnectorFactory.ensureMethodMetaInformationPresent(method);
Request request = new Request(method.getName(), args, method.getParameterTypes());
Reply reply;
String requestReplyId = request.getRequestReplyId();
SynchronizedReplyCaller synchronizedReplyCaller = new SynchronizedReplyCaller(fromParticipantId, requestReplyId, request);
ExpiryDate expiryDate = DispatcherUtils.convertTtlToExpirationDate(qosSettings.getRoundTripTtl_ms());
replyCallerDirectory.addReplyCaller(requestReplyId, synchronizedReplyCaller, expiryDate);
reply = (Reply) requestReplyManager.sendSyncRequest(fromParticipantId, toDiscoveryEntries.iterator().next(), request, synchronizedReplyCaller, qosSettings);
if (reply.getError() == null) {
if (method.getReturnType().equals(void.class)) {
return null;
}
Object response = RpcUtils.reconstructReturnedObject(method, methodMetaInformation, reply.getResponse());
logger.debug("REQUEST returns successful: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), response);
return response;
} else if (reply.getError() instanceof ApplicationException) {
logger.debug("REQUEST returns error: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), reply.getError());
throw (ApplicationException) reply.getError();
} else {
logger.debug("REQUEST returns error: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), reply.getError());
throw (JoynrRuntimeException) reply.getError();
}
}
use of joynr.Reply 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.Reply in project joynr by bmwcarit.
the class ProxyTest method createProxyAndCallSyncMethodSuccess.
@Test
public void createProxyAndCallSyncMethodSuccess() throws Exception {
String requestReplyId = "createProxyAndCallSyncMethod_requestReplyId";
Mockito.when(requestReplyManager.sendSyncRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<SynchronizedReplyCaller>any(), Mockito.<MessagingQos>any())).thenReturn(new Reply(requestReplyId, "Answer"));
ProxyBuilder<TestInterface> proxyBuilder = getProxyBuilder(TestInterface.class);
TestInterface proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
String result = proxy.method1();
Assert.assertEquals("Answer", result);
}
use of joynr.Reply in project joynr by bmwcarit.
the class SerializationTest method serializeReplyWithProviderRuntimenException.
@Test
public void serializeReplyWithProviderRuntimenException() throws IOException {
ProviderRuntimeException error = new ProviderRuntimeException("detail message: ProviderRuntimeException");
Reply reply = new Reply(UUID.randomUUID().toString(), error);
String writeValueAsString = objectMapper.writeValueAsString(reply);
System.out.println(writeValueAsString);
Reply receivedReply = objectMapper.readValue(writeValueAsString, Reply.class);
Assert.assertEquals(reply, receivedReply);
}
Aggregations