Author: ataylor
Date: 2010-02-26 09:40:18 -0500 (Fri, 26 Feb 2010)
New Revision: 8903
Modified:
trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java
Log:
https://jira.jboss.org/jira/browse/HORNETQ-313 - add checks only for local tx when id is
the same
Modified: trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2010-02-26 14:37:37
UTC (rev 8902)
+++ trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2010-02-26 14:40:18
UTC (rev 8903)
@@ -523,7 +523,7 @@
public void xaCommit(final Xid xid, final boolean onePhase) throws Exception
{
- if (tx != null)
+ if (tx != null && tx.getXid().equals(xid))
{
final String msg = "Cannot commit, session is currently doing work in
transaction " + tx.getXid();
@@ -557,7 +557,7 @@
if (theTx.getState() == Transaction.State.SUSPENDED)
{
// Put it back
- resourceManager.putTransaction(xid, tx);
+ resourceManager.putTransaction(xid, theTx);
throw new HornetQXAException(XAException.XAER_PROTO, "Cannot commit
transaction, it is suspended " + xid);
}
@@ -697,7 +697,7 @@
public void xaRollback(final Xid xid) throws Exception
{
- if (tx != null)
+ if (tx != null && tx.getXid().equals(xid))
{
final String msg = "Cannot roll back, session is currently doing work in a
transaction " + tx.getXid();
@@ -794,7 +794,7 @@
public void xaPrepare(final Xid xid) throws Exception
{
- if (tx != null)
+ if (tx != null && tx.getXid().equals(xid))
{
final String msg = "Cannot commit, session is currently doing work in a
transaction " + tx.getXid();
Modified: trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java 2010-02-26 14:37:37
UTC (rev 8902)
+++ trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java 2010-02-26 14:40:18
UTC (rev 8903)
@@ -139,6 +139,64 @@
session2.close();
}
+
+
+ public void testXAInterleaveResourceSuspendWorkCommit() throws Exception
+ {
+ Xid xid = newXID();
+ Xid xid2 = newXID();
+ ClientProducer clientProducer = clientSession.createProducer(atestq);
+ ClientSession recSession = sessionFactory.createSession();
+ recSession.start();
+ ClientConsumer clientConsumer = recSession.createConsumer(atestq);
+ ClientMessage m1 = createTextMessage(clientSession, "m1");
+ ClientMessage m2 = createTextMessage(clientSession, "m2");
+ clientSession.start(xid, XAResource.TMNOFLAGS);
+ clientProducer.send(m1);
+ clientSession.end(xid, XAResource.TMSUSPEND);
+ clientSession.start(xid2, XAResource.TMNOFLAGS);
+ clientProducer.send(m2);
+ clientSession.end(xid, XAResource.TMSUCCESS);
+ clientSession.commit(xid, true);
+ ClientMessage message = clientConsumer.receiveImmediate();
+ assertNotNull(message);
+ message = clientConsumer.receiveImmediate();
+ assertNull(message);
+ clientSession.end(xid2, XAResource.TMSUCCESS);
+ clientSession.commit(xid2, true);
+ message = clientConsumer.receiveImmediate();
+ assertNotNull(message);
+ }
+
+ public void testXAInterleaveResourceRollbackAfterPrepare() throws Exception
+ {
+ Xid xid = newXID();
+ Xid xid2 = newXID();
+ Xid xid3 = newXID();
+ ClientProducer clientProducer = clientSession.createProducer(atestq);
+ ClientConsumer clientConsumer = clientSession.createConsumer(atestq);
+ ClientMessage m1 = createTextMessage(clientSession, "m1");
+ clientSession.start(xid, XAResource.TMNOFLAGS);
+ clientProducer.send(m1);
+ clientSession.end(xid, XAResource.TMSUCCESS);
+ clientSession.prepare(xid);
+ clientSession.commit(xid, false);
+ clientSession.start();
+ clientSession.start(xid2, XAResource.TMNOFLAGS);
+ ClientMessage m2 = clientConsumer.receiveImmediate();
+ assertNotNull(m2);
+ clientSession.end(xid2, XAResource.TMSUCCESS);
+ clientSession.prepare(xid2);
+ clientSession.rollback(xid2);
+
+ clientSession.start(xid3, XAResource.TMNOFLAGS);
+ m2 = clientConsumer.receiveImmediate();
+ assertNotNull(m2);
+ clientSession.end(xid3, XAResource.TMSUCCESS);
+ clientSession.prepare(xid3);
+ clientSession.commit(xid3, false);
+ }
+
public void testSendPrepareDoesntRollbackOnClose() throws Exception
{
Xid xid = newXID();