[jboss-cvs] JBossAS SVN: r111087 - in projects/ejb3/trunk/testsuite: src/test/java/org/jboss/ejb3/test and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 1 09:09:21 EDT 2011


Author: wolfc
Date: 2011-04-01 09:09:21 -0400 (Fri, 01 Apr 2011)
New Revision: 111087

Added:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/Helper.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/HelperMBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/ReplyingMDB.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/unit/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/unit/SendMessagesTestCase.java
   projects/ejb3/trunk/testsuite/src/test/resources/test/jbas7922-mbean/
   projects/ejb3/trunk/testsuite/src/test/resources/test/jbas7922-mbean/META-INF/
   projects/ejb3/trunk/testsuite/src/test/resources/test/jbas7922-mbean/META-INF/jboss-service.xml
Modified:
   projects/ejb3/trunk/testsuite/build-test.xml
Log:
JBAPP-5516 / JBAS-7922: added unit test


Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml	2011-04-01 13:05:49 UTC (rev 111086)
+++ projects/ejb3/trunk/testsuite/build-test.xml	2011-04-01 13:09:21 UTC (rev 111087)
@@ -2455,6 +2455,24 @@
       <build-simple-jar name="jbas4489"/>
    </target>
    
+   <target name="jbas7922"
+      description="Builds a simple jar files."
+      >
+
+      <jar jarfile="${build.lib}/jbas7922.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/jbas7922/ReplyingMDB.class"/>
+         </fileset>
+      </jar>
+
+      <jar jarfile="${build.lib}/jbas7922-mbean.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/jbas7922/Helper*.class"/>
+         </fileset>
+         <fileset dir="${resources}/test/jbas7922-mbean"/>
+      </jar>
+   </target>
+
    <target name="jaxws"
       description="Builds a simple jar."
       >
@@ -4254,7 +4272,9 @@
       ejbthree2095,
       ejbthree2193,
       ejbthree2238,
-   	  jaxws, jbas4489, epcpropagation, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency,
+   	  jaxws, jbas4489,
+      jbas7922,
+      epcpropagation, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency,
       securitydomain, enventry, security5,
       jms/managed, naming, bmt, jca/inflowmdb, pool, jms, security, reference21_30, factory, dd/web, txexceptions,
       exception, dd/override, stateless, dd/mdb, bank, longlived, xmlcfg, hbm, pkg, regressionHHH275,
@@ -5102,6 +5122,9 @@
          <param name="test" value="jbas4489"/>
       </antcall>
       <antcall target="test" inheritRefs="true">
