예제 #1
0
  @Test(expected = RequestAbortedException.class)
  public void testExecAbortedPriorToConnectionLease() throws Exception {
    final HttpRoute route = new HttpRoute(target);
    final HttpClientContext context = new HttpClientContext();
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));

    Mockito.when(managedConn.isOpen()).thenReturn(Boolean.FALSE);
    Mockito.when(execAware.isAborted()).thenReturn(Boolean.TRUE);
    try {
      mainClientExec.execute(route, request, context, execAware);
    } catch (final IOException ex) {
      Mockito.verify(connRequest, Mockito.times(1)).cancel();
      throw ex;
    }
  }
예제 #2
0
  @Test(expected = RequestAbortedException.class)
  public void testExecAbortedPriorToRequestExecution() throws Exception {
    final HttpRoute route = new HttpRoute(target);
    final HttpClientContext context = new HttpClientContext();
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));

    Mockito.when(managedConn.isOpen()).thenReturn(Boolean.FALSE);
    Mockito.when(execAware.isAborted()).thenReturn(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE);
    try {
      mainClientExec.execute(route, request, context, execAware);
    } catch (final IOException ex) {
      Mockito.verify(connRequest, Mockito.times(1)).get(0, TimeUnit.MILLISECONDS);
      Mockito.verify(connManager, Mockito.times(1)).connect(managedConn, route, 0, context);
      Mockito.verify(requestExecutor, Mockito.never())
          .execute(
              Mockito.same(request),
              Mockito.<HttpClientConnection>any(),
              Mockito.<HttpClientContext>any());
      throw ex;
    }
  }