[jboss-cvs] JBossAS SVN: r66961 - in branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions: unit and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 12 09:29:09 EST 2007
Author: wolfc
Date: 2007-11-12 09:29:09 -0500 (Mon, 12 Nov 2007)
New Revision: 66961
Added:
branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java
Modified:
branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java
Log:
JBPAPP-347: Working on mdbtransactions
Added: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java (rev 0)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.java 2007-11-12 14:29:09 UTC (rev 66961)
@@ -0,0 +1,115 @@
+/*
+ * 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/A.
+ *
+ * @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);
+ }
+ }
+}
Property changes on: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/ReplyToCMDB.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/mdbtransactions/unit/MDBUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java 2007-11-12 14:25:51 UTC (rev 66960)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java 2007-11-12 14:29:09 UTC (rev 66961)
@@ -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,7 +63,70 @@
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");
@@ -100,17 +167,45 @@
TestStatus status = (TestStatus)getInitialContext().lookup("TestStatusBean/remote");
status.clear();
- sendMessages("queue/badcreationmdb", 1);
-
- Thread.sleep(5000);
-
- Queue queue = (Queue) getInitialContext().lookup("queue/DLQ");
- QueueConnectionFactory factory = getQueueConnectionFactory();
+ InitialContext ctx = new InitialContext();
+ Queue dlq = (Queue) ctx.lookup("queue/DLQ");
+ log.info("queue = " + dlq);
+ QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
QueueConnection connection = factory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
- QueueReceiver receiver = session.createReceiver(queue);
- Message message = receiver.receiveNoWait();
+ /*
+ {
+ QueueBrowser browser = session.createBrowser(dlq);
+ Enumeration<?> e = browser.getEnumeration();
+ int size = 0;
+ while(e.hasMoreElements())
+ {
+ e.nextElement();
+ size++;
+ }
+ browser.close();
+
+ log.info("queue size = " + size);
+ }
+ */
+ QueueReceiver receiver = session.createReceiver(dlq);
+
+ //sendMessages("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();
@@ -143,6 +238,7 @@
stateless.clear(entity);
ObjectMessage msg = session.createObjectMessage(entity);
+ msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 0);
sender = session.createSender(queue);
@@ -156,15 +252,8 @@
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