public void testDoesntSleepIfDurationIsZeroOrLess() throws Exception { Thread.sleep(10); timer.sleep(-1234567890); long mark = timer.getIdleNanos(); assertEquals(0, timer.getActualSleepDuration()); assertEquals("time of last activity: " + mark, true, mark < ONE_MILLION); assertEquals(0, timer.getSleepJiggle()); Thread.sleep(10); timer.sleep(TEN_MILLION); timer.sleep(0); mark = timer.getIdleNanos(); assertEquals(0, timer.getActualSleepDuration()); assertEquals("time of last activity: " + mark, true, mark < ONE_MILLION); assertEquals(0, timer.getSleepJiggle()); }
public void testSleeping() { long before = System.nanoTime(); timer.sleep(TEN_MILLION); long after = System.nanoTime(); long sleepDuration = after - before; assertEquals( "actual sleep duration: " + sleepDuration, true, (sleepDuration > NINE_MILLION && sleepDuration < ELEVEN_MILLION)); assertEquals( true, timer.getActualSleepDuration() > NINE_MILLION && timer.getActualSleepDuration() < ELEVEN_MILLION); assertEquals(true, timer.getIdleNanos() < ONE_MILLION); assertEquals(true, timer.getSleepJiggle() < ONE_MILLION); }
public void testSleepDurationAndJiggle() throws Exception { for (int i = 0; i < 10; i++) { long before = System.nanoTime(); timer.sleep(TEN_MILLION); long after = System.nanoTime(); long sleepDuration = after - before; // System.err.println("sleepDuration = " + sleepDuration + " actual: " + // timer.getActualSleepDuration() + " jiggle: " + timer.getSleepJiggle()); if (sleepDuration > TEN_MILLION) { assertEquals(true, timer.getSleepJiggle() < 0); } else if (sleepDuration < TEN_MILLION) { assertEquals(true, timer.getSleepJiggle() > 0); } else { assertEquals(0, timer.getSleepJiggle()); } } }