@Ignore("Test requires available CPU resources for background threads")
  @Test
  public void testWithoutContention() throws Exception {
    final long execTime = 100;

    MetricsSource ms  = ReadWriteLockMetrics.createLockMetricsSource("test1");
    ReadWriteLock rwl = create(new ReentrantReadWriteLock(), ms);
    LockHolder    lhR = new LockHolder(rwl.readLock(), execTime);

    // wait for the thread to do its locks and waits (for 100ms)
    lhR.join();

    // get the reported metrics
    MockMetricsCollector tmc = new MockMetricsCollector();
    ms.getMetrics(tmc, true);

    List<MockMetricsCollector.MockRecord> result = tmc.getRecords();
    assertEquals("Unexpected amount of metrics", 1, result.size());
    MockMetricsCollector.MockRecord rec = result.get(0);

    // verify label and context (context is hard coded)
    assertEquals("Invalid record label", "test1", rec.getLabel());
    assertEquals("Invalid record context", "Locking", rec.getContext());

    // we expect around exectome / thread loop time executions
    assertWithTolerance("Unexpected count of lock executions (reader)",
        execTime / LockHolder.LOCK_HOLD_TIME,  lhR.getLockCount());
    assertEquals("Counting the locks failed",
                 lhR.getLockCount(), rec.getMetrics().get(ReadLockCount));

    // sanity check in read lock metrics
    assertNotEquals("Local thread should have lock time", lhR.getLockSum(), 0);
    assertNotEquals("Accounted lock time zero",
                    rec.getMetrics().get(ReadLockWaitTimeTotal), 0);
    assertTrue("Local measurement larger (overhead)",
               rec.getMetrics().get(ReadLockWaitTimeTotal).longValue()
                                    < lhR.getLockSum());

    assertNotEquals("Local thread should have max lock time",
                    lhR.getLockMax(), 0);
    assertNotEquals("Accounted lock max time zero",
                    rec.getMetrics().get(ReadLockWaitTimeMax), 0);

    assertTrue("Local max larger (overhead)",
               rec.getMetrics().get(ReadLockWaitTimeMax).longValue()
                                    < lhR.getLockMax());

    assertTrue("Max greater or equal to average lock time",
               (rec.getMetrics().get(ReadLockWaitTimeTotal).longValue()
                / rec.getMetrics().get(ReadLockCount).longValue())
                  <= rec.getMetrics().get(ReadLockWaitTimeMax).longValue());

    assertTrue("Lock time less than 1% (no contention)",
               rec.getMetrics().get(ReadLockWaitTimeTotal).longValue()
               < toNano(execTime / 100L));

    // sanity check on write lock metrics (should be all zero)
    assertEquals("No writer lock activity expected (total)",
                 rec.getMetrics().get(WriteLockWaitTimeTotal), 0L);
    assertEquals("No writer lock activity expected (max)",
                 rec.getMetrics().get(WriteLockWaitTimeMax), 0L);
    assertEquals("No writer lock activity expected (count)",
                 rec.getMetrics().get(WriteLockCount), 0L);
  }
Runs a simple test where a thread is running in a loop, getting read locks w/o having to
deal with any contention. The test shows that the locks are received rather quick and tha
all metrics for write locks remain zero.
llap-common/src/test/org/apache/hadoop/hive/llap/metrics/TestReadWriteLockMetrics.java