[jboss-cvs] JBoss Messaging SVN: r1976 - branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jan 17 22:24:01 EST 2007
Author: ovidiu.feodorov at jboss.com
Date: 2007-01-17 22:24:01 -0500 (Wed, 17 Jan 2007)
New Revision: 1976
Modified:
branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/XATest.java
Log:
Back-ported XATest::testConvertFromLocalTx, XATest::testTransactionIdSetAfterCommit, XATest::testTransactionIdSetAfterRollback
from Branch_1_0. These are related to http://jira.jboss.com/jira/browse/JBMESSAGING-721.
XATest::testConvertFromLocalTx currently fails.
Modified: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/XATest.java 2007-01-18 03:22:26 UTC (rev 1975)
+++ branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/XATest.java 2007-01-18 03:24:01 UTC (rev 1976)
@@ -51,11 +51,11 @@
*/
public class XATest extends MessagingTestCase
{
- // Constants -----------------------------------------------------
+ // Constants ------------------------------------------------------------------------------------
- // Static --------------------------------------------------------
+ // Static ---------------------------------------------------------------------------------------
- // Attributes ----------------------------------------------------
+ // Attributes -----------------------------------------------------------------------------------
protected InitialContext initialContext;
@@ -65,14 +65,14 @@
protected Transaction suspendedTx;
- // Constructors --------------------------------------------------
+ // Constructors ---------------------------------------------------------------------------------
public XATest(String name)
{
super(name);
}
- // TestCase overrides -------------------------------------------
+ // TestCase overrides --------------------------------------------------------------------------
public void setUp() throws Exception
{
@@ -83,13 +83,21 @@
initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
- if (!ServerManagement.isRemote()) tm = TransactionManagerLocator.getInstance().locate();
-
+ if (!ServerManagement.isRemote())
+ {
+ tm = TransactionManagerLocator.getInstance().locate();
+ }
+
ServerManagement.undeployQueue("Queue");
ServerManagement.deployQueue("Queue");
queue = (Destination)initialContext.lookup("/queue/Queue");
- if (!ServerManagement.isRemote()) suspendedTx = tm.suspend();
+ this.drainDestination(cf, queue);
+
+ if (!ServerManagement.isRemote())
+ {
+ suspendedTx = tm.suspend();
+ }
}
public void tearDown() throws Exception
@@ -116,9 +124,344 @@
- // Public --------------------------------------------------------
+ // Public ---------------------------------------------------------------------------------------
-
+ //http://jira.jboss.com/jira/browse/JBMESSAGING-721
+ public void testConvertFromLocalTx() throws Exception
+ {
+ if (ServerManagement.isRemote())
+ {
+ return;
+ }
+
+ Connection conn = null;
+
+ XAConnection xaConn = null;
+
+ try
+ {
+
+ // First send some messages to a queue
+
+ conn = cf.createConnection();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSend.createProducer(queue);
+
+ TextMessage tm1 = sessSend.createTextMessage("message1");
+
+ TextMessage tm2 = sessSend.createTextMessage("message2");
+
+ prod.send(tm1);
+
+ prod.send(tm2);
+
+
+ xaConn = cf.createXAConnection();
+
+ XASession xaSession = xaConn.createXASession();
+
+ xaConn.start();
+
+ MessageConsumer cons = xaSession.createConsumer(queue);
+
+ // Receive the two messages outside of a transaction
+
+ TextMessage rm1 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm1);
+
+ assertEquals("message1", rm1.getText());
+
+ TextMessage rm2 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm2);
+
+ assertEquals("message2", rm2.getText());
+
+ Message rm3 = cons.receive(1000);
+
+ assertNull(rm3);
+
+ // Now we enlist the session in an xa transaction
+
+ log.info("enlisting");
+ XAResource res = xaSession.getXAResource();
+
+ tm.begin();
+
+ Transaction tx = tm.getTransaction();
+ tx.enlistResource(res);
+
+ // This should cause the work done previously to be converted into work done in the XA
+ // transaction. This is what an MDB does. There is a difficulty in transactional delivery
+ // with an MDB. The message is received from the destination and then sent to the MDB
+ // container so it can call onMessage().
+ // For transactional delivery the receipt of the message should be in a transaction but by
+ // the time the MDB container is invoked the message has already been received it is too
+ // late - the message has already been received and passed on (see page 199 (chapter 5 JMS
+ // and Transactions, section "Application Server Integration" of Mark Little's book Java
+ // Transaction processing for a discussion of how different app serves deal with this).
+ // The way JBoss Messaging (and JBossMQ) deals with this is to convert any work done prior
+ // to when the XASession is enlisted in the transaction, into work done in the XA
+ // transaction
+
+ // Now rollback the tx - this should cause redelivery of the two messages
+ tx.rollback();
+
+ rm1 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm1);
+
+ assertEquals("message1", rm1.getText());
+
+ rm2 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm2);
+
+ assertEquals("message2", rm2.getText());
+
+ rm3 = cons.receive(1000);
+
+ assertNull(rm3);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ if (xaConn != null)
+ {
+ xaConn.close();
+ }
+ }
+ }
+
+ //http://jira.jboss.com/jira/browse/JBMESSAGING-721
+ public void testTransactionIdSetAfterCommit() throws Exception
+ {
+ if (ServerManagement.isRemote()) return;
+
+ Connection conn = null;
+
+ XAConnection xaConn = null;
+
+ try
+ {
+
+ //First send some messages to a queue
+
+ conn = cf.createConnection();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSend.createProducer(queue);
+
+ TextMessage tm1 = sessSend.createTextMessage("message1");
+
+ TextMessage tm2 = sessSend.createTextMessage("message2");
+
+ prod.send(tm1);
+
+ prod.send(tm2);
+
+
+ xaConn = cf.createXAConnection();
+
+ XASession xaSession = xaConn.createXASession();
+
+ xaConn.start();
+
+ MessageConsumer cons = xaSession.createConsumer(queue);
+
+ //Now we enlist the session in an xa transaction
+
+ log.info("enlisting");
+ XAResource res = xaSession.getXAResource();
+
+ tm.begin();
+
+ Transaction tx = tm.getTransaction();
+ tx.enlistResource(res);
+
+ //Then we do a commit
+ tm.commit();
+
+ //And enlist again
+
+ tx = tm.getTransaction();
+
+
+ tm.begin();
+
+ tx = tm.getTransaction();
+ tx.enlistResource(res);
+
+ //Then we receive the messages
+
+ TextMessage rm1 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm1);
+
+ assertEquals("message1", rm1.getText());
+
+ TextMessage rm2 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm2);
+
+ assertEquals("message2", rm2.getText());
+
+ Message rm3 = cons.receive(1000);
+
+ assertNull(rm3);
+
+ //Now rollback the tx - this should cause redelivery of the two messages
+ tx.rollback();
+
+ rm1 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm1);
+
+ assertEquals("message1", rm1.getText());
+
+ rm2 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm2);
+
+ assertEquals("message2", rm2.getText());
+
+ rm3 = cons.receive(1000);
+
+ assertNull(rm3);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ if (xaConn != null)
+ {
+ xaConn.close();
+ }
+ }
+
+ }
+
+ //http://jira.jboss.com/jira/browse/JBMESSAGING-721
+ public void testTransactionIdSetAfterRollback() throws Exception
+ {
+ if (ServerManagement.isRemote()) return;
+
+ Connection conn = null;
+
+ XAConnection xaConn = null;
+
+ try
+ {
+
+ //First send some messages to a queue
+
+ conn = cf.createConnection();
+
+ Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = sessSend.createProducer(queue);
+
+ TextMessage tm1 = sessSend.createTextMessage("message1");
+
+ TextMessage tm2 = sessSend.createTextMessage("message2");
+
+ prod.send(tm1);
+
+ prod.send(tm2);
+
+
+ xaConn = cf.createXAConnection();
+
+ XASession xaSession = xaConn.createXASession();
+
+ xaConn.start();
+
+ MessageConsumer cons = xaSession.createConsumer(queue);
+
+ //Now we enlist the session in an xa transaction
+
+ log.info("enlisting");
+ XAResource res = xaSession.getXAResource();
+
+ tm.begin();
+
+ Transaction tx = tm.getTransaction();
+ tx.enlistResource(res);
+
+ //Then we do a rollback
+ tm.rollback();
+
+ tm.begin();
+
+ //And enlist again
+
+ tx = tm.getTransaction();
+ tx.enlistResource(res);
+
+ //Then we receive the messages
+
+ TextMessage rm1 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm1);
+
+ assertEquals("message1", rm1.getText());
+
+ TextMessage rm2 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm2);
+
+ assertEquals("message2", rm2.getText());
+
+ Message rm3 = cons.receive(1000);
+
+ assertNull(rm3);
+
+ //Now rollback the tx - this should cause redelivery of the two messages
+ tx.rollback();
+
+ rm1 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm1);
+
+ assertEquals("message1", rm1.getText());
+
+ rm2 = (TextMessage)cons.receive(1000);
+
+ assertNotNull(rm2);
+
+ assertEquals("message2", rm2.getText());
+
+ rm3 = cons.receive(1000);
+
+ assertNull(rm3);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+
+ if (xaConn != null)
+ {
+ xaConn.close();
+ }
+ }
+
+ }
+
+
public void test2PCSendCommit1PCOptimization() throws Exception
{
if (ServerManagement.isRemote()) return;
@@ -2081,13 +2424,13 @@
}
- // Package protected ---------------------------------------------
+ // Package protected ----------------------------------------------------------------------------
- // Protected -----------------------------------------------------
+ // Protected ------------------------------------------------------------------------------------
- // Private -------------------------------------------------------
+ // Private --------------------------------------------------------------------------------------
- // Inner classes -------------------------------------------------
+ // Inner classes --------------------------------------------------------------------------------
static class DummyXAResource implements XAResource
{
More information about the jboss-cvs-commits
mailing list