public void testMoveMarkBack() throws Exception { timer.markTime(); long mark = timer.getTimeOfLastActivity(); timer.moveMarkBackInTime(12345); assertEquals(12345, (mark - timer.getTimeOfLastActivity())); }
@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 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()); } } }
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 testIdleTime() throws Exception { assertEquals(true, timer.getIdleNanos() < ONE_MILLION); Thread.sleep(10); assertEquals(true, timer.getIdleNanos() > TEN_MILLION); }
public void testStartTime() throws Exception { long now = System.nanoTime(); long then = timer.getTimeOfLastActivity(); assertEquals("" + (now - then), true, now - then < ONE_MILLION); // less than 1 milisecond }
@Test public void testGetSeconds() throws InterruptedException { final NanoTimer t = new NanoTimer(); Thread.sleep(1000); assertEquals(1, t.getSeconds(), 0.01); // time = 1 second within .01 seconds tolerance }