geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akulshresh...@apache.org
Subject svn commit: r503422 - in /geronimo/server/trunk/modules/geronimo-tomcat6/src: main/java/org/apache/geronimo/tomcat/ main/java/org/apache/geronimo/tomcat/stats/ test/java/org/apache/geronimo/tomcat/
Date Sun, 04 Feb 2007 15:05:05 GMT
Author: akulshreshtha
Date: Sun Feb  4 07:05:04 2007
New Revision: 503422

URL: http://svn.apache.org/viewvc?view=rev&rev=503422
Log:
GERONIMO-1293 Added initial statistics collection support to tomcat

Added:
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebModule.java
  (with props)
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ConnectorStats.java
  (with props)
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ModuleStats.java
  (with props)
    geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/StatTest.java
  (with props)
Modified:
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/ConnectorGBean.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/ConnectorGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/ConnectorGBean.java?view=diff&rev=503422&r1=503421&r2=503422
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/ConnectorGBean.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/ConnectorGBean.java
Sun Feb  4 07:05:04 2007
@@ -21,6 +21,7 @@
 import java.net.InetAddress;
 import java.util.Map;
 import java.util.HashMap;
+import javax.management.j2ee.statistics.Stats;
 
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.connector.Connector;
@@ -30,12 +31,14 @@
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.management.StatisticsProvider;
+import org.apache.geronimo.tomcat.stats.ConnectorStats;
 import org.apache.geronimo.management.geronimo.WebManager;
 
 /**
  * @version $Rev$ $Date$
  */
