[jboss-cvs] JBossAS SVN: r66818 - in branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 7 09:01:20 EST 2007


Author: wolfc
Date: 2007-11-07 09:01:19 -0500 (Wed, 07 Nov 2007)
New Revision: 66818

Added:
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/MDBCallable.java
Removed:
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/MDBInvoker.java
Modified:
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/StrictlyPooledMDB.java
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/StrictPoolUnitTestCase.java
Log:
JBPAPP-347: fixed strictpool message driven test (no EJBTHREE-1003)

Deleted: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/MDBInvoker.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/MDBInvoker.java	2007-11-07 13:12:18 UTC (rev 66817)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/MDBInvoker.java	2007-11-07 14:01:19 UTC (rev 66818)
@@ -1,89 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.test.strictpool;
-
-import javax.jms.QueueSession;
-import javax.jms.Queue;
-import javax.jms.QueueSender;
-import javax.jms.TextMessage;
-import javax.jms.QueueReceiver;
-import javax.jms.Message;
-import javax.jms.ObjectMessage;
-
-import EDU.oswego.cs.dl.util.concurrent.CountDown;
-import org.jboss.logging.Logger;
-
-/**
- * Adapted from the EJB 2.1 tests (org.jboss.test.cts.test.SessionInvoker)
- * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
- * @version $Revision$
- */
-public class MDBInvoker extends Thread
-{
-   QueueSession session;
-   Queue queueA;
-   Queue queueB;
-   int id;
-   CountDown done;
-   public Exception runEx;
-
-   public MDBInvoker(QueueSession session, Queue queueA, Queue queueB, int id, CountDown done)
-   {
-      super("MDBInvoker#"+id);
-      this.session = session;
-      this.queueA = queueA;
-      this.queueB = queueB;
-      this.id = id;
-      this.done = done;
-   }
-   public void run()
-   {
-      System.out.println("Begin run, this="+this);
-      try
-      {
-         QueueSender sender = session.createSender(queueA);
-         TextMessage message = session.createTextMessage();
-         message.setText(this.toString());
-         sender.send(message);
-         QueueReceiver receiver = session.createReceiver(queueB);
-         Message reply = receiver.receive(20000);
-         if( reply == null )
-         {
-            runEx = new IllegalStateException("Message receive timeout");
-         }
-         else
-         {
-            Message tm = (Message) reply;
-            System.out.println(tm);
-         }
-         sender.close();
-         receiver.close();
-      }
-      catch(Exception e)
-      {
-         runEx = e;
-      }
-      done.release();
-      System.out.println("End run, this="+this);
-   }
-
-}

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/StrictlyPooledMDB.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/StrictlyPooledMDB.java	2007-11-07 13:12:18 UTC (rev 66817)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/StrictlyPooledMDB.java	2007-11-07 14:01:19 UTC (rev 66818)
@@ -26,6 +26,7 @@
 import javax.ejb.EJBException;
 import javax.ejb.MessageDriven;
 import javax.ejb.MessageDrivenContext;
+import javax.jms.DeliveryMode;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageListener;
@@ -39,6 +40,7 @@
 
 import org.jboss.annotation.ejb.PoolClass;
 import org.jboss.annotation.ejb.PoolClass;
+import org.jboss.logging.Logger;
 
 /**
  * Adapted from the EJB 2.1 tests (org.jboss.test.cts.ejb.StrictlyPooledMDB)
@@ -50,12 +52,15 @@
         @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
         @ActivationConfigProperty(propertyName="destination", propertyValue="queue/queueA"),
         @ActivationConfigProperty(propertyName="maxMessages", propertyValue="10"),
-        @ActivationConfigProperty(propertyName="minSession", propertyValue="10"),
-        @ActivationConfigProperty(propertyName="maxSession", propertyValue="10")
+        @ActivationConfigProperty(propertyName="minSession", propertyValue="2"),
+        @ActivationConfigProperty(propertyName="maxSession", propertyValue="2")
         })
- at PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=StrictlyPooledMDB.maxActiveCount, timeout=10000)
+// EJBTHREE-1003 is not implemented in EAP 4
+//@PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=StrictlyPooledMDB.maxActiveCount, timeout=10000)
 public class StrictlyPooledMDB implements MessageListener
 {
+   private static final Logger log = Logger.getLogger(StrictlyPooledMDB.class);
+   
    /** The class wide max count of instances allows */
    public static final int maxActiveCount = 2;
    /** The class wide count of instances active in business code */
