@Test public void testGetMeanFailuresLowRate() throws Exception { assertEquals(1, history.getMean(), 0.01); history .failure(); // need an extra now that we can't determine the time between the first and // previous history.failure(); assertEquals(average(0), history.getMean(), 0.01); history.failure(); assertEquals(average(0, 0), history.getMean(), 0.01); history.success(); assertEquals(average(0, 0, 0.33), history.getMean(), 0.1); }
@Test @Ignore public void testPerf() { ExponentialMovingAverageRatio ratio = new ExponentialMovingAverageRatio(60, 10); for (int i = 0; i < 100000; i++) { if (i % 10 == 0) { ratio.failure(); } else { ratio.success(); } } }
@Test public void testRatio() { ExponentialMovingAverageRatio ratio = new ExponentialMovingAverageRatio(60, 10, true); for (int i = 0; i < 100; i++) { if (i % 10 == 1) { ratio.failure(); } else { ratio.success(); } } assertEquals(0.9, ratio.getMax(), 0.02); assertEquals(0.9, ratio.getMean(), 0.03); }
@Test public void testReset() throws Exception { assertEquals(0, history.getStandardDeviation(), 0.01); history.success(); history.failure(); assertThat(history.getStandardDeviation(), not(equalTo(0))); history.reset(); assertEquals(0, history.getStandardDeviation(), 0.01); assertEquals(0, history.getCount()); assertEquals(0, history.getTimeSinceLastMeasurement(), 0.01); assertEquals(1, history.getMean(), 0.01); assertEquals(0, history.getMin(), 0.01); assertEquals(0, history.getMax(), 0.01); history.success(); assertEquals(1, history.getMin(), 0.01); }
@Test public void testDecayedMean() throws Exception { history.failure(System.nanoTime() - 200000000); assertEquals(average(0, Math.exp(-0.4)), history.getMean(), 0.01); }
@Test public void testGetEarlyFailure() throws Exception { assertEquals(1, history.getMean(), 0.01); history.failure(); assertEquals(0, history.getMean(), 0.01); }