-public class ConnectorGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever,
TomcatWebConnector {
+public class ConnectorGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever,
TomcatWebConnector, StatisticsProvider {
     private static final Log log = LogFactory.getLog(ConnectorGBean.class);
     public final static String CONNECTOR_CONTAINER_REFERENCE = "TomcatContainer";
 
@@ -43,6 +46,9 @@
     private final TomcatContainer container;
     private String name;
     private String connectHost;
+    
+//  JSR77 stats
+    private ConnectorStats conStats = new ConnectorStats();
 
     public ConnectorGBean(String name, String protocol, String host, int port, TomcatContainer
container) throws Exception {
         super(); // TODO: make it an attribute
@@ -562,6 +568,28 @@
 
     public String getStrategy() {
         return (String) connector.getAttribute("strategy");
+    }
+    
+//  JSR77 stuff
+    public String getObjectName() {
+        return name; // really an objectName
+    }
+
+    public boolean isStateManageable() {
+        return false;
+    }
+
+    public boolean isStatisticsProvider() {
+        return true;
+    }
+
+    public boolean isEventProvider() {
+        return false;
+    }
+
+    public Stats getStats() {
+        String port = String.valueOf(getPort());
+        return conStats.getStats(port);
     }
 
     public static final GBeanInfo GBEAN_INFO;

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java?view=diff&rev=503422&r1=503421&r2=503422
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
Sun Feb  4 07:05:04 2007
@@ -30,6 +30,7 @@
 
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
+import javax.management.j2ee.statistics.Stats;
 import javax.naming.directory.DirContext;
 import javax.transaction.TransactionManager;
 import javax.transaction.UserTransaction;
@@ -52,10 +53,12 @@
 import org.apache.geronimo.kernel.ObjectNameUtil;
 import org.apache.geronimo.management.J2EEApplication;
 import org.apache.geronimo.management.J2EEServer;
+import org.apache.geronimo.management.StatisticsProvider;
 import org.apache.geronimo.management.geronimo.WebConnector;
 import org.apache.geronimo.management.geronimo.WebContainer;
 import org.apache.geronimo.management.geronimo.WebModule;
 import org.apache.geronimo.tomcat.util.SecurityHolder;
+import org.apache.geronimo.tomcat.stats.ModuleStats;
 import org.apache.geronimo.transaction.GeronimoUserTransaction;
 import org.apache.geronimo.webservices.WebServiceContainer;
 import org.apache.geronimo.webservices.WebServiceContainerFactory;
@@ -66,7 +69,7 @@
  *
  * @version $Rev$ $Date$
  */
-public class TomcatWebAppContext implements GBeanLifecycle, TomcatContext, WebModule {
+public class TomcatWebAppContext implements GBeanLifecycle, TomcatContext, WebModule, StatisticsProvider
{
 
     private static Log log = LogFactory.getLog(TomcatWebAppContext.class);
 
@@ -123,6 +126,9 @@
     private final String j2EEServer;
     
     private final String j2EEApplication;
+    
+//  statistics
+    private ModuleStats statsProvider;
 
     public TomcatWebAppContext(
             ClassLoader classLoader,
@@ -272,7 +278,7 @@
     }
 
     public boolean isStatisticsProvider() {
-        return false;
+        return true;
     }
 
     public boolean isEventProvider() {
@@ -465,6 +471,17 @@
     public String getDeploymentDescriptor() {
         return originalSpecDD;
     }
+    
+//  JSR 77 statistics - The static values are initialized at the time of 
+    // creration, getStats return fresh value everytime
+    public Stats getStats() {
+        return statsProvider.getStats();
+    }
+    
+    // Is this needed ?
+    public void reset() {
+        statsProvider.reset();
+    }
 
     public void doStart() throws Exception {
 
@@ -475,11 +492,14 @@
         //register the classloader <> dir context association so that tomcat's jndi
based getResources works.
         DirContext resources = context.getResources();
         DirContextURLStreamHandler.bind(classLoader, resources);
+        if (context instanceof StandardContext)
+            statsProvider =  new ModuleStats((StandardContext)context);
 
         log.debug("TomcatWebAppContext started for " + path);
     }
 
     public void doStop() throws Exception {
+        statsProvider = null;
         container.removeContext(this);
         DirContextURLStreamHandler.unbind(classLoader);
 
@@ -490,6 +510,7 @@
     }
 
     public void doFail() {
+        statsProvider = null;
         container.removeContext(this);
 
         // No more logging will occur for this ClassLoader. Inform the LogFactory to avoid
a memory leak.

Added: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebModule.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebModule.java?view=auto&rev=503422
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebModule.java
(added)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebModule.java
Sun Feb  4 07:05:04 2007
@@ -0,0 +1,36 @@
+package org.apache.geronimo.tomcat;
+
+import javax.management.j2ee.statistics.Stats;
+
+import org.apache.catalina.Context;
+import org.apache.geronimo.management.geronimo.WebModule;
+
+/**
+ * @version $Revision$ $Date$
+ * 
+ */
+public interface TomcatWebModule extends WebModule {
+
+    public Context getContext();
+
+    public Stats getStats();
+
+    /**
+     * @return The cumulative processing times of requests by all servlets in
+     *         this Context
+     */
+    public long getProcessingTime();
+
+    /**
+     * @return The time this context was started.
+     */
+    public long getStartTime();
+
+    /**
+     * @return The time (in milliseconds) it took to start this context.
+     */
+    public long getStartupTime();
+
+    public long getTldScanTime();
+
+}

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebModule.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatWebModule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ConnectorStats.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ConnectorStats.java?view=auto&rev=503422
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ConnectorStats.java
(added)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ConnectorStats.java
Sun Feb  4 07:05:04 2007
@@ -0,0 +1,130 @@
+/**
+ *  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.geronimo.tomcat.stats;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.j2ee.statistics.Stats;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tomcat.util.modeler.Registry;
+import org.apache.geronimo.management.stats.WebConnectorStatsImpl;
+
+/**
+ * This will query MBeanServer and provide jsr77 Stats for connectors.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class ConnectorStats {
+    private static final Log log = LogFactory.getLog(ModuleStats.class);
+    protected MBeanServer mBeanServer = null;
+
+    protected Registry registry;
+
+    private ObjectName grpName;
+
+    private ObjectName tpName;
+
+    private WebConnectorStatsImpl stats = new WebConnectorStatsImpl();
+
+    public ConnectorStats() {
+        // Retrieve the MBean server
+        registry = Registry.getRegistry(null, null);
+        mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
+        try {
+            grpName = new ObjectName("*:type=GlobalRequestProcessor,*");
+            tpName = new ObjectName("*:type=ThreadPool,*");
+        } catch (Exception ex) {
+            log.error("Error - " + ex.toString());
+        }
+    }
+
+    public Stats getStats(String port) {
+        getStats(stats, port);
+        return stats;
+
+    }
+
+    private void getStats(WebConnectorStatsImpl stats, String port) {
+        Iterator iterator;
+        Set set;
+        ObjectName objectName;
+        try {
+            // Query Thread Pools
+            set = mBeanServer.queryMBeans(tpName, null);
+            iterator = set.iterator();
+            while (iterator.hasNext()) {
+                ObjectInstance oi = (ObjectInstance) iterator.next();
+                objectName = oi.getObjectName();
+                if (objectName.getKeyProperty("name").indexOf(port) > -1) {
+                    tpName = objectName;
+                    break;
+                }
+            }
+            // Query Global Request Processors
+            set = mBeanServer.queryMBeans(grpName, null);
+            iterator = set.iterator();
+            while (iterator.hasNext()) {
+                ObjectInstance oi = (ObjectInstance) iterator.next();
+                objectName = oi.getObjectName();
+                if (objectName.getKeyProperty("name").indexOf(port) > -1) {
+                    grpName = objectName;
+                    break;
+                }
+            }
+            // Any http connector !
+            stats.setStartTime(); // TODO provide a stats enable mechanism
+            stats.setLastSampleTime();
+            long maxTime = ((Long) (mBeanServer.getAttribute(grpName, "maxTime"))).longValue();
+            long processingTime = ((Long) (mBeanServer.getAttribute(grpName, "processingTime"))).longValue();
+            int requestCount = ((Integer) (mBeanServer.getAttribute(grpName, "requestCount"))).intValue();
+            int errorCount = ((Integer) (mBeanServer.getAttribute(grpName, "errorCount"))).intValue();
+            long bytesReceived = ((Long) (mBeanServer.getAttribute(grpName, "bytesReceived"))).longValue();
+            long bytesSent = ((Long) (mBeanServer.getAttribute(grpName, "bytesSent"))).longValue();
+            stats.setRequestTime(requestCount, -1, maxTime, processingTime);
+            stats.setErrorCount(errorCount);            
+            stats.setBytesSentCount(bytesSent);
+            stats.setBytesReceivedCount(bytesReceived);
+            long openConnections = 0;
+            // TODO find these
+            //long openConnections = ((Long) (mBeanServer.getAttribute(grpName, "countOpenConnections"))).longValue();
+            long maxOpenConnections = 0;
+            //long maxOpenConnections = ((Long) (mBeanServer.getAttribute(grpName, "maxOpenConnections"))).longValue();
+            stats.setOpenConnection(openConnections, maxOpenConnections, 0);
+            // ThreadPool 
+            int currentThreadsBusy = ((Integer) (mBeanServer.getAttribute(tpName, "currentThreadsBusy"))).intValue();
+            //stats.setActiveRequestCount(currentThreadsBusy); ??
+            int currentThreadCount = ((Integer) (mBeanServer.getAttribute(tpName, "currentThreadCount"))).intValue();
+            // these are available from "*:type=Connector,*"
+            //int minSpareThreads = ((Integer) (mBeanServer.getAttribute(tpName, "minSpareThreads"))).intValue();
+            //int maxSpareThreads = ((Integer) (mBeanServer.getAttribute(tpName, "maxSpareThreads"))).intValue();
+            int maxThreads = ((Integer) (mBeanServer.getAttribute(tpName, "maxThreads"))).intValue();
+            // keepAliveCount is also available
+            stats.setBusyThreads(currentThreadsBusy, currentThreadCount, 0, maxThreads, 0);
+            // TODO - spareThreads (current-busy, maxSpareThread, minSpareThreads)
+        } catch (Exception ex) {
+            log.error("Error getting attribute " + grpName + " " + ex.toString());
+        }
+
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ConnectorStats.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ConnectorStats.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ConnectorStats.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ModuleStats.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ModuleStats.java?view=auto&rev=503422
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ModuleStats.java
(added)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ModuleStats.java
Sun Feb  4 07:05:04 2007
@@ -0,0 +1,131 @@
+/**
+ *
+ *  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.geronimo.tomcat.stats;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.j2ee.statistics.Stats;
+
+import org.apache.catalina.core.StandardContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tomcat.util.modeler.Registry;
+import org.apache.geronimo.management.stats.WebModuleStatsImpl;
+
+/**
+ * Query MBeanServer and provide jsr77 Stats for module, i.e. a webapp
+ * 
+ * @version $Revision$ $Date$
+ */
+
+public class ModuleStats {
+
+    private static final Log log = LogFactory.getLog(ModuleStats.class);
+
+    private MBeanServer mBeanServer = null;
+
+    private ObjectName mgrName;
+
+    private WebModuleStatsImpl stats = new WebModuleStatsImpl();
+
+    public ModuleStats(StandardContext context) {
+        assert context != null;
+        // Retrieve the MBean server
+        mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
+
+        try {
+            // org.apache.commons.modeler.BaseModelMBean@Geronimo:type=Manager,path=/,host=localhost
+            mgrName = new ObjectName("*:type=Manager,*");
+        } catch (Exception ex) {
+            log.error("Error - " + ex.toString());
+        }
+        // Query Session Managers
+        Set set = mBeanServer.queryMBeans(mgrName, null);
+        Iterator iterator = set.iterator();
+        ObjectName objectName;
+        while (iterator.hasNext()) {
+            ObjectInstance oi = (ObjectInstance) iterator.next();
+            objectName = oi.getObjectName();
+            if (objectName.getKeyProperty("path").indexOf(context.getPath()) > -1) {
+                mgrName = objectName;
+                break;
+            }
+        }
+        // Initialize startTime for all statistics 
+        stats.setStartTime();
+//      initialize static values
+        stats.setProcessingTime(context.getProcessingTime());
+        stats.setStartupTime(context.getStartupTime());
+        stats.setTldScanTime(context.getTldScanTime());
+    }
+
+    public Stats getStats() {
+        // get transient statistics
+        updateStats(stats);
+        return stats;
+
+    }
+
+    public void reset() {
+        // TODO - reset transient statistics
+        // set starTime and lastSampleTime to now, and
+    }
+
+    /*
+     * return updated value of all trainsient statistics
+     * 
+     */
+    private void updateStats(WebModuleStatsImpl stats) {
+        stats.setLastSampleTime();
+
+        // transient data
+        try {
+            int maxActive = ((Integer) (mBeanServer.getAttribute(mgrName,
+                    "maxActive"))).intValue();
+            int sessionMaxAliveTime = ((Integer) (mBeanServer.getAttribute(
+                    mgrName, "sessionMaxAliveTime"))).intValue();
+            int sessionAverageAliveTime = ((Integer) (mBeanServer.getAttribute(
+                    mgrName, "sessionAverageAliveTime"))).intValue();
+            int activeSessions = ((Integer) (mBeanServer.getAttribute(mgrName,
+                    "activeSessions"))).intValue();
+            int rejectedSessions = ((Integer) (mBeanServer.getAttribute(
+                    mgrName, "rejectedSessions"))).intValue();
+            int expiredSessions = ((Integer) (mBeanServer.getAttribute(mgrName,
+                    "expiredSessions"))).intValue();
+            int sessionCounter = ((Integer) (mBeanServer.getAttribute(mgrName,
+                    "sessionCounter"))).intValue();
+
+            stats.setSessionAliveTime(maxActive, -1, sessionMaxAliveTime,
+                    sessionAverageAliveTime * maxActive);
+            stats.setRejectedSessionCount(rejectedSessions);
+            stats.setExpiredSessionCount(expiredSessions);
+            stats.setActiveSessionCount(activeSessions);
+            stats.setSessionCount(sessionCounter);
+
+        } catch (Exception ex) {
+            log.error("Error getting attribute " + mgrName + " " + ex.toString());
+        }
+
+    }
+
+}

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ModuleStats.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ModuleStats.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/stats/ModuleStats.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java?view=diff&rev=503422&r1=503421&r2=503422
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
Sun Feb  4 07:05:04 2007
@@ -54,7 +54,7 @@
     
     protected ClassLoader cl;
     protected final static String securityRealmName = "demo-properties-realm";
-    private ConnectorGBean connector;
+    protected ConnectorGBean connector;
     protected TomcatContainer container;
     private TransactionManager transactionManager;
     private ConnectionTrackingCoordinator connectionTrackingCoordinator;

Added: geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/StatTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/StatTest.java?view=auto&rev=503422
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/StatTest.java
(added)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/StatTest.java
Sun Feb  4 07:05:04 2007
@@ -0,0 +1,77 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  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.
+ */
+package org.apache.geronimo.tomcat;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.management.ObjectName;
+import javax.management.j2ee.statistics.BoundedRangeStatistic;
+import javax.management.j2ee.statistics.CountStatistic;
+import javax.management.j2ee.statistics.RangeStatistic;
+import javax.management.j2ee.statistics.Statistic;
+import javax.management.j2ee.statistics.Stats;
+import javax.management.j2ee.statistics.TimeStatistic;
+
+import org.apache.geronimo.management.stats.WebServletStatsImpl;
+import org.apache.geronimo.tomcat.TomcatWebAppContext;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class StatTest extends AbstractWebModuleTest {
+
+    private ObjectName webModuleName;
+
+    public void testStats() throws Exception {
+        TomcatWebAppContext webModule;
+        webModule = setUpInsecureAppContext(new File(BASEDIR, "target/var/catalina/webapps/war1/").toURI(),
new File(
+                BASEDIR, "target/var/catalina/webapps/war1/WEB-INF/web.xml").toURL(), null,
null, null);
+
+            HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/test/hello.txt")
+                    .openConnection();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+            assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
+            assertEquals("Hello World", reader.readLine());
+            //connection.disconnect();
+        // Stats stats = (Stats) kernel.getAttribute(webModuleName, "stats");
+        Stats[] allStats = { webModule.getStats(), connector.getStats() };
+        Stats stats;
+        for (int j = 0; j < allStats.length; j++) {
+            stats = allStats[j];
+            Statistic[] stts = stats.getStatistics();
+            Statistic aStts;
+            String[] sttsNames = stats.getStatisticNames();
+            for (int i = 0; i < sttsNames.length; i++) {
+                assertFalse(sttsNames[i].equals(stts[i].getName()));
+                aStts = stats.getStatistic(sttsNames[i]);
+                assertTrue("startTime was not set", aStts.getStartTime() != 0);
+                assertTrue("lastSampleTime was not set", aStts.getLastSampleTime() != 0);
+                System.out.println(aStts);
+            }
+        }
+        connection.disconnect();
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        super.init(null);
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/StatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/StatTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-tomcat6/src/test/java/org/apache/geronimo/tomcat/StatTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message