[jboss-cvs] JBossAS SVN: r91450 - in branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test: ejb3 and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 20 17:24:39 EDT 2009


Author: ALRubinger
Date: 2009-07-20 17:24:39 -0400 (Mon, 20 Jul 2009)
New Revision: 91450

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/ejb3/TestLocalBusiness.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestLoggingMDB.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestStatefulBean.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestStatelessBean.java
Log:
[JBAS-7108] Update EJB3 Metrics Test Case to make/test invocations

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-07-20 21:23:03 UTC (rev 91449)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/Ejb3MetricsUnitTestCase.java	2009-07-20 21:24:39 UTC (rev 91450)
@@ -27,6 +27,15 @@
 import java.util.List;
 import java.util.Set;
 
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.jboss.deployers.spi.management.ManagementView;
@@ -38,6 +47,7 @@
 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.TestLocalBusiness;
 import org.jboss.test.profileservice.test.ejb3.TestLoggingMDB;
 import org.jboss.test.profileservice.test.ejb3.TestStatefulBean;
 import org.jboss.test.profileservice.test.ejb3.TestStatelessBean;
@@ -139,7 +149,13 @@
     * The name of the test JAR to deploy
     */
    private static final String NAME_TEST_JAR = "testEjb3xMetrics.jar";
+   
+   /**
+    * Name of the Queue Connection Factory in JNDI
+    */
+   private static final String JNDI_NAME_CONNECTION_FACTORY = "ConnectionFactory";
 
+
    // ---------------------------------------------------------------------------------------||
    // Instance Members ----------------------------------------------------------------------||
    // ---------------------------------------------------------------------------------------||
@@ -241,7 +257,7 @@
       this.ensureManagementPropertiesExposed(component, PROPERTY_NAMES_SLSB);
       this.ensureManagementOperationsExposed(component, OPERATION_NAMES_SLSB);
 
-      validateInvocationStats(component);
+      validateInvocationSessionStats(component,ejbName);
    }
 
    /**
@@ -266,7 +282,7 @@
       this.ensureManagementPropertiesExposed(component, PROPERTY_NAMES_SFSB);
       this.ensureManagementOperationsExposed(component, OPERATION_NAMES_SFSB);
 
-      validateInvocationStats(component);
+      validateInvocationSessionStats(component,ejbName);
    }
    
    /**
@@ -322,7 +338,7 @@
       this.ensureManagementPropertiesExposed(component, PROPERTY_NAMES_MDB);
       this.ensureManagementOperationsExposed(component, OPERATION_NAMES_MDB);
 
-      validateInvocationStats(component);
+      validateInvocationMdbStats(component);
    }
 
    // ---------------------------------------------------------------------------------------||
@@ -504,16 +520,123 @@
       }
    }
 
-   protected void validateInvocationStats(ManagedComponent component)
+   /**
+    * Validates that the invocation statistics are in place for the specified 
+    * EJB3 Session Bean ManagedComponent with specified EJB Name
+    * 
+    * @param component
+    * @param ejbName
+    * @throws IllegalArgumentException If either argument is not specified
+    */
+   protected void validateInvocationSessionStats(final ManagedComponent component, final String ejbName)
+         throws IllegalArgumentException, Exception
    {
-      // TODO: Invoke some methods on the EJB to populate some stats.
+      // Precondition checks
+      if (component == null)
+      {
+         throw new IllegalArgumentException("component must be specified");
+      }
+      if (ejbName == null || ejbName.length() == 0)
+      {
+         throw new IllegalArgumentException("ejbName must be specified");
+      }
+
+      // Obtain invocation stats
       InvocationStats invocationStats = getInvocationStats(component);
-      // TODO: Check that the stats have the expected values.
+
+      // Ensure the stats are expected (empty)
+      List<MethodStats> methodStats = invocationStats.methodStats;
+      log.info("Method stats before invocation: " + methodStats);
+      Assert.assertTrue("Method stats should be empty", methodStats.isEmpty());
+
+      // Invoke upon the EJB
+      TestLocalBusiness localBusiness = (TestLocalBusiness) getInitialContext().lookup(ejbName + "/remote");
+      localBusiness.echo("Some test String");
+
+      // Ensure the stats reflect the invocation
+      invocationStats = getInvocationStats(component);
+      methodStats = invocationStats.methodStats;
+      log.info("Method stats after invocation: " + methodStats);
+      Assert.assertEquals("One invocation should be represented in stats", 1, methodStats.size());
+
+      // Reset the stats
       resetInvocationStats(component);
       invocationStats = getInvocationStats(component);
-      // TODO: Check that the stats were reset.      
+
+      // Ensure the stats were reset
+      invocationStats = getInvocationStats(component);
+      methodStats = invocationStats.methodStats;
+      log.info("Method stats after reset: " + methodStats);
+      Assert.assertTrue("Method stats should be empty, was instead of size: " + methodStats.size(), methodStats.isEmpty());
    }
