INT-4250: Fix Statistics Mean Decay with Time

JIRA: https://jira.spring.io/browse/INT-4250

When retrieving the mean from `ExponentialMovingAverageRate` or
`ExponentialMovingAverageRatio` via `getStatistics()` the mean did not
decay over time.

The mean did decay when using `getMean()`.

This was caused by the statistics performance refactoring.
This commit is contained in:
Gary Russell
2017-03-29 13:00:21 -04:00
committed by Artem Bilan
parent b06db72652
commit fac04aeece
5 changed files with 53 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -106,6 +106,7 @@ public class ExponentialMovingAverageRateTests {
Thread.sleep(20L);
history.increment();
double before = history.getMean();
Statistics statisticsBefore = history.getStatistics();
long elapsed = System.currentTimeMillis() - t0;
if (elapsed < 50L) {
assertTrue(before > 10);
@@ -113,6 +114,7 @@ public class ExponentialMovingAverageRateTests {
elapsed = System.currentTimeMillis() - t0;
if (elapsed < 80L) {
assertThat(history.getMean(), lessThan(before));
assertThat(history.getStatistics().getMean(), lessThan(statisticsBefore.getMean()));
}
else {
logger.warn("Test took too long to verify mean");

View File

@@ -17,6 +17,7 @@
package org.springframework.integration.support.management;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@@ -96,6 +97,13 @@ public class ExponentialMovingAverageRatioTests {
public void testDecayedMean() throws Exception {
history.failure(System.nanoTime() - 200000000);
assertEquals(average(0, Math.exp(-0.4)), history.getMean(), 0.01);
history.success();
history.failure();
double mean = history.getMean();
Statistics statistics = history.getStatistics();
Thread.sleep(50);
assertThat(history.getMean(), greaterThan(mean));
assertThat(history.getStatistics().getMean(), greaterThan(statistics.getMean()));
}
@Test