use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testCancelBeforeMethodInvocation.
@Test
public void testCancelBeforeMethodInvocation() {
final String methodName = "Method";
final Integer invocationId = Integer.valueOf(0);
final String invocationParameter = "InvocationParameter";
// setup server
final ICancelService serverCancelService = Mockito.mock(ICancelService.class);
InvocationServerToolkit.getRegistry(BROKER_ID).register(serverCancelService);
final IMethod serverMethodMock = Mockito.mock(IMethod.class);
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethodMock);
// setup client
final IInvocationCallbackService clientInvocationCallback = Mockito.mock(IInvocationCallbackService.class);
InvocationClientToolkit.getRegistry(BROKER_ID).register(clientInvocationCallback);
final IInvocationClient client = InvocationClientToolkit.getClient(BROKER_ID);
final IMethod clientMethod = client.getMethod(methodName);
final ICancelService cancelService = client.getCancelService();
// invoke methods on client
clientMethod.invoke(invocationId, invocationParameter);
cancelService.canceled(invocationId);
Mockito.verify(serverMethodMock, Mockito.never()).invoke(invocationId, invocationParameter);
Mockito.verify(serverCancelService, Mockito.never()).canceled(invocationId);
messaging.getMessageReceiverBroker().dispatchMessages();
Mockito.verify(serverMethodMock, Mockito.times(1)).invoke(invocationId, invocationParameter);
Mockito.verify(serverCancelService, Mockito.times(1)).canceled(invocationId);
assertNoLogErrorOrWarning();
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationServiceClientImpl method getMethodService.
@Override
public <RES, INT_RES, REQ, RESP, PARAM> IMethodInvocationService<RES, INT_RES, REQ, RESP, PARAM> getMethodService(final String methodName, final long timeout) {
Assert.paramNotNull(methodName, "methodName");
return new IMethodInvocationService<RES, INT_RES, REQ, RESP, PARAM>() {
@Override
public void invoke(final IInvocationCallback<RES> invocationCallback, final IInterimResponseCallback<INT_RES> interimResponseCallback, final IInterimRequestCallback<REQ, RESP> interimRequestCallback, final PARAM parameter) {
final IMethod method = invocationClient.getMethod(methodName);
if (method == null) {
throw new IllegalArgumentException("No server method registered for method name '" + methodName + "'.");
} else {
final Object invocationId = invocationCallbackService.registerInvocation(invocationCallback, interimResponseCallback, interimRequestCallback, timeout, invocationClient);
method.invoke(invocationId, parameter);
}
}
};
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationClientImpl method getMethod.
@Override
public IMethod getMethod(final String methodName) {
return new IMethod() {
@Override
public void invoke(final Object invocationId, final Object parameter) {
final MethodInvocationMessage message = new MethodInvocationMessage(invocationId, methodName, parameter);
messageChannel.send(message, new ExceptionCallback(invocationClientServiceRegistry, invocationId));
}
};
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationServerServiceRegistryImpl method onMethodInvocation.
public void onMethodInvocation(final MethodInvocationMessage message) {
final IMethod method = methods.get(message.getMethodName());
method.invoke(message.getInvocationId(), message.getParameter());
}
use of org.jowidgets.invocation.common.api.IMethod in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testCancelExceptionAfterCancel.
@Test
public void testCancelExceptionAfterCancel() {
final String methodName = "Method";
final Integer invocationId = Integer.valueOf(0);
final String invocationParameter = "InvocationParameter";
final RuntimeException cancelException = new RuntimeException("Service was canceled");
final CountDownLatch cancelLatch = new CountDownLatch(1);
final CountDownLatch serverFinsihedLatch = new CountDownLatch(1);
// setup server
final ICancelService serverCancelService = Mockito.mock(ICancelService.class);
InvocationServerToolkit.getRegistry(BROKER_ID).register(serverCancelService);
final IInvocationCallbackService serverInvocationCallback = InvocationServerToolkit.getServer(BROKER_ID).getInvocationCallbackService();
final IMethod serverMethodMock = Mockito.mock(IMethod.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
// wait until service was canceled
cancelLatch.await();
// after service was canceled return a cancel exception
serverInvocationCallback.exeption(invocationId, cancelException);
return null;
}
}).when(serverMethodMock).invoke(Mockito.any(), Mockito.any());
InvocationServerToolkit.getRegistry(BROKER_ID).register(methodName, serverMethodMock);
// setup client
final IInvocationCallbackService clientInvocationCallback = Mockito.mock(IInvocationCallbackService.class);
InvocationClientToolkit.getRegistry(BROKER_ID).register(clientInvocationCallback);
final IInvocationClient client = InvocationClientToolkit.getClient(BROKER_ID);
final IMethod clientMethod = client.getMethod(methodName);
final ICancelService cancelService = client.getCancelService();
// invoke methods on client
clientMethod.invoke(invocationId, invocationParameter);
// dispatch method on server
final AtomicReference<JUnitLogger> serverMethodThreadLogger = new AtomicReference<JUnitLogger>();
new Thread(new Runnable() {
@Override
public void run() {
serverMethodThreadLogger.set(JUnitLoggerProvider.getGlobalLogger());
messaging.getMessageReceiverBroker().dispatchMessages();
serverFinsihedLatch.countDown();
}
}).start();
// invoke cancel on client
cancelService.canceled(invocationId);
// dispatch cancel message on server
final AtomicReference<JUnitLogger> serverCancelThreadLogger = new AtomicReference<JUnitLogger>();
new Thread(new Runnable() {
@Override
public void run() {
serverCancelThreadLogger.set(JUnitLoggerProvider.getGlobalLogger());
messaging.getMessageReceiverBroker().dispatchMessages();
cancelLatch.countDown();
}
}).start();
try {
serverFinsihedLatch.await();
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
messaging.getMessageChannelBroker().dispatchReturnedMessages();
Mockito.verify(serverCancelService, Mockito.times(1)).canceled(invocationId);
Mockito.verify(clientInvocationCallback, Mockito.never()).exeption(invocationId, cancelException);
Assert.assertFalse(serverMethodThreadLogger.get().hasMessage());
Assert.assertFalse(serverCancelThreadLogger.get().hasMessage());
assertNoLogErrorOrWarning();
}
Aggregations