*
* @throws NotCompliantMBeanException not expected
*/
@Test
public void test_statistics() throws NotCompliantMBeanException {
final SummaryStatistics durationStats = new SummaryStatistics();
final SummaryStatistics servletCallCountStats = new SummaryStatistics();
final SummaryStatistics peakRecursionDepthStats = new SummaryStatistics();
final RequestProcessorMBeanImpl bean = new RequestProcessorMBeanImpl();
assertEquals(0l, bean.getRequestsCount());
assertEquals(Long.MAX_VALUE, bean.getMinRequestDurationMsec());
assertEquals(0l, bean.getMaxRequestDurationMsec());
assertEquals(0.0, bean.getMeanRequestDurationMsec(), 0);
assertEquals(0.0, bean.getStandardDeviationDurationMsec(), 0);
assertEquals(Integer.MAX_VALUE, bean.getMinServletCallCount());
assertEquals(0l, bean.getMaxServletCallCount());
assertEquals(0.0, bean.getMeanServletCallCount(), 0);
assertEquals(0.0, bean.getStandardDeviationServletCallCount(), 0);
assertEquals(Integer.MAX_VALUE, bean.getMinPeakRecursionDepth());
assertEquals(0l, bean.getMaxPeakRecursionDepth());
assertEquals(0.0, bean.getMeanPeakRecursionDepth(), 0);
assertEquals(0.0, bean.getStandardDeviationPeakRecursionDepth(), 0);
final Random random = new Random(System.currentTimeMillis() / 17);
final int num = 10000;
final int min = 85;
final int max = 250;
for (int i = 0; i < num; i++) {
final long durationValue = min + random.nextInt(max - min);
final int callCountValue = min + random.nextInt(max - min);
final int peakRecursionDepthValue = min + random.nextInt(max - min);
durationStats.addValue(durationValue);
servletCallCountStats.addValue(callCountValue);
peakRecursionDepthStats.addValue(peakRecursionDepthValue);
final RequestData requestData = context.mock(RequestData.class, "requestData" + i);
context.checking(new Expectations() {{
one(requestData).getElapsedTimeMsec();
will(returnValue(durationValue));
one(requestData).getServletCallCount();
will(returnValue(callCountValue));
one(requestData).getPeakRecusionDepth();
will(returnValue(peakRecursionDepthValue));
}});
bean.addRequestData(requestData);
}
assertEquals("Number of points must be the same", durationStats.getN(), bean.getRequestsCount());
assertEquals("Min Duration must be equal", (long) durationStats.getMin(), bean.getMinRequestDurationMsec());
assertEquals("Max Duration must be equal", (long) durationStats.getMax(), bean.getMaxRequestDurationMsec());
assertAlmostEqual("Mean Duration", durationStats.getMean(), bean.getMeanRequestDurationMsec(), num);
assertAlmostEqual("Standard Deviation Duration", durationStats.getStandardDeviation(),
bean.getStandardDeviationDurationMsec(), num);
assertEquals("Min Servlet Call Count must be equal", (long) servletCallCountStats.getMin(), bean.getMinServletCallCount());
assertEquals("Max Servlet Call Count must be equal", (long) servletCallCountStats.getMax(), bean.getMaxServletCallCount());
assertAlmostEqual("Mean Servlet Call Count", servletCallCountStats.getMean(), bean.getMeanServletCallCount(), num);
assertAlmostEqual("Standard Deviation Servlet Call Count", servletCallCountStats.getStandardDeviation(),
bean.getStandardDeviationServletCallCount(), num);
assertEquals("Min Peak Recursion Depth must be equal", (long) peakRecursionDepthStats.getMin(), bean.getMinPeakRecursionDepth());
assertEquals("Max Peak Recursion Depth must be equal", (long) peakRecursionDepthStats.getMax(), bean.getMaxPeakRecursionDepth());
assertAlmostEqual("Mean Peak Recursion Depth", peakRecursionDepthStats.getMean(), bean.getMeanPeakRecursionDepth(), num);
assertAlmostEqual("Standard Deviation Peak Recursion Depth", peakRecursionDepthStats.getStandardDeviation(),
bean.getStandardDeviationPeakRecursionDepth(), num);
//check method resetStatistics
//In the previous test, some requests have been processed, now we reset the statistics so everything statistic is reinitialized
bean.resetStatistics();