PersistentLockManager implements AutoCloseable { public void acquirePersistentLockWithRetry() { while (!tryAcquirePersistentLock()) { waitForRetry(); } } PersistentLockManager(MetricsManager metricsManager,
            PersistentLockService persistentLockService, long persistentLockRetryWaitMillis); @Override void close(); synchronized void shutdown(); void acquirePersistentLockWithRetry(); synchronized void releasePersistentLock();  }
@Test @GuardedBy("manager") public void canAcquireLock() { manager.acquirePersistentLockWithRetry(); assertThat(manager.lockId, is(mockLockId)); verify(mockPls, times(1)).acquireBackupLock("Sweep"); }
@Test public void acquireLockRetries() { when(mockPls.acquireBackupLock(anyString())) .thenThrow(mock(CheckAndSetException.class)) .thenReturn(mockLockId); manager.acquirePersistentLockWithRetry(); verify(mockPls, times(2)).acquireBackupLock("Sweep"); }
@Test @GuardedBy("manager") public void callingAcquireTwiceGivesUsTheSameLock() { whenWeGetTheLockFirstTimeAndThenHoldItForever(); manager.acquirePersistentLockWithRetry(); assertThat(manager.lockId, is(FIRST_LOCK_ID)); manager.acquirePersistentLockWithRetry(); assertThat(manager.lockId, is(FIRST_LOCK_ID)); }