[hornetq-commits] JBoss hornetq SVN: r8926 - in trunk: tests/src/org/hornetq/tests/integration/xa and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Mar 12 18:20:42 EST 2010
Author: clebert.suconic at jboss.com
Date: 2010-03-12 18:20:41 -0500 (Fri, 12 Mar 2010)
New Revision: 8926
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-328 - ServerSession should throw an exception if XID was not initialized on a XA Session
Modified: trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2010-03-11 16:16:48 UTC (rev 8925)
+++ trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2010-03-12 23:20:41 UTC (rev 8926)
@@ -104,6 +104,8 @@
private final Map<Long, ServerConsumer> consumers = new ConcurrentHashMap<Long, ServerConsumer>();
private Transaction tx;
+
+ private final boolean xa;
private final StorageManager storageManager;
@@ -183,6 +185,8 @@
{
tx = new TransactionImpl(storageManager);
}
+
+ this.xa = xa;
this.strictUpdateDeliveryCount = strictUpdateDeliveryCount;
@@ -481,6 +485,11 @@
public void acknowledge(final long consumerID, final long messageID) throws Exception
{
ServerConsumer consumer = consumers.get(consumerID);
+
+ if (this.xa && tx == null)
+ {
+ throw new HornetQXAException(XAException.XAER_PROTO, "Invalid transaction state");
+ }
consumer.acknowledge(autoCommitAcks, tx, messageID);
}
@@ -1241,6 +1250,11 @@
throw e;
}
+ if (this.xa && tx == null)
+ {
+ throw new HornetQXAException(XAException.XAER_PROTO, "Invalid transaction state");
+ }
+
if (tx == null || autoCommitSends)
{
}
Modified: trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java 2010-03-11 16:16:48 UTC (rev 8925)
+++ trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java 2010-03-12 23:20:41 UTC (rev 8926)
@@ -112,7 +112,105 @@
super.tearDown();
}
+
+
+ public void testSendWithoutXID() throws Exception
+ {
+ // Since both resources have same RM, TM will probably use 1PC optimization
+
+ ClientSessionFactory factory = createInVMFactory();
+
+ ClientSession session = null;
+
+ try
+ {
+
+ session = factory.createSession(true, false, false);
+
+ session.createQueue("Test", "Test");
+
+ ClientProducer prod = session.createProducer("Test");
+
+ prod.send(session.createMessage(true));
+
+ session.start();
+
+ ClientConsumer cons = session.createConsumer("Test");
+
+ assertNull("Send went through an invalid XA Session", cons.receiveImmediate());
+ }
+ finally
+ {
+ factory.close();
+
+ session.close();
+ }
+ }
+
+
+ public void testACKWithoutXID() throws Exception
+ {
+ // Since both resources have same RM, TM will probably use 1PC optimization
+
+
+ ClientSessionFactory factory = createInVMFactory();
+
+ ClientSession session = null;
+
+ try
+ {
+
+ session = factory.createSession(false, true, true);
+
+ session.createQueue("Test", "Test");
+
+ ClientProducer prod = session.createProducer("Test");
+
+ prod.send(session.createMessage(true));
+
+ session.close();
+
+ session = factory.createSession(true, false, false);
+
+ session.start();
+
+ ClientConsumer cons = session.createConsumer("Test");
+
+ ClientMessage msg = cons.receive(5000);
+
+ assertNotNull(msg);
+
+ msg.acknowledge();
+
+ session.close();
+
+
+ session = factory.createSession(false, false, false);
+
+ session.start();
+
+ cons = session.createConsumer("Test");
+
+ msg = cons.receiveImmediate();
+
+ assertNotNull("Acknowledge went through invalid XA Session", msg);
+
+ assertNull(cons.receiveImmediate());
+
+
+
+ }
+ finally
+ {
+ factory.close();
+
+ session.close();
+ }
+ }
+
+
+
public void testIsSameRM() throws Exception
{
ClientSessionFactory nettyFactory = createNettyFactory();
More information about the hornetq-commits
mailing list