### Question:
FutureRequestExecutionService implements Closeable { public <T> FutureTask<T> execute( final ClassicHttpRequest request, final HttpContext context, final HttpClientResponseHandler<T> HttpClientResponseHandler) { return execute(request, context, HttpClientResponseHandler, null); } FutureRequestExecutionService(
            final HttpClient httpclient,
            final ExecutorService executorService); FutureTask<T> execute(
            final ClassicHttpRequest request,
            final HttpContext context,
            final HttpClientResponseHandler<T> HttpClientResponseHandler); FutureTask<T> execute(
            final ClassicHttpRequest request,
            final HttpContext context,
            final HttpClientResponseHandler<T> HttpClientResponseHandler,
            final FutureCallback<T> callback); FutureRequestExecutionMetrics metrics(); @Override void close();  }### Answer:
@Test public void shouldExecuteSingleCall() throws InterruptedException, ExecutionException { final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute( new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler()); Assert.assertTrue("request should have returned OK", task.get().booleanValue()); }
@Test public void shouldCancel() throws InterruptedException, ExecutionException { thrown.expect(CoreMatchers.anyOf( CoreMatchers.instanceOf(CancellationException.class), CoreMatchers.instanceOf(ExecutionException.class))); final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute( new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler()); task.cancel(true); task.get(); }
@Test public void shouldTimeout() throws InterruptedException, ExecutionException, TimeoutException { thrown.expect(TimeoutException.class); blocked.set(true); final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute( new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler()); task.get(10, TimeUnit.MILLISECONDS); }
@Test public void shouldExecuteMultipleCalls() throws Exception { final int reqNo = 100; final Queue<Future<Boolean>> tasks = new LinkedList<>(); for(int i = 0; i < reqNo; i++) { final Future<Boolean> task = httpAsyncClientWithFuture.execute( new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler()); tasks.add(task); } for (final Future<Boolean> task : tasks) { final Boolean b = task.get(); Assert.assertNotNull(b); Assert.assertTrue("request should have returned OK", b.booleanValue()); } }
@Test public void shouldExecuteMultipleCallsAndCallback() throws Exception { final int reqNo = 100; final Queue<Future<Boolean>> tasks = new LinkedList<>(); final CountDownLatch latch = new CountDownLatch(reqNo); for(int i = 0; i < reqNo; i++) { final Future<Boolean> task = httpAsyncClientWithFuture.execute( new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler(), new CountingCallback(latch)); tasks.add(task); } Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); for (final Future<Boolean> task : tasks) { final Boolean b = task.get(); Assert.assertNotNull(b); Assert.assertTrue("request should have returned OK", b.booleanValue()); } }