You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2009/11/21 15:42:39 UTC
svn commit: r882917 - in /cocoon/cocoon3/trunk/cocoon-monitoring: ./
src/main/java/org/apache/cocoon/monitoring/statistics/
src/main/java/org/apache/cocoon/monitoring/statistics/aspects/
src/main/resources/META-INF/cocoon/spring/ src/test/ src/test/jav...
Author: reinhard
Date: Sat Nov 21 14:42:35 2009
New Revision: 882917
URL: http://svn.apache.org/viewvc?rev=882917&view=rev
Log:
COCOON3-41 This patch adds the StatisticsCollector class that will be collecting all statistics in this module. This class support getting list of most- and less-usage entry's and also get usage of "key" in given time.
Added:
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/Statistics.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsCollector.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsEnabled.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsInitializer.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsSourceEnabled.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/CacheStatisticsAspect.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/PipelineHitCountStatisticsAspect.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/ServletHitCountStatisticsAspect.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/UrlHitCountStatisticsAspect.java (with props)
cocoon/cocoon3/trunk/cocoon-monitoring/src/test/
cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/
cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/
cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/
cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/
cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/
cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/
cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/StatisticsCollectorTest.java (with props)
Modified:
cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml
cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml
Modified: cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml?rev=882917&r1=882916&r2=882917&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/pom.xml Sat Nov 21 14:42:35 2009
@@ -64,7 +64,18 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.cocoon.pipeline</groupId>
+ <artifactId>cocoon-pipeline</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/Statistics.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/Statistics.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/Statistics.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/Statistics.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,53 @@
+/*
+ * 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.cocoon.monitoring.statistics;
+
+import java.util.Map;
+
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedOperationParameter;
+import org.springframework.jmx.export.annotation.ManagedOperationParameters;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+@ManagedResource
+public class Statistics {
+
+ private final StatisticsSourceEnabled stats;
+
+ public Statistics(StatisticsEnabled stats) {
+ this.stats = stats.getStatistics();
+ }
+
+ @ManagedAttribute(description = "Returns all hit count since system start.")
+ public double getAllHitCount() {
+ return this.stats.getHitCountSum();
+ }
+
+ @ManagedAttribute(description = "Returns a map of all hits and their counts.")
+ public Map<String, Double> getHits() {
+ return this.stats.getHits();
+ }
+
+ @ManagedOperation(description = "Returns a map of all hits and their counts limited by a time parameter.")
+ @ManagedOperationParameters( { @ManagedOperationParameter(name = "time", description = "Time in miliseconds.") })
+ public Map<String, Long> getHits(long time) {
+ return this.stats.getHits(time);
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/Statistics.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/Statistics.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/Statistics.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsCollector.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsCollector.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsCollector.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsCollector.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,190 @@
+/*
+ * 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.cocoon.monitoring.statistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class StatisticsCollector implements StatisticsSourceEnabled {
+
+ /**
+ * Default refresh time: 10s;
+ */
+ public static final long DEFAULT_REFRESH_DELAY = 1000 * 10;
+
+ /**
+ * Default value of maxKeepTime: 24h.
+ */
+ public static final long DEFAULT_MAX_KEEP_TIME = 1000 * 60 * 60 * 24;
+
+ private final Map<String, Double> allHitCount;
+ private final Map<String, List<Long>> coutners;
+ private final long maxKeepTime;
+
+ /**
+ * This constructor uses default values of {@link StatisticsCollector#DEFAULT_MAX_KEEP_TIME DEFAULT_MAX_KEEP_TIME},
+ * and {@link StatisticsCollector#DEFAULT_REFRESH_DELAY DEFAULT_REFRESH_DELAY} to pass into
+ * {@link StatisticsCollector#StatisticsCollector(long, long) StatisticsCollector(long, long)}
+ */
+ public StatisticsCollector() {
+ this(DEFAULT_MAX_KEEP_TIME, DEFAULT_REFRESH_DELAY);
+ }
+
+ /**
+ *
+ * @param maxKeepTime how long (in milliseconds) should be statistics data kept in collector
+ * @param refreshDelay delay time (in milliseconds) between run of cleaning thread, that will remove entry's
+ * are older than value in <code>maxKeepTime</code>
+ */
+ public StatisticsCollector(long maxKeepTime, long refreshDelay) {
+ this.maxKeepTime = maxKeepTime;
+ this.allHitCount = Collections.synchronizedMap(new HashMap<String, Double>());
+ this.coutners = Collections.synchronizedMap(new HashMap<String, List<Long>>());
+
+ this.initCleaningThread(refreshDelay);
+ }
+
+ /** @{inheritDoc} */
+ public Map<String, Double> getHits() {
+ return new HashMap<String, Double>(this.allHitCount); // defense copy
+ }
+
+ /** @{inheritDoc} */
+ public Map<String, Long> getHits(long time) {
+ final Map<String, Long> result = new HashMap<String, Long>();
+ long timeBorder = new Date().getTime() - time;
+
+ for (String key : this.coutners.keySet()) {
+ long sum = 0;
+ for (long item : this.coutners.get(key)) {
+ if (item > timeBorder) {
+ sum++;
+ }
+ }
+ result.put(key, sum);
+ }
+
+ return result;
+ }
+
+ /** @{inheritDoc} */
+ public double getHitCount(String key) {
+ return this.allHitCount.containsKey(key) ? this.allHitCount.get(key) : 0;
+ }
+
+ /** @{inheritDoc} */
+ public double getHitCountSum() {
+ double result = 0;
+ for (Double count : this.allHitCount.values()) {
+ result += count;
+ }
+ return result;
+ }
+
+ /** @{inheritDoc} */
+ public long getRequestCount(String key, long time) {
+ if (!this.coutners.containsKey(key)) {
+ return 0;
+ }
+
+ List<Long> counter = this.coutners.get(key);
+
+ long hitCount = 0;
+ long currentTimestamp = new Date().getTime() - time;
+
+ for (Long timestamp : counter) {
+ if (timestamp > 0 && currentTimestamp < timestamp) {
+ hitCount++;
+ }
+ }
+
+ return hitCount;
+ }
+
+ /**
+ * Only adds key into counter but don't increment hit count for this
+ * <code>key</code>. It is useful if you want to have this <code>key</code> in a list
+ * of all used key's with value <strong>0</strong> (i.e. for registered but never used
+ * cache entry's).
+ *
+ * @param key
+ */
+ public void putKey(String key) {
+ this.insertDataIntoCounter(key, -1l);
+ }
+
+ /**
+ * Increment value of counter for particular <code>key</code>.
+ *
+ * <p>In fact this method adds actual time (in milliseconds) into list that is connected with
+ * this <code>key</code>.
+ *
+ * @param key
+ */
+ public void incerementCounter(String key) {
+ this.insertDataIntoCounter(key, new Date().getTime());
+ }
+
+ private void insertDataIntoCounter(String key, long data) {
+ if (!this.coutners.containsKey(key)) {
+ List<Long> list = new ArrayList<Long>();
+ list.add(data);
+ this.coutners.put(key, list);
+ } else {
+ this.coutners.get(key).add(data);
+ }
+
+ if (this.allHitCount.containsKey(key) && data > 0) {
+ this.allHitCount.put(key, this.allHitCount.get(key) + 1);
+ } else if (data > 0) {
+ this.allHitCount.put(key, 1d);
+ } else {
+ this.allHitCount.put(key, 0d);
+ }
+ }
+
+ private void initCleaningThread(long refreshDelay) {
+ Timer cleaningTimer = new Timer("RequestCounterCleaningTask", true);
+ cleaningTimer.scheduleAtFixedRate(new TimerTask() {
+
+ @Override
+ public void run() {
+ List<Long> toRemove = new ArrayList<Long>();
+ long currentTimestamp = new Date().getTime();
+
+ for (List<Long> counter : StatisticsCollector.this.coutners.values()) {
+ for (Long timestamp : counter) {
+ if (timestamp > 0 && currentTimestamp - timestamp > StatisticsCollector.this.maxKeepTime) {
+ toRemove.add(timestamp);
+ }
+ }
+ counter.removeAll(toRemove);
+ toRemove.clear();
+ }
+
+ }
+ }, refreshDelay, refreshDelay);
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsCollector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsCollector.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsCollector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsEnabled.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsEnabled.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsEnabled.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsEnabled.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,27 @@
+/*
+ * 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.cocoon.monitoring.statistics;
+
+
+public interface StatisticsEnabled {
+
+ String statisticsSourceName();
+
+ StatisticsSourceEnabled getStatistics();
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsEnabled.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsEnabled.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsEnabled.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsInitializer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsInitializer.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsInitializer.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsInitializer.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.cocoon.monitoring.statistics;
+
+import java.util.Map;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.jmx.export.MBeanExporter;
+
+public class StatisticsInitializer {
+
+ private final Log logger = LogFactory.getLog(this.getClass());
+
+ public StatisticsInitializer(Map<String, StatisticsEnabled> statsSources, MBeanExporter exporter) {
+ for (StatisticsEnabled stat : statsSources.values()) {
+ String stringName = "org.apache.cocoon.monitoring:group=Statistics,name=" + stat.statisticsSourceName();
+
+ ObjectName name;
+ try {
+ name = new ObjectName(stringName);
+ } catch (MalformedObjectNameException e) {
+ this.logger.error("Invalid name of manager resource: " + stringName, e);
+ continue;
+ } catch (NullPointerException e) {
+ this.logger.error("Should never happened. Value of name parameter always is different than null.", e);
+ continue;
+ }
+
+ exporter.registerManagedResource(new Statistics(stat), name);
+ }
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsInitializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsInitializer.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsInitializer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsSourceEnabled.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsSourceEnabled.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsSourceEnabled.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsSourceEnabled.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,67 @@
+/*
+ * 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,in ascending order
+ * 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.cocoon.monitoring.statistics;
+
+import java.util.Map;
+
+public interface StatisticsSourceEnabled {
+
+ /**
+ * Returns sum for all hit count for given key. It will return <strong>0<strong> if given key does not
+ * have any statistics data (that means, that <strong>0</strong> if given key does not exist in statistics
+ * source).
+ *
+ * @param key
+ * @return hit count for passed arguments
+ */
+ public double getHitCount(String key);
+
+ /**
+ * Returns all hit count for this statistics source (sum of all hit counts for all contained key's).
+ *
+ * @return
+ */
+ double getHitCountSum();
+
+ /**
+ * Returns unordered {@link Map} of summed value of all hit
+ *
+ * @return
+ */
+ Map<String, Double> getHits();
+
+ /**
+ * Returns unordered {@link Map}, where <code>key</code> is source name and <code>value</code> is
+ * sum of hit count, limited only to entry's that are younger then <code>time</code> parameter
+ *
+ * @param time
+ * @return
+ */
+ Map<String, Long> getHits(long time);
+
+ /**
+ * Returns hit count for particular <code>key</code> in particular <code>time</code>
+ *
+ * @param key
+ * @param time
+ * @return
+ */
+ long getRequestCount(String key, long time);
+
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsSourceEnabled.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsSourceEnabled.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/StatisticsSourceEnabled.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/CacheStatisticsAspect.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/CacheStatisticsAspect.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/CacheStatisticsAspect.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/CacheStatisticsAspect.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.cocoon.monitoring.statistics.aspects;
+
+import org.apache.cocoon.monitoring.statistics.StatisticsCollector;
+import org.apache.cocoon.monitoring.statistics.StatisticsEnabled;
+import org.apache.cocoon.monitoring.statistics.StatisticsSourceEnabled;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class CacheStatisticsAspect implements StatisticsEnabled {
+
+ private final StatisticsCollector collector;
+
+ public CacheStatisticsAspect() {
+ this(StatisticsCollector.DEFAULT_MAX_KEEP_TIME, StatisticsCollector.DEFAULT_REFRESH_DELAY);
+ }
+
+ public CacheStatisticsAspect(long maxKeepTime, long refreshDelay) {
+ this.collector = new StatisticsCollector(maxKeepTime, refreshDelay);
+ }
+
+ @After("execution(* put(..)) && target(org.apache.cocoon.pipeline.caching.Cache) && args(key, ..)")
+ public void handleCachePutRequest(CacheKey key) throws Throwable {
+ this.collector.putKey(key.toString());
+ }
+
+ @After("execution(* get(..)) && target(org.apache.cocoon.pipeline.caching.Cache) && args(key, ..)")
+ public void handleCacheGetRequest(CacheKey key) throws Throwable {
+ this.collector.incerementCounter(key.toString());
+ }
+
+ public StatisticsSourceEnabled getStatistics() {
+ return this.collector;
+ }
+
+ public String statisticsSourceName() {
+ return "CacheHitCount";
+ }
+
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/CacheStatisticsAspect.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/CacheStatisticsAspect.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/CacheStatisticsAspect.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/PipelineHitCountStatisticsAspect.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/PipelineHitCountStatisticsAspect.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/PipelineHitCountStatisticsAspect.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/PipelineHitCountStatisticsAspect.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,44 @@
+/*
+ * 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.cocoon.monitoring.statistics.aspects;
+
+import org.apache.cocoon.monitoring.statistics.StatisticsCollector;
+import org.apache.cocoon.monitoring.statistics.StatisticsEnabled;
+import org.apache.cocoon.monitoring.statistics.StatisticsSourceEnabled;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class PipelineHitCountStatisticsAspect implements StatisticsEnabled {
+
+ private final StatisticsCollector collector;
+
+ public PipelineHitCountStatisticsAspect() {
+ this(StatisticsCollector.DEFAULT_MAX_KEEP_TIME, StatisticsCollector.DEFAULT_REFRESH_DELAY);
+ }
+
+ public PipelineHitCountStatisticsAspect(long maxKeepTime, long refreshDelay) {
+ this.collector = new StatisticsCollector(maxKeepTime, refreshDelay);
+ }
+
+ public StatisticsSourceEnabled getStatistics() {
+ return this.collector;
+ }
+
+ public String statisticsSourceName() {
+ return "PipeLineHitCount";
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/PipelineHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/PipelineHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/PipelineHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/ServletHitCountStatisticsAspect.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/ServletHitCountStatisticsAspect.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/ServletHitCountStatisticsAspect.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/ServletHitCountStatisticsAspect.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,55 @@
+/*
+ * 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.cocoon.monitoring.statistics.aspects;
+
+import org.apache.cocoon.monitoring.statistics.StatisticsCollector;
+import org.apache.cocoon.monitoring.statistics.StatisticsEnabled;
+import org.apache.cocoon.monitoring.statistics.StatisticsSourceEnabled;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class ServletHitCountStatisticsAspect implements StatisticsEnabled {
+
+ private final StatisticsCollector collector;
+
+ public ServletHitCountStatisticsAspect() {
+ this(StatisticsCollector.DEFAULT_MAX_KEEP_TIME, StatisticsCollector.DEFAULT_REFRESH_DELAY);
+ }
+
+ public ServletHitCountStatisticsAspect(long maxKeepTime, long refreshDelaty) {
+ this.collector = new StatisticsCollector(maxKeepTime, refreshDelaty);
+ }
+
+ @Around("execution(* service(..)) && target(javax.servlet.Servlet))")
+ public Object handleServletRequest(ProceedingJoinPoint pjp) throws Throwable {
+ String className = pjp.getTarget().getClass().getName();
+ if (!className.startsWith("$Proxy")) {
+ this.collector.incerementCounter(className);
+ }
+ return pjp.proceed(pjp.getArgs());
+ }
+
+ public StatisticsSourceEnabled getStatistics() {
+ return this.collector;
+ }
+
+ public String statisticsSourceName() {
+ return "ServletHitCount";
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/ServletHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/ServletHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/ServletHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/UrlHitCountStatisticsAspect.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/UrlHitCountStatisticsAspect.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/UrlHitCountStatisticsAspect.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/UrlHitCountStatisticsAspect.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.cocoon.monitoring.statistics.aspects;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cocoon.monitoring.statistics.StatisticsCollector;
+import org.apache.cocoon.monitoring.statistics.StatisticsEnabled;
+import org.apache.cocoon.monitoring.statistics.StatisticsSourceEnabled;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class UrlHitCountStatisticsAspect implements StatisticsEnabled {
+
+ private final StatisticsCollector collector;
+
+ public UrlHitCountStatisticsAspect() {
+ this(StatisticsCollector.DEFAULT_MAX_KEEP_TIME, StatisticsCollector.DEFAULT_REFRESH_DELAY);
+ }
+
+ public UrlHitCountStatisticsAspect(long maxKeepTime, long refreshDelaty) {
+ this.collector = new StatisticsCollector(maxKeepTime, refreshDelaty);
+ }
+
+ @Around("execution(* service(..)) && target(javax.servlet.Servlet) && args(req, ..)")
+ public Object handleUrlRequest(ProceedingJoinPoint pjp, HttpServletRequest req) throws Throwable {
+ String className = pjp.getTarget().getClass().getName();
+ if (!className.startsWith("$Proxy")) {
+ this.collector.incerementCounter(req.getRequestURI());
+ }
+ return pjp.proceed(pjp.getArgs());
+ }
+
+ public StatisticsSourceEnabled getStatistics() {
+ return this.collector;
+ }
+
+ public String statisticsSourceName() {
+ return "UrlHitCount";
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/UrlHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/UrlHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/java/org/apache/cocoon/monitoring/statistics/aspects/UrlHitCountStatisticsAspect.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml?rev=882917&r1=882916&r2=882917&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/main/resources/META-INF/cocoon/spring/cocoon-monitoring.xml Sat Nov 21 14:42:35 2009
@@ -18,9 +18,13 @@
under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:configurator="http://cocoon.apache.org/schema/configurator"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.1.xsd">
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
@@ -71,4 +75,20 @@
</constructor-arg>
<constructor-arg ref="exporter" index="1" />
</bean>
+
+ <!-- configuration for statistics submodule -->
+ <bean id="org.apache.cocoon.monitoring.statistics.aspects.ServletHitCountStatisticsAspect" class="org.apache.cocoon.monitoring.statistics.aspects.ServletHitCountStatisticsAspect" />
+
+ <bean id="org.apache.cocoon.monitoring.statistics.aspects.UrlHitCountStatisticsAspect" class="org.apache.cocoon.monitoring.statistics.aspects.UrlHitCountStatisticsAspect" />
+
+ <bean id="org.apache.cocoon.monitoring.statistics.aspects.CacheStatisticsAspect" class="org.apache.cocoon.monitoring.statistics.aspects.CacheStatisticsAspect" />
+
+ <bean id="org.apache.cocoon.monitoring.statistics.StatisticsInitializer" class="org.apache.cocoon.monitoring.statistics.StatisticsInitializer">
+ <constructor-arg index="0">
+ <configurator:bean-map type="org.apache.cocoon.monitoring.statistics.StatisticsEnabled" />
+ </constructor-arg>
+ <constructor-arg ref="exporter" index="1" />
+ </bean>
+
+ <aop:aspectj-autoproxy/>
</beans>
Added: cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/StatisticsCollectorTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/StatisticsCollectorTest.java?rev=882917&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/StatisticsCollectorTest.java (added)
+++ cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/StatisticsCollectorTest.java Sat Nov 21 14:42:35 2009
@@ -0,0 +1,210 @@
+/*
+ * 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.cocoon.monitoring.statistics;
+
+import static org.junit.Assert.*;
+
+import java.util.Map;
+
+import org.junit.Test;
+
+public class StatisticsCollectorTest {
+
+ private static final String testKey1 = "test1";
+ private static final String testKey2 = "test2";
+ private static final String testKey3 = "test3";
+
+ @Test
+ public void testGetHitCount() {
+ StatisticsCollector collector = new StatisticsCollector();
+ collector.incerementCounter(testKey1);
+ assertEquals(1, collector.getHitCount(testKey1), 0);
+
+ collector.incerementCounter(testKey1);
+ assertEquals(2, collector.getHitCount(testKey1), 0);
+
+ collector.incerementCounter(testKey2);
+ assertEquals(1, collector.getHitCount(testKey2), 0);
+
+ collector.incerementCounter(testKey2);
+ assertEquals(2, collector.getHitCount(testKey2), 0);
+
+ collector.incerementCounter(testKey1);
+ assertEquals(3, collector.getHitCount(testKey1), 0);
+ }
+
+ @Test
+ public void testGetAllHitCount() {
+ StatisticsCollector collector = new StatisticsCollector();
+ collector.incerementCounter(testKey1);
+ assertEquals(1, collector.getHitCountSum(), 0);
+
+ collector.incerementCounter(testKey1);
+ assertEquals(2, collector.getHitCountSum(), 0);
+
+ collector.incerementCounter(testKey2);
+ assertEquals(3, collector.getHitCountSum(), 0);
+
+ collector.incerementCounter(testKey2);
+ assertEquals(4, collector.getHitCountSum(), 0);
+
+ collector.incerementCounter(testKey1);
+ assertEquals(5, collector.getHitCountSum(), 0);
+ }
+
+ @Test
+ public void testGetHitCountList() {
+ StatisticsCollector collector = new StatisticsCollector(100000, 100000);
+
+ collector.incerementCounter(testKey1);
+ collector.incerementCounter(testKey1);
+ collector.incerementCounter(testKey1);
+
+ collector.incerementCounter(testKey2);
+
+ this.sleep(60);
+
+ collector.incerementCounter(testKey3);
+ collector.incerementCounter(testKey3);
+ collector.incerementCounter(testKey3);
+ collector.incerementCounter(testKey3);
+
+ collector.incerementCounter(testKey2);
+
+ Map<String, Long> timeOut50ms = collector.getHits(50);
+ Map<String, Long> timeOut70ms = collector.getHits(70);
+
+ assertEquals(3, timeOut50ms.size());
+
+ assertTrue(timeOut50ms.containsKey(testKey3));
+ assertEquals(4, timeOut50ms.get(testKey3).longValue());
+
+ assertTrue(timeOut50ms.containsKey(testKey2));
+ assertEquals(1, timeOut50ms.get(testKey2).longValue());
+
+ assertTrue(timeOut50ms.containsKey(testKey1));
+ assertEquals(0, timeOut50ms.get(testKey1).longValue());
+
+ assertEquals(3, timeOut50ms.size());
+
+ assertTrue(timeOut70ms.containsKey(testKey3));
+ assertEquals(4, timeOut70ms.get(testKey3).longValue());
+
+ assertTrue(timeOut70ms.containsKey(testKey1));
+ assertEquals(3, timeOut70ms.get(testKey1).longValue());
+
+ assertTrue(timeOut70ms.containsKey(testKey2));
+ assertEquals(2, timeOut70ms.get(testKey2).longValue());
+
+ }
+
+ @Test
+ public void testGetRequestCount() {
+ StatisticsCollector collector = new StatisticsCollector(1000, 1000);
+
+ collector.incerementCounter(testKey1);
+
+ this.sleep(10);
+ assertEquals(1, collector.getRequestCount(testKey1, 50), 0);
+
+ this.sleep(300);
+ collector.incerementCounter(testKey1);
+ assertEquals(1, collector.getRequestCount(testKey1, 50), 0);
+ assertEquals(2, collector.getRequestCount(testKey1, 500), 0);
+
+ this.sleep(900);
+ collector.incerementCounter(testKey1);
+ assertEquals(1, collector.getRequestCount(testKey1, 50), 0);
+ assertEquals(1, collector.getRequestCount(testKey1, 500), 0);
+ assertEquals(2, collector.getRequestCount(testKey1, 1000), 0);
+
+ this.sleep(100);
+ assertEquals(1, collector.getRequestCount(testKey1, 1000), 0);
+
+ // wait for cleaning action
+ this.sleep(1000);
+
+ // check that everything was cleaned
+ assertEquals(0, collector.getRequestCount(testKey1, 50), 0);
+ assertEquals(0, collector.getRequestCount(testKey1, 500), 0);
+ assertEquals(0, collector.getRequestCount(testKey1, 1000), 0);
+
+ }
+
+ @Test
+ public void testIncerementCounter() {
+ StatisticsCollector collector = new StatisticsCollector();
+ collector.incerementCounter(testKey1);
+ assertEquals(1, collector.getHitCountSum(), 0);
+
+ Map<String, Long> map = collector.getHits(100);
+
+ assertEquals(1, map.size());
+ assertTrue(map.containsKey(testKey1));
+ assertEquals(1, map.get(testKey1).longValue());
+ }
+
+ @Test
+ public void testGetAllHitCountMap() {
+ StatisticsCollector collector = new StatisticsCollector();
+
+ collector.incerementCounter(testKey1);
+ collector.incerementCounter(testKey2);
+ collector.incerementCounter(testKey3);
+ collector.incerementCounter(testKey1);
+ collector.incerementCounter(testKey2);
+ collector.incerementCounter(testKey1);
+
+ Map<String, Double> allHitMap = collector.getHits();
+
+ assertEquals(3, allHitMap.size());
+
+ assertTrue(allHitMap.containsKey(testKey1));
+ assertTrue(allHitMap.containsKey(testKey2));
+ assertTrue(allHitMap.containsKey(testKey3));
+
+ assertEquals(3, allHitMap.get(testKey1), 0);
+ assertEquals(2, allHitMap.get(testKey2), 0);
+ assertEquals(1, allHitMap.get(testKey3), 0);
+
+ allHitMap.put(testKey1, 40d);
+ assertNotSame(40, collector.getHits().get(testKey1));
+ }
+
+ @Test
+ public void testPutKey() {
+ StatisticsCollector collector = new StatisticsCollector();
+ collector.putKey(testKey1);
+
+ assertEquals(0, collector.getHitCountSum(), 0);
+ assertEquals(1, collector.getHits(100).size(), 0);
+
+ assertEquals(0, collector.getRequestCount(testKey1, 100));
+ assertEquals(0, collector.getHits(100).get(testKey1).floatValue(), 0);
+ }
+
+ private void sleep(long time) {
+ try {
+ Thread.sleep(time);
+ } catch (final InterruptedException e) {
+ throw new RuntimeException("Should never happens!");
+ }
+ }
+
+}
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/StatisticsCollectorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/StatisticsCollectorTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-monitoring/src/test/java/org/apache/cocoon/monitoring/statistics/StatisticsCollectorTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain