@Test
  public void testSimpleLocking() throws Exception {
    ByteBufferCache cache = new ByteBufferCache(40, 80, true);
    ByteBufferDirectory dir = new ByteBufferDirectory(cache);

    Lock lock = dir.makeLock("testlock");

    assertThat(lock.isLocked(), equalTo(false));
    assertThat(lock.obtain(200), equalTo(true));
    assertThat(lock.isLocked(), equalTo(true));
    try {
      assertThat(lock.obtain(200), equalTo(false));
      assertThat("lock should be thrown", false, equalTo(true));
    } catch (LockObtainFailedException e) {
      // all is well
    }
    lock.release();
    assertThat(lock.isLocked(), equalTo(false));
    dir.close();
    cache.close();
  }
 private boolean assertEnvIsLocked() {
   if (!closed.get() && locks != null) {
     for (Lock lock : locks) {
       try {
         assert lock.isLocked() : "Lock: " + lock + "is not locked";
       } catch (IOException e) {
         logger.warn("lock assertion failed", e);
         return false;
       }
     }
   }
   return true;
 }