qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1228109 - in /qpid/trunk/qpid/java: client/src/main/java/org/apache/qpid/client/ systests/src/main/java/org/apache/qpid/test/unit/transacted/
Date Fri, 06 Jan 2012 11:28:36 GMT
Author: robbie
Date: Fri Jan  6 11:28:35 2012
New Revision: 1228109

URL: http://svn.apache.org/viewvc?rev=1228109&view=rev
Log:
QPID-3716: restore throwing of IllegalStateException upon invoking Session#getTransacted()
on a closed session

Applied patch from Oleksandr Rudyy<orudyy@gmail.com>

Modified:
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactedTest.java

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java?rev=1228109&r1=1228108&r2=1228109&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
(original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
Fri Jan  6 11:28:35 2012
@@ -308,7 +308,7 @@ public class AMQConnectionDelegate_8_0 i
         {
             AMQSession s = (AMQSession) it.next();
             // _protocolHandler.addSessionByChannel(s.getChannelId(), s);
-            reopenChannel(s.getChannelId(), s.getDefaultPrefetchHigh(), s.getDefaultPrefetchLow(),
s.getTransacted());
+            reopenChannel(s.getChannelId(), s.getDefaultPrefetchHigh(), s.getDefaultPrefetchLow(),
s.isTransacted());
             s.resubscribe();
         }
     }

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java?rev=1228109&r1=1228108&r2=1228109&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java Fri Jan
 6 11:28:35 2012
@@ -256,7 +256,7 @@ public abstract class AMQSession<C exten
     protected AMQConnection _connection;
 
     /** Used to indicate whether or not this is a transactional session. */
-    protected boolean _transacted;
+    protected final boolean _transacted;
 
     /** Holds the sessions acknowledgement mode. */
     protected final int _acknowledgeMode;
@@ -1619,7 +1619,24 @@ public abstract class AMQSession<C exten
         return _ticket;
     }
 
-    public boolean getTransacted()
+    /**
+     * Indicates whether the session is in transacted mode.
+     *
+     * @return true if the session is in transacted mode
+     * @throws IllegalStateException - if session is closed.
+     */
+    public boolean getTransacted() throws JMSException
+    {
+        // Sun TCK checks that javax.jms.IllegalStateException is thrown for closed session
+        // nowhere else this behavior is documented
+        checkNotClosed();
+        return _transacted;
+    }
+
+    /**
+     * Indicates whether the session is in transacted mode.
+     */
+    public boolean isTransacted()
     {
         return _transacted;
     }

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java?rev=1228109&r1=1228108&r2=1228109&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java Fri
Jan  6 11:28:35 2012
@@ -152,7 +152,7 @@ public class AMQSession_0_8 extends AMQS
             _logger.debug("Sending ack for delivery tag " + deliveryTag + " on channel "
+ _channelId);
         }
 
-        getProtocolHandler().writeFrame(ackFrame, !getTransacted());
+        getProtocolHandler().writeFrame(ackFrame, !isTransacted());
         _unacknowledgedMessageTags.remove(deliveryTag);
     }
 

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactedTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactedTest.java?rev=1228109&r1=1228108&r2=1228109&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactedTest.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactedTest.java
Fri Jan  6 11:28:35 2012
@@ -31,6 +31,8 @@ import org.apache.qpid.test.utils.QpidBr
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jms.Connection;
+import javax.jms.IllegalStateException;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
@@ -303,6 +305,70 @@ public class TransactedTest extends Qpid
         con2.close();
     }
 
+    public void testCommitOnClosedConnection() throws Exception
+    {
+        Connection connnection = getConnection();
+        javax.jms.Session transactedSession = connnection.createSession(true, Session.SESSION_TRANSACTED);
+        connnection.close();
+        try
+        {
+            transactedSession.commit();
+            fail("Commit on closed connection should throw IllegalStateException!");
+        }
+        catch(IllegalStateException e)
+        {
+            // passed
+        }
+    }
+
+    public void testCommitOnClosedSession() throws Exception
+    {
+        Connection connnection = getConnection();
+        javax.jms.Session transactedSession = connnection.createSession(true, Session.SESSION_TRANSACTED);
+        transactedSession.close();
+        try
+        {
+            transactedSession.commit();
+            fail("Commit on closed session should throw IllegalStateException!");
+        }
+        catch(IllegalStateException e)
+        {
+            // passed
+        }
+    }
+
+    public void testRollbackOnClosedSession() throws Exception
+    {
+        Connection connnection = getConnection();
+        javax.jms.Session transactedSession = connnection.createSession(true, Session.SESSION_TRANSACTED);
+        transactedSession.close();
+        try
+        {
+            transactedSession.rollback();
+            fail("Rollback on closed session should throw IllegalStateException!");
+        }
+        catch(IllegalStateException e)
+        {
+            // passed
+        }
+    }
+
+    public void testGetTransactedOnClosedSession() throws Exception
+    {
+        Connection connnection = getConnection();
+        javax.jms.Session transactedSession = connnection.createSession(true, Session.SESSION_TRANSACTED);
+        transactedSession.close();
+        try
+        {
+            transactedSession.getTransacted();
+            fail("According to Sun TCK invocation of Session#getTransacted on closed session
should throw IllegalStateException!");
+        }
+        catch(IllegalStateException e)
+        {
+            // passed
+        }
+    }
+
     private void expect(String text, Message msg) throws JMSException
     {
         expect(text, msg, false);



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message