[jboss-cvs] JBoss Messaging SVN: r5621 - branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 13 12:11:41 EST 2009
Author: clebert.suconic at jboss.com
Date: 2009-01-13 12:11:41 -0500 (Tue, 13 Jan 2009)
New Revision: 5621
Modified:
branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XATest.java
Log:
Cleanup only
Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XATest.java 2009-01-13 16:02:55 UTC (rev 5620)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/XATest.java 2009-01-13 17:11:41 UTC (rev 5621)
@@ -21,14 +21,44 @@
*/
package org.jboss.test.messaging.jms;
+import java.util.ArrayList;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.XAConnection;
+import javax.jms.XAConnectionFactory;
+import javax.jms.XASession;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
+
import org.jboss.jms.client.JBossConnection;
import org.jboss.jms.client.JBossSession;
import org.jboss.jms.client.delegate.ClientConnectionDelegate;
import org.jboss.jms.client.delegate.DelegateSupport;
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.client.state.SessionState;
-import org.jboss.jms.tx.*;
+import org.jboss.jms.tx.ClientTransaction;
+import org.jboss.jms.tx.LocalTx;
+import org.jboss.jms.tx.MessagingXAResource;
+import org.jboss.jms.tx.MessagingXid;
+import org.jboss.jms.tx.ResourceManager;
+import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.logging.Logger;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.container.InVMInitialContextFactory;
@@ -36,16 +66,6 @@
import org.jboss.tm.TransactionManagerLocator;
import org.jboss.tm.TxUtils;
-import javax.jms.*;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAException;
-import javax.transaction.xa.XAResource;
-import javax.transaction.xa.Xid;
-import java.util.ArrayList;
-
/**
*
* A XATestBase
@@ -65,7 +85,7 @@
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
-
+
protected TransactionManager tm;
protected Transaction suspendedTx;
@@ -74,26 +94,25 @@
// Constructors --------------------------------------------------
- public XATest(String name)
+ public XATest(final String name)
{
super(name);
}
-
// TestCase overrides -------------------------------------------
public void setUp() throws Exception
- {
+ {
super.setUp();
-
- ResourceManagerFactory.instance.clear();
- //Also need a local tx mgr if test is running remote
+ ResourceManagerFactory.instance.clear();
+
+ // Also need a local tx mgr if test is running remote
if (ServerManagement.isRemote())
{
- sc = new ServiceContainer("transaction");
+ sc = new ServiceContainer("transaction");
- //Don't drop the tables again!
+ // Don't drop the tables again!
sc.start(false);
}
@@ -102,7 +121,7 @@
tm = (TransactionManager)localIc.lookup(ServiceContainer.TRANSACTION_MANAGER_JNDI_NAME);
assertTrue(tm instanceof TransactionManagerImple);
-
+
if (!ServerManagement.isRemote())
{
suspendedTx = tm.suspend();
@@ -110,24 +129,28 @@
}
public void tearDown() throws Exception
- {
+ {
if (TxUtils.isUncommitted(tm))
{
- //roll it back
+ // roll it back
try
{
tm.rollback();
}
catch (Throwable ignore)
{
- //The connection will probably be closed so this may well throw an exception
+ // The connection will probably be closed so this may well throw an exception
}
}
if (tm.getTransaction() != null)
{
Transaction tx = tm.suspend();
if (tx != null)
- log.warn("Transaction still associated with thread " + tx + " at status " + TxUtils.getStatusAsString(tx.getStatus()));
+ {
+ log.warn("Transaction still associated with thread " + tx +
+ " at status " +
+ TxUtils.getStatusAsString(tx.getStatus()));
+ }
}
if (suspendedTx != null)
@@ -139,7 +162,7 @@
{
sc.stop();
}
-
+
super.tearDown();
}
@@ -161,12 +184,11 @@
validate that both sets of work W1 and W2 get applied.
*/
- //http://jira.jboss.com/jira/browse/JBMESSAGING-1221
+ // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
public void testMemoryLeakForLocalTXsWithWork() throws Exception
{
XAConnection conn = null;
- Transaction tx1 = null;
try
{
@@ -180,12 +202,12 @@
ResourceManager rm = state.getResourceManager();
- //Create a session
- JBossSession sess1 = (JBossSession) conn.createXASession();
+ // Create a session
+ JBossSession sess1 = (JBossSession)conn.createXASession();
DummyListener listener = new DummyListener();
sess1.setMessageListener(listener);
conn.start();
- MessagingXAResource res1 = (MessagingXAResource) sess1.getXAResource();
+ MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
tm.begin();
Transaction trans = tm.getTransaction();
@@ -194,41 +216,44 @@
MessageProducer p = sess1.createProducer(queue1);
MessageConsumer cons = sess1.createConsumer(queue1);
conn.start();
- //send 10 messages
- for(int i = 0; i < 10; i++)
+ // send 10 messages
+ for (int i = 0; i < 10; i++)
{
TextMessage message = sess1.createTextMessage("delistedwork" + i);
p.send(message);
}
- //now receive 5
- for(int i = 0; i < 5; i++)
+ // now receive 5
+ for (int i = 0; i < 5; i++)
{
- TextMessage textMessage = (TextMessage) cons.receive();
+ TextMessage textMessage = (TextMessage)cons.receive();
assertEquals("delistedwork" + i, textMessage.getText());
}
- //once we enlist ensure that the 5 acks are merged ok, the first timne we do this there is nothing to merge in the global tx
- //so all acks are just copied
+ // once we enlist ensure that the 5 acks are merged ok, the first timne we do this there is nothing to merge in
+ // the global tx
+ // so all acks are just copied
trans.enlistResource(res1);
SessionState sstate = (SessionState)((DelegateSupport)sess1.getDelegate()).getState();
ClientTransaction clientTransaction = rm.getTx(sstate.getCurrentTxId());
- assertEquals("to many session states", clientTransaction.getSessionStates().size(), 1 );
- ClientTransaction.SessionTxState sessionTxState = (ClientTransaction.SessionTxState) clientTransaction.getSessionStates().get(0);
- assertEquals("wrong number of acks",5, sessionTxState.getAcks().size());
+ assertEquals("to many session states", clientTransaction.getSessionStates().size(), 1);
+ ClientTransaction.SessionTxState sessionTxState = (ClientTransaction.SessionTxState)clientTransaction.getSessionStates()
+ .get(0);
+ assertEquals("wrong number of acks", 5, sessionTxState.getAcks().size());
trans.delistResource(res1, XAResource.TMSUCCESS);
- for(int i = 5; i < 10; i++)
+ for (int i = 5; i < 10; i++)
{
- TextMessage textMessage = (TextMessage) cons.receive();
+ TextMessage textMessage = (TextMessage)cons.receive();
assertEquals("delistedwork" + i, textMessage.getText());
}
- //now reenlist and make sure that there are now 10 acks, this time around a merge will be done with the first 5 acks
+ // now reenlist and make sure that there are now 10 acks, this time around a merge will be done with the first
+ // 5 acks
//
trans.enlistResource(res1);
clientTransaction = rm.getTx(sstate.getCurrentTxId());
- assertEquals("to many session states", clientTransaction.getSessionStates().size(), 1 );
- sessionTxState = (ClientTransaction.SessionTxState) clientTransaction.getSessionStates().get(0);
- assertEquals("wrong number of acks",10, sessionTxState.getAcks().size());
+ assertEquals("to many session states", clientTransaction.getSessionStates().size(), 1);
+ sessionTxState = (ClientTransaction.SessionTxState)clientTransaction.getSessionStates().get(0);
+ assertEquals("wrong number of acks", 10, sessionTxState.getAcks().size());
tm.commit();
@@ -244,12 +269,11 @@
}
- //http://jira.jboss.com/jira/browse/JBMESSAGING-1221
+ // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
public void testMemoryLeakForLocalTXsOnJoinOnePhase() throws Exception
{
XAConnection conn = null;
- Transaction tx1 = null;
try
{
@@ -263,9 +287,9 @@
ResourceManager rm = state.getResourceManager();
- //Create a session
+ // Create a session
XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource) sess1.getXAResource();
+ MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
int rmSizeBeforeStart = rm.size();
@@ -292,12 +316,12 @@
}
}
- //http://jira.jboss.com/jira/browse/JBMESSAGING-1221
+
+ // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
public void testMemoryLeakForLocalTXsOnJoinTwoPhase() throws Exception
{
XAConnection conn = null;
- Transaction tx1 = null;
try
{
@@ -311,9 +335,9 @@
ResourceManager rm = state.getResourceManager();
- //Create a session
+ // Create a session
XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource) sess1.getXAResource();
+ MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
int rmSizeBeforeStart = rm.size();
@@ -341,12 +365,12 @@
}
}
- //http://jira.jboss.com/jira/browse/JBMESSAGING-1221
+
+ // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
public void testMemoryLeakForLocalTXsOnResumeOnePhase() throws Exception
{
XAConnection conn = null;
- Transaction tx1 = null;
try
{
@@ -360,9 +384,9 @@
ResourceManager rm = state.getResourceManager();
- //Create a session
+ // Create a session
XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource) sess1.getXAResource();
+ MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
int rmSizeBeforeStart = rm.size();
@@ -389,12 +413,12 @@
}
}
- //http://jira.jboss.com/jira/browse/JBMESSAGING-1221
+
+ // http://jira.jboss.com/jira/browse/JBMESSAGING-1221
public void testMemoryLeakForLocalTXsOnJResumeTwoPhase() throws Exception
{
XAConnection conn = null;
- Transaction tx1 = null;
try
{
@@ -408,9 +432,9 @@
ResourceManager rm = state.getResourceManager();
- //Create a session
+ // Create a session
XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource) sess1.getXAResource();
+ MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
int rmSizeBeforeStart = rm.size();
@@ -438,6 +462,7 @@
}
}
+
/* If there is no global tx present the send must behave as non transacted.
* See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
* http://jira.jboss.com/jira/browse/JBMESSAGING-410
@@ -461,7 +486,7 @@
XAConnection xconn = xcf.createXAConnection();
XASession xs = xconn.createXASession();
-
+
MessageProducer p = xs.createProducer(queue1);
Message m = xs.createTextMessage("one");
@@ -489,7 +514,6 @@
}
}
-
/*
* If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
* falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
@@ -533,7 +557,7 @@
try
{
ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
- Integer count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(1, count.intValue());
// using XA with a ConnectionConsumer (testing the transaction behavior under MDBs)
@@ -553,7 +577,7 @@
assertEquals(1, listener.messages.size());
// Message should still be on server
- count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(1, count.intValue());
XAResource resource = xasession.getXAResource();
@@ -581,7 +605,7 @@
trans.commit();
// After commit the message should be consumed
- count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(0, count.intValue());
}
finally
@@ -596,8 +620,7 @@
}
}
}
-
-
+
/*
* If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
* falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
@@ -657,11 +680,11 @@
TextMessage rm = (TextMessage)c.receive(1000);
assertEquals("one", rm.getText());
-
+
// messages should be acked
count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(0, count.intValue());
-
+
xconn.close();
}
finally
@@ -673,7 +696,6 @@
}
}
}
-
/*
* If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
@@ -842,7 +864,7 @@
// I can't call xasession.close for this test as JCA layer would cache the session
// So.. keep this close commented!
- //xasession.close();
+ // xasession.close();
count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(0, count.intValue());
@@ -856,7 +878,7 @@
}
}
- //See http://jira.jboss.com/jira/browse/JBMESSAGING-638
+ // See http://jira.jboss.com/jira/browse/JBMESSAGING-638
public void testResourceManagerMemoryLeakOnCommit() throws Exception
{
XAConnection xaConn = null;
@@ -918,7 +940,7 @@
}
}
- //See http://jira.jboss.com/jira/browse/JBMESSAGING-638
+ // See http://jira.jboss.com/jira/browse/JBMESSAGING-638
public void testResourceManagerMemoryLeakOnRollback() throws Exception
{
XAConnection xaConn = null;
@@ -990,10 +1012,10 @@
try
{
- //First send some messages to a queue
+ // First send some messages to a queue
ObjectName queueMBean = new ObjectName("jboss.messaging.destination:service=Queue,name=Queue1");
- Integer count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ Integer count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(0, count.intValue());
conn = cf.createConnection();
@@ -1010,7 +1032,7 @@
prod.send(tm2);
- count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(2, count.intValue());
xaConn = cf.createXAConnection();
@@ -1031,15 +1053,15 @@
assertEquals(2, listener.messages.size());
- assertEquals("message1", ((TextMessage)(listener.messages.get(0))).getText());
- assertEquals("message2", ((TextMessage)(listener.messages.get(1))).getText());
+ assertEquals("message1", ((TextMessage)listener.messages.get(0)).getText());
+ assertEquals("message2", ((TextMessage)listener.messages.get(1)).getText());
- count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(2, count.intValue());
listener.messages.clear();
- //Now we enlist the session in an xa transaction
+ // Now we enlist the session in an xa transaction
XAResource res = xaSession.getXAResource();
@@ -1048,25 +1070,26 @@
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 jboss mq) deals with this is to convert any work done
- //prior to when the xasession is enlisted in the tx, into work done in the xa tx
+ // 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 jboss mq) deals with this is to convert any work done
+ // prior to when the xasession is enlisted in the tx, into work done in the xa tx
tx.delistResource(res, XAResource.TMSUCCESS);
- //Now rollback the tx - this should cause redelivery of the two messages
+ // Now rollback the tx - this should cause redelivery of the two messages
tm.rollback();
- count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(2, count.intValue());
Thread.sleep(1000);
@@ -1086,7 +1109,7 @@
assertEquals(0, listener.messages.size());
- count = (Integer) ServerManagement.getAttribute(queueMBean, "MessageCount");
+ count = (Integer)ServerManagement.getAttribute(queueMBean, "MessageCount");
assertEquals(0, count.intValue());
assertNull(tm.getTransaction());
@@ -1103,16 +1126,17 @@
xaConn.close();
}
- /* if (suspended != null)
- {
- tm.resume(suspended);
- }*/
+ /* if (suspended != null)
+ {
+ tm.resume(suspended);
+ }*/
}
}
- //http://jira.jboss.com/jira/browse/JBMESSAGING-721
+ // http://jira.jboss.com/jira/browse/JBMESSAGING-721
// Note: The behavior of this test was changed after http://jira.jboss.com/jira/browse/JBMESSAGING-946
- // When you have a XASession without a transaction enlisted we will behave the same way as non transactedSession, AutoAck
+ // When you have a XASession without a transaction enlisted we will behave the same way as non transactedSession,
+ // AutoAck
public void testTransactionIdSetAfterCommit() throws Exception
{
Connection conn = null;
@@ -1121,7 +1145,7 @@
try
{
- //First send some messages to a queue
+ // First send some messages to a queue
conn = cf.createConnection();
@@ -1137,7 +1161,6 @@
prod.send(tm2);
-
xaConn = cf.createXAConnection();
XASession xaSession = xaConn.createXASession();
@@ -1146,7 +1169,7 @@
MessageConsumer cons = xaSession.createConsumer(queue1);
- //Now we enlist the session in an xa transaction
+ // Now we enlist the session in an xa transaction
XAResource res = xaSession.getXAResource();
@@ -1157,15 +1180,15 @@
tx.delistResource(res, XAResource.TMSUCCESS);
- //Then we do a commit
+ // Then we do a commit
tm.commit();
// I have changed where this begin was originally set
// as when you don't have a resource enlisted, XASessions will act as
// non transacted + AutoAck
- //And enlist again - this should convert the work done in the local tx
- //into the global branch
+ // And enlist again - this should convert the work done in the local tx
+ // into the global branch
tx = tm.getTransaction();
@@ -1174,7 +1197,7 @@
tx = tm.getTransaction();
tx.enlistResource(res);
- //Then we receive the messages outside the tx
+ // Then we receive the messages outside the tx
TextMessage rm1 = (TextMessage)cons.receive(1000);
@@ -1194,7 +1217,7 @@
tx.delistResource(res, XAResource.TMSUCCESS);
- //Now rollback the tx - this should cause redelivery of the two messages
+ // Now rollback the tx - this should cause redelivery of the two messages
tx.rollback();
rm1 = (TextMessage)cons.receive(1000);
@@ -1228,7 +1251,7 @@
}
- //http://jira.jboss.com/jira/browse/JBMESSAGING-721
+ // http://jira.jboss.com/jira/browse/JBMESSAGING-721
public void testTransactionIdSetAfterRollback() throws Exception
{
Connection conn = null;
@@ -1237,7 +1260,7 @@
try
{
- //First send some messages to a queue
+ // First send some messages to a queue
conn = cf.createConnection();
@@ -1261,7 +1284,7 @@
MessageConsumer cons = xaSession.createConsumer(queue1);
- //Now we enlist the session in an xa transaction
+ // Now we enlist the session in an xa transaction
XAResource res = xaSession.getXAResource();
@@ -1271,12 +1294,12 @@
tx.enlistResource(res);
tx.delistResource(res, XAResource.TMSUCCESS);
- //Then we do a rollback
+ // Then we do a rollback
tm.rollback();
tm.begin();
- //And enlist again - the work should then be converted into the global tx branch
+ // And enlist again - the work should then be converted into the global tx branch
// I have changed where this begin was originally set
// as when you don't have a resource enlisted, XASessions will act as
@@ -1286,7 +1309,7 @@
tx.enlistResource(res);
- //Then we receive the messages outside the global tx
+ // Then we receive the messages outside the global tx
TextMessage rm1 = (TextMessage)cons.receive(1000);
@@ -1305,7 +1328,7 @@
assertNull(rm3);
tx.delistResource(res, XAResource.TMSUCCESS);
- //Now rollback the tx - this should cause redelivery of the two messages
+ // Now rollback the tx - this should cause redelivery of the two messages
tx.rollback();
rm1 = (TextMessage)cons.receive(1000);
@@ -1376,16 +1399,16 @@
res1.prepare(trailing);
- //Now "crash" the server
+ // Now "crash" the server
ServerManagement.stopServerPeer();
ServerManagement.startServerPeer();
deployAndLookupAdministeredObjects();
-
+
conn1.close();
-
+
conn1 = cf.createXAConnection();
XAResource res = conn1.createXASession().getXAResource();
@@ -1409,7 +1432,7 @@
finally
{
removeAllMessages(queue1.getQueueName(), true, 0);
-
+
if (conn1 != null)
{
try
@@ -1418,7 +1441,7 @@
}
catch (Exception e)
{
- //Ignore
+ // Ignore
}
}
}
@@ -1426,7 +1449,7 @@
public void test2PCSendCommit1PCOptimization() throws Exception
{
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
@@ -1482,8 +1505,6 @@
}
}
-
-
public void test2PCSendCommit() throws Exception
{
XAConnection conn = null;
@@ -1500,7 +1521,7 @@
MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
XAResource res2 = new DummyXAResource();
- //To prevent 1PC optimization being used
+ // To prevent 1PC optimization being used
res.setPreventJoining(true);
Transaction tx = tm.getTransaction();
@@ -1543,10 +1564,9 @@
}
}
-
public void test2PCSendRollback1PCOptimization() throws Exception
{
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
@@ -1598,7 +1618,6 @@
}
}
-
public void test2PCSendFailOnPrepare() throws Exception
{
XAConnection conn = null;
@@ -1612,7 +1631,7 @@
XASession sess = conn.createXASession();
MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
- //prevent 1Pc optimisation
+ // prevent 1Pc optimisation
res.setPreventJoining(true);
XAResource res2 = new DummyXAResource(true);
@@ -1645,7 +1664,7 @@
}
catch (Exception e)
{
- //We should expect this
+ // We should expect this
}
conn2 = cf.createConnection();
@@ -1681,7 +1700,7 @@
XASession sess = conn.createXASession();
MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
- //prevent 1Pc optimisation
+ // prevent 1Pc optimisation
res.setPreventJoining(true);
XAResource res2 = new DummyXAResource();
@@ -1725,7 +1744,7 @@
public void test2PCReceiveCommit1PCOptimization() throws Exception
{
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
@@ -1735,7 +1754,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
@@ -1757,7 +1776,6 @@
MessageConsumer cons = sess.createConsumer(queue1);
-
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(m2);
@@ -1773,7 +1791,7 @@
tm.commit();
- //New tx
+ // New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
@@ -1812,7 +1830,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
@@ -1835,7 +1853,6 @@
MessageConsumer cons = sess.createConsumer(queue1);
-
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(m2);
@@ -1851,7 +1868,7 @@
tm.commit();
- //New tx
+ // New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
@@ -1882,7 +1899,7 @@
public void test2PCReceiveRollback1PCOptimization() throws Exception
{
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
Connection conn2 = null;
@@ -1891,7 +1908,7 @@
{
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
@@ -1914,7 +1931,6 @@
MessageConsumer cons = sess.createConsumer(queue1);
-
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
@@ -1927,9 +1943,9 @@
tm.rollback();
- //Message should be redelivered
+ // Message should be redelivered
- //New tx
+ // New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
@@ -1971,14 +1987,13 @@
{
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
conn = cf.createXAConnection();
conn.start();
@@ -1996,7 +2011,6 @@
MessageConsumer cons = sess.createConsumer(queue1);
-
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(m2);
assertEquals("XATest1", m2.getText());
@@ -2009,9 +2023,9 @@
tm.rollback();
- //Message should be redelivered
+ // Message should be redelivered
- //New tx
+ // New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
@@ -2046,7 +2060,6 @@
}
-
public void test1PCSendCommit() throws Exception
{
XAConnection conn = null;
@@ -2061,11 +2074,9 @@
XASession sess = conn.createXASession();
XAResource res = sess.getXAResource();
-
Transaction tx = tm.getTransaction();
tx.enlistResource(res);
-
MessageProducer prod = sess.createProducer(queue1);
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Message m = sess.createTextMessage("XATest1");
@@ -2102,7 +2113,6 @@
}
-
public void test1PCSendRollback() throws Exception
{
XAConnection conn = null;
@@ -2161,7 +2171,7 @@
conn2 = cf.createConnection();
conn2.start();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
@@ -2180,7 +2190,6 @@
MessageConsumer cons = sess.createConsumer(queue1);
-
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(m2);
@@ -2194,7 +2203,7 @@
tm.commit();
- //New tx
+ // New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
@@ -2230,13 +2239,12 @@
{
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("XATest1");
prod.send(m);
m = sessProducer.createTextMessage("XATest2");
prod.send(m);
-
conn = cf.createXAConnection();
conn.start();
@@ -2250,7 +2258,6 @@
MessageConsumer cons = sess.createConsumer(queue1);
-
TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(m2);
@@ -2265,9 +2272,9 @@
tm.rollback();
- //Message should be redelivered
+ // Message should be redelivered
- //New tx
+ // New tx
tm.begin();
tx = tm.getTransaction();
tx.enlistResource(res);
@@ -2308,26 +2315,25 @@
XAConnection conn = null;
Connection conn2 = null;
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
try
{
- //First send 2 messages
+ // First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
prod.send(m);
-
conn = cf.createXAConnection();
conn.start();
tm.begin();
- //Create 2 sessions and enlist them
+ // Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
XASession sess2 = conn.createXASession();
@@ -2337,7 +2343,7 @@
tx.enlistResource(res1);
tx.enlistResource(res2);
- //Receive the messages, one on each consumer
+ // Receive the messages, one on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
@@ -2355,7 +2361,7 @@
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
- //commit
+ // commit
tm.commit();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -2387,22 +2393,21 @@
try
{
- //First send 2 messages
+ // First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
prod.send(m);
-
conn = cf.createXAConnection();
conn.start();
tm.begin();
- //Create 2 sessions and enlist them
+ // Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
XASession sess2 = conn.createXASession();
@@ -2414,7 +2419,7 @@
tx.enlistResource(res1);
tx.enlistResource(res2);
- //Receive the messages, one on each consumer
+ // Receive the messages, one on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
@@ -2432,7 +2437,7 @@
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
- //commit
+ // commit
tm.commit();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -2457,20 +2462,19 @@
}
-
public void testMultipleSessionsOneTxRollbackAcknowledge1PCOptimization() throws Exception
{
XAConnection conn = null;
Connection conn2 = null;
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
try
{
- //First send 2 messages
+ // First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -2480,13 +2484,12 @@
m = sessProducer.createTextMessage("jellyfish4");
prod.send(m);
-
conn = cf.createXAConnection();
conn.start();
tm.begin();
- //Create 2 sessions and enlist them
+ // Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
XASession sess2 = conn.createXASession();
@@ -2496,7 +2499,7 @@
tx.enlistResource(res1);
tx.enlistResource(res2);
- //Receive the messages, two on each consumer
+ // Receive the messages, two on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
@@ -2523,18 +2526,18 @@
cons2.close();
- //rollback
+ // rollback
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
tm.rollback();
- //Rollback causes cancel which is asynch
+ // Rollback causes cancel which is asynch
Thread.sleep(1000);
- //We cannot assume anything about the order in which the transaction manager rollsback
- //the sessions - this is implementation dependent
+ // We cannot assume anything about the order in which the transaction manager rollsback
+ // the sessions - this is implementation dependent
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue1);
@@ -2578,7 +2581,6 @@
assertEquals("jellyfish4", r.getText());
-
}
else
{
@@ -2627,10 +2629,10 @@
try
{
- //First send 2 messages
+ // First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -2640,13 +2642,12 @@
m = sessProducer.createTextMessage("jellyfish4");
prod.send(m);
-
conn = cf.createXAConnection();
conn.start();
tm.begin();
- //Create 2 sessions and enlist them
+ // Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
XASession sess2 = conn.createXASession();
@@ -2658,7 +2659,7 @@
tx.enlistResource(res1);
tx.enlistResource(res2);
- //Receive the messages, two on each consumer
+ // Receive the messages, two on each consumer
MessageConsumer cons1 = sess1.createConsumer(queue1);
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
@@ -2672,7 +2673,7 @@
cons1.close();
- //Cancel is asynch
+ // Cancel is asynch
Thread.sleep(500);
MessageConsumer cons2 = sess2.createConsumer(queue1);
@@ -2686,7 +2687,7 @@
assertNotNull(r2);
assertEquals("jellyfish4", r2.getText());
- //rollback
+ // rollback
cons2.close();
@@ -2698,10 +2699,9 @@
// Rollback causes cancel which is asynch
Thread.sleep(1000);
- //We cannot assume anything about the order in which the transaction manager rollsback
- //the sessions - this is implementation dependent
+ // We cannot assume anything about the order in which the transaction manager rollsback
+ // the sessions - this is implementation dependent
-
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
@@ -2744,7 +2744,6 @@
assertEquals("jellyfish4", r.getText());
-
}
else
{
@@ -2791,10 +2790,10 @@
try
{
- //First send 4 messages
+ // First send 4 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
@@ -2846,16 +2845,15 @@
cons1.close();
+ // try and commit - and we're going to make the dummyxaresource throw an exception on commit,
+ // which should cause rollback to be called on the other resource
- //try and commit - and we're going to make the dummyxaresource throw an exception on commit,
- //which should cause rollback to be called on the other resource
-
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
- //rollback will cause an attemp to deliver messages locally to the original consumers.
- //the original consumer has closed, so it will cancelled to the server
- //the server cancel is asynch, so we need to sleep for a bit to make sure it completes
+ // rollback will cause an attemp to deliver messages locally to the original consumers.
+ // the original consumer has closed, so it will cancelled to the server
+ // the server cancel is asynch, so we need to sleep for a bit to make sure it completes
log.trace("Forcing failure");
try
{
@@ -2864,12 +2862,11 @@
}
catch (Exception e)
{
- //We should expect this
+ // We should expect this
}
Thread.sleep(1000);
-
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createConsumer(queue1);
conn2.start();
@@ -2918,7 +2915,7 @@
public void testMultipleSessionsOneTxCommitSend1PCOptimization() throws Exception
{
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
@@ -2931,7 +2928,7 @@
tm.begin();
- //Create 2 sessions and enlist them
+ // Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
XASession sess2 = conn.createXASession();
@@ -2952,10 +2949,10 @@
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
- //commit
+ // commit
tm.commit();
- //Messages should be in queue
+ // Messages should be in queue
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -2986,7 +2983,7 @@
public void testMultipleSessionsOneTxCommitSend() throws Exception
{
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
@@ -3000,7 +2997,7 @@
tm.begin();
- //Create 2 sessions and enlist them
+ // Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
XASession sess2 = conn.createXASession();
@@ -3023,10 +3020,10 @@
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
- //commit
+ // commit
tm.commit();
- //Messages should be in queue
+ // Messages should be in queue
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -3057,10 +3054,9 @@
}
-
public void testMultipleSessionsOneTxRollbackSend1PCOptimization() throws Exception
{
- //Since both resources have some RM, TM will probably use 1PC optimization
+ // Since both resources have some RM, TM will probably use 1PC optimization
XAConnection conn = null;
@@ -3073,7 +3069,7 @@
tm.begin();
- //Create 2 sessions and enlist them
+ // Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
XASession sess2 = conn.createXASession();
@@ -3094,10 +3090,10 @@
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
- //rollback
+ // rollback
tm.rollback();
- //Messages should not be in queue
+ // Messages should not be in queue
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -3135,7 +3131,7 @@
tm.begin();
- //Create 2 sessions and enlist them
+ // Create 2 sessions and enlist them
XASession sess1 = conn.createXASession();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
XASession sess2 = conn.createXASession();
@@ -3158,10 +3154,10 @@
tx.delistResource(res1, XAResource.TMSUCCESS);
tx.delistResource(res2, XAResource.TMSUCCESS);
- //rollback
+ // rollback
tm.rollback();
- //Messages should not be in queue
+ // Messages should not be in queue
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -3184,7 +3180,6 @@
}
}
-
public void testOneSessionTwoTransactionsCommitAcknowledge() throws Exception
{
XAConnection conn = null;
@@ -3193,10 +3188,10 @@
try
{
- //First send 2 messages
+ // First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -3204,7 +3199,7 @@
conn = cf.createXAConnection();
- //Create a session
+ // Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
@@ -3216,13 +3211,13 @@
Transaction tx1 = tm.getTransaction();
tx1.enlistResource(res1);
- //Receive one message in one tx
+ // Receive one message in one tx
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
- //suspend the tx
+ // suspend the tx
Transaction suspended = tm.suspend();
tm.begin();
@@ -3230,17 +3225,17 @@
Transaction tx2 = tm.getTransaction();
tx2.enlistResource(res1);
- //Receive 2nd message in a different tx
+ // Receive 2nd message in a different tx
TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r2);
assertEquals("jellyfish2", r2.getText());
tx2.delistResource(res1, XAResource.TMSUCCESS);
- //commit this transaction
+ // commit this transaction
tm.commit();
- //verify that no messages are available
+ // verify that no messages are available
conn2.close();
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -3249,7 +3244,7 @@
TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
assertNull(r3);
- //now resume the first tx and then commit it
+ // now resume the first tx and then commit it
tm.resume(suspended);
tx1.delistResource(res1, XAResource.TMSUCCESS);
@@ -3269,7 +3264,6 @@
}
}
-
public void testOneSessionTwoTransactionsRollbackAcknowledge() throws Exception
{
XAConnection conn = null;
@@ -3278,10 +3272,10 @@
try
{
- //First send 2 messages
+ // First send 2 messages
conn2 = cf.createConnection();
Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
+ MessageProducer prod = sessProducer.createProducer(queue1);
Message m = sessProducer.createTextMessage("jellyfish1");
prod.send(m);
m = sessProducer.createTextMessage("jellyfish2");
@@ -3289,7 +3283,7 @@
conn = cf.createXAConnection();
- //Create a session
+ // Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
@@ -3301,13 +3295,13 @@
Transaction tx1 = tm.getTransaction();
tx1.enlistResource(res1);
- //Receive one message in one tx
+ // Receive one message in one tx
TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r1);
assertEquals("jellyfish1", r1.getText());
- //suspend the tx
+ // suspend the tx
Transaction suspended = tm.suspend();
tm.begin();
@@ -3315,7 +3309,7 @@
Transaction tx2 = tm.getTransaction();
tx2.enlistResource(res1);
- //Receive 2nd message in a different tx
+ // Receive 2nd message in a different tx
TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
assertNotNull(r2);
assertEquals("jellyfish2", r2.getText());
@@ -3324,10 +3318,10 @@
tx1.delistResource(res1, XAResource.TMSUCCESS);
- //rollback this transaction
+ // rollback this transaction
tm.rollback();
- //verify that second message is available
+ // verify that second message is available
conn2.close();
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -3341,12 +3335,11 @@
r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
assertNull(r3);
-
- //rollback the other tx
+ // rollback the other tx
tm.resume(suspended);
tm.rollback();
- //Verify the first message is now available
+ // Verify the first message is now available
r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(r3);
assertEquals("jellyfish1", r3.getText());
@@ -3369,7 +3362,6 @@
}
-
public void testOneSessionTwoTransactionsCommitSend() throws Exception
{
XAConnection conn = null;
@@ -3380,7 +3372,7 @@
{
conn = cf.createXAConnection();
- //Create a session
+ // Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
@@ -3391,27 +3383,27 @@
Transaction tx1 = tm.getTransaction();
tx1.enlistResource(res1);
- //Send a message
+ // Send a message
prod1.send(sess1.createTextMessage("kangaroo1"));
- //suspend the tx
+ // suspend the tx
Transaction suspended = tm.suspend();
tm.begin();
- //Send another message in another tx using the same session
+ // Send another message in another tx using the same session
Transaction tx2 = tm.getTransaction();
tx2.enlistResource(res1);
- //Send a message
+ // Send a message
prod1.send(sess1.createTextMessage("kangaroo2"));
tx2.delistResource(res1, XAResource.TMSUCCESS);
- //commit this transaction
+ // commit this transaction
tm.commit();
- //verify only kangaroo2 message is sent
+ // verify only kangaroo2 message is sent
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn2.start();
@@ -3422,14 +3414,14 @@
TextMessage r2 = (TextMessage)cons.receive(MIN_TIMEOUT);
assertNull(r2);
- //now resume the first tx and then commit it
+ // now resume the first tx and then commit it
tm.resume(suspended);
tx1.delistResource(res1, XAResource.TMSUCCESS);
tm.commit();
- //verify that the first text message is received
+ // verify that the first text message is received
TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(r3);
assertEquals("kangaroo1", r3.getText());
@@ -3450,7 +3442,6 @@
}
-
public void testOneSessionTwoTransactionsRollbackSend() throws Exception
{
XAConnection conn = null;
@@ -3462,7 +3453,7 @@
conn = cf.createXAConnection();
- //Create a session
+ // Create a session
XASession sess1 = conn.createXASession();
XAResource res1 = sess1.getXAResource();
@@ -3473,27 +3464,27 @@
Transaction tx1 = tm.getTransaction();
tx1.enlistResource(res1);
- //Send a message
+ // Send a message
prod1.send(sess1.createTextMessage("kangaroo1"));
- //suspend the tx
+ // suspend the tx
Transaction suspended = tm.suspend();
tm.begin();
- //Send another message in another tx using the same session
+ // Send another message in another tx using the same session
Transaction tx2 = tm.getTransaction();
tx2.enlistResource(res1);
- //Send a message
+ // Send a message
prod1.send(sess1.createTextMessage("kangaroo2"));
tx2.delistResource(res1, XAResource.TMSUCCESS);
- //rollback this transaction
+ // rollback this transaction
tm.rollback();
- //verify no messages are sent
+ // verify no messages are sent
conn2 = cf.createConnection();
Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn2.start();
@@ -3502,15 +3493,14 @@
assertNull(r1);
-
- //now resume the first tx and then commit it
+ // now resume the first tx and then commit it
tm.resume(suspended);
tx1.delistResource(res1, XAResource.TMSUCCESS);
tm.commit();
- //verify that the first text message is received
+ // verify that the first text message is received
TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
assertNotNull(r3);
assertEquals("kangaroo1", r3.getText());
@@ -3537,7 +3527,7 @@
// Private -------------------------------------------------------
- private void assertEqualByteArrays(byte[] b1, byte[] b2)
+ private void assertEqualByteArrays(final byte[] b1, final byte[] b2)
{
log.info("b1 length: " + b1.length + " b2 length " + b2.length);
@@ -3557,7 +3547,6 @@
// Inner classes -------------------------------------------------
-
static class DummyListener implements MessageListener
{
@@ -3565,7 +3554,7 @@
public ArrayList messages = new ArrayList();
- public void onMessage(Message message)
+ public void onMessage(final Message message)
{
log.info("Message received on DummyListener " + message);
messages.add(message);
@@ -3574,9 +3563,9 @@
static class MockServerSessionPool implements ServerSessionPool
{
- private ServerSession serverSession;
+ private final ServerSession serverSession;
- MockServerSessionPool(Session sess)
+ MockServerSessionPool(final Session sess)
{
serverSession = new MockServerSession(sess);
}
@@ -3591,12 +3580,11 @@
{
Session session;
- MockServerSession(Session sess)
+ MockServerSession(final Session sess)
{
- this.session = sess;
+ session = sess;
}
-
public Session getSession() throws JMSException
{
return session;
@@ -3609,8 +3597,6 @@
}
-
-
static class DummyXAResource implements XAResource
{
boolean failOnPrepare;
@@ -3619,34 +3605,34 @@
{
}
- DummyXAResource(boolean failOnPrepare)
+ DummyXAResource(final boolean failOnPrepare)
{
this.failOnPrepare = failOnPrepare;
}
- public void commit(Xid arg0, boolean arg1) throws XAException
+ public void commit(final Xid arg0, final boolean arg1) throws XAException
{
}
- public void end(Xid arg0, int arg1) throws XAException
+ public void end(final Xid arg0, final int arg1) throws XAException
{
}
- public void forget(Xid arg0) throws XAException
+ public void forget(final Xid arg0) throws XAException
{
}
public int getTransactionTimeout() throws XAException
{
- return 0;
+ return 0;
}
- public boolean isSameRM(XAResource arg0) throws XAException
+ public boolean isSameRM(final XAResource arg0) throws XAException
{
return false;
}
- public int prepare(Xid arg0) throws XAException
+ public int prepare(final Xid arg0) throws XAException
{
if (failOnPrepare)
{
@@ -3655,21 +3641,21 @@
return XAResource.XA_OK;
}
- public Xid[] recover(int arg0) throws XAException
+ public Xid[] recover(final int arg0) throws XAException
{
return null;
}
- public void rollback(Xid arg0) throws XAException
+ public void rollback(final Xid arg0) throws XAException
{
}
- public boolean setTransactionTimeout(int arg0) throws XAException
+ public boolean setTransactionTimeout(final int arg0) throws XAException
{
return false;
}
- public void start(Xid arg0, int arg1) throws XAException
+ public void start(final Xid arg0, final int arg1) throws XAException
{
}
More information about the jboss-cvs-commits
mailing list