コード例 #1
0
  @Test
  public void testInactiveControlRetriedOnceAndSucceeds() throws InterruptedException {
    final WebTarget QUALIFY_TARGET = Mockito.mock(WebTarget.class);
    final WebTarget FOLLOW_TARGET = Mockito.mock(WebTarget.class);
    final Invocation.Builder QUALIFY_BUILDER = Mockito.mock(Invocation.Builder.class);
    final AsyncInvoker QUALIFY_ASYNC = Mockito.mock(AsyncInvoker.class);
    final Invocation.Builder FOLLOW_BUILDER = Mockito.mock(Invocation.Builder.class);
    final AsyncInvoker FOLLOW_ASYNC = Mockito.mock(AsyncInvoker.class);

    Mockito.when(QUALIFY_TARGET.request()).thenReturn(QUALIFY_BUILDER);
    Mockito.when(QUALIFY_BUILDER.async()).thenReturn(QUALIFY_ASYNC);
    Mockito.when(FOLLOW_TARGET.request()).thenReturn(FOLLOW_BUILDER);
    Mockito.when(FOLLOW_BUILDER.async()).thenReturn(FOLLOW_ASYNC);

    final ChannelMonitor MONITOR =
        new RetryingControlChannelMonitor(config(), QUALIFY_TARGET, FOLLOW_TARGET);
    final Future CAPTURE_FUTURE = Mockito.mock(Future.class);
    final DataUnitCounter COUNTER = Mockito.mock(DataUnitCounter.class);

    Mockito.when(COUNTER.getDataUnitCount()).thenReturn(0);

    final ControlChannelId id = new ControlChannelId(10, 20, 30, 40);
    final Identifiable capture = new FollowRequest(10d, 20d, 0, 1337d, id);

    assert MONITOR.monitor(capture, CAPTURE_FUTURE, COUNTER);
    assert MONITOR.contains(id);
    Mockito.verify(CAPTURE_FUTURE, Mockito.never()).cancel(Mockito.anyBoolean());

    Thread.sleep(1100);

    Mockito.verify(CAPTURE_FUTURE, Mockito.times(1)).cancel(Mockito.anyBoolean());
    assert MONITOR.contains(id);

    ArgumentCaptor<InvocationCallback> QUALIFY_CALLBACK =
        ArgumentCaptor.forClass(InvocationCallback.class);
    Mockito.verify(QUALIFY_ASYNC).post(Mockito.any(Entity.class), QUALIFY_CALLBACK.capture());

    ControlChannelQualities QUALITIES = Mockito.mock(ControlChannelQualities.class);
    Mockito.when(QUALITIES.getWacn()).thenReturn(id.getWacn());
    Mockito.when(QUALITIES.getSystemId()).thenReturn(id.getSystemId());
    Mockito.when(QUALITIES.getRfSubsystemId()).thenReturn(id.getRfSubsystemId());
    Mockito.when(QUALITIES.getSiteId()).thenReturn(id.getSiteId());

    QUALIFY_CALLBACK.getValue().completed(QUALITIES);

    assert !MONITOR.contains(id);
    Mockito.verify(FOLLOW_ASYNC, Mockito.times(1))
        .post(Mockito.any(Entity.class), Mockito.any(InvocationCallback.class));
  }
コード例 #2
0
 @Override
 public <T> Future<T> submit(InvocationCallback<T> callback) {
   return invBuilder.async().method(httpMethod, entity, callback);
 }
コード例 #3
0
 @Override
 public <T> Future<T> submit(Class<T> cls) {
   return invBuilder.async().method(httpMethod, entity, cls);
 }
コード例 #4
0
 @Override
 public <T> Future<T> submit(GenericType<T> type) {
   return invBuilder.async().method(httpMethod, entity, type);
 }
コード例 #5
0
 @Override
 public Future<Response> submit() {
   return invBuilder.async().method(httpMethod, entity);
 }