diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRate.java b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRate.java index 6e672e3624..db6d68880d 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRate.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/monitor/ExponentialMovingAverageRate.java @@ -1,11 +1,11 @@ /* - * Copyright 2009-2010 the original author or authors. - * + * Copyright 2009-2013 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. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. @@ -25,9 +25,10 @@ package org.springframework.integration.monitor; *
  • per measurement according to the lapse window supplied: weight = exp(-i/L) where L is * the lapse window and i is the sequence number of the measurement.
  • * - * + * * @author Dave Syer - * + * @author Gary Russell + * */ public class ExponentialMovingAverageRate { @@ -54,7 +55,7 @@ public class ExponentialMovingAverageRate { * @param window the exponential lapse window (number of measurements) */ public ExponentialMovingAverageRate(double period, double lapsePeriod, int window) { - rates = new ExponentialMovingAverage(10); + rates = new ExponentialMovingAverage(window); this.lapse = lapsePeriod > 0 ? 0.001 / lapsePeriod : 0; // convert to milliseconds this.period = period * 1000; // convert to milliseconds } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateTests.java index 436bc158e3..edb35ce8e3 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ExponentialMovingAverageRateTests.java @@ -21,6 +21,8 @@ import org.apache.commons.logging.LogFactory; import org.junit.Ignore; import org.junit.Test; +import org.springframework.integration.test.util.TestUtils; + /** * @author Dave Syer * @author Gary Russell @@ -32,6 +34,13 @@ public class ExponentialMovingAverageRateTests { private final ExponentialMovingAverageRate history = new ExponentialMovingAverageRate(1., 10., 10); + @Test + public void testWindow() { + ExponentialMovingAverageRate rate = new ExponentialMovingAverageRate(1., 10., 20); + double decay = TestUtils.getPropertyValue(rate, "rates.decay", Double.class); + assertEquals(95, (int) (decay * 100.)); + } + @Test public void testGetCount() { assertEquals(0, history.getCount());