[jboss-cvs] JBossAS SVN: r68305 - in branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca: interfaces and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Dec 14 14:07:09 EST 2007
Author: adrian at jboss.org
Date: 2007-12-14 14:07:09 -0500 (Fri, 14 Dec 2007)
New Revision: 68305
Modified:
branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java
Log:
[JBAS-5084] - Add a test for jms activity in a rolledback transaction due to tx timeout
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java 2007-12-14 18:57:28 UTC (rev 68304)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java 2007-12-14 19:07:09 UTC (rev 68305)
@@ -28,9 +28,16 @@
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
import javax.naming.InitialContext;
import javax.sql.DataSource;
-import javax.transaction.Status;
import javax.transaction.UserTransaction;
import org.jboss.logging.Logger;
@@ -202,6 +209,191 @@
}
}
+ public void setupQueue()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/testQueue");
+ UserTransaction ut = sessionCtx.getUserTransaction();
+ ut.begin();
+ try
+ {
+ ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");
+ javax.jms.Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer mc = s.createConsumer(queue);
+ while (mc.receive(1000) != null);
+ mc.close();
+
+ MessageProducer p = s.createProducer(queue);
+ Message m = s.createTextMessage("101");
+ p.send(m);
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ ut.commit();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
+ public void changeQueue()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/testQueue");
+ UserTransaction ut = sessionCtx.getUserTransaction();
+ ut.setTransactionTimeout(5);
+ ut.begin();
+ try
+ {
+ ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");
+ javax.jms.Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer mc = s.createConsumer(queue);
+ mc.receive(1000);
+ mc.close();
+
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException ignored)
+ {
+ }
+
+ try
+ {
+ MessageProducer p = s.createProducer(queue);
+ Message m = s.createTextMessage("100");
+ p.send(m);
+ }
+ catch (JMSException expected)
+ {
+ }
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ ut.commit();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
+ public void checkQueue()
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ Queue queue = (Queue) ctx.lookup("queue/testQueue");
+ UserTransaction ut = sessionCtx.getUserTransaction();
+ ut.begin();
+ try
+ {
+ ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:JmsXA");
+ javax.jms.Connection c = cf.createConnection();
+ try
+ {
+ c.start();
+ Session s = c.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer mc = s.createConsumer(queue);
+ Message m = mc.receive(1000);
+ if (m == null || m instanceof TextMessage == false)
+ throw new RuntimeException("Expected one text message: " + m);
+ String value = ((TextMessage) m).getText();
+ if ("101".equals(value) == false)
+ throw new RuntimeException("Message should have text 101 got: " + value);
+ if (mc.receive(1000) != null)
+ throw new RuntimeException("Did not expect two messages");
+ }
+ finally
+ {
+ try
+ {
+ c.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ ut.commit();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected Error: ", e);
+ }
+ }
+
public void ejbCreate()
{
}
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java 2007-12-14 18:57:28 UTC (rev 68304)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java 2007-12-14 19:07:09 UTC (rev 68305)
@@ -36,4 +36,7 @@
void setupDatabase() throws RemoteException;
void changeDatabase() throws RemoteException;
void checkDatabase() throws RemoteException;
+ void setupQueue() throws RemoteException;
+ void changeQueue() throws RemoteException;
+ void checkQueue() throws RemoteException;
}
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java 2007-12-14 18:57:28 UTC (rev 68304)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java 2007-12-14 19:07:09 UTC (rev 68305)
@@ -53,4 +53,13 @@
remote.changeDatabase();
remote.checkDatabase();
}
+
+ public void testJMSTransactionActive() throws Exception
+ {
+ TransactionActiveHome home = (TransactionActiveHome) getInitialContext().lookup("test/ejbs/TxActiveBean");
+ TransactionActiveRemote remote = home.create();
+ remote.setupQueue();
+ remote.changeQueue();
+ remote.checkQueue();
+ }
}
More information about the jboss-cvs-commits
mailing list