示例#1
0
 @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);
 }
示例#2
0
  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());
  }
示例#3
0
  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);
  }
示例#4
0
 public void testIdleTime() throws Exception {
   assertEquals(true, timer.getIdleNanos() < ONE_MILLION);
   Thread.sleep(10);
   assertEquals(true, timer.getIdleNanos() > TEN_MILLION);
 }