@Test
  public void testWrap() throws Exception {
    Configuration testConf = new Configuration();
    MetricsSource ms = ReadWriteLockMetrics.createLockMetricsSource("testConf");

    // default = passthrough
    ReadWriteLock rwlDef =
        ReadWriteLockMetrics.wrap(testConf, new ReentrantReadWriteLock(), ms);
    assertTrue("Basic ReentrantReadWriteLock expected",
        rwlDef instanceof ReentrantReadWriteLock);
    assertFalse("Basic ReentrantReadWriteLock expected",
        rwlDef instanceof ReadWriteLockMetrics);

    // false = pass through
    HiveConf.setBoolVar(testConf,
        HiveConf.ConfVars.LLAP_COLLECT_LOCK_METRICS, false);
    ReadWriteLock rwlBasic =
        ReadWriteLockMetrics.wrap(testConf, new ReentrantReadWriteLock(), ms);
    assertTrue("Basic ReentrantReadWriteLock expected",
               rwlBasic instanceof ReentrantReadWriteLock);
    assertFalse("Basic ReentrantReadWriteLock expected",
               rwlBasic instanceof ReadWriteLockMetrics);

    // true = wrap
    HiveConf.setBoolVar(testConf,
                        HiveConf.ConfVars.LLAP_COLLECT_LOCK_METRICS, true);
    ReadWriteLock rwlWrap =
        ReadWriteLockMetrics.wrap(testConf, new ReentrantReadWriteLock(), ms);
    assertTrue("Wrapped lock expected",
               rwlWrap instanceof ReadWriteLockMetrics);

    // null = passthrough
    ReadWriteLock rwlNoConf =
        ReadWriteLockMetrics.wrap(null, new ReentrantReadWriteLock(), null);
    assertTrue("Basic ReentrantReadWriteLock expected",
               rwlNoConf instanceof ReentrantReadWriteLock);
    assertFalse("Basic ReentrantReadWriteLock expected",
                rwlNoConf instanceof ReadWriteLockMetrics);
  }
Testing the <code>wrap</code> function for different configuration
combinations.
llap-common/src/test/org/apache/hadoop/hive/llap/metrics/TestReadWriteLockMetrics.java