@Test
  public void testTake() throws Exception {
    final RegionNormalizerWorkQueue<Integer> queue = new RegionNormalizerWorkQueue<>();
    final ConcurrentLinkedQueue<Long> takeTimes = new ConcurrentLinkedQueue<>();
    final AtomicBoolean finished = new AtomicBoolean(false);
    final int count = 5;
    final Runnable consumer = () -> {
      try {
        while (!finished.get()) {
          queue.take();
          takeTimes.add(System.nanoTime());
        }
      } catch (InterruptedException e) {
        fail("interrupted.");
      }
    };

    CompletableFuture<Void> worker = CompletableFuture.runAsync(consumer);
    final long testStart = System.nanoTime();
    for (int i = 0; i < count; i++) {
      Thread.sleep(10);
      queue.put(i);
    }
    // should have timing information for 5 calls to take.
    Waiter.waitFor(HBaseConfiguration.create(), 1000, () -> count == takeTimes.size());
    // set finished = true and pipe one more value in case the thread needs an extra pass through
    // the loop.
    finished.set(true);
    queue.put(1);
    worker.get(1, TimeUnit.SECONDS);

    final Iterator<Long> times = takeTimes.iterator();
    for (int i = 0; i < count; i++) {
      assertThat(
        "Observations collected in takeTimes should increase by roughly 10ms every interval",
        times.next(), greaterThan(testStart + TimeUnit.MILLISECONDS.toNanos(i * 10)));
    }
  }
Test that calls to {@link RegionNormalizerWorkQueue#take()} block the requesting thread. The
producing thread places new entries onto the queue following a known schedule. The consuming
thread collects a time measurement between calls to {@code take}. Finally, the test makes
coarse-grained assertions of the consumer's observations based on the producer's schedule.
hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorkQueue.java