FixedDelay extends BaleenScheduler { protected boolean delay() { if (lastRunTime == 0) { lastRunTime = System.currentTimeMillis(); return true; } try { final long periodInMs = period * 1000; Thread.sleep(Math.max(0, periodInMs)); lastRunTime = System.currentTimeMillis(); return true; } catch (final InterruptedException e) { getMonitor().warn("Interrupted, stopping the scheduler"); Thread.currentThread().interrupt(); return false; } }   static final String PARAM_PERIOD; }
@Test @SuppressWarnings("squid:S2925" ) public void testDelay() throws CollectionException, IOException, ResourceInitializationException, InterruptedException { FixedDelay scheduler = create("period", "1"); long start = System.currentTimeMillis(); assertTrue(scheduler.hasNext()); Thread.sleep(1000); assertTrue(scheduler.hasNext()); Thread.sleep(1000); assertTrue(scheduler.hasNext()); long end = System.currentTimeMillis(); System.out.println(end - start); long diff = end - start; assertTrue(String.format("Diff was %d", diff), diff >= 3900 && diff <= 4100); }