public void mastersStartedCallback() {
    if (mExclusiveOnlyDeadlineMs == -1) {
      long exclusiveOnlyDurationMs =
          Configuration.getMs(PropertyKey.MASTER_BACKUP_STATE_LOCK_EXCLUSIVE_DURATION);
      mExclusiveOnlyDeadlineMs = System.currentTimeMillis() + exclusiveOnlyDurationMs;
      if (exclusiveOnlyDurationMs > 0) {
        LOG.info("State-lock will remain in exclusive-only mode for {}ms until {}",
            exclusiveOnlyDurationMs, new Date(mExclusiveOnlyDeadlineMs).toString());
      }
    }
  }
@Test
  public void testExclusiveOnlyMode() throws Throwable {
    // Configure exclusive-only duration to cover the entire test execution.
    final long exclusiveOnlyDurationMs = 30 * 1000;
    Configuration.set(PropertyKey.MASTER_BACKUP_STATE_LOCK_EXCLUSIVE_DURATION,
        exclusiveOnlyDurationMs);

    // The state-lock instance.
    StateLockManager stateLockManager = new StateLockManager();
    // Simulate masters-started event to initiate the exclusive-only phase.
    stateLockManager.mastersStartedCallback();

    for (int i = 0; i < 10; i++) {
      StateLockingThread sharedHolderThread = new StateLockingThread(stateLockManager, false);
      sharedHolderThread.start();
      // Shared lockers are expected to fail.
      mExpected.expect(IllegalStateException.class);
      sharedHolderThread.waitUntilStateLockAcquired();
    }

    // Exclusive locking should be allowed.
    StateLockingThread exclusiveHolderThread = new StateLockingThread(stateLockManager, true);
    exclusiveHolderThread.start();
    // State lock should be acquired.
    exclusiveHolderThread.waitUntilStateLockAcquired();
    // Signal exit and wait for the exclusive locker.
    exclusiveHolderThread.unlockExit();
    exclusiveHolderThread.join();
  }