incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1550098 - in /sling/trunk/bundles/engine/src: main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java
Date Wed, 11 Dec 2013 10:33:24 GMT
Author: bdelacretaz
Date: Wed Dec 11 10:33:24 2013
New Revision: 1550098

URL: http://svn.apache.org/r1550098
Log:
SLING-3277 - fix RequestProcessorMBeanImpl.resetStatistics, contributed by Francisco Chicharro,
thanks!

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java
    sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java?rev=1550098&r1=1550097&r2=1550098&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/RequestProcessorMBeanImpl.java
Wed Dec 11 10:33:24 2013
@@ -116,7 +116,7 @@ class RequestProcessorMBeanImpl extends 
         if (this.n > 1) {
             // algorithm taken from
             // http://de.wikipedia.org/wiki/Standardabweichung section
-            // "Berechnung für auflaufende Messwerte"
+            // "Berechnung fuer auflaufende Messwerte"
             return Math.sqrt((this.durationMsecSumX2 - this.durationMsecSumX * this.durationMsecSumX
/ this.n) / (this.n - 1));
         }
 
@@ -139,9 +139,13 @@ class RequestProcessorMBeanImpl extends 
         this.servletCallCountMax = 0;
         this.peakRecursionDepthMin = Integer.MAX_VALUE;
         this.peakRecursionDepthMax = 0;
-        
+        this.durationMsecSumX=0d;
+        this.durationMsecSumX2=0d;
+        this.peakRecursionDepthSumX=0d;
+        this.peakRecursionDepthSumX2=0d;
+        this.servletCallCountSumX=0d;
+        this.servletCallCountSumX2=0d;
         this.n = 0;
-        
     }
 
     public int getMaxPeakRecursionDepth() {

Modified: sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java?rev=1550098&r1=1550097&r2=1550098&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java
(original)
+++ sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/RequestProcessorMBeanImplTest.java
Wed Dec 11 10:33:24 2013
@@ -44,7 +44,9 @@ public class RequestProcessorMBeanImplTe
     /**
      * Asserts that the simple standard deviation algorithm used by the
      * RequestProcessorMBeanImpl is equivalent to the Commons Math
-     * SummaryStatistics implementation
+     * SummaryStatistics implementation.
+     * 
+     * It also tests that resetStatistics method, actually resets all the statistics
      *
      * @throws NotCompliantMBeanException not expected
      */
@@ -118,6 +120,45 @@ public class RequestProcessorMBeanImplTe
         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();
+        
+        //Simulate a single request 
+        final long durationValue = min + random.nextInt(max - min);
+        final int callCountValue = min + random.nextInt(max - min);
+        final int peakRecursionDepthValue = min + random.nextInt(max - min);
+        
+        final RequestData requestData = context.mock(RequestData.class, "requestDataAfterReset");
+        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);
+        
+        //As only one request has been simulated since resetStatiscts: min, max and mean
statistics should be equals to the request data
+        assertEquals("After resetStatistics Number of requests must be one",1, bean.getRequestsCount());
+        assertEquals("After resetStatistics Min Duration must be equal", bean.getMinRequestDurationMsec(),
(long) durationValue);
+        assertEquals("After resetStatistics Max Duration must be equal", bean.getMaxRequestDurationMsec(),
(long) durationValue);
+        assertEquals("After resetStatistics Mean Duration must be equal",  bean.getMeanRequestDurationMsec(),(double)
durationValue, 0d);
+
+        
+        assertEquals("After resetStatistics Min Servlet Call Count must be equal",bean.getMinServletCallCount(),
callCountValue);
+        assertEquals("After resetStatistics Max Servlet Call Count must be equal",bean.getMaxServletCallCount(),
callCountValue);
+        assertEquals("After resetStatistics Mean Servlet Call Count", bean.getMeanServletCallCount(),
(double)callCountValue, 0d);
+        
+        assertEquals("After resetStatistics Min Peak Recursion Depth must be equal", bean.getMinPeakRecursionDepth(),peakRecursionDepthValue
);
+        assertEquals("After resetStatistics Max Peak Recursion Depth must be equal", bean.getMinPeakRecursionDepth(),
peakRecursionDepthValue);
+        assertEquals("After resetStatistics Mean Peak Recursion Depth", bean.getMeanPeakRecursionDepth(),
(double)peakRecursionDepthValue, 0d);
     }
 
     private void assertAlmostEqual(final String message, final double v1, final double v2,
int samples) {



Mime
View raw message