@@ -78,7 +83,7 @@
    @Resource public void setMessageDrivenContext(MessageDrivenContext ctx)
       throws EJBException
    {
-      System.out.println("setMessageDrivenContext()");
+      log.info("setMessageDrivenContext()");
       this.ctx = ctx;
       try
       {
@@ -86,12 +91,12 @@
          QueueConnectionFactory factory = (QueueConnectionFactory) iniCtx.lookup("java:/ConnectionFactory");
          queConn = factory.createQueueConnection();
          session = queConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-         Queue queue = (Queue) iniCtx.lookup("queue/queueB");
-         sender = session.createSender(queue);
+         sender = session.createSender(null);
+         sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
       }
       catch(Exception e)
       {
-         System.out.println("Setup failure");
+         log.info("Setup failure");
          e.printStackTrace();
          throw new EJBException("Setup failure", e);
       }
@@ -114,7 +119,7 @@
       }
       catch(Exception e)
       {
-         System.out.println("Failed to close JMS resources");
+         log.info("Failed to close JMS resources");
          e.printStackTrace();
       }
    }
@@ -122,7 +127,7 @@
    public void onMessage(Message message)
    {
       int count = incActiveCount();
-      System.out.println("Begin onMessage, activeCount="+count+", ctx="+ctx);
+      log.info("Begin onMessage, activeCount="+count+", ctx="+ctx);
       try
       {
          Message reply = null;
@@ -140,12 +145,12 @@
             // Send an ack
             reply = session.createTextMessage("Recevied msg="+tm.getText());
          }
-         Thread.currentThread().sleep(1000);
-         sender.send(reply);
+         Thread.sleep(1000);
+         sender.send(message.getJMSReplyTo(), reply);
       }
       catch(JMSException e)
       {
-         System.out.println("Failed to send error message");
+         log.info("Failed to send error message");
          e.printStackTrace();
       }
       catch(InterruptedException e)
@@ -154,7 +159,7 @@
       finally
       {
          count = decActiveCount();
-         System.out.println("End onMessage, activeCount="+count+", ctx="+ctx);
+         log.info("End onMessage, activeCount="+count+", ctx="+ctx);
       }
    }
 }

Added: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/MDBCallable.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/MDBCallable.java	                        (rev 0)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/MDBCallable.java	2007-11-07 14:01:19 UTC (rev 66818)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.strictpool.unit;
+
+import java.util.concurrent.Callable;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Send a JMS text message and expect a reply.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MDBCallable implements Callable<String>
+{
+   private static final Logger log = Logger.getLogger(MDBCallable.class);
+   
+   private QueueConnection connection;
+   private Queue queue;
+   private String text;
+   
+   public MDBCallable(QueueConnection connection, Queue queue, String text)
+   {
+      assert connection != null : "connection is null";
+      assert queue != null : "queue is null";
+      assert text != null : "text is null";
+      
+      this.connection = connection;
+      this.queue = queue;
+      this.text = text;
+   }
+   
+   public String call() throws Exception
+   {
+      log.info("start mdb call " + this);
+      // JMS 1.1 4.4.6: since we're concurrent, let's create our own session
+      QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+      try
+      {
+         TemporaryQueue replyQueue = session.createTemporaryQueue();
+         QueueReceiver receiver = session.createReceiver(replyQueue);
+         
+         QueueSender sender = session.createSender(queue);
+         sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         TextMessage message = session.createTextMessage();
+         message.setJMSReplyTo(replyQueue);
+         message.setText(text);
+         sender.send(message);
+         sender.close();
+         
+         Message reply = receiver.receive(20000);
+         receiver.close();
+         replyQueue.delete();
+         
+         if(reply instanceof TextMessage)
+            return ((TextMessage) reply).getText();
+         
+         if(reply instanceof ObjectMessage)
+         {
+            Object obj = ((ObjectMessage) reply).getObject();
+            if(obj instanceof Exception)
+               throw (Exception) obj;
+            
+            if(obj instanceof String)
+               return (String) obj;
+            
+            throw new IllegalStateException("Can't handle " + obj);
+         }
+         
+         throw new IllegalStateException("Can't handle " + reply);
+      }
+      finally
+      {
+         session.close();
+         log.info("end mdb call " + this);
+      }
+   }
+}


