@Test
public void shouldFetchOnlyOnceWhenMultipleThreadsTryToGetKeys() throws Exception {

  final KeysDownloader instance = newInstanceForTests();
  httpResponseBuilder = new HttpResponseBuilder().setContent("keys");
  List<FutureTask<String>> tasks = new ArrayList<>();
  for (int i = 0; i < 10; i++) {
    tasks.add(
        new FutureTask<String>(
            new Callable<String>() {
              @Override
              public String call() throws Exception {
                return instance.download();
              }
            }));
  }
  // Force the HTTP responses to be delayed until the latch goes down to 0.
  delayHttpResponseLatch = new CountDownLatch(1);
  // Execute the all fetches in parallel.
  for (FutureTask<String> task : tasks) {
    executor.execute(task);
  }
  // Releasing the response.
  delayHttpResponseLatch.countDown();
  for (FutureTask<String> task : tasks) {
    assertEquals("keys", task.get(5, TimeUnit.SECONDS));
  }
  // Should only have hit the network once.
  assertEquals(1, httpTransportGetCount.get());
}