RecoveryLock { boolean acquireRecoveryLock(int recoveredBy) { ClusterNodeInfoDocument doc = store.find(CLUSTER_NODES, String.valueOf(clusterId)); if (doc == null) { return false; } if (!doc.isRecoveryNeeded(clock.getTime())) { return false; } if (tryAcquireRecoveryLock(doc, recoveredBy)) { return true; } return doc.isBeingRecoveredBy(recoveredBy) || tryBreakRecoveryLock(doc, recoveredBy); } RecoveryLock(DocumentStore store, Clock clock, int clusterId);   }
@Test public void recoveryNotNeeded() { assertFalse(lock1.acquireRecoveryLock(2)); }
@Test public void acquireUnknown() { assertFalse(lock2.acquireRecoveryLock(1)); }
@Test public void acquireAfterLeaseEnd() throws Exception { clock.waitUntil(info1.getLeaseEndTime() + DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS); assertTrue(lock1.acquireRecoveryLock(2)); ClusterNodeInfoDocument c = infoDocument(1); assertTrue(c.isActive()); assertTrue(c.isBeingRecovered()); assertEquals(Long.valueOf(2), c.getRecoveryBy()); assertNotNull(c.get(ClusterNodeInfo.LEASE_END_KEY)); }
@Test public void inactive() { info1.dispose(); assertFalse(lock1.acquireRecoveryLock(1)); assertFalse(lock1.acquireRecoveryLock(2)); }