use of org.jowidgets.invocation.client.api.IInvocationClient in project jo-client-platform by jo-source.
the class InvocationIntegrationTest method testCancelAfterMessageInvocation.
@Test
public void testCancelAfterMessageInvocation() {
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 clientCancelService = client.getCancelService();
// invoke methods on client
clientMethod.invoke(invocationId, invocationParameter);
Mockito.verify(serverMethodMock, Mockito.never()).invoke(invocationId, invocationParameter);
messaging.getMessageReceiverBroker().dispatchMessages();
Mockito.verify(serverMethodMock, Mockito.times(1)).invoke(invocationId, invocationParameter);
clientCancelService.canceled(invocationId);
Mockito.verify(serverCancelService, Mockito.never()).canceled(invocationId);
messaging.getMessageReceiverBroker().dispatchMessages();
Mockito.verify(serverCancelService, Mockito.times(1)).canceled(invocationId);
assertNoLogErrorOrWarning();
}
use of org.jowidgets.invocation.client.api.IInvocationClient 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.client.api.IInvocationClient 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