MissingLastRevSeeker { public boolean acquireRecoveryLock(int clusterId, int recoveredBy) { return new RecoveryLock(store, clock, clusterId) .acquireRecoveryLock(recoveredBy); } MissingLastRevSeeker(DocumentStore store, Clock clock); @NotNull Iterable<ClusterNodeInfoDocument> getAllClusters(); @Nullable ClusterNodeInfoDocument getClusterNodeInfo(final int clusterId); @NotNull Iterable<NodeDocument> getCandidates(final long startTime); boolean acquireRecoveryLock(int clusterId, int recoveredBy); void releaseRecoveryLock(int clusterId, boolean success); NodeDocument getRoot(); boolean isRecoveryNeeded(); boolean isRecoveryNeeded(@NotNull ClusterNodeInfoDocument nodeInfo);  }
@Test public void acquireRecoveryLockOnActiveClusterNode() { ClusterNodeInfo.getInstance(store, NOOP, null, null, 1); assertFalse(seeker.acquireRecoveryLock(1, 2)); }
@Test public void acquireRecoveryLockOnInactiveClusterNode() { ClusterNodeInfo nodeInfo1 = ClusterNodeInfo.getInstance(store, NOOP, null, null, 1); nodeInfo1.dispose(); assertFalse(seeker.acquireRecoveryLock(1, 2)); }
@Test public void acquireRecoveryLockOnExpiredLease() throws Exception { ClusterNodeInfo.getInstance(store, NOOP, null, null, 1); clock.waitUntil(clock.getTime() + DEFAULT_LEASE_DURATION_MILLIS + 1); assertTrue(seeker.acquireRecoveryLock(1, 2)); }
@Test public void acquireRecoveryLockOnAlreadyLocked() throws Exception { ClusterNodeInfo.getInstance(store, NOOP, null, null, 1); clock.waitUntil(clock.getTime() + DEFAULT_LEASE_DURATION_MILLIS + 1); ClusterNodeInfo.getInstance(store, NOOP, null, null, 2); assertTrue(seeker.acquireRecoveryLock(1, 2)); assertFalse(seeker.acquireRecoveryLock(1, 3)); }
@Test public void acquireRecoveryLockAgain() throws Exception { ClusterNodeInfo.getInstance(store, NOOP, null, null, 1); clock.waitUntil(clock.getTime() + DEFAULT_LEASE_DURATION_MILLIS + 1); assertTrue(seeker.acquireRecoveryLock(1, 2)); assertTrue(seeker.acquireRecoveryLock(1, 2)); }