@Test
  public void testEntityLockTimeout() throws Exception {
    final long workerSleepTime = 200; // in ms
    Abortable abortable = Mockito.mock(Abortable.class);
    EntityLock lock = admin.namespaceLock("namespace", "description", abortable);
    lock.setTestingSleepTime(workerSleepTime);

    when(master.requestLock(any(), any()))
      .thenReturn(LockResponse.newBuilder().setProcId(procId).build());
    // Acquires the lock, but then it times out (since we don't call unlock() on it).
    when(master.lockHeartbeat(any(), any())).thenReturn(LOCKED_RESPONSE, UNLOCKED_RESPONSE);

    lock.requestLock();
    lock.await();
    assertTrue(lock.isLocked());
    // Should get unlocked in next heartbeat i.e. after workerSleepTime. Wait 10x time to be sure.
    assertTrue(waitLockTimeOut(lock, 10 * workerSleepTime));

    // Works' run() returns, there is a small gap that the thread is still alive(os
    // has not declare it is dead yet), so remove the following assertion.
    // assertFalse(lock.getWorker().isAlive());
    verify(abortable, times(1)).abort(any(), eq(null));
  }
Test that abort is called when lock times out.
hbase-server/src/test/java/org/apache/hadoop/hbase/client/locking/TestEntityLocks.java