use of io.joynr.dispatching.rpc.ReplyCaller in project joynr by bmwcarit.
the class RequestReplyManagerImpl method handleReply.
@Override
public void handleReply(final Reply reply) {
final ReplyCaller callBack = replyCallerDirectory.remove(reply.getRequestReplyId());
if (callBack == null) {
logger.warn("No reply caller found for id: " + reply.getRequestReplyId());
return;
}
callBack.messageCallBack(reply);
}
use of io.joynr.dispatching.rpc.ReplyCaller in project joynr by bmwcarit.
the class ProxyTest method createProxyAndCallAsyncMethodFail.
@Test
public void createProxyAndCallAsyncMethodFail() throws Exception {
// Expect this exception to be passed back to the callback onFailure and thrown in the future
final JoynrCommunicationException expectedException = new JoynrCommunicationException();
// final JoynCommunicationException expectedException = null;
TestInterface proxy = getTestInterfaceProxy();
// when joynrMessageSender1.sendRequest is called, get the replyCaller from the mock dispatcher and call
// messageCallback on it.
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws JsonParseException, JsonMappingException, IOException {
// capture the replyCaller passed into the dispatcher for calling later
ArgumentCaptor<ReplyCaller> replyCallerCaptor = ArgumentCaptor.forClass(ReplyCaller.class);
verify(replyCallerDirectory).addReplyCaller(anyString(), replyCallerCaptor.capture(), any(ExpiryDate.class));
// pass the exception to the replyCaller
replyCallerCaptor.getValue().error(expectedException);
return null;
}
}).when(requestReplyManager).sendRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<MessagingQos>any());
boolean exceptionThrown = false;
String reply = "";
final Future<String> future = proxy.asyncMethod(callback);
try {
// the test usually takes only 200 ms, so if we wait 1 sec, something has gone wrong
reply = future.get(1000);
} catch (JoynrCommunicationException e) {
exceptionThrown = true;
}
Assert.assertTrue("exception must be thrown from get", exceptionThrown);
verify(callback).onFailure(expectedException);
verifyNoMoreInteractions(callback);
Assert.assertEquals(RequestStatusCode.ERROR, future.getStatus().getCode());
Assert.assertEquals("", reply);
}
use of io.joynr.dispatching.rpc.ReplyCaller in project joynr by bmwcarit.
the class RequestReplyManagerTest method requestReplyMessagesRemoveCallBackByTtl.
@Test
public void requestReplyMessagesRemoveCallBackByTtl() throws Exception {
TestProvider testResponder = new TestProvider(1);
ExpiryDate ttlReplyCaller = ExpiryDate.fromRelativeTtl(1000L);
final ReplyCaller replyCaller = mock(ReplyCaller.class);
replyCallerDirectory.addReplyCaller(request1.getRequestReplyId(), replyCaller, ttlReplyCaller);
Thread.sleep(ttlReplyCaller.getRelativeTtl() + 100);
requestReplyManager.handleReply(new Reply(request1.getRequestReplyId(), testResponder.getSentPayloadFor(request1)));
verify(replyCaller, never()).messageCallBack(any(Reply.class));
}
use of io.joynr.dispatching.rpc.ReplyCaller in project joynr by bmwcarit.
the class ProxyTest method createProxyAndCallAsyncMethodSuccess.
@Test
public void createProxyAndCallAsyncMethodSuccess() throws Exception {
TestInterface proxy = getTestInterfaceProxy();
// when joynrMessageSender1.sendRequest is called, get the replyCaller from the mock dispatcher and call
// messageCallback on it.
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws JsonParseException, JsonMappingException, IOException {
// capture the replyCaller passed into the dispatcher for calling later
ArgumentCaptor<ReplyCaller> replyCallerCaptor = ArgumentCaptor.forClass(ReplyCaller.class);
verify(replyCallerDirectory).addReplyCaller(anyString(), replyCallerCaptor.capture(), Mockito.any(ExpiryDate.class));
String requestReplyId = "createProxyAndCallAsyncMethodSuccess_requestReplyId";
// pass the response to the replyCaller
replyCallerCaptor.getValue().messageCallBack(new Reply(requestReplyId, new TextNode(asyncReplyText)));
return null;
}
}).when(requestReplyManager).sendRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<MessagingQos>any());
final Future<String> future = proxy.asyncMethod(callback);
// the test usually takes only 200 ms, so if we wait 1 sec, something has gone wrong
String reply = future.get(1000);
verify(callback).resolve(asyncReplyText);
Assert.assertEquals(RequestStatusCode.OK, future.getStatus().getCode());
Assert.assertEquals(asyncReplyText, reply);
}
use of io.joynr.dispatching.rpc.ReplyCaller in project joynr by bmwcarit.
the class ProxyTest method createProxyAndCallAsyncMethodFailWithApplicationError.
@SuppressWarnings({ "unchecked" })
@Test
public void createProxyAndCallAsyncMethodFailWithApplicationError() throws Exception {
final ApplicationException expected = new ApplicationException(ApplicationErrors.ERROR_VALUE_3, "TEST: createProxyAndCallAsyncMethodFailWithApplicationError");
TestInterface proxy = getTestInterfaceProxy();
// when joynrMessageSender1.sendRequest is called, get the replyCaller from the mock dispatcher and call
// messageCallback on it.
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws JsonParseException, JsonMappingException, IOException {
// capture the replyCaller passed into the dispatcher for calling later
ArgumentCaptor<ReplyCaller> replyCallerCaptor = ArgumentCaptor.forClass(ReplyCaller.class);
verify(replyCallerDirectory).addReplyCaller(anyString(), replyCallerCaptor.capture(), any(ExpiryDate.class));
String requestReplyId = "createProxyAndCallAsyncMethodSuccess_requestReplyId";
// pass the response to the replyCaller
replyCallerCaptor.getValue().messageCallBack(new Reply(requestReplyId, expected));
return null;
}
}).when(requestReplyManager).sendRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<MessagingQos>any());
CallbackWithModeledError<String, Enum<?>> callbackWithApplicationException = Mockito.mock(CallbackWithModeledError.class);
final Future<String> future = proxy.asyncMethodWithApplicationError(callbackWithApplicationException);
// the test usually takes only 200 ms, so if we wait 1 sec, something has gone wrong
try {
future.get(1000);
Assert.fail("Should throw ApplicationException");
} catch (ApplicationException e) {
Assert.assertEquals(expected, e);
}
verify(callbackWithApplicationException).onFailure(expected.getError());
Assert.assertEquals(RequestStatusCode.ERROR, future.getStatus().getCode());
}
Aggregations