public void acquirePersistentLockWithRetry() { while (!tryAcquirePersistentLock()) { waitForRetry(); } }
@Test public void noOpPersistentLockCanLockTwice() { PersistentLockManager noOpManager = new PersistentLockManager( metricsManager, new NoOpPersistentLockService(), 0L); assertTrue("NoOpPersistentLockService should return true when acquiring lock", noOpManager.tryAcquirePersistentLock()); assertTrue("NoOpPersistentLockService should return true when acquiring lock for the second time", noOpManager.tryAcquirePersistentLock()); }
@Test public void noOpPersistentLockDoesNotThrow() { PersistentLockManager noOpManager = new PersistentLockManager( metricsManager, new NoOpPersistentLockService(), 0L); assertTrue("NoOpPersistentLockService should return true when acquiring lock", noOpManager.tryAcquirePersistentLock()); noOpManager.releasePersistentLock(); }
@Test @GuardedBy("manager") public void cannotAcquireAfterReleaseSeemsToFailButSecretlySucceedsAndThenSomeoneElseTakesTheLock() { doThrow(RuntimeException.class).when(mockPls).releaseBackupLock(any()); manager.acquirePersistentLockWithRetry(); try { manager.releasePersistentLock(); } catch (RuntimeException e) { // Expected } LockEntry usurper = ImmutableLockEntry.builder() .lockName("BackupLock") .instanceId(UUID.randomUUID()) .reason("backup") .build(); CheckAndSetException casException = new CheckAndSetException(Cell.create(PtBytes.toBytes("unu"), PtBytes.toBytes("sed")), TableReference.createFromFullyQualifiedName("unu.sed"), PtBytes.toBytes("unused"), ImmutableList.of(usurper.value()) ); when(mockPls.acquireBackupLock(anyString())) .thenThrow(casException); // We call the non-retrying version here, because we: // (a) don't want the test to hang // (b) want to verify that we adjusted our view of the lockId. manager.tryAcquirePersistentLock(); verify(mockPls, times(2)).acquireBackupLock("Sweep"); assertNull(manager.lockId); }
public void acquirePersistentLockWithRetry() { while (!tryAcquirePersistentLock()) { waitForRetry(); } }