You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2015/01/12 19:05:24 UTC

[2/2] qpid-jms git commit: add tests of behaviour after session closure, resolve issues with QueueSender instances

add tests of behaviour after session closure, resolve issues with QueueSender instances


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/2ff38ef6
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/2ff38ef6
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/2ff38ef6

Branch: refs/heads/master
Commit: 2ff38ef6d3244fe208d7d08833809ec255e5017c
Parents: d4d4d70
Author: Robert Gemmell <ro...@apache.org>
Authored: Mon Jan 12 17:53:24 2015 +0000
Committer: Robert Gemmell <ro...@apache.org>
Committed: Mon Jan 12 18:05:04 2015 +0000

----------------------------------------------------------------------
 .../java/org/apache/qpid/jms/JmsSession.java    |  1 +
 .../jms/session/JmsQueueSessionClosedTest.java  | 89 ++++++++++++++++++++
 .../qpid/jms/session/JmsSessionClosedTest.java  | 86 +++++++++++++++++++
 .../jms/session/JmsTopicSessionClosedTest.java  | 88 +++++++++++++++++++
 4 files changed, 264 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2ff38ef6/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
index 7a01147..185dd36 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
@@ -465,6 +465,7 @@ public class JmsSession implements Session, QueueSession, TopicSession, JmsMessa
         checkClosed();
         JmsDestination dest = JmsMessageTransformation.transformDestination(connection, queue);
         JmsQueueSender result = new JmsQueueSender(getNextProducerId(), this, dest);
+        add(result);
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2ff38ef6/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsQueueSessionClosedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsQueueSessionClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsQueueSessionClosedTest.java
new file mode 100644
index 0000000..9e91c30
--- /dev/null
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsQueueSessionClosedTest.java
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms.session;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+
+import org.apache.qpid.jms.JmsConnectionFactory;
+import org.apache.qpid.jms.support.AmqpTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests behaviour after a QueueSession is closed.
+ */
+public class JmsQueueSessionClosedTest extends AmqpTestSupport {
+
+    private QueueSession session;
+    private QueueSender sender;
+    private QueueReceiver receiver;
+
+    protected void createAndCloseSession() throws Exception {
+        JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI());
+        connection = factory.createQueueConnection();
+
+        session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+        Queue destination = session.createQueue(name.getMethodName());
+
+        sender = session.createSender(destination);
+        receiver = session.createReceiver(destination);
+
+        // Close the session explicitly, without closing the above.
+        session.close();
+    }
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        createAndCloseSession();
+    }
+
+    @Test(timeout=30000)
+    public void testSessionCloseAgain() throws Exception {
+        // Close it again
+        session.close();
+    }
+
+    @Test(timeout=30000)
+    public void testReceiverCloseAgain() throws Exception {
+        // Close it again (closing the session should have closed it already).
+        receiver.close();
+    }
+
+    @Test(timeout=30000)
+    public void testSenderCloseAgain() throws Exception {
+        // Close it again (closing the session should have closed it already).
+        sender.close();
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testReceiverGetQueueFails() throws Exception {
+        receiver.getQueue();
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testSenderGetQueueFails() throws Exception {
+        sender.getQueue();
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2ff38ef6/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java
new file mode 100644
index 0000000..9e233f9
--- /dev/null
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms.session;
+
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.apache.qpid.jms.JmsConnectionFactory;
+import org.apache.qpid.jms.support.AmqpTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests behaviour after a QueueSession is closed.
+ */
+public class JmsSessionClosedTest extends AmqpTestSupport {
+
+    private Session session;
+    private MessageProducer sender;
+    private MessageConsumer receiver;
+
+    protected void createAndCloseSession() throws Exception {
+        JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI());
+        connection = factory.createQueueConnection();
+
+        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Queue destination = session.createQueue(name.getMethodName());
+
+        sender = session.createProducer(destination);
+        receiver = session.createConsumer(destination);
+
+        // Close the session explicitly, without closing the above.
+        session.close();
+    }
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        createAndCloseSession();
+    }
+
+    @Test(timeout=30000)
+    public void testSessionCloseAgain() throws Exception {
+        // Close it again
+        session.close();
+    }
+
+    @Test(timeout=30000)
+    public void testConsumerCloseAgain() throws Exception {
+        // Close it again (closing the session should have closed it already).
+        receiver.close();
+    }
+
+    @Test(timeout=30000)
+    public void testProducerCloseAgain() throws Exception {
+        // Close it again (closing the session should have closed it already).
+        sender.close();
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testConsumerGetMessageListenerFails() throws Exception {
+        receiver.getMessageListener();
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testProducerGetDestinationFails() throws Exception {
+        sender.getDestination();
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/2ff38ef6/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java
new file mode 100644
index 0000000..53a3e4f
--- /dev/null
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms.session;
+
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+
+import org.apache.qpid.jms.JmsConnectionFactory;
+import org.apache.qpid.jms.support.AmqpTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests behaviour after a TopicSession is closed.
+ */
+public class JmsTopicSessionClosedTest extends AmqpTestSupport {
+
+    private TopicSession session;
+    private TopicPublisher publisher;
+    private TopicSubscriber subscriber;
+
+    protected void createAndCloseSession() throws Exception {
+        JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI());
+        connection = factory.createTopicConnection();
+
+        session = ((TopicConnection) connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+        Topic destination = session.createTopic(name.getMethodName());
+
+        publisher = session.createPublisher(destination);
+        subscriber = session.createSubscriber(destination);
+
+        // Close the session explicitly, without closing the above.
+        session.close();
+    }
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        createAndCloseSession();
+    }
+
+    @Test(timeout=30000)
+    public void testSessionCloseAgain() throws Exception {
+        // Close it again
+        session.close();
+    }
+
+    @Test(timeout=30000)
+    public void testSubscriberCloseAgain() throws Exception {
+        // Close it again (closing the session should have closed it already).
+        subscriber.close();
+    }
+
+    @Test(timeout=30000)
+    public void testPublisherCloseAgain() throws Exception {
+        // Close it again (closing the session should have closed it already).
+        publisher.close();
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testSubscriberGetTopicFails() throws Exception {
+        subscriber.getTopic();
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testPublisherGetTopicFails() throws Exception {
+        publisher.getTopic();
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org