[jboss-cvs] JBossAS SVN: r90258 - branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 16 11:06:00 EDT 2009


Author: ispringer
Date: 2009-06-16 11:06:00 -0400 (Tue, 16 Jun 2009)
New Revision: 90258

Modified:
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/Ejb3MetricsUnitTestCase.java
Log:
update EJB3 MO test case to include tests for MDB and entity bean MOs, and for invocation stats

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/Ejb3MetricsUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/Ejb3MetricsUnitTestCase.java	2009-06-16 14:54:38 UTC (rev 90257)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/Ejb3MetricsUnitTestCase.java	2009-06-16 15:06:00 UTC (rev 90258)
@@ -22,7 +22,9 @@
 package org.jboss.test.profileservice.test;
 
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import junit.framework.TestCase;
@@ -34,6 +36,8 @@
 import org.jboss.managed.api.ManagedComponent;
 import org.jboss.managed.api.ManagedOperation;
 import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.SimpleValue;
 import org.jboss.test.profileservice.test.ejb3.TestStatefulBean;
 import org.jboss.test.profileservice.test.ejb3.TestStatelessBean;
 
@@ -63,34 +67,70 @@
    /**
     * Component subtype for Stateless Session Beans
     */
-   private static final String COMPONENT_SUBTYPE_SLSB = "SLSB";
+   private static final String COMPONENT_SUBTYPE_STATELESS_SESSION = "StatelessSession";
 
    /**
     * Component subtype for Stateful Session Beans
     */
-   private static final String COMPONENT_SUBTYPE_SFSB = "SFSB";
+   private static final String COMPONENT_SUBTYPE_STATEFUL_SESSION = "StatefulSession";
 
    /**
     * Component subtype for Message-Driven Beans
     */
-   private static final String COMPONENT_SUBTYPE_MDB = "MDB";
+   private static final String COMPONENT_SUBTYPE_MESSAGE_DRIVEN = "MessageDriven";
 
    /**
+    * Component subtype for Entity Beans
+    */
+   private static final String COMPONENT_SUBTYPE_ENTITY = "Entity";
+   
+   /**
     * Properties which should be exposed by SLSB MOs.
     */
    private static final String[] PROPERTY_NAMES_SLSB = new String[]
-   {"name", "currentSize", "createCount", "removeCount", "availableCount", 
-       "maxSize", "invocationStats", "invocationStatsLastResetTime"};
+   {
+      // general EJB metrics
+      "name", "invocationStats",
+      // session bean specific metrics
+      "availableCount", "createCount", "currentSize", "maxSize", "removeCount"
+    };
 
    /**
     * Properties which should be exposed by SFSB MOs.
     */
    private static final String[] PROPERTY_NAMES_SFSB = new String[]
-   {"name", "currentSize", "createCount", "removeCount", "availableCount", 
-       "maxSize", "cacheSize", "totalSize",
-       "passivatedCount", "invocationStats", "invocationStatsLastResetTime"};
+   {
+      // general EJB metrics
+      "name", "invocationStats",
+      // session bean specific metrics
+      "availableCount", "createCount", "currentSize", "maxSize", "removeCount",
+      // stateful session bean specific metrics      
+      "cacheSize", "passivatedCount", "totalSize"
+   };
 
    /**
+    * Properties which should be exposed by MDB MOs.
+    */
+   private static final String[] PROPERTY_NAMES_MDB = new String[]
+   {
+      // general EJB metrics
+      "name", "invocationStats",
+      // message-driven bean specific metrics
+      "deliveryActive", "keepAliveMillis", "maxMessages", "maxPoolSize", "minPoolSize"
+   };
+
+   /**
+    * Properties which should be exposed by Entity Bean MOs.
+    */
+   private static final String[] PROPERTY_NAMES_ENTITY = new String[]
+   {
+      // general EJB metrics
+      "name", "invocationStats",
+      // entity bean specific metrics
+      "availableCount", "createCount", "currentSize", "removeCount", "maxSize"
+   };
+       
+   /**
     * Operations which should be exposed by SLSB MOs
     */
    private static final String[] OPERATION_NAMES_SLSB = new String[]
@@ -101,6 +141,18 @@
     */
    private static final String[] OPERATION_NAMES_SFSB = new String[]
    {"resetInvocationStats"};
