@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));
  }
示例#8
0
 @Override
 public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) {
   registry.register(method, args);
   return nextInvocationRegistrarIfPossible(method.getReturnType());
 }