@Test public void backupResponse_whenInvocationMissing_thenNothingBadHappens() { Invocation invocation = newInvocation(); long callId = invocation.op.getCallId(); invocationRegistry.register(invocation); invocationRegistry.deregister(invocation); invocationRegistry.notifyBackupComplete(callId); assertNull(invocationRegistry.get(callId)); }
@Test public void normalResponse_whenInvocationMissing_thenNothingBadHappens() { Invocation invocation = newInvocation(); invocationRegistry.register(invocation); long callId = invocation.op.getCallId(); invocationRegistry.deregister(invocation); invocationRegistry.notifyNormalResponse(callId, "foo", 0, null); assertNull(invocationRegistry.get(callId)); }
@Test public void timeoutResponse() { Invocation invocation = newInvocation(); invocationRegistry.register(invocation); long callId = invocation.op.getCallId(); invocationRegistry.notifyCallTimeout(callId, null); assertNull(invocation.future.join()); assertNull(invocationRegistry.get(callId)); }
@Test public void errorResponse_whenInvocationMissing_thenNothingBadHappens() { Invocation invocation = newInvocation(); invocationRegistry.register(invocation); long callId = invocation.op.getCallId(); invocationRegistry.deregister(invocation); invocationRegistry.notifyErrorResponse(callId, new ExpectedRuntimeException(), null); assertNull(invocationRegistry.get(callId)); }
@Test public void normalResponse_whenInvocationExist() { Invocation invocation = newInvocation(); invocationRegistry.register(invocation); long callId = invocation.op.getCallId(); Object value = "foo"; invocationRegistry.notifyNormalResponse(callId, value, 0, null); assertEquals(value, invocation.future.join()); assertNull(invocationRegistry.get(callId)); }
@Test public void normalResponse_whenBackupMissing_thenEventuallySuccess() throws Exception { Invocation invocation = newInvocation(); invocationRegistry.register(invocation); long callId = invocation.op.getCallId(); String result = "foo"; invocationRegistry.notifyNormalResponse(callId, result, 1, null); assertEquals(result, invocation.future.get(1, TimeUnit.MINUTES)); assertNull(invocationRegistry.get(callId)); }
@Test public void errorResponse_whenInvocationExists() { Invocation invocation = newInvocation(); invocationRegistry.register(invocation); long callId = invocation.op.getCallId(); invocationRegistry.notifyErrorResponse(callId, new ExpectedRuntimeException(), null); try { invocation.future.join(); fail(); } catch (ExpectedRuntimeException expected) { } assertNull(invocationRegistry.get(callId)); }
public void shutdown() { logger.finest("Shutting down OperationService"); invocationRegistry.shutdown(); invocationMonitor.shutdown(); operationExecutor.shutdown(); asyncResponseHandler.shutdown(); slowOperationDetector.shutdown(); try { invocationMonitor.awaitTermination(TERMINATION_TIMEOUT_MILLIS); } catch (InterruptedException e) { // restore the interrupt. // todo: we need a better mechanism for dealing with interruption and waiting for termination Thread.currentThread().interrupt(); EmptyStatement.ignore(e); } }
public void reset() { invocationRegistry.reset(); }
@Override public int getRemoteOperationsCount() { return invocationRegistry.size(); }
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) { registry.register(method, args); return nextInvocationRegistrarIfPossible(method.getReturnType()); }