/** * restores the clock; see {@link #testFetchEmptyRecentlyFinishedFlows()} */ @After public void clockReset() { DateTimeUtils.setCurrentMillisOffset(0); }
@Test public void testFetchEmptyRecentlyFinishedFlows() throws Exception { final ExecutableFlow flow1 = createTestFlow(); this.executionFlowDao.uploadExecutableFlow(flow1); flow1.setStatus(Status.SUCCEEDED); flow1.setEndTime(DateTimeUtils.currentTimeMillis()); this.executionFlowDao.updateExecutableFlow(flow1); //Todo jamiesjc: use java8.java.time api instead of jodatime //Mock flow finished time to be 2 min ago. DateTimeUtils.setCurrentMillisOffset(-FLOW_FINISHED_TIME.toMillis()); flow1.setEndTime(DateTimeUtils.currentTimeMillis()); this.executionFlowDao.updateExecutableFlow(flow1); //Fetch recently finished flows within 1 min. Should be empty. final List<ExecutableFlow> flows = this.executionFlowDao .fetchRecentlyFinishedFlows(RECENTLY_FINISHED_LIFETIME); assertThat(flows.size()).isEqualTo(0); }
public static Date offset(Long offsetInMillis) { DateTimeUtils.setCurrentMillisOffset(offsetInMillis); return new Date(DateTimeUtils.currentTimeMillis()); }
public static Date offset(Long offsetInMillis) { DateTimeUtils.setCurrentMillisOffset(offsetInMillis); return new Date(DateTimeUtils.currentTimeMillis()); }
@BeforeMethod(alwaysRun = true) public void setUp() throws Exception { count = new AtomicLong(0); offsetTime = new AtomicLong(0); countTask = count::incrementAndGet; slowTask = () -> { try { DateTimeUtils.setCurrentMillisOffset( offsetTime.addAndGet(20000) ); } catch (SecurityException e) { throw new RuntimeException("security exception on incrementing the system time!", e); } count.incrementAndGet(); }; latchTask = LatchTask.createPaused(); mockExecutor = new MockExecutor(); executorFront = new ExecutorServiceFront( mockExecutor, 10000, TimeUnit.MILLISECONDS ); executorFront2 = new ExecutorServiceFront( new LinkedBlockingQueue<>(), mockExecutor, "fuu", 2, 10000, TimeUnit.MILLISECONDS ); }
DateTimeUtils.setCurrentMillisOffset(0);
/** * This test will submit several tasks two of which will * expire. We check the drainer(s) in the pending list * before and after the expiration. */ @Test(groups = "fast") public void testExpiringDualDrainer() throws Exception { // submit three tasks executorFront2.execute(slowTask); executorFront2.execute(countTask); executorFront2.execute(slowTask); Assert.assertEquals(mockExecutor.getNumPendingTasks(), 2); AnnotatedRunnable drainer2 = mockExecutor.getRunnableList().get(1); mockExecutor.removeHead().run(); // Drainer1 expires after the 1st task completes, // and is rescheduled to the end of the pending list. Assert.assertEquals(mockExecutor.getNumPendingTasks(), 2); // Drainer2 should be on the head of the pending list Assert.assertSame(drainer2, mockExecutor.getRunnableList().get(0)); mockExecutor.removeHead().run(); // Drainer2 expires after the 2nd and 3rd task complete. AnnotatedRunnable drainer1 = mockExecutor.getRunnableList().get(0); // Drainer1 should be on the head of the pending list Assert.assertNotSame(drainer1, drainer2); // should have 2 slow tasks and 1 count tasks Assert.assertEquals(count.get(), 3); // must clear the timer offset DateTimeUtils.setCurrentMillisOffset(0); }
public void setCurrentDateTime(DateTime someDateTime) { resetToCurrentSystemDateTime(); DateTimeUtils.setCurrentMillisOffset(someDateTime.getMillis() - new DateTime().getMillis()); }