[jboss-cvs] JBossAS SVN: r61746 - trunk/testsuite/src/main/org/jboss/test/messagedriven/support.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 27 11:45:34 EDT 2007


Author: adrian at jboss.org
Date: 2007-03-27 11:45:34 -0400 (Tue, 27 Mar 2007)
New Revision: 61746

Modified:
   trunk/testsuite/src/main/org/jboss/test/messagedriven/support/BasicMessageDrivenUnitTest.java
   trunk/testsuite/src/main/org/jboss/test/messagedriven/support/JMSContainerInvokerSimpleMessageDrivenUnitTest.java
   trunk/testsuite/src/main/org/jboss/test/messagedriven/support/SendMessageOperation.java
Log:
[JBAS-4247] - Fix this broken test where the exception listener was not being installed and the sendMessage was not retrying

Modified: trunk/testsuite/src/main/org/jboss/test/messagedriven/support/BasicMessageDrivenUnitTest.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/messagedriven/support/BasicMessageDrivenUnitTest.java	2007-03-27 15:44:37 UTC (rev 61745)
+++ trunk/testsuite/src/main/org/jboss/test/messagedriven/support/BasicMessageDrivenUnitTest.java	2007-03-27 15:45:34 UTC (rev 61746)
@@ -1,24 +1,24 @@
 /*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt 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.
-  */
+ * 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.test.messagedriven.support;
 
 import java.util.ArrayList;
@@ -28,6 +28,8 @@
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
@@ -44,7 +46,7 @@
  * @author <a href="mailto:adrian at jboss.com>Adrian Brock</a>
  * @version <tt>$Revision: 1.4</tt>
  */
-public abstract class BasicMessageDrivenUnitTest extends JBossTestCase
+public abstract class BasicMessageDrivenUnitTest extends JBossTestCase implements ExceptionListener
 {
    protected static final long WAIT_TIME = 5000L;
    protected static final long REPEATED_WAIT = 4;
@@ -176,6 +178,7 @@
       
       ConnectionFactory factory = (ConnectionFactory) lookup(connectionFactoryJNDI, ConnectionFactory.class);
       connection = factory.createConnection();
+      connection.setExceptionListener(this);
       return connection;
    }
    
@@ -186,9 +189,26 @@
 
       ConnectionFactory factory = (ConnectionFactory) lookup(connectionFactoryJNDI, ConnectionFactory.class);
       connection = factory.createConnection(user, password);
+      connection.setExceptionListener(this);
       return connection;
    }
    
+   public void onException(JMSException e)
+   {
+      log.debug("Notified of error", e);
+      Connection temp = connection;
+      connection = null;
+      try
+      {
+         if (temp != null)
+            temp.close();
+      }
+      catch (JMSException ignored)
+      {
+         log.debug("Ignored ", ignored);
+      }
+   }
+   
    public Message getTestMessage() throws Exception
    {
       return getSession().createMessage();
@@ -196,7 +216,6 @@
 
    protected void setUp() throws Exception
    {
-      super.setUp();
       if ("testServerFound".equals(getName()))
          return;
       deploy(mbeansar);
@@ -214,7 +233,6 @@
       {
          getLog().error("Error undeploying: " + mbeansar, t);
       }
-      super.tearDown();
    }
    
    protected void startTest(Properties props) throws Exception
@@ -227,6 +245,8 @@
       deploy(getMDBDeployment());
       try
       {
+         // FIXME Need to wait for asynchrounous bootstrap of container
+         Thread.sleep(5000);
          startReceiverThread();
       }
       catch (Exception e)
@@ -335,6 +355,18 @@
       getServer().invoke(name, "stopDelivery", new Object[0], new String[0]);
    }
    
+   protected void start(ObjectName name) throws Exception
+   {
+      getServer().invoke(name, "create", new Object[0], new String[0]);
+      getServer().invoke(name, "start", new Object[0], new String[0]);
+   }
+   
+   protected void stop(ObjectName name) throws Exception
+   {
+      getServer().invoke(name, "stop", new Object[0], new String[0]);
+      getServer().invoke(name, "destroy", new Object[0], new String[0]);
+   }
+   
    protected void initProperties(Properties props) throws Exception
    {
       getLog().info("Init properties " + props);

Modified: trunk/testsuite/src/main/org/jboss/test/messagedriven/support/JMSContainerInvokerSimpleMessageDrivenUnitTest.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/messagedriven/support/JMSContainerInvokerSimpleMessageDrivenUnitTest.java	2007-03-27 15:44:37 UTC (rev 61745)
+++ trunk/testsuite/src/main/org/jboss/test/messagedriven/support/JMSContainerInvokerSimpleMessageDrivenUnitTest.java	2007-03-27 15:45:34 UTC (rev 61746)
@@ -1,24 +1,24 @@
 /*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt 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.
-  */
+ * 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.test.messagedriven.support;
 
 import java.util.Properties;
@@ -35,13 +35,15 @@
  */
 public abstract class JMSContainerInvokerSimpleMessageDrivenUnitTest extends SimpleMessageDrivenUnitTest
 {
+   protected ObjectName persistenceManager = ObjectNameFactory.create("jboss.mq:service=PersistenceManager");
+   
    protected ObjectName mdbInvoker = ObjectNameFactory.create("jboss.j2ee:service=EJB,jndiName=TestMDB,plugin=invoker,binding=jms-container-invoker-driven-bean");
    
    public JMSContainerInvokerSimpleMessageDrivenUnitTest(String name, ObjectName jmxDestination, Properties defaultProps)
    {
       super(name, jmxDestination, defaultProps);
    }
-   
+
    public void testDeliveryActive() throws Exception
    {
       Properties props = (Properties) defaultProps.clone();

Modified: trunk/testsuite/src/main/org/jboss/test/messagedriven/support/SendMessageOperation.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/messagedriven/support/SendMessageOperation.java	2007-03-27 15:44:37 UTC (rev 61745)
+++ trunk/testsuite/src/main/org/jboss/test/messagedriven/support/SendMessageOperation.java	2007-03-27 15:45:34 UTC (rev 61746)
@@ -1,26 +1,27 @@
 /*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt 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.
-  */
+ * 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.test.messagedriven.support;
 
+import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageProducer;
 
@@ -44,9 +45,26 @@
 
    public void run() throws Exception
    {
-      MessageProducer producer = test.getMessageProducer();
-      Message message = test.getTestMessage();
-      message.setStringProperty(MESSAGEID, id);
-      producer.send(message);
+      int retries = 5;
+      while (true)
+      {
+         try
+         {
+            MessageProducer producer = test.getMessageProducer();
+            Message message = test.getTestMessage();
+            message.setStringProperty(MESSAGEID, id);
+            producer.send(message);
+            // DONE
+            return;
+         }
+         catch (JMSException e)
+         {
+            // Got an error, sleep then retry
+            if (retries-- > 0)
+               Thread.sleep(1000);
+            else
+               throw e;
+         }
+      }
    }
 }




More information about the jboss-cvs-commits mailing list