Search in sources :

Example 11 with Snapshot

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

the class WeightedSnapshotTest method worksWithOverestimatedCollections.

@Test
public void worksWithOverestimatedCollections() throws Exception {
    final List<WeightedSample> items = spy(WeightedArray(new long[] { 5, 1, 2, 3, 4 }, new double[] { 1, 2, 3, 2, 2 }));
    when(items.size()).thenReturn(6, 5);
    final Snapshot other = new WeightedSnapshot(items);
    assertThat(other.getValues()).containsOnly(1, 2, 3, 4, 5);
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) WeightedSnapshot(io.dropwizard.metrics.WeightedSnapshot) WeightedSnapshot(io.dropwizard.metrics.WeightedSnapshot) WeightedSample(io.dropwizard.metrics.WeightedSnapshot.WeightedSample) Test(org.junit.Test)

Example 12 with Snapshot

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

the class WeightedSnapshotTest method calculatesAMeanOfZeroForAnEmptySnapshot.

@Test
public void calculatesAMeanOfZeroForAnEmptySnapshot() throws Exception {
    final Snapshot emptySnapshot = new WeightedSnapshot(WeightedArray(new long[] {}, new double[] {}));
    assertThat(emptySnapshot.getMean()).isZero();
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) WeightedSnapshot(io.dropwizard.metrics.WeightedSnapshot) WeightedSnapshot(io.dropwizard.metrics.WeightedSnapshot) Test(org.junit.Test)

Example 13 with Snapshot

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

the class ConsoleReporterTest method reportsTimerValues.

@Test
public void reportsTimerValues() throws Exception {
    final Timer timer = mock(Timer.class);
    when(timer.getCount()).thenReturn(1L);
    when(timer.getMeanRate()).thenReturn(2.0);
    when(timer.getOneMinuteRate()).thenReturn(3.0);
    when(timer.getFiveMinuteRate()).thenReturn(4.0);
    when(timer.getFifteenMinuteRate()).thenReturn(5.0);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
    when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
    when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
    when(snapshot.getStdDev()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(400));
    when(snapshot.getMedian()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(500));
    when(snapshot.get75thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(600));
    when(snapshot.get95thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(700));
    when(snapshot.get98thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(800));
    when(snapshot.get99thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(900));
    when(snapshot.get999thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(1000));
    when(timer.getSnapshot()).thenReturn(snapshot);
    reporter.report(this.map(), this.map(), this.map(), this.map(), map("test.another.timer", timer));
    assertThat(consoleOutput()).isEqualTo(lines("3/17/13 6:04:36 PM =============================================================", "", "-- Timers ----------------------------------------------------------------------", "test.another.timer", "             count = 1", "         mean rate = 2.00 calls/second", "     1-minute rate = 3.00 calls/second", "     5-minute rate = 4.00 calls/second", "    15-minute rate = 5.00 calls/second", "               min = 300.00 milliseconds", "               max = 100.00 milliseconds", "              mean = 200.00 milliseconds", "            stddev = 400.00 milliseconds", "            median = 500.00 milliseconds", "              75% <= 600.00 milliseconds", "              95% <= 700.00 milliseconds", "              98% <= 800.00 milliseconds", "              99% <= 900.00 milliseconds", "            99.9% <= 1000.00 milliseconds", "", ""));
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Timer(io.dropwizard.metrics.Timer) Test(org.junit.Test)

Example 14 with Snapshot

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

the class ConsoleReporterTest method reportsHistogramValues.

@Test
public void reportsHistogramValues() throws Exception {
    final Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(1L);
    final Snapshot snapshot = mock(Snapshot.class);
    when(snapshot.getMax()).thenReturn(2L);
    when(snapshot.getMean()).thenReturn(3.0);
    when(snapshot.getMin()).thenReturn(4L);
    when(snapshot.getStdDev()).thenReturn(5.0);
    when(snapshot.getMedian()).thenReturn(6.0);
    when(snapshot.get75thPercentile()).thenReturn(7.0);
    when(snapshot.get95thPercentile()).thenReturn(8.0);
    when(snapshot.get98thPercentile()).thenReturn(9.0);
    when(snapshot.get99thPercentile()).thenReturn(10.0);
    when(snapshot.get999thPercentile()).thenReturn(11.0);
    when(histogram.getSnapshot()).thenReturn(snapshot);
    reporter.report(this.map(), this.map(), map("test.histogram", histogram), this.map(), this.map());
    assertThat(consoleOutput()).isEqualTo(lines("3/17/13 6:04:36 PM =============================================================", "", "-- Histograms ------------------------------------------------------------------", "test.histogram", "             count = 1", "               min = 4", "               max = 2", "              mean = 3.00", "            stddev = 5.00", "            median = 6.00", "              75% <= 7.00", "              95% <= 8.00", "              98% <= 9.00", "              99% <= 10.00", "            99.9% <= 11.00", "", ""));
}
Also used : Snapshot(io.dropwizard.metrics.Snapshot) Histogram(io.dropwizard.metrics.Histogram) Test(org.junit.Test)

Example 15 with Snapshot

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

the class ExponentiallyDecayingReservoirTest method aReservoirOf100OutOf1000Elements.

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

Aggregations

Snapshot (io.dropwizard.metrics.Snapshot)33 Test (org.junit.Test)28 WeightedSnapshot (io.dropwizard.metrics.WeightedSnapshot)8 UniformSnapshot (io.dropwizard.metrics.UniformSnapshot)6 Histogram (io.dropwizard.metrics.Histogram)4 Timer (io.dropwizard.metrics.Timer)4 InfluxDbPoint (io.dropwizard.metrics.influxdb.data.InfluxDbPoint)4 ExponentiallyDecayingReservoir (io.dropwizard.metrics.ExponentiallyDecayingReservoir)3 WeightedSample (io.dropwizard.metrics.WeightedSnapshot.WeightedSample)2 UniformReservoir (io.dropwizard.metrics.UniformReservoir)1 Before (org.junit.Before)1