[jboss-cvs] JBossAS SVN: r99681 - in branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 20 17:23:07 EST 2010


Author: ALRubinger
Date: 2010-01-20 17:23:07 -0500 (Wed, 20 Jan 2010)
New Revision: 99681

Modified:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb/QueueTestMDB.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MetricsUnitTestCase.java
Log:
[JBPAPP-3479] Show failing test; inflow does not account for MDB invocation statistics

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb/QueueTestMDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb/QueueTestMDB.java	2010-01-20 22:21:31 UTC (rev 99680)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb/QueueTestMDB.java	2010-01-20 22:23:07 UTC (rev 99681)
@@ -21,21 +21,20 @@
  */
 package org.jboss.ejb3.test.mdb;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.annotation.security.RunAs;
 import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJB;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenContext;
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.InvocationContext;
-import javax.ejb.MessageDriven;
-import javax.ejb.MessageDrivenContext;
-import javax.ejb.EJB;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.annotation.Resource;
 import javax.jms.Message;
 import javax.jms.MessageListener;
 import javax.naming.InitialContext;
 
-import javax.annotation.security.RunAs;
-
 import org.jboss.annotation.ejb.PoolClass;
 import org.jboss.annotation.security.SecurityDomain;
 import org.jboss.logging.Logger;
@@ -50,7 +49,7 @@
       activationConfig =
         {
         @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
-        @ActivationConfigProperty(propertyName="destination", propertyValue="queue/mdbtest")
+        @ActivationConfigProperty(propertyName="destination", propertyValue=QueueTestMDB.NAME_QUEUE)
         })
 @PoolClass(value=org.jboss.ejb3.StrictMaxPool.class, maxSize=1, timeout=10000)
 @RunAs("TestRole")
@@ -59,6 +58,8 @@
 extends AbstractQueueTestMDB
 implements MessageListener, QueueTestInterface
 {
+   
+   public static final String NAME_QUEUE = "queue/mdbtest";
    private static final Logger log = Logger.getLogger(QueueTestMDB.class);
    
    @EJB(beanName="LocalStateless")

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MetricsUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MetricsUnitTestCase.java	2010-01-20 22:21:31 UTC (rev 99680)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MetricsUnitTestCase.java	2010-01-20 22:23:07 UTC (rev 99681)
@@ -21,57 +21,88 @@
  */
 package org.jboss.ejb3.test.mdb.unit;
 
+import java.util.Map;
+
+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.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.Context;
 
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.statistics.InvocationStatistics;
+import org.jboss.ejb3.test.mdb.QueueTestMDB;
 import org.jboss.logging.Logger;
 import org.jboss.test.JBossTestCase;
-import junit.framework.Test;
 
-import javax.management.ObjectName;
-
 /**
  * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
  */
-public class MetricsUnitTestCase
-extends JBossTestCase
+public class MetricsUnitTestCase extends JBossTestCase
 {
    private static final Logger log = Logger.getLogger(MetricsUnitTestCase.class);
 
+   /**
+    * Name of the Queue Connection Factory in JNDI
+    */
+   private static final String JNDI_NAME_CONNECTION_FACTORY = "ConnectionFactory";
 
    public MetricsUnitTestCase(String name)
    {
       super(name);
    }
-   
+
    public void testJmxMetrics() throws Exception
    {
-	   MBeanServerConnection server = getServer();
-      
+      MBeanServerConnection server = getServer();
+
       int size = 0;
-	      
+
       ObjectName testerName = new ObjectName("jboss.j2ee:jar=mdb-test.jar,name=QueueMDB,service=EJB3");
-      
-      size = (Integer)server.getAttribute(testerName, "MinPoolSize");
+
+      size = (Integer) server.getAttribute(testerName, "MinPoolSize");
       assertEquals(1, size);
-      
-      size = (Integer)server.getAttribute(testerName, "MaxPoolSize");
+
+      size = (Integer) server.getAttribute(testerName, "MaxPoolSize");
       assertEquals(1, size);
-      
-      size = (Integer)server.getAttribute(testerName, "MaxMessages");
+
+      size = (Integer) server.getAttribute(testerName, "MaxMessages");
       assertEquals(1, size);
-      
-      size = (Integer)server.getAttribute(testerName, "KeepAliveMillis");
+
+      size = (Integer) server.getAttribute(testerName, "KeepAliveMillis");
       assertEquals(60000, size);
-      
+
+      // Get the invocation stats
+      Map invokeStats = ((InvocationStatistics) server.getAttribute(testerName, "InvokeStats")).getStats();
+      log.info("Stats before invocation: " + invokeStats);
+      // Ensure stats are first empty
+      TestCase.assertTrue("Stats should be empty before invoked", invokeStats.isEmpty());
+      // Invoke by sending a message to the Queue
+      this.sendTextMessageToQueue("test", QueueTestMDB.NAME_QUEUE);
+      // Wait
+      Thread.sleep(2000L);
+      // Get stats again
+      invokeStats = ((InvocationStatistics) server.getAttribute(testerName, "InvokeStats")).getStats();
+      log.info("Stats after invocation: " + invokeStats);
+      // Check content
+      TestCase.assertEquals("Stats should have been invoked once", 1, invokeStats.size());
+
       testerName = new ObjectName("jboss.j2ee:jar=mdb-test.jar,name=TransactionQueueTestMDB,service=EJB3");
-      
-      size = (Integer)server.getAttribute(testerName, "MaxPoolSize");
+
+      size = (Integer) server.getAttribute(testerName, "MaxPoolSize");
       assertEquals(1, size);
-      
+
       testerName = new ObjectName("jboss.j2ee:jar=mdb-test.jar,name=DefaultedQueueTestMDB,service=EJB3");
-      
-      size = (Integer)server.getAttribute(testerName, "MaxPoolSize");
+
+      size = (Integer) server.getAttribute(testerName, "MaxPoolSize");
       assertEquals(30, size);
+
    }
 
    public static Test suite() throws Exception
@@ -79,4 +110,50 @@
       return getDeploySetup(MetricsUnitTestCase.class, "mdbtest-${jboss.jms.provider}-service.xml, mdb-test.jar");
    }
 
+   /**
+    * Sends a JMS {@link TextMessage} containing the specified contents to the 
+    * queue of the specified name  
+    * 
+    * @param contents
+    * @param queueName
+    * @throws Exception
+    * @throws IllegalArgumentException If either argument is not provided
+    */
+   private void sendTextMessageToQueue(final String contents, final String queueName) throws Exception,
+         IllegalArgumentException
+   {
+      // Precondition check
+      if (contents == null || contents.length() == 0)
+      {
+         throw new IllegalArgumentException("contents must be provided");
+      }
+      if (queueName == null || queueName.length() == 0)
+      {
+         throw new IllegalArgumentException("queueName must be provided");
+      }
+
+      // Get the queue from JNDI
+      final Context context = this.getInitialContext();
+      final Queue queue = (Queue) context.lookup(queueName);
+
+      // Get the ConnectionFactory from JNDI
+      final QueueConnectionFactory factory = (QueueConnectionFactory) context.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 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();
+   }
+
 }




More information about the jboss-cvs-commits mailing list