@Test
  public void testHeartbeatException() throws Exception {
    final long workerSleepTime = 100; // 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());
    when(master.lockHeartbeat(any(), any())).thenReturn(LOCKED_RESPONSE)
      .thenThrow(new ServiceException("Failed heartbeat!"));

    lock.requestLock();
    lock.await();
    assertTrue(waitLockTimeOut(lock, 100 * workerSleepTime));
    while (lock.getWorker().isAlive()) {
      TimeUnit.MILLISECONDS.sleep(100);
    }
    verify(abortable, times(1)).abort(any(), isA(HBaseIOException.class));
    assertFalse(lock.getWorker().isAlive());
  }
Test that abort is called when lockHeartbeat fails with IOException.
hbase-server/src/test/java/org/apache/hadoop/hbase/client/locking/TestEntityLocks.java