Source:
public void testDifferentTriggers() throws Exception { properties.setProperty("store.enable.compaction", Boolean.toString(true)); blobStore.details = generateRandomCompactionDetails(2); properties.setProperty("store.compaction.triggers", "Time"); Runnable timeTriggerCode = () -> { try { assertTrue("Compaction calls did not come within the expected time", blobStore.compactCallsCountdown.await(1, TimeUnit.SECONDS)); } catch (InterruptedException e) { throw new IllegalStateException(e); } if (blobStore.callOrderException != null) { throw new IllegalStateException(blobStore.callOrderException); } assertTrue("compact() should have been called", blobStore.compactCalled); }; Runnable adminTriggerCode = () -> assertFalse("Compaction should not be scheduled", compactionManager.scheduleNextForCompaction(blobStore)); doTestTrigger(Arrays.asList(timeTriggerCode, adminTriggerCode)); properties.setProperty("store.compaction.triggers", "Admin"); long startTimeMs = time.milliseconds(); adminTriggerCode = () -> { assertTrue("Compaction should be scheduled", compactionManager.scheduleNextForCompaction(blobStore)); try { assertTrue("Compaction calls did not come within the expected time", blobStore.compactCallsCountdown.await(1, TimeUnit.SECONDS)); } catch (InterruptedException e) { throw new IllegalStateException(e); } if (blobStore.callOrderException != null) { throw new IllegalStateException(blobStore.callOrderException); } assertTrue("compact() should have been called", blobStore.compactCalled); }; timeTriggerCode = () -> assertEquals("Time should not have moved forward", startTimeMs, time.milliseconds()); doTestTrigger(Arrays.asList(adminTriggerCode, timeTriggerCode)); }

Target:
public void testDifferentTriggers() throws Exception { blobStore.details = generateRandomCompactionDetails(2); Runnable adminDisabledChecker = () -> assertFalse("Compaction should not be scheduled", compactionManager.scheduleNextForCompaction(blobStore)); properties.setProperty("store.compaction.triggers", ""); AtomicLong startTimeMs = new AtomicLong(time.milliseconds()); Runnable periodicDisabledChecker = () -> assertEquals("Time should not have moved forward", startTimeMs.get(), time.milliseconds()); doTestTrigger(Arrays.asList(adminDisabledChecker, periodicDisabledChecker)); properties.setProperty("store.compaction.triggers", "Periodic"); Runnable periodicEnabledChecker = () -> { try { assertTrue("Compaction calls did not come within the expected time", blobStore.compactCallsCountdown.await(1, TimeUnit.SECONDS)); } catch (InterruptedException e) { throw new IllegalStateException(e); } if (blobStore.callOrderException != null) { throw new IllegalStateException(blobStore.callOrderException); } assertTrue("compact() should have been called", blobStore.compactCalled); }; doTestTrigger(Arrays.asList(adminDisabledChecker, periodicEnabledChecker)); properties.setProperty("store.compaction.triggers", "Admin"); startTimeMs.set(time.milliseconds()); Runnable adminEnabledChecker = () -> { assertTrue("Compaction should be scheduled", compactionManager.scheduleNextForCompaction(blobStore)); try { assertTrue("Compaction calls did not come within the expected time", blobStore.compactCallsCountdown.await(1, TimeUnit.SECONDS)); } catch (InterruptedException e) { throw new IllegalStateException(e); } if (blobStore.callOrderException != null) { throw new IllegalStateException(blobStore.callOrderException); } assertTrue("compact() should have been called", blobStore.compactCalled); }; periodicDisabledChecker = () -> assertEquals("Time should not have moved forward", startTimeMs.get(), time.milliseconds()); doTestTrigger(Arrays.asList(adminEnabledChecker, periodicDisabledChecker)); }