You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2006/12/12 16:50:55 UTC

svn commit: r486198 - in /incubator/qpid/trunk/qpid/java/client/src: main/java/org/apache/qpid/client/AMQSession.java test/java/org/apache/qpid/test/unit/close/ test/java/org/apache/qpid/test/unit/close/TopicPublisherCloseTest.java

Author: rgreig
Date: Tue Dec 12 07:50:54 2006
New Revision: 486198

URL: http://svn.apache.org/viewvc?view=rev&rev=486198
Log:
QPID-171 Patch supplied by Rob Godfrey to fix problem where close check for publisher methods did not appear to be done.

Added:
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/TopicPublisherCloseTest.java   (with props)
Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java?view=diff&rev=486198&r1=486197&r2=486198
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java Tue Dec 12 07:50:54 2006
@@ -7,9 +7,9 @@
  * 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
@@ -728,10 +728,12 @@
             public Object operation() throws JMSException
             {
                 checkNotClosed();
-
-                return new BasicMessageProducer(_connection, (AMQDestination) destination, _transacted, _channelId,
-                                                AMQSession.this, _connection.getProtocolHandler(),
-                                                getNextProducerId(), immediate, mandatory, waitUntilSent);
+                long producerId = getNextProducerId();
+                BasicMessageProducer producer = new BasicMessageProducer(_connection, (AMQDestination) destination, _transacted, _channelId,
+                                                                         AMQSession.this, _connection.getProtocolHandler(),
+                                                                         producerId, immediate, mandatory, waitUntilSent);
+                registerProducer(producerId, producer);
+                return producer;
             }
         }.execute(_connection);
     }
@@ -745,7 +747,7 @@
      */
     public QueueReceiver createQueueReceiver(Destination destination) throws JMSException
     {
-    	checkValidDestination(destination);    	
+    	checkValidDestination(destination);
         AMQQueue dest = (AMQQueue) destination;
         BasicMessageConsumer consumer = (BasicMessageConsumer) createConsumer(destination);
         return new QueueReceiverAdaptor(dest, consumer);
@@ -1024,7 +1026,7 @@
     public Topic createTopic(String topicName) throws JMSException
     {
     	checkNotClosed();
-    	
+
         if (topicName.indexOf('/') == -1)
         {
             return new AMQTopic(topicName);
@@ -1142,7 +1144,7 @@
     public void unsubscribe(String name) throws JMSException
     {
     	checkNotClosed();
-    	    	
+
         //send a queue.delete for the subscription
         String queue = _connection.getClientID() + ":" + name;
         AMQFrame frame = QueueDeleteBody.createAMQFrame(_channelId, 0, queue, false, false, true);
@@ -1344,7 +1346,7 @@
         AMQFrame channelFlowFrame = ChannelFlowBody.createAMQFrame(_channelId, true);
         _connection.getProtocolHandler().writeFrame(channelFlowFrame);
     }
-    
+
     /*
      * I could have combined the last 3 methods, but this way it improves readability
      */
@@ -1353,13 +1355,13 @@
     		throw new javax.jms.InvalidDestinationException("Invalid Topic");
     	}
     }
-    
+
     private void checkValidQueue(Queue queue) throws InvalidDestinationException{
     	if (queue == null){
     		throw new javax.jms.InvalidDestinationException("Invalid Queue");
     	}
     }
-    
+
     private void checkValidDestination(Destination destination) throws InvalidDestinationException{
     	if (destination == null){
     		throw new javax.jms.InvalidDestinationException("Invalid Queue");

Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/TopicPublisherCloseTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/TopicPublisherCloseTest.java?view=auto&rev=486198
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/TopicPublisherCloseTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/TopicPublisherCloseTest.java Tue Dec 12 07:50:54 2006
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.test.unit.close;
+
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.client.*;
+import junit.framework.TestCase;
+
+import javax.jms.Session;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.Topic;
+
+/**
+ * @author Apache Software Foundation
+ */
+public class TopicPublisherCloseTest extends TestCase
+{
+
+    public String _connectionString = "vm://:1";
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        TransportConnection.createVMBroker(1);
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        TransportConnection.killAllVMBrokers();
+    }
+
+    public void testAllMethodsThrowAfterConnectionClose() throws Exception
+    {
+        AMQConnection connection = new AMQConnection(_connectionString, "guest", "guest", "Client", "/test_path");
+
+        Topic destination1 = new AMQTopic("t1");
+        TopicSession session1 = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+        TopicPublisher pub = session1.createPublisher(destination1);
+        connection.close();
+        try
+        {
+            pub.getDeliveryMode();
+            fail("Expected exception not thrown");
+        }
+        catch (javax.jms.IllegalStateException e)
+        {
+            // PASS
+        }
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/TopicPublisherCloseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native