@Test public void idleTime() throws Exception { assertEquals(true, timer.getIdleNanos() < ONE_MILLION); Thread.sleep(10); // Doesn't necessarily sleep a full 10 millis assertEquals( "" + timer.getIdleNanos() + " should > NINE_MILLION", true, timer.getIdleNanos() > NINE_MILLION); }
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 testIdleTime() throws Exception { assertEquals(true, timer.getIdleNanos() < ONE_MILLION); Thread.sleep(10); assertEquals(true, timer.getIdleNanos() > TEN_MILLION); }