Exemplo n.º 1
0
  @Test
  public void testEmpty() throws InterruptedException {
    final RollingWindowAverageFakeTime rwa =
        new RollingWindowAverageFakeTime(
            1 * RollingWindowAverage.SECOND, 100 * RollingWindowAverage.MILLIS);

    assertEquals("Average incorrect.", 0, rwa.getCurrentAverage(), 0.01d);
  }
Exemplo n.º 2
0
  @Test
  public void testRollingAverage() throws InterruptedException {
    final RollingWindowAverageFakeTime rwa =
        new RollingWindowAverageFakeTime(
            1 * RollingWindowAverage.SECOND, 100 * RollingWindowAverage.MILLIS);

    rwa.add(now, 2);
    rwa.add(now, 3);
    rwa.add(now, 5);

    assertEquals("Average incorrect.", (2.0 + 3 + 5) / 3, rwa.getCurrentAverage(), 0.01d);

    sleep(120 * RollingWindowAverage.MILLIS);

    rwa.add(now, 7);

    assertEquals("Average incorrect.", (2.0 + 3 + 5 + 7) / 4, rwa.getCurrentAverage(), 0.01d);

    sleep(500 * RollingWindowAverage.MILLIS);

    rwa.add(now, 9);

    assertEquals("Average incorrect.", (2.0 + 3 + 5 + 7 + 9) / 5, rwa.getCurrentAverage(), 0.01d);

    sleep(1200 * RollingWindowAverage.MILLIS);

    assertEquals("Average incorrect.", 0, rwa.getCurrentAverage(), 0.01d);
  }
Exemplo n.º 3
0
  @Test
  public void testBucketsNumber() throws InterruptedException {
    final RollingWindowAverageFakeTime rwa =
        new RollingWindowAverageFakeTime(
            1 * RollingWindowAverage.SECOND, 100 * RollingWindowAverage.MILLIS);

    rwa.add(now, 2);
    rwa.add(now, 3);
    rwa.add(now, 5);

    assertEquals(1, rwa.buckets.size());

    sleep(120 * RollingWindowAverage.MILLIS);

    rwa.add(now, 7);

    assertEquals(2, rwa.buckets.size());

    sleep(3000 * RollingWindowAverage.MILLIS);

    rwa.getCurrentAverage();
    assertEquals(0, rwa.buckets.size());
  }