From 885b8c97752c8ff81ff994a4b490cd991424a6ec Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Fri, 8 Mar 2013 15:22:17 +0000 Subject: [PATCH] fix up tck violation on xasession interface after close expectations git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1454422 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/ActiveMQXASession.java | 3 +++ .../ActiveMQXAConnectionFactoryTest.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASession.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASession.java index 3e2ffdfdc2..6e92416c03 100755 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASession.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASession.java @@ -69,14 +69,17 @@ public class ActiveMQXASession extends ActiveMQSession implements QueueSession, } public boolean getTransacted() throws JMSException { + checkClosed(); return getTransactionContext().isInXATransaction(); } public void rollback() throws JMSException { + checkClosed(); throw new TransactionInProgressException("Cannot rollback() inside an XASession"); } public void commit() throws JMSException { + checkClosed(); throw new TransactionInProgressException("Cannot commit() inside an XASession"); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java index e4d39a29ff..87f618e81e 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java @@ -387,6 +387,30 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport { broker.stop(); } + public void testExceptionAfterClose() throws Exception { + + ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false"); + XAConnection connection1 = (XAConnection)cf1.createConnection(); + connection1.start(); + + XASession session = connection1.createXASession(); + session.close(); + try { + session.commit(); + fail("expect exception after close"); + } catch (javax.jms.IllegalStateException expected) {} + + try { + session.rollback(); + fail("expect exception after close"); + } catch (javax.jms.IllegalStateException expected) {} + + try { + session.getTransacted(); + fail("expect exception after close"); + } catch (javax.jms.IllegalStateException expected) {} + } + private void assertTransactionGoneFromFailoverState( ActiveMQXAConnection connection1, Xid tid) throws Exception {