jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1182871 - in /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats: ./ TimeSeriesRecorderTest.java
Date Thu, 13 Oct 2011 14:25:13 GMT
Author: jukka
Date: Thu Oct 13 14:25:12 2011
New Revision: 1182871

URL: http://svn.apache.org/viewvc?rev=1182871&view=rev
Log:
JCR-3040 JMX Stats for the Session

Add a unit test for the TimeSeriesRecorder class

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorderTest.java

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorderTest.java?rev=1182871&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorderTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TimeSeriesRecorderTest.java
Thu Oct 13 14:25:12 2011
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.jackrabbit.core.stats;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.jackrabbit.api.stats.RepositoryStatistics;
+
+import junit.framework.TestCase;
+
+public class TimeSeriesRecorderTest extends TestCase {
+
+    public void testCounter() {
+        TimeSeriesRecorder recorder = new TimeSeriesRecorder(
+                RepositoryStatistics.Type.SESSION_READ_COUNTER);
+        AtomicLong counter = recorder.getCounter();
+
+        // initial values
+        assertValues(recorder.getValuePerSecond());
+        assertValues(recorder.getValuePerMinute());
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek());
+
+        // no changes in first second
+        recorder.recordOneSecond();
+        assertValues(recorder.getValuePerSecond());
+        assertValues(recorder.getValuePerMinute());
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek());
+
+        // one increment in second
+        counter.incrementAndGet();
+        recorder.recordOneSecond();
+        assertValues(recorder.getValuePerSecond(), 1);
+        assertValues(recorder.getValuePerMinute());
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek());
+
+        // two increments in second
+        counter.incrementAndGet();
+        counter.incrementAndGet();
+        recorder.recordOneSecond();
+        assertValues(recorder.getValuePerSecond(), 2, 1);
+        assertValues(recorder.getValuePerMinute());
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek());
+
+        // no changes in a second
+        recorder.recordOneSecond();
+        assertValues(recorder.getValuePerSecond(), 0, 2, 1);
+        assertValues(recorder.getValuePerMinute());
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek());
+
+        // ten increments in a second
+        counter.addAndGet(10);
+        recorder.recordOneSecond();
+        assertValues(recorder.getValuePerSecond(), 10, 0, 2, 1);
+        assertValues(recorder.getValuePerMinute());
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek());
+
+        // one minute
+        for (int i = 0; i < 60; i++) {
+            recorder.recordOneSecond();
+        }
+        assertValues(recorder.getValuePerSecond());
+        assertValues(recorder.getValuePerMinute(), 13);
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek());
+
+        // second minute
+        for (int i = 0; i < 60; i++) {
+            recorder.recordOneSecond();
+        }
+        assertValues(recorder.getValuePerSecond());
+        assertValues(recorder.getValuePerMinute(), 0, 13);
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek());
+
+        // one hour
+        for (int i = 0; i < 60 * 60; i++) {
+            recorder.recordOneSecond();
+        }
+        assertValues(recorder.getValuePerSecond());
+        assertValues(recorder.getValuePerMinute());
+        assertValues(recorder.getValuePerHour(), 13);
+        assertValues(recorder.getValuePerWeek());
+
+        // one week
+        for (int i = 0; i < 7 * 24 * 60 * 60; i++) {
+            recorder.recordOneSecond();
+        }
+        assertValues(recorder.getValuePerSecond());
+        assertValues(recorder.getValuePerMinute());
+        assertValues(recorder.getValuePerHour());
+        assertValues(recorder.getValuePerWeek(), 13);
+    }
+
+    private void assertValues(long[] values, long... expected) {
+        for (int i = 0; i < expected.length; i++) {
+            assertEquals(expected[i], values[values.length - i - 1]);
+        }
+        for (int i = expected.length; i < values.length; i++) {
+            assertEquals(0, values[values.length - i - 1]);
+        }
+    }
+
+}



Mime
View raw message