[jboss-cvs] JBossAS SVN: r91207 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/test/org/jboss/ejb3/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 14 09:01:24 EDT 2009
Author: wolfc
Date: 2009-07-14 09:01:24 -0400 (Tue, 14 Jul 2009)
New Revision: 91207
Added:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/StressQueueBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/StressQueueRemote.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/TransactionMDB.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/unit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
Log:
JBPAPP-2260: unit test
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2009-07-14 12:27:47 UTC (rev 91206)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2009-07-14 13:01:24 UTC (rev 91207)
@@ -2207,6 +2207,18 @@
</jar>
</target>
+ <target name="jbpapp2260"
+ description="Builds a simple jar files."
+ depends="compile-classes">
+
+ <jar jarfile="${build.lib}/jbpapp2260.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/common/*.class"/>
+ <include name="org/jboss/ejb3/test/jbpapp2260/*.class"/>
+ </fileset>
+ </jar>
+ </target>
+
<target name="jaxws"
description="Builds a simple jar."
depends="compile-classes">
@@ -3908,6 +3920,7 @@
jbpapp1224,
jbpapp1668,
jbpapp1951,
+ jbpapp2260,
jbas4489, epcpropagation, jaccpropagation,
aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, jaxws,
pkg, securitydomain, enventry, externalpersistenceunit,
@@ -4561,6 +4574,9 @@
<antcall target="test" inheritRefs="true">
<param name="test" value="jbpapp1951"/>
</antcall>
+ <antcall target="test" inheritRefs="true">
+ <param name="test" value="jbpapp2260"/>
+ </antcall>
</target>
<target name="entity-tests" depends="init" description="Execute all tests">
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/StressQueueBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/StressQueueBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/StressQueueBean.java 2009-07-14 13:01:24 UTC (rev 91207)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.jbpapp2260;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateless;
+import javax.jms.DeliveryMode;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+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;
+
+/**
+ * Create some messages on a queue within the same VM.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+//@TransactionManagement(TransactionManagementType.BEAN)
+public class StressQueueBean implements StressQueueRemote
+{
+ private static final Logger log = Logger.getLogger(StressQueueBean.class);
+
+ private static final String QUEUE_NAME = "jbpapp2260";
+
+ @Resource(mappedName="java:/JmsXA")
+ private QueueConnectionFactory factory;
+
+ @Resource(mappedName="queue/" + QUEUE_NAME)
+ private Queue queue;
+
+ public void fireMessages(int num) throws Exception
+ {
+ QueueConnection conn = factory.createQueueConnection();
+ try
+ {
+ QueueSession session = conn.createQueueSession(true, QueueSession.SESSION_TRANSACTED);
+ TemporaryQueue replyQueue = session.createTemporaryQueue();
+ QueueReceiver receiver = session.createReceiver(replyQueue);
+ QueueSender sender = session.createSender(queue);
+ conn.start();
+ try
+ {
+ log.info("Firing messages...");
+
+ for(int i = 0; i < num; i++)
+ {
+ TextMessage msg = session.createTextMessage("message #" + i);
+ msg.setJMSReplyTo(replyQueue);
+ msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 1);
+
+ sender.send(msg);
+ }
+
+ //session.commit();
+
+ /*
+ log.info("Waiting for replies...");
+
+ for(int i = 0; i < num; i++)
+ {
+ Message reply = receiver.receive(5000);
+ if(reply == null)
+ throw new IllegalStateException("received null reply");
+
+ Serializable obj = ((ObjectMessage) reply).getObject();
+ if(obj instanceof Exception)
+ throw (Exception) obj;
+ }
+ */
+
+ log.info("Sleeping...");
+ Thread.sleep(40000);
+
+ log.info("Done");
+ }
+ finally
+ {
+ //conn.stop();
+ sender.close();
+ receiver.close();
+ session.close();
+ }
+ }
+ finally
+ {
+ conn.close();
+ }
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/StressQueueRemote.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/StressQueueRemote.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/StressQueueRemote.java 2009-07-14 13:01:24 UTC (rev 91207)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.jbpapp2260;
+
+import javax.ejb.Remote;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Remote
+public interface StressQueueRemote
+{
+ void fireMessages(int num) throws Exception;
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/TransactionMDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/TransactionMDB.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/TransactionMDB.java 2009-07-14 13:01:24 UTC (rev 91207)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.jbpapp2260;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.ejb3.test.common.AbstractReplierMDB;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig = {
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/jbpapp2260"),
+ @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1"),
+ @ActivationConfigProperty(propertyName = "dLQMaxResent", propertyValue = "1"),
+ @ActivationConfigProperty(propertyName = "maxMessages", propertyValue = "50") })
+public class TransactionMDB extends AbstractReplierMDB
+{
+ private static final Logger log = Logger.getLogger(TransactionMDB.class);
+
+ // this goes against spec, normally you would use BMT and UserTransaction
+ @Resource(mappedName="java:/TransactionManager")
+ private TransactionManager tm;
+
+ private ConcurrentHashMap<String, AtomicInteger> stats = new ConcurrentHashMap<String, AtomicInteger>();
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ log.info(Thread.currentThread() + " " + this + " " + tm.getTransaction());
+ // The original plan was to get the tx in a rollback state and then
+ // observe the next message failing. This has a drawback that communicating
+ // back to the test case is a bit awkward.
+// if(message instanceof TextMessage)
+// {
+// String cmd = ((TextMessage) message).getText();
+// if(cmd.equals("abort"))
+// {
+// log.info("setting tx to rollback only");
+// tm.setRollbackOnly();
+// }
+// else if(cmd.equals("RuntimeException"))
+// {
+// log.info("throwing a RuntimeException");
+// throw new RuntimeException("throw it");
+// }
+// }
+ // So instead let's keep track of the transactions.
+ String key = tm.getTransaction().toString();
+ if(stats.get(key) == null)
+ stats.put(key, new AtomicInteger());
+ stats.get(key).incrementAndGet();
+ // a minimal sleep to make sure we build up some backlog
+ sleep(10, MILLISECONDS);
+ sendReply(message.getJMSReplyTo(), stats);
+ }
+ catch(JMSException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (SystemException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void sleep(int duration, TimeUnit unit)
+ {
+ long millis = MILLISECONDS.convert(duration, unit);
+ try
+ {
+ Thread.sleep(millis);
+ }
+ catch(InterruptedException e)
+ {
+ // ignore
+ }
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java 2009-07-14 13:01:24 UTC (rev 91207)
@@ -0,0 +1,235 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.jbpapp2260.unit;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+import javax.management.ObjectName;
+import javax.transaction.Status;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.common.EJB3TestCase;
+import org.jboss.ejb3.test.jbpapp2260.StressQueueRemote;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MessageInflowTransactionUnitTestCase extends EJB3TestCase
+{
+ private static final Logger log = Logger.getLogger(MessageInflowTransactionUnitTestCase.class);
+
+ private static final String QUEUE_NAME = "jbpapp2260";
+
+ public MessageInflowTransactionUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public Object sendMessage(String queueName, String text) throws Exception
+ {
+ return sendMessage(queueName, text, 1);
+ }
+
+ public Object sendMessage(String queueName, String text, int redeliveryLimit) throws Exception
+ {
+ Queue queue = lookup("queue/" + queueName, Queue.class);
+ QueueConnectionFactory factory = getQueueConnectionFactory();
+ QueueConnection conn = factory.createQueueConnection();
+ try
+ {
+ QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ TemporaryQueue replyQueue = session.createTemporaryQueue();
+ QueueReceiver receiver = session.createReceiver(replyQueue);
+ QueueSender sender = session.createSender(queue);
+ conn.start();
+ try
+ {
+ TextMessage msg = session.createTextMessage(text);
+ msg.setJMSReplyTo(replyQueue);
+ msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", redeliveryLimit);
+
+ sender.send(msg);
+
+ Message reply = receiver.receive(5000);
+ assertNotNull(reply);
+
+ Serializable obj = ((ObjectMessage) reply).getObject();
+ if(obj instanceof Exception)
+ throw (Exception) obj;
+ else
+ return obj;
+ }
+ finally
+ {
+ conn.stop();
+ sender.close();
+ receiver.close();
+ session.close();
+ }
+ }
+ finally
+ {
+ conn.close();
+ }
+ }
+
+ public void _testBreak() throws Exception
+ {
+ Object result = sendMessage(QUEUE_NAME, "abort");
+ System.out.println("testBreak: result = " + result);
+ }
+
+ public void testDefault() throws Exception
+ {
+ Map<String, AtomicInteger> result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
+ int base = result.size();
+ result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
+ assertEquals(base + 1, result.size());
+ result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
+ assertEquals(base + 2, result.size());
+ }
+
+ public void _testDefault2() throws Exception
+ {
+ StressQueueRemote bean = lookup("StressQueueBean/remote", StressQueueRemote.class);
+
+ bean.fireMessages(100);
+ }
+
+ public void _testRuntimeException() throws Exception
+ {
+ ObjectName name = new ObjectName("jboss.j2ee:jar=jbpapp2260.jar,name=TransactionMDB,service=EJB3");
+ getServer().invoke(name, "startDelivery", null, null);
+ try
+ {
+ Object result = sendMessage(QUEUE_NAME, "RuntimeException", 2);
+ assertEquals("Wrong transaction status", Status.STATUS_ACTIVE, result);
+// result = sendMessage(QUEUE_NAME, "RuntimeException");
+// assertEquals("Wrong transaction status", Status.STATUS_ACTIVE, result);
+// result = sendMessage(QUEUE_NAME, "RuntimeException");
+// assertEquals("Wrong transaction status", Status.STATUS_ACTIVE, result);
+ }
+ finally
+ {
+ getServer().invoke(name, "stopDelivery", null, null);
+ }
+ }
+
+ public void testStress() throws Exception
+ {
+ Map<String, AtomicInteger> result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
+ int base = result.size();
+
+ Queue queue = lookup("queue/" + QUEUE_NAME, Queue.class);
+ QueueConnectionFactory factory = getQueueConnectionFactory();
+ QueueConnection conn = factory.createQueueConnection();
+ try
+ {
+ QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ TemporaryQueue replyQueue = session.createTemporaryQueue();
+ QueueReceiver receiver = session.createReceiver(replyQueue);
+ QueueSender sender = session.createSender(queue);
+ conn.start();
+ try
+ {
+ log.info("Firing messages...");
+
+ for(int i = 0; i < 100; i++)
+ {
+ TextMessage msg = session.createTextMessage("message #" + i);
+ msg.setJMSReplyTo(replyQueue);
+ msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 1);
+
+ sender.send(msg);
+ }
+
+ log.info("Waiting for replies...");
+
+ for(int i = 0; i < 100; i++)
+ {
+ Message reply = receiver.receive(5000);
+ assertNotNull(reply);
+
+ Serializable obj = ((ObjectMessage) reply).getObject();
+ if(obj instanceof Exception)
+ throw (Exception) obj;
+
+ result = (Map<String, AtomicInteger>) obj;
+ assertEquals("Message was not delivered in unique transaction", base + 1 + i, result.size());
+ }
+
+ log.info("Done");
+ }
+ finally
+ {
+ conn.stop();
+ sender.close();
+ receiver.close();
+ session.close();
+ }
+ }
+ finally
+ {
+ conn.close();
+ }
+ }
+
+ public void _testStress2() throws Exception
+ {
+ StressQueueRemote bean = lookup("StressQueueBean/remote", StressQueueRemote.class);
+
+ ObjectName name = new ObjectName("jboss.j2ee:jar=jbpapp2260.jar,name=TransactionMDB,service=EJB3");
+ getServer().invoke(name, "startDelivery", null, null);
+
+ try
+ {
+ bean.fireMessages(100);
+ }
+ finally
+ {
+ getServer().invoke(name, "stopDelivery", null, null);
+ }
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(MessageInflowTransactionUnitTestCase.class, "jbpapp2260.jar");
+ }
+}
More information about the jboss-cvs-commits
mailing list