Search in sources :

Example 6 with ExponentiallyDecayingReservoir

use of io.dropwizard.metrics.ExponentiallyDecayingReservoir in project light-4j by networknt.

the class ExponentiallyDecayingReservoirTest method longPeriodsOfInactivityShouldNotCorruptSamplingState.

@Test
public void longPeriodsOfInactivityShouldNotCorruptSamplingState() {
    final ManualClock clock = new ManualClock();
    final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(10, 0.015, clock);
    // add 1000 values at a rate of 10 values/second
    for (int i = 0; i < 1000; i++) {
        reservoir.update(1000 + i);
        clock.addMillis(100);
    }
    assertThat(reservoir.getSnapshot().size()).isEqualTo(10);
    assertAllValuesBetween(reservoir, 1000, 2000);
    // wait for 15 hours and add another value.
    // this should trigger a rescale. Note that the number of samples will be reduced to 2
    // because of the very small scaling factor that will make all existing priorities equal to
    // zero after rescale.
    clock.addHours(15);
    reservoir.update(2000);
    assertThat(reservoir.getSnapshot().size()).isEqualTo(2);
    assertAllValuesBetween(reservoir, 1000, 3000);
    // add 1000 values at a rate of 10 values/second
    for (int i = 0; i < 1000; i++) {
        reservoir.update(3000 + i);
        clock.addMillis(100);
    }
    assertThat(reservoir.getSnapshot().size()).isEqualTo(10);
    assertAllValuesBetween(reservoir, 3000, 4000);
}
Also used : ExponentiallyDecayingReservoir(io.dropwizard.metrics.ExponentiallyDecayingReservoir) Test(org.junit.Test)

Example 7 with ExponentiallyDecayingReservoir

use of io.dropwizard.metrics.ExponentiallyDecayingReservoir in project light-4j by networknt.

the class ExponentiallyDecayingReservoirTest method aReservoirOf100OutOf10Elements.

@Test
public void aReservoirOf100OutOf10Elements() throws Exception {
    final ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(100, 0.99);
    for (int i = 0; i < 10; i++) {
        reservoir.update(i);
    }
    final Snapshot snapshot = reservoir.getSnapshot();
    assertThat(snapshot.size()).isEqualTo(10);
    assertThat(snapshot.size()).isEqualTo(10);
    assertAllValuesBetween(reservoir, 0, 10);
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) ExponentiallyDecayingReservoir(io.dropwizard.metrics.ExponentiallyDecayingReservoir) Test(org.junit.Test)

Aggregations

ExponentiallyDecayingReservoir (io.dropwizard.metrics.ExponentiallyDecayingReservoir)7 Test (org.junit.Test)7 Snapshot (io.dropwizard.metrics.Snapshot)3