+   
+   /**
+    * Validates that the invocation statistics are in place for the specified 
+    * EJB3 MDB ManagedComponent with specified EJB Name
+    * 
+    * @param component
+    * @throws IllegalArgumentException If the component is not specified
+    */
+   protected void validateInvocationMdbStats(final ManagedComponent component)
+         throws IllegalArgumentException, Exception
+   {
+      // Precondition checks
+      if (component == null)
+      {
+         throw new IllegalArgumentException("component must be specified");
+      }
+      // Obtain invocation stats
+      InvocationStats invocationStats = getInvocationStats(component);
 
+      // Ensure the stats are expected (empty)
+      List<MethodStats> methodStats = invocationStats.methodStats;
+      Assert.assertTrue("Method stats should be empty", methodStats.isEmpty());
+
+      // Get the queue from JNDI
+      final Context naimgContext = getInitialContext();
+      final Queue queue = (Queue) naimgContext.lookup(TestLoggingMDB.QUEUE_NAME);
+
+      // Get the ConnectionFactory from JNDI
+      final QueueConnectionFactory factory = (QueueConnectionFactory) naimgContext
+            .lookup(JNDI_NAME_CONNECTION_FACTORY);
+
+      // Make a Connection
+      final QueueConnection connection = factory.createQueueConnection();
+      final QueueSession sendSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+      // Make the message
+      final String contents = "Test Message Contents";
+      final TextMessage message = sendSession.createTextMessage(contents);
+
+      // Send the message
+      final QueueSender sender = sendSession.createSender(queue);
+      sender.send(message);
+      log.info("Sent message " + message + " with contents: " + contents);
+
+      // Clean up
+      sendSession.close();
+      connection.close();
+      
+      // Wait, this is async
+      Thread.sleep(3000);
+
+      // Ensure the stats reflect the invocation
+      invocationStats = getInvocationStats(component);
+      methodStats = invocationStats.methodStats;
+      log.info("Method stats after invocation: " + methodStats);
+      Assert.assertEquals("One invocation should be represented in stats", 1, methodStats.size());
+
+      // Reset the stats
+      resetInvocationStats(component);
+      invocationStats = getInvocationStats(component);
+
+      // Ensure the stats were reset
+      invocationStats = getInvocationStats(component);
+      methodStats = invocationStats.methodStats;
+      log.info("Method stats after reset: " + methodStats);
+      Assert.assertTrue("Method stats should be empty", methodStats.isEmpty());
+   }
+
    private InvocationStats getInvocationStats(ManagedComponent component)
    {
       InvocationStats invocationStats = new InvocationStats();
@@ -550,11 +673,19 @@
       Set<ManagedOperation> operations = component.getOperations();
       for (ManagedOperation operation : operations)
       {
-         if (operation.getName().equals("resetInvocationStats"))
+         final String resetMethodName = "resetInvocationStats";
+         boolean invoked = false;
+         if (operation.getName().equals(resetMethodName))
          {
             operation.invoke();
+            invoked = true;
             break;
          }
+         
+         if (!invoked)
+         {
+            Assert.fail("No operation named \"" + resetMethodName + "\" exists in " + component);
+         }
       }
    }
 
@@ -565,6 +696,13 @@
       long beginTime;
 
       long endTime;