+         <param name="test" value="jbas7922"/>
+      </antcall>
+      <antcall target="test" inheritRefs="true">
          <param name="test" value="changexml"/>
       </antcall>
    </target>

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/Helper.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/Helper.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/Helper.java	2011-04-01 13:09:21 UTC (rev 111087)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2011, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.test.jbas7922;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class Helper implements HelperMBean
+{
+   public static final CyclicBarrier barrier = new CyclicBarrier(2);
+   
+   public int await(long timeout, TimeUnit unit) throws BrokenBarrierException, TimeoutException, InterruptedException
+   {
+      return barrier.await(timeout, unit);
+   }
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/HelperMBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/HelperMBean.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/HelperMBean.java	2011-04-01 13:09:21 UTC (rev 111087)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2011, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.test.jbas7922;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public interface HelperMBean
+{
+   int await(long timeout, TimeUnit unit) throws BrokenBarrierException, TimeoutException, InterruptedException;
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/ReplyingMDB.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/ReplyingMDB.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/ReplyingMDB.java	2011-04-01 13:09:21 UTC (rev 111087)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2011, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.test.jbas7922;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.*;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.TimeoutException;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static javax.jms.DeliveryMode.NON_PERSISTENT;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at MessageDriven(activationConfig =
+        {
+                @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+                @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/send"),
+                @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1"),
+                @ActivationConfigProperty(propertyName = "useDLQ", propertyValue = "false")
+        })
+public class ReplyingMDB implements MessageListener
+{
+   @Resource(mappedName="ConnectionFactory")
+   private QueueConnectionFactory factory;
+
+   private QueueConnection connection;
+   private QueueSession session;
+   private QueueSender sender;
+
+   public void onMessage(Message message)
+   {
+      try
+      {
+         TextMessage reply;
+         if(message instanceof TextMessage)
+         {
+            String text = ((TextMessage) message).getText();
+            if(text.equals("await"))
+            {
+               // we have received the first message
+               Helper.barrier.await(10, SECONDS);
+               Helper.barrier.reset();
+               // wait for undeploy
+               Helper.barrier.await(10, SECONDS);
+               Helper.barrier.reset();
+            }
+            reply = session.createTextMessage("Reply: " + text);
+         }
+         else
+         {
+            reply = session.createTextMessage("Unknown message");
+         }
+         Destination destination = message.getJMSReplyTo();
+         sender.send(destination, reply, NON_PERSISTENT, 1, SECONDS.toMillis(10));
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (InterruptedException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (BrokenBarrierException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (TimeoutException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   @PostConstruct
+   public void postConstruct()
+   {
+      try
+      {
+         connection = factory.createQueueConnection();
+         session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         sender = session.createSender(null);
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   @PreDestroy
+   public void preDestroy()
+   {
+      try
+      {
+         if(sender != null)
+            sender.close();
+         if(session != null)
+            session.close();
+         if(connection != null)
+            connection.close();
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/unit/SendMessagesTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/unit/SendMessagesTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/jbas7922/unit/SendMessagesTestCase.java	2011-04-01 13:09:21 UTC (rev 111087)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2011, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.test.jbas7922.unit;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import org.jboss.ejb3.test.common.EJB3TestCase;
+
+import javax.jms.*;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.*;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class SendMessagesTestCase extends EJB3TestCase
+{
+   private static final String JAR = "jbas7922.jar";
+   private static final String DEPLOYABLES = "jbas7922-mbean.jar," + JAR;
+
+   private ExecutorService executor = Executors.newSingleThreadExecutor();
+   
+   public SendMessagesTestCase(String name)
+   {
+      super(name);
+   }
+
+   private void await() throws Exception
+   {
+      MBeanServerConnection server = getServer();
+      ObjectName name = new ObjectName("jboss.ejb3:service=Helper");
+      long timeout = 10;
+      TimeUnit unit = TimeUnit.SECONDS;
+      Object[] params = { timeout, unit };
+      String[] sig = { long.class.getName(), TimeUnit.class.getName() };
+      server.invoke(name, "await", params, sig);
+   }
+
+   private static void sendMessage(QueueSession session, QueueSender sender, Queue replyQueue, String txt) throws JMSException
+   {
+      TextMessage msg = session.createTextMessage(txt);
+      msg.setJMSReplyTo(replyQueue);
+      //sender.send(msg, NON_PERSISTENT, 1, SECONDS.toMillis(10));
+      sender.send(msg);
+   }
+
+   public void testShutdown() throws Exception
+   {
+      Queue queue = lookup("queue/send", Queue.class);
+      Queue replyQueue = lookup("queue/reply", Queue.class);
+      QueueConnectionFactory factory = lookup("ConnectionFactory", QueueConnectionFactory.class);
+      QueueConnection connection = factory.createQueueConnection();
+      try
+      {
+         connection.start();
+         QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         QueueSender sender = session.createSender(queue);
+         QueueReceiver receiver = session.createReceiver(replyQueue);
+
+         SortedSet<String> expected = new TreeSet<String>();
+         sendMessage(session, sender, replyQueue, "await");
+         expected.add("Reply: await");
+
+         await(); // receive of first
+         Future<?> undeployed = executor.submit(undeployTask());
+         // Hmm, we really want to wait for MDB.stop going into the semaphore
+         Thread.sleep(1000);
+         for(int i = 0; i < 50; i++)
+         {
+            String msg = "Do not lose! (" + i + ")";
+            sendMessage(session, sender, replyQueue, msg); // should be bounced by BlockContainerShutdownInterceptor
+            expected.add("Reply: " + msg);
+         }
+         await(); // finalizing first
+         undeployed.get(10, SECONDS);
+
+         deploy(JAR);
+
+         for(int i = 0; i < 10; i++)
+         {
+            String msg = "Some more (" + i + ")";
+            sendMessage(session, sender, replyQueue, msg);
+            expected.add("Reply: " + msg);
+         }
+
+         SortedSet<String> received = new TreeSet<String>();
+         for(int i = 0; i < (1 + 50 + 10); i++)
+         {
+            Message msg = receiver.receive(SECONDS.toMillis(10));
+            assertNotNull(msg);
+            String text = ((TextMessage) msg).getText();
+            received.add(text);
+            log.info(i + ": " + text);
+         }
+
+         assertEquals(expected, received);
+
+         connection.stop();
+      }
+      finally
+      {
+         connection.close();
+      }
+   }
+
+   private Callable<Void> undeployTask()
+   {
+      return new Callable<Void>()
+      {
+         public Void call() throws Exception
+         {
+            SendMessagesTestCase.this.undeploy(JAR);
+            return null;
+         }
+      };
+   }
+
+   public static Test suite() throws Exception
+   {
+      return new TestSetup(getDeploySetup(SendMessagesTestCase.class, DEPLOYABLES))
+      {
+         @Override
+         protected void setUp() throws Exception
+         {
+            deployQueue("reply");
+            deployQueue("send");
+         }
+
+         @Override
+         protected void tearDown() throws Exception
+         {
+            undeployQueue("send");
+            undeployQueue("reply");
+         }
+      };
+   }
+}

Added: projects/ejb3/trunk/testsuite/src/test/resources/test/jbas7922-mbean/META-INF/jboss-service.xml
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/jbas7922-mbean/META-INF/jboss-service.xml	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/jbas7922-mbean/META-INF/jboss-service.xml	2011-04-01 13:09:21 UTC (rev 111087)
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+   <mbean code="org.jboss.ejb3.test.jbas7922.Helper" name="jboss.ejb3:service=Helper"/>
+</server>



More information about the jboss-cvs-commits mailing list