@Test
public void testReadLockEnabledByDefault()
    throws IOException, InterruptedException {

  final FsDatasetSpi ds = dataset;
  AtomicBoolean accessed = new AtomicBoolean(false);
  CountDownLatch latch = new CountDownLatch(1);
  CountDownLatch waiterLatch = new CountDownLatch(1);
  Thread holder = new Thread() {
    public void run() {
      try (AutoCloseableLock l = ds.acquireDatasetReadLock()) {
        latch.countDown();
        sleep(10000);
      } catch (Exception e) {
      }
    }
  };
  Thread waiter = new Thread() {
    public void run() {
      try (AutoCloseableLock l = ds.acquireDatasetReadLock()) {
        waiterLatch.countDown();
        accessed.getAndSet(true);
      } catch (Exception e) {
      }
    }
  };
  holder.start();
  latch.await();
  waiter.start();
  waiterLatch.await();
  // The holder thread is still holding the lock, but the waiter can still
  // run as the lock is a shared read lock.
  assertEquals(true, accessed.get());
  holder.interrupt();
  holder.join();
  waiter.join();
}