+
+      @Override
+      public String toString()
+      {
+         return "InvocationStats [beginTime=" + beginTime + ", endTime=" + endTime + ", methodStats=" + methodStats
+               + "]";
+      }
    }
 
    class MethodStats
@@ -578,5 +716,12 @@
       long maxTime;
 
       long totalTime;
+
+      @Override
+      public String toString()
+      {
+         return "MethodStats [count=" + count + ", maxTime=" + maxTime + ", minTime=" + minTime + ", name=" + name
+               + ", totalTime=" + totalTime + "]";
+      }
    }
 }

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestLocalBusiness.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestLocalBusiness.java	2009-07-20 21:23:03 UTC (rev 91449)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestLocalBusiness.java	2009-07-20 21:24:39 UTC (rev 91450)
@@ -31,5 +31,11 @@
  */
 public interface TestLocalBusiness
 {
-   // No business methods required
+   /**
+    * Returns a String equal by value to the argument
+    * 
+    * @param echo
+    * @return
+    */
+   String echo(String echo);
 }

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestLoggingMDB.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestLoggingMDB.java	2009-07-20 21:23:03 UTC (rev 91449)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestLoggingMDB.java	2009-07-20 21:24:39 UTC (rev 91450)
@@ -40,7 +40,7 @@
  */
 @MessageDriven(activationConfig =
 {@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
-      @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/ejb3MetricsTestQueue")})
+      @ActivationConfigProperty(propertyName = "destination", propertyValue = TestLoggingMDB.QUEUE_NAME)})
 @Depends("jboss.mq.destination:service=Queue,name=ejb3MetricsTestQueue")
 public class TestLoggingMDB implements MessageListener
 {
@@ -53,6 +53,11 @@
     * Logger
     */
    private static final Logger log = Logger.getLogger(TestLoggingMDB.class);
+   
+   /**
+    * Name of the queue
+    */
+   public static final String QUEUE_NAME = "queue/ejb3MetricsTestQueue";
 
    //-------------------------------------------------------------------------------------||
    // Required Implementations -----------------------------------------------------------||

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestStatefulBean.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestStatefulBean.java	2009-07-20 21:23:03 UTC (rev 91449)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestStatefulBean.java	2009-07-20 21:24:39 UTC (rev 91450)
@@ -21,7 +21,7 @@
  */
 package org.jboss.test.profileservice.test.ejb3;
 
-import javax.ejb.Local;
+import javax.ejb.Remote;
 import javax.ejb.Stateful;
 
 /**
@@ -33,8 +33,16 @@
  * @version $Revision: $
  */
 @Stateful
- at Local(TestLocalBusiness.class)
+ at Remote(TestLocalBusiness.class)
 public class TestStatefulBean implements TestLocalBusiness
 {
-   // No business methods required
+   /*
+    * (non-Javadoc)
+    * @see org.jboss.test.profileservice.test.ejb3.TestLocalBusiness#echo(java.lang.String)
+    */
+   public String echo(String echo)
+   {
+      return echo;
+   }
+
 }

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestStatelessBean.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestStatelessBean.java	2009-07-20 21:23:03 UTC (rev 91449)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ejb3/TestStatelessBean.java	2009-07-20 21:24:39 UTC (rev 91450)
@@ -21,7 +21,7 @@
  */
 package org.jboss.test.profileservice.test.ejb3;
 
-import javax.ejb.Local;
+import javax.ejb.Remote;
 import javax.ejb.Stateless;
 
 /**
@@ -33,8 +33,15 @@
  * @version $Revision: $
  */
 @Stateless
- at Local(TestLocalBusiness.class)
+ at Remote(TestLocalBusiness.class)
 public class TestStatelessBean implements TestLocalBusiness
 {
-   // No business methods required
+   /*
+    * (non-Javadoc)
+    * @see org.jboss.test.profileservice.test.ejb3.TestLocalBusiness#echo(java.lang.String)
+    */
+   public String echo(String echo)
+   {
+      return echo;
+   }
 }




More information about the jboss-cvs-commits mailing list