/* This succeeds if it passes quietly. */
  @Test
  public void test() throws InterruptedException {
    StopWatchFactory swf = StopWatchFactory.getDefault();

    int iterations = 120;

    for (int i = 0; i < iterations; i++) {
      StopWatch sw = swf.getStopWatch("foo");

      Thread.sleep(10 + (long) (Math.random() * 10));

      sw.stop("iteration:success");
    }
  }
  @Test
  public void testSlf4jLog() throws InterruptedException {
    Slf4jLog log = new Slf4jLog();
    log.setSlf4jLogname("foo");
    StopWatchFactory swf = StopWatchFactory.getInstance(log);

    int iterations = 100;

    for (int i = 0; i < iterations; i++) {
      StopWatch sw = swf.getStopWatch("foo");

      Thread.sleep(10 + (long) (Math.random() * 10));

      sw.stop("iteration:success");
    }
  }
  @Test
  public void testPeriodicalLog() throws InterruptedException {
    PeriodicalLog log = new PeriodicalLog();
    log.setSlf4jLogname("foo");
    log.setPeriod(5);
    log.setName("testLog");
    log.setJmx("iteration:1,iteration:2,iteration:3,iteration:4,iteration:N");

    StopWatchFactory swf = StopWatchFactory.getInstance(log);

    int iterations = 1000;

    for (int i = 0; i < iterations; i++) {
      StopWatch sw = swf.getStopWatch("foo");

      long waitPeriod = (long) (Math.random() * 10);

      Thread.sleep(10 + waitPeriod);

      sw.stop("iteration:" + waitPeriod);
    }
  }
  /** Test that we can find a test factory with the special settings. */
  @Test
  public void testLoggerSetting() {
    StopWatchFactory swf = StopWatchFactory.getInstance("testFactory");

    assertNotNull("StopWatchFactory not found", swf);
  }