private void updateLastModified(String name) { try { // Update file timestamp manually to mimic last updated time updates without sleeping CLOCK.waitUntil(CLOCK.getTime() + TimeUnit.SECONDS.toMillis(2)); File f = new File(directory, name); f.setLastModified(CLOCK.getTimeIncreasing()); } catch (InterruptedException ie) { // ignored } }
@Before public void before() throws Exception { clock.waitUntil(System.currentTimeMillis()); Revision.setClock(clock); }
protected Clock getTestClock() throws InterruptedException { Clock clock = new Clock.Virtual(); clock.waitUntil(getCurrentTimestamp()); return clock; }
@Test public void refreshOnFirstWrite() throws Exception{ clock.waitUntil(System.currentTimeMillis()); policy.refreshOnWriteIfRequired(refreshCallback); refreshCallback.assertInvokedAndReset(); }
@Before public void before() throws Exception { clock = new Clock.Virtual(); clock.waitUntil(System.currentTimeMillis()); Revision.setClock(clock); ClusterNodeInfo.setClock(clock); }
@Test public void leaseUpdate() throws Exception { clock.waitUntil(clock.getTime() + ClusterNodeInfo.DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS * 2); assertTrue(nodeStore.renewClusterIdLease()); verify(statsCollector).doneLeaseUpdate(anyLong()); }
@Test public void gc() throws Exception { createGarbage(); clock.waitUntil(clock.getTime() + TimeUnit.HOURS.toMillis(1)); VersionGarbageCollector gc = ns.getVersionGarbageCollector(); gc.gc(30, TimeUnit.MINUTES); List<String> messages = getDeleteMessages(); assertThat(messages.size(), greaterThan(0)); for (String msg : messages) { assertThat(getNumDeleted(msg), lessThan(BATCH_SIZE + 1)); } }
@Test public void disbaled() throws Exception{ handler.setClock(clock); handler.indexUpdateFailed("async", "/oak:index/foo", new Exception()); clock.waitUntil(clock.getTime() + handler.getCorruptIntervalMillis() + 1); assertTrue(handler.getCorruptIndexData("async").containsKey("/oak:index/foo")); handler.setCorruptInterval(0, TimeUnit.SECONDS); //With timeout set to zero no corrupt index should be reported assertFalse(handler.getCorruptIndexData("async").containsKey("/oak:index/foo")); }
@Override public Long call() throws Exception { long t0 = Clock.ACCURATE.getTime(); Clock.ACCURATE.waitUntil(Clock.ACCURATE.getTime() + 100); assertSame(AFTER, limiter.processCommit(EMPTY_NODE, AFTER, null)); return Clock.ACCURATE.getTime() - t0; } });
@Test public void acquireRecoveryLockOnExpiredLease() throws Exception { ClusterNodeInfo.getInstance(store, NOOP, null, null, 1); // expire the lease clock.waitUntil(clock.getTime() + DEFAULT_LEASE_DURATION_MILLIS + 1); assertTrue(seeker.acquireRecoveryLock(1, 2)); }
@Test public void releaseRemovedClusterNodeInfo() throws Exception { clock.waitUntil(info1.getLeaseEndTime() + DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS); assertTrue(lock1.acquireRecoveryLock(2)); store.remove(CLUSTER_NODES, String.valueOf(info1.getId())); try { lock1.releaseRecoveryLock(false); fail("Must fail with DocumentStoreException"); } catch (DocumentStoreException e) { assertThat(e.getMessage(), containsString("does not exist")); } }
private void expireLease(ClusterNodeInfo info) throws InterruptedException { // let lease expire clock.waitUntil(info.getLeaseEndTime() + ClusterNodeInfo.DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS); // check if expired -> recovery is needed MissingLastRevSeeker util = new MissingLastRevSeeker(store, clock); String key = String.valueOf(info.getId()); ClusterNodeInfoDocument infoDoc = store.find(Collection.CLUSTER_NODES, key); assertNotNull(infoDoc); assertTrue(infoDoc.isRecoveryNeeded(clock.getTime())); }
@Before public void before() throws Exception { clock = new Clock.Virtual(); clock.waitUntil(System.currentTimeMillis()); Revision.setClock(clock); ClusterNodeInfo.setClock(clock); store = new FailingDocumentStore(new MemoryDocumentStore()); ns = createDocumentNodeStore(0); }
@Before public void before() throws Exception { clock = new Clock.Virtual(); clock.waitUntil(System.currentTimeMillis()); Revision.setClock(clock); ClusterNodeInfo.setClock(clock); store = new FailingDocumentStore(new MemoryDocumentStore()); ns = createDocumentNodeStore(); }
@Test public void acquireRecoveryLockAgain() throws Exception { ClusterNodeInfo.getInstance(store, NOOP, null, null, 1); // expire the lease clock.waitUntil(clock.getTime() + DEFAULT_LEASE_DURATION_MILLIS + 1); assertTrue(seeker.acquireRecoveryLock(1, 2)); assertTrue(seeker.acquireRecoveryLock(1, 2)); }
@Test public void testLastRevRestore() throws Exception { clock.waitUntil(clock.getTime() + mk.getClusterInfo().getLeaseTime() + 10); setupScenario(); int pendingCount = mk.getPendingWriteCount(); // so that the current time is more than the current lease end clock.waitUntil(clock.getTime() + mk.getClusterInfo().getLeaseTime() + 1000); LastRevRecoveryAgent recoveryAgent = mk.getNodeStore().getLastRevRecoveryAgent(); /** All pending updates should have been restored **/ assertEquals(pendingCount, recoveryAgent.recover(mk.getClusterInfo().getId())); }
@Test public void lenientLeaseCheckMode() throws Exception { ClusterNodeInfo info = newClusterNodeInfo(1); info.setLeaseCheckMode(LeaseCheckMode.LENIENT); clock.waitUntil(info.getLeaseEndTime()); // must still be able to renew assertTrue(info.renewLease()); assertFalse(handler.isLeaseFailure()); }
@Test public void acquireRecoveryLockOnAlreadyLocked() throws Exception { ClusterNodeInfo.getInstance(store, NOOP, null, null, 1); // expire the lease 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 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 successfulRecovery() throws Exception { clock.waitUntil(info1.getLeaseEndTime() + DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS); assertTrue(lock1.acquireRecoveryLock(2)); lock1.releaseRecoveryLock(true); ClusterNodeInfoDocument c = infoDocument(1); assertFalse(c.isActive()); assertFalse(c.isBeingRecovered()); assertFalse(c.isBeingRecoveredBy(2)); assertNull(c.get(ClusterNodeInfo.LEASE_END_KEY)); }