public LockResource lockExclusive(StateLockOptions lockOptions)
      throws TimeoutException, InterruptedException, IOException {
    return lockExclusive(lockOptions, null);
  }
@Test
  public void testGraceMode_Timeout() throws Throwable {
    configureInterruptCycle(false);
    // The state-lock instance.
    StateLockManager stateLockManager = new StateLockManager();
    // Start a thread that owns the state-lock in shared mode.
    StateLockingThread sharedHolderThread = new StateLockingThread(stateLockManager, false);
    sharedHolderThread.start();
    sharedHolderThread.waitUntilStateLockAcquired();
    // Expect timeout when the lock is held in shared mode.
    mExpected.expect(TimeoutException.class);
    stateLockManager
        .lockExclusive(new StateLockOptions(GraceMode.TIMEOUT, 10, 0, 100));
    // Exit the shared holder.
    sharedHolderThread.unlockExit();
    sharedHolderThread.join();
    // Create an exclusive owner of the state-lock.
    StateLockingThread exclusiveHolderThread = new StateLockingThread(stateLockManager, true);
    exclusiveHolderThread.start();
    exclusiveHolderThread.waitUntilStateLockAcquired();
    // Expect timeout when the lock is held in exclusive mode.
    mExpected.expect(TimeoutException.class);
    stateLockManager
        .lockExclusive(new StateLockOptions(GraceMode.TIMEOUT, 10, 0, 100));
    // Exit the exclusive holder.
    exclusiveHolderThread.unlockExit();
    exclusiveHolderThread.join();
    // Now the lock can be acquired within the grace-cycle.
    try (LockResource lr = stateLockManager
        .lockExclusive(new StateLockOptions(GraceMode.TIMEOUT, 10, 0, 100))) {
      // Acquired within the grace-cycle with no active holder.
    }
  }