[jboss-cvs] JBoss Messaging SVN: r2611 - in projects/jms-integration/src/main/org/jboss/test/jms/integration: support/ejb20 and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 25 18:03:26 EDT 2007
Author: clebert.suconic at jboss.com
Date: 2007-04-25 18:03:26 -0400 (Wed, 25 Apr 2007)
New Revision: 2611
Modified:
projects/jms-integration/src/main/org/jboss/test/jms/integration/mdb/TransactionedMDBTest.java
projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/StatefulBean.java
projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/StatefulRemote.java
Log:
Improving tests
Modified: projects/jms-integration/src/main/org/jboss/test/jms/integration/mdb/TransactionedMDBTest.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/mdb/TransactionedMDBTest.java 2007-04-25 15:52:40 UTC (rev 2610)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/mdb/TransactionedMDBTest.java 2007-04-25 22:03:26 UTC (rev 2611)
@@ -113,6 +113,8 @@
TextMessage receivedMessage = (TextMessage) consumer.receive(10000);
assertNotNull(receivedMessage);
assertEquals(msg, receivedMessage.getText());
+
+ remote.remove();
}
finally
{
@@ -121,10 +123,125 @@
conn.close();
}
}
-
-
}
+ public void testReceiveOnEJB() throws Exception
+ {
+ Connection conn = cf.createConnection();
+
+ try
+ {
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = sess.createProducer(responseDestination);
+
+ Random random = new Random();
+ String msg = "Msg " + random.nextLong();
+
+ producer.send(sess.createTextMessage(msg));
+
+ InitialContext ctx = new InitialContext();
+ StatefulHome home = (StatefulHome)ctx.lookup("ejb/StatefulTest");
+ StatefulRemote remote = home.create();
+
+ assertEquals(msg, remote.receiveMessage(TEST_QUEUE_RESPONSE, false, false));
+
+ conn.start();
+
+ MessageConsumer consumer = sess.createConsumer(responseDestination);
+ TextMessage txtmsg = (TextMessage) consumer.receive(10000);
+ assertNull(txtmsg);
+
+ System.out.println("return was " + txtmsg);
+ }
+ finally
+ {
+ if (conn!=null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ public void testReceiveOnEJBWithRollback() throws Exception
+ {
+ Connection conn = cf.createConnection();
+
+ try
+ {
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = sess.createProducer(responseDestination);
+
+ Random random = new Random();
+ String msg = "Msg " + random.nextLong();
+
+ producer.send(sess.createTextMessage(msg));
+
+ InitialContext ctx = new InitialContext();
+ StatefulHome home = (StatefulHome)ctx.lookup("ejb/StatefulTest");
+ StatefulRemote remote = home.create();
+
+ assertEquals(msg, remote.receiveMessage(TEST_QUEUE_RESPONSE, true, false));
+
+ conn.start();
+
+ MessageConsumer consumer = sess.createConsumer(responseDestination);
+ TextMessage txtmsg = (TextMessage) consumer.receive(10000);
+ assertNotNull(txtmsg);
+
+ System.out.println("return was " + txtmsg + " with string=" + txtmsg.getText());
+ }
+ finally
+ {
+ if (conn!=null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ public void testReceiveOnEJBWithCommit() throws Exception
+ {
+ Connection conn = cf.createConnection();
+
+ try
+ {
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = sess.createProducer(responseDestination);
+
+ Random random = new Random();
+ String msg = "Msg " + random.nextLong();
+
+ producer.send(sess.createTextMessage(msg));
+
+ InitialContext ctx = new InitialContext();
+ StatefulHome home = (StatefulHome)ctx.lookup("ejb/StatefulTest");
+ StatefulRemote remote = home.create();
+
+ assertEquals(msg, remote.receiveMessage(TEST_QUEUE_RESPONSE, true, true));
+
+ conn.start();
+
+ MessageConsumer consumer = sess.createConsumer(responseDestination);
+ TextMessage txtmsg = (TextMessage) consumer.receive(10000);
+ assertNull(txtmsg);
+
+ System.out.println("return was " + txtmsg);
+ }
+ finally
+ {
+ if (conn!=null)
+ {
+ conn.close();
+ }
+ }
+ }
+
public static Test suite() throws Exception
{
Modified: projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/StatefulBean.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/StatefulBean.java 2007-04-25 15:52:40 UTC (rev 2610)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/StatefulBean.java 2007-04-25 22:03:26 UTC (rev 2611)
@@ -8,6 +8,7 @@
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
+import javax.transaction.UserTransaction;
public class StatefulBean implements SessionBean
{
@@ -37,9 +38,6 @@
{
InitialContext ctx = new InitialContext();
QueueConnectionFactory cf = (QueueConnectionFactory)ctx.lookup("java:comp/env/jms/MyQueueConnectionFactory");
- //QueueConnectionFactory cf = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");
- System.out.println("cf=" + cf);
- System.out.println("cf(2)=" + cf.getClass().getName());
Destination queue = (Destination) ctx.lookup("queue/A_Integration");
Connection conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -55,5 +53,56 @@
throw jmsE;
}
}
+
+ public String receiveMessage(String jndiQueue, boolean transact, boolean commit) throws JMSException
+ {
+ UserTransaction userTrans = null;
+ try
+ {
+ InitialContext ctx = new InitialContext();
+
+ if (transact)
+ {
+ userTrans = (UserTransaction) ctx.lookup("UserTransaction");
+ userTrans.begin();
+ }
+
+ QueueConnectionFactory cf = (QueueConnectionFactory)ctx.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ Destination queue = (Destination) ctx.lookup(jndiQueue);
+ Connection conn = cf.createConnection();
+ conn.start();
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+ TextMessage txt = (TextMessage )consumer.receive(10000);
+
+ String strReturn = txt!=null ? txt.getText() : null;
+
+ System.out.println("StrReturn = " + strReturn);
+
+ if (transact)
+ {
+ if (commit)
+ {
+ userTrans.commit();
+ }
+ else
+ {
+ userTrans.rollback();
+ }
+
+ }
+
+ conn.close();
+
+ return strReturn;
+ }
+ catch (Exception e)
+ {
+ JMSException jmsE = new JMSException (e.getMessage());
+ jmsE.initCause(e);
+ throw jmsE;
+ }
+ }
+
}
Modified: projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/StatefulRemote.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/StatefulRemote.java 2007-04-25 15:52:40 UTC (rev 2610)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/StatefulRemote.java 2007-04-25 22:03:26 UTC (rev 2611)
@@ -4,10 +4,13 @@
import javax.ejb.*;
import javax.jms.JMSException;
-import javax.jms.Destination;
+
public interface StatefulRemote extends EJBObject
{
public void sendTestMessage(String message) throws JMSException, RemoteException;
+
+ public String receiveMessage(String jndiQueue, boolean transact, boolean commit) throws JMSException, RemoteException;
+
}
More information about the jboss-cvs-commits
mailing list