@Test
  public void verifyOnCompleteWhenCancelled() throws Exception {
    DummyListenableFuture<String> future =
      new DummyListenableFuture<String>(false, service);

    final CountDownLatch latch = new CountDownLatch(1);
    future.addListener(new GenericCompletionListener() {
      @Override
      public void onComplete(Future future) throws Exception {
        assertTrue(future.isCancelled());
        latch.countDown();
      }
    });

    future.cancel(true);

    assertTrue(latch.await(1, TimeUnit.SECONDS));
  }
Use an unbounded thread pool for testing, which is very similar to
the one used in the {@link DefaultConnectionFactory}.
src/test/java/net/spy/memcached/internal/ListenableFutureTest.java