[jboss-cvs] JBossAS SVN: r67009 - in trunk/ejb3/src: test/org/jboss/ejb3/test/mdbtransactions and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 13 04:51:52 EST 2007
Author: wolfc
Date: 2007-11-13 04:51:52 -0500 (Tue, 13 Nov 2007)
New Revision: 67009
Added:
trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/BadCreationMDB.java
trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java
Modified:
trunk/ejb3/src/resources/test/mdbtransactions/mdbtransactionstest-service.xml
trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueTestMDB.java
trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/RollbackQueueTestMDB.java
trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacadeBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java
Log:
Merged 63280, 66861 and 66994: EJBTHREE-783 and JBM integration
Modified: trunk/ejb3/src/resources/test/mdbtransactions/mdbtransactionstest-service.xml
===================================================================
--- trunk/ejb3/src/resources/test/mdbtransactions/mdbtransactionstest-service.xml 2007-11-13 09:27:51 UTC (rev 67008)
+++ trunk/ejb3/src/resources/test/mdbtransactions/mdbtransactionstest-service.xml 2007-11-13 09:51:52 UTC (rev 67009)
@@ -6,6 +6,11 @@
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
</mbean>
<mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.mq.destination:service=Queue,name=badcreationtest">
+ <attribute name="JNDIName">queue/badcreationmdb</attribute>
+ <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+ </mbean>
+ <mbean code="org.jboss.mq.server.jmx.Queue"
name="jboss.mq.destination:service=Queue,name=rollbackqueuetest">
<attribute name="JNDIName">queue/rollbackmdbtest</attribute>
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
@@ -14,5 +19,22 @@
name="jboss.mq.destination:service=Queue,name=queue21test">
<attribute name="JNDIName">queue/mdb21test</attribute>
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
- </mbean>
+ </mbean>
+
+ <!-- there have nothing to do with the test itself, just to test preconditions -->
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.mq.destination:service=Queue,name=A">
+ <attribute name="JNDIName">queue/A</attribute>
+ <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+ </mbean>
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.mq.destination:service=Queue,name=B">
+ <attribute name="JNDIName">queue/B</attribute>
+ <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+ </mbean>
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.mq.destination:service=Queue,name=C">
+ <attribute name="JNDIName">queue/C</attribute>
+ <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+ </mbean>
</server>
Copied: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/BadCreationMDB.java (from rev 66949, branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/BadCreationMDB.java)
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/BadCreationMDB.java (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/BadCreationMDB.java 2007-11-13 09:51:52 UTC (rev 67009)
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+package org.jboss.ejb3.test.mdbtransactions;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJB;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at MessageDriven(activationConfig =
+ {
+ @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName="destination", propertyValue="queue/badcreationmdb")
+ })
+public class BadCreationMDB implements MessageListener
+{
+ private static final Logger log = Logger.getLogger(BadCreationMDB.class);
+
+ @EJB(mappedName="bogus") StatelessFacade stateless;
+
+ public void onMessage(Message recvMsg)
+ {
+ log.info("*** onMessage " + recvMsg);
+ }
+}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueTestMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueTestMDB.java 2007-11-13 09:27:51 UTC (rev 67008)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueTestMDB.java 2007-11-13 09:51:52 UTC (rev 67009)
@@ -22,14 +22,13 @@
package org.jboss.ejb3.test.mdbtransactions;
import javax.ejb.ActivationConfigProperty;
-import javax.ejb.EJB;
import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
-
import org.jboss.logging.Logger;
/**
@@ -45,20 +44,19 @@
private static final Logger log = Logger.getLogger(QueueTestMDB.class);
private @PersistenceContext EntityManager manager;
- @EJB StatelessFacade stateless;
public void onMessage(Message recvMsg)
{
try
{
ObjectMessage message = (ObjectMessage)recvMsg;
- Entity entity = (Entity)message.getObject();
- stateless.persist(entity);
- ++TestStatusBean.messageCount;
+ Entity entity = (Entity)message.getObject();
+ manager.remove(entity);
}
- catch (Throwable t)
+ catch (JMSException e)
{
- TestStatusBean.caughtRollback = true;
+ e.printStackTrace();
+ throw new RuntimeException(e);
}
}
}
Copied: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java (from rev 66961, branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java)
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java 2007-11-13 09:51:52 UTC (rev 67009)
@@ -0,0 +1,116 @@
+/*
+ * 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.mdbtransactions;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+
+/**
+ * Reply a message to queue/C whenever a message is received on queue/B.
+ * Note that this has nothing to do with the actual test.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision$
+ */
+ at MessageDriven(activationConfig =
+{
+ @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName="destination", propertyValue="queue/B")
+})
+public class ReplyToCMDB implements MessageListener
+{
+ @Resource(mappedName="ConnectionFactory")
+ private QueueConnectionFactory factory;
+
+ @Resource(mappedName="queue/C")
+ private Queue replyQueue;
+
+ private QueueConnection connection;
+ private QueueSession session;
+ private QueueSender sender;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ TextMessage reply;
+ if(message instanceof TextMessage)
+ {
+ reply = session.createTextMessage("Reply: " + ((TextMessage) message).getText());
+ }
+ else
+ {
+ reply = session.createTextMessage("Unknown message");
+ }
+ sender.send(reply);
+ }
+ catch(JMSException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @PostConstruct
+ public void postConstruct()
+ {
+ try
+ {
+ connection = factory.createQueueConnection();
+ session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ sender = session.createSender(replyQueue);
+ }
+ 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);
+ }
+ }
+}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/RollbackQueueTestMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/RollbackQueueTestMDB.java 2007-11-13 09:27:51 UTC (rev 67008)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/RollbackQueueTestMDB.java 2007-11-13 09:51:52 UTC (rev 67009)
@@ -24,6 +24,7 @@
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
@@ -52,12 +53,18 @@
try
{
ObjectMessage message = (ObjectMessage)recvMsg;
- Entity entity = (Entity)message.getObject();
- manager.remove(entity);
+ Entity entity = (Entity)message.getObject();
+ stateless.persist(entity);
+ ++TestStatusBean.messageCount;
}
- catch (Throwable t)
+ catch (JMSException e)
{
- t.printStackTrace();
+ e.printStackTrace();
}
+ catch (RuntimeException e)
+ {
+ TestStatusBean.caughtRollback = true;
+ throw e;
+ }
}
}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacadeBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacadeBean.java 2007-11-13 09:27:51 UTC (rev 67008)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacadeBean.java 2007-11-13 09:51:52 UTC (rev 67009)
@@ -54,7 +54,7 @@
}
catch (Throwable t)
{
- t.printStackTrace();
+ log.error("clear failed", t);
}
}
@@ -67,7 +67,7 @@
}
catch (Throwable t)
{
- t.printStackTrace();
+ log.error("persist failed", t);
}
}
}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java 2007-11-13 09:27:51 UTC (rev 67008)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java 2007-11-13 09:51:52 UTC (rev 67009)
@@ -21,14 +21,18 @@
*/
package org.jboss.ejb3.test.mdbtransactions.unit;
+import java.util.Enumeration;
+
import javax.jms.Message;
import javax.jms.Queue;
+import javax.jms.QueueBrowser;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -59,32 +63,196 @@
super(name);
}
-
+
+ /**
+ * This tests the basic functionality of sending a message.
+ * Precondition for the actual test.
+ * @throws Exception
+ */
+ public void testSimpleQueue() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/A");
+ QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+ QueueConnection connection = factory.createQueueConnection();
+ try
+ {
+ connection.start();
+ QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ QueueSender sender = session.createSender(queue);
+ TextMessage message = session.createTextMessage("Hello world");
+ sender.send(message);
+ sender.close();
+ QueueReceiver receiver = session.createReceiver(queue);
+ Message msg = receiver.receive(5000);
+ assertNotNull(msg);
+ receiver.close();
+ session.close();
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ /**
+ * Send a message to a MDB and receive it back on another queue.
+ * Precondition for the actual test.
+ * @throws Exception
+ */
+ public void testPingPong() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/B");
+ Queue replyQueue = (Queue) ctx.lookup("queue/C");
+ QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+ QueueConnection connection = factory.createQueueConnection();
+ try
+ {
+ connection.start();
+ QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ QueueSender sender = session.createSender(queue);
+ TextMessage message = session.createTextMessage("Hello world");
+ sender.send(message);
+ sender.close();
+ QueueReceiver receiver = session.createReceiver(replyQueue);
+ Message msg = receiver.receive(5000);
+ assertNotNull(msg);
+ receiver.close();
+ session.close();
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
public void testMdbTransactions() throws Exception
{
TestStatus status = (TestStatus)getInitialContext().lookup("TestStatusBean/remote");
status.clear();
- sendMessages("queue/mdbtest", 2);
+ sendMessages("queue/rollbackmdbtest", 2);
Thread.sleep(5000);
assertEquals(1, status.messageCount());
assertTrue(status.caughtRollback());
+
+ Queue queue = (Queue) getInitialContext().lookup("queue/DLQ");
+ QueueConnectionFactory factory = getQueueConnectionFactory();
+ QueueConnection connection = factory.createQueueConnection();
+ try
+ {
+ connection.start();
+ QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+ QueueReceiver receiver = session.createReceiver(queue);
+
+ /*
+ {
+ Queue sendQueue = (Queue) getInitialContext().lookup("queue/rollbackmdbtest");
+ QueueSender sender = session.createSender(sendQueue);
+ TextMessage message = session.createTextMessage("Should never arrive");
+ message.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 0);
+ sender.send(message);
+ sender.close();
+ }
+ */
+
+ Message message = receiver.receive(5000);
+ assertNotNull(message);
+
+ session.close();
+ connection.close();
+ }
+ finally
+ {
+ connection.close();
+ }
+
+ sendMessages("queue/mdbtest", 1);
}
+ public void testRollback() throws Exception
+ {
+ TestStatus status = (TestStatus)getInitialContext().lookup("TestStatusBean/remote");
+ status.clear();
+
+ }
+
+ /**
+ * Test sending a message to a MDB which can not be created.
+ * @throws Exception
+ */
+ public void testBadCreation() throws Exception
+ {
+ TestStatus status = (TestStatus)getInitialContext().lookup("TestStatusBean/remote");
+ status.clear();
+
+ sendMessages("queue/badcreationmdb", 1);
+
+ InitialContext ctx = getInitialContext();
+ Queue dlq = (Queue) ctx.lookup("queue/DLQ");
+ QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+ QueueConnection connection = factory.createQueueConnection();
+ try
+ {
+ connection.start();
+ QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ QueueReceiver receiver = session.createReceiver(dlq);
+
+ //sendMessages(session, "queue/badcreationmdb", 1);
+ /*
+ {
+ Queue queue = (Queue) ctx.lookup("queue/badcreationmdb");
+ QueueSender sender = session.createSender(queue);
+ TextMessage message = session.createTextMessage("Should never arrive");
+ message.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 0);
+ sender.send(message);
+ sender.close();
+ }
+ */
+
+ //Thread.sleep(5000);
+
+ log.info("ENTERING RECEIVE");
+ Message message = receiver.receive(5000);
+ log.info("EXITING RECEIVE WITH " + message);
+ assertNotNull(message);
+
+ session.close();
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
protected void sendMessages(String queueName, int numMessages) throws Exception
{
- QueueConnection connection = null;
+ InitialContext ctx = getInitialContext();
+ QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+ QueueConnection connection = factory.createQueueConnection();
+ try
+ {
+ connection.start();
+ QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ sendMessages(session, queueName, numMessages);
+ session.close();
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ protected void sendMessages(QueueSession session, String queueName, int numMessages) throws Exception
+ {
QueueSender sender = null;
- QueueSession session = null;
Queue queue = (Queue) getInitialContext().lookup(
queueName);
- QueueConnectionFactory factory = getQueueConnectionFactory();
- connection = factory.createQueueConnection();
- connection.start();
- session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = session.createReceiver(queue);
Message message = receiver.receiveNoWait();
@@ -99,50 +267,19 @@
stateless.clear(entity);
ObjectMessage msg = session.createObjectMessage(entity);
+ msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 0);
sender = session.createSender(queue);
for (int i = 0 ; i < numMessages ; ++i)
sender.send(msg);
-
- session.close();
- connection.close();
}
- public void testRollback() throws Exception
- {
- TestStatus status = (TestStatus)getInitialContext().lookup("TestStatusBean/remote");
- status.clear();
-
- sendMessages("queue/rollbackmdbtest", 1);
-
- Thread.sleep(5000);
-
- Queue queue = (Queue) getInitialContext().lookup("queue/DLQ");
- QueueConnectionFactory factory = getQueueConnectionFactory();
- QueueConnection connection = factory.createQueueConnection();
- connection.start();
- QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
- QueueReceiver receiver = session.createReceiver(queue);
- Message message = receiver.receiveNoWait();
- assertNotNull(message);
-
- session.close();
- connection.close();
- }
-
protected QueueConnectionFactory getQueueConnectionFactory()
throws Exception
{
- try
- {
- return (QueueConnectionFactory) getInitialContext().lookup(
- "ConnectionFactory");
- } catch (NamingException e)
- {
- return (QueueConnectionFactory) getInitialContext().lookup(
- "java:/ConnectionFactory");
- }
+ // We want the server connection factory
+ return (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
}
protected InitialContext getInitialContext() throws Exception
More information about the jboss-cvs-commits
mailing list