+
+   /**
+    * Operations which should be exposed by MDB MOs
+    */
+   private static final String[] OPERATION_NAMES_MDB = new String[]
+   {"resetInvocationStats", "startDelivery", "stopDelivery"};
+
+   /**
+    * Operations which should be exposed by Entity Bean MOs
+    */
+   private static final String[] OPERATION_NAMES_ENTITY = new String[]
+   {"resetInvocationStats"};
    
    /**
     * The name of the test JAR to deploy
@@ -209,22 +261,16 @@
       // Ensure component exists.
       final String ejbName = TestStatelessBean.class.getSimpleName();      
       final String componentName = ejbName;
-      final ManagedComponent component = this.getManagedComponent(COMPONENT_SUBTYPE_SLSB, componentName);
+      final ManagedComponent component = this.getManagedComponent(COMPONENT_SUBTYPE_STATELESS_SESSION, componentName);
       
       // Check component has expected props and ops.
       this.ensureManagementPropertiesExposed(component, PROPERTY_NAMES_SLSB);
       this.ensureManagementOperationsExposed(component, OPERATION_NAMES_SLSB);
       
-      //      ManagedProperty slsbStats = slsb.getProperty("stats");
-      //      assertNotNull(slsbStats);
-      //      TableValue table = (TableValue) slsbStats.getValue();
-      //      assertNotNull(table);
-      //      getLog().debug(table);
-
-      //
+      validateInvocationStats(component);
+                  
       //     ComponentType slsbType = new ComponentType("EJB3", "SLSB");
-      //     Set<ManagedComponent> slsbs = mgtView.getComponentsForType(slsbType);
-      //     
+      //     Set<ManagedComponent> slsbs = mgtView.getComponentsForType(slsbType);          
       //     ManagedComponent slsb = slsbs.iterator().next();
       //     ManagedProperty currentSize = slsb.getProperty("currentSize");
       //     assertNotNull(currentSize);
@@ -246,11 +292,13 @@
       // Ensure component exists.
       final String ejbName = TestStatefulBean.class.getSimpleName();
       final String componentName = ejbName;
-      final ManagedComponent component = this.getManagedComponent(COMPONENT_SUBTYPE_SFSB, componentName);
+      final ManagedComponent component = this.getManagedComponent(COMPONENT_SUBTYPE_STATEFUL_SESSION, componentName);
       
       // Check component has expected props and ops.
       this.ensureManagementPropertiesExposed(component, PROPERTY_NAMES_SFSB);      
       this.ensureManagementOperationsExposed(component, OPERATION_NAMES_SFSB);
+      
+      validateInvocationStats(component);
    }
 
    /**
@@ -263,8 +311,39 @@
       // Log
       this.getLog().info("testMdb");
 
-      // TODO
+      // Ensure component exists.
+      final String ejbName = "FooBarMDB";
+      final String componentName = ejbName;
+      final ManagedComponent component = this.getManagedComponent(COMPONENT_SUBTYPE_MESSAGE_DRIVEN, componentName);
+      
+      // Check component has expected props and ops.
+      this.ensureManagementPropertiesExposed(component, PROPERTY_NAMES_MDB);      
+      this.ensureManagementOperationsExposed(component, OPERATION_NAMES_MDB);
+      
+      validateInvocationStats(component);
    }
+
+   /**
+    * Ensures that MOs with the correct metrics and operations are exposed for Entity Beans.
+    * 
+    * @throws Exception
+    */
+   public void testEntityBean() throws Exception
+   {
+      // Log
+      this.getLog().info("testEntityBean");
+
+      // Ensure component exists.
+      final String ejbName = "FooBarEntityBean";
+      final String componentName = ejbName;
+      final ManagedComponent component = this.getManagedComponent(COMPONENT_SUBTYPE_ENTITY, componentName);
+      
+      // Check component has expected props and ops.
+      this.ensureManagementPropertiesExposed(component, PROPERTY_NAMES_ENTITY);      
+      this.ensureManagementOperationsExposed(component, OPERATION_NAMES_ENTITY);
+      
+      validateInvocationStats(component);
+   }
    
    // ---------------------------------------------------------------------------------------||
    // Internal Helper Methods ---------------------------------------------------------------||
@@ -409,4 +488,62 @@
       }
    }
 
+    protected void validateInvocationStats(ManagedComponent component) {
+        // TODO: Invoke some methods on the EJB to populate some stats.
+        InvocationStats invocationStats = getInvocationStats(component);
+        // TODO: Check that the stats have the expected values.
+        resetInvocationStats(component);
+        invocationStats = getInvocationStats(component);
+        // TODO: Check that the stats were reset.      
+    }
+           
+    private InvocationStats getInvocationStats(ManagedComponent component) {
+        InvocationStats invocationStats = new InvocationStats();
+        List<MethodStats> allMethodStats = new ArrayList<MethodStats>();
+        ManagedProperty invocationStatsProp = component.getProperty("invocationStats");
+        invocationStats.endTime = System.currentTimeMillis();
+        CompositeValue invocationStatsMetaValue = (CompositeValue)invocationStatsProp.getValue();
+        CompositeValue allMethodStatsMetaValue = (CompositeValue) invocationStatsMetaValue.get("methodStats");
+        Set<String> methodNames = allMethodStatsMetaValue.getMetaType().keySet();
+        for (String methodName : methodNames) {
+            CompositeValue methodStatsMetaValue = (CompositeValue)allMethodStatsMetaValue.get(methodName);
+            MethodStats methodStats = new MethodStats();
+            methodStats.name = methodName;
+            methodStats.count = Long.parseLong(((SimpleValue)methodStatsMetaValue.get("count")).getValue().toString());
+            methodStats.totalTime = Long.parseLong(((SimpleValue)methodStatsMetaValue.get("totalTime")).getValue().toString());
+            methodStats.minTime = Long.parseLong(((SimpleValue)methodStatsMetaValue.get("minTime")).getValue().toString());
+            methodStats.maxTime = Long.parseLong(((SimpleValue)methodStatsMetaValue.get("maxTime")).getValue().toString());
+            allMethodStats.add(methodStats);
+        }
+        invocationStats.methodStats = allMethodStats;
+
+        SimpleValue lastResetTimeMetaValue = (SimpleValue)invocationStatsMetaValue.get("lastResetTime");
+        invocationStats.beginTime = Long.valueOf(lastResetTimeMetaValue.getValue().toString()); // TODO: handle null value?
+
+        return invocationStats;
+    }
+   
+    private void resetInvocationStats(ManagedComponent component) {
+        Set<ManagedOperation> operations = component.getOperations();
+        for (ManagedOperation operation : operations) {
+            if (operation.getName().equals("resetInvocationStats")) {
+                operation.invoke();
+                break;
+            }
+        }
+    }
+   
+    class InvocationStats {
+        List<MethodStats> methodStats;
+        long beginTime;
+        long endTime;
+    }
+
+    class MethodStats {
+        String name;
+        long count;
+        long minTime;
+        long maxTime;
+        long totalTime;
+    }   
 }




More information about the jboss-cvs-commits mailing list