Property changes on: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/MDBCallable.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/StrictPoolUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/StrictPoolUnitTestCase.java	2007-11-07 13:12:18 UTC (rev 66817)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/unit/StrictPoolUnitTestCase.java	2007-11-07 14:01:19 UTC (rev 66818)
@@ -21,15 +21,31 @@
  */
 package org.jboss.ejb3.test.strictpool.unit;
 
-import javax.jms.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.jms.TextMessage;
 import javax.naming.InitialContext;
-import org.jboss.ejb3.test.strictpool.MDBInvoker;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.strictpool.Counter;
 import org.jboss.ejb3.test.strictpool.SessionInvoker;
 import org.jboss.ejb3.test.strictpool.StrictlyPooledSession;
-import org.jboss.ejb3.test.strictpool.Counter;
 import org.jboss.test.JBossTestCase;
+
 import EDU.oswego.cs.dl.util.concurrent.CountDown;
-import junit.framework.Test;
 
 
 /**
@@ -81,37 +97,39 @@
    public void testMessageDriven() throws Exception
    {
       System.out.println("*** testMessageDriven");
-      CountDown done = new CountDown(MAX_SIZE);
       InitialContext ctx = new InitialContext();
       QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup(QUEUE_FACTORY);
       QueueConnection queConn = factory.createQueueConnection();
-      QueueSession session = queConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
       Queue queueA = (Queue) ctx.lookup("queue/queueA");
-      Queue queueB = (Queue) ctx.lookup("queue/queueB");
       queConn.start();
-      MDBInvoker[] threads = new MDBInvoker[MAX_SIZE];
+      ExecutorService executor = Executors.newFixedThreadPool(MAX_SIZE);
+      List<Future<String>> results = new ArrayList<Future<String>>();
       for(int n = 0; n < MAX_SIZE; n ++)
       {
-         MDBInvoker t = new MDBInvoker(session, queueA, queueB, n, done);
-         threads[n] = t;
-         t.start();
+         results.add(executor.submit(new MDBCallable(queConn, queueA, "message " + n)));
       }
-      assertTrue("Acquired done", done.attempt(1500 * MAX_SIZE));
-      session.close();
+      executor.shutdown();
+      boolean terminated = executor.awaitTermination(MAX_SIZE * 2, TimeUnit.SECONDS);
+      if(!terminated)
+      {
+         for(Future<String> result : results)
+         {
+            result.cancel(true);
+         }
+         fail("executor failed to terminate in time");
+      }
       queConn.close();
 
       for(int n = 0; n < MAX_SIZE; n ++)
       {
-         MDBInvoker t = threads[n];
-         if( t.runEx != null )
-         {
-            t.runEx.printStackTrace();
-            fail("Inovker.runEx != null, msg="+t.runEx.getMessage());
-         }
+         String result = results.get(n).get();
+         assertEquals("Recevied msg=message " + n, result);
       }
    }
+   
    public void testPoolTimeout() throws Exception
    {
+      System.out.println("*** testPoolTimeout");
       InitialContext ctx = new InitialContext();
       ConnectionFactory factory = (ConnectionFactory)ctx.lookup("ConnectionFactory");
       Connection conn = factory.createConnection();
@@ -126,7 +144,7 @@
       TextMessage msg2 = session.createTextMessage("hello world 2");
       msg2.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 1);
       sender.send(msg2);
-
+      
       Thread.sleep(5000);
       Counter counter = (Counter)ctx.lookup("CounterBean/remote");
       assertEquals(1, counter.getCount());




More information about the jboss-cvs-commits mailing list