Author: ritchiem
Date: Fri Sep  4 16:31:11 2009
New Revision: 811472

URL: http://svn.apache.org/viewvc?rev=811472&view=rev
Log:
QPID-2081, QPID-155 : Provide a test for Dynamic Queue/Exchange toggling and 
fixed the issue with ChannelCloseExceptions by closing the channel and not 
sending the ChannelClose when the Channel has already been closed by the broker.

Added:
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
Modified:
    
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
    qpid/trunk/qpid/java/test-profiles/Excludes

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=811472&r1=811471&r2=811472&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 Sep  4 16:31:11 2009
@@ -65,6 +65,7 @@
 import org.apache.qpid.AMQException;
 import org.apache.qpid.AMQInvalidArgumentException;
 import org.apache.qpid.AMQInvalidRoutingKeyException;
+import org.apache.qpid.AMQChannelClosedException;
 import org.apache.qpid.client.failover.FailoverException;
 import org.apache.qpid.client.failover.FailoverNoopSupport;
 import org.apache.qpid.client.failover.FailoverProtectedOperation;
@@ -629,6 +630,11 @@
      */
     public void close(long timeout) throws JMSException
     {
+        close(timeout, true);
+    }
+
+    private void close(long timeout, boolean sendClose) throws JMSException
+    {
         if (_logger.isInfoEnabled())
         {
             StackTraceElement[] stackTrace = 
Thread.currentThread().getStackTrace();
@@ -654,9 +660,12 @@
                         // If the connection is open or we are in the process
                         // of closing the connection then send a cance
                         // no point otherwise as the connection will be gone
-                        if (!_connection.isClosed() || 
_connection.isClosing())                        
+                        if (!_connection.isClosed() || _connection.isClosing())
                         {
-                            sendClose(timeout);
+                            if (sendClose)
+                            {
+                                sendClose(timeout);
+                            }
                         }
                     }
                     catch (AMQException e)
@@ -1737,6 +1746,11 @@
                         }
                         catch (AMQException e)
                         {
+                            if (e instanceof AMQChannelClosedException)
+                            {
+                                close(-1, false);
+                            }
+
                             JMSException ex = new JMSException("Error 
registering consumer: " + e);
 
                             ex.setLinkedException(e);

Added: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java?rev=811472&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
 (added)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
 Fri Sep  4 16:31:11 2009
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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.client;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+public class DynamicQueueExchangeCreateTest extends QpidTestCase
+{
+
+    public void testQueueDeclare() throws Exception
+    {
+        setSystemProperty("qpid.declare_queues", "false");
+
+        Connection connection = getConnection();
+
+        Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+
+        Queue queue = session.createQueue(getTestQueueName());
+
+        try
+        {
+            session.createConsumer(queue);
+            fail("JMSException should be thrown as the queue does not exist");
+        }
+        catch (JMSException e)
+        {
+            assertTrue(e.getMessage().contains("does not exist"));
+        }
+    }
+
+    public void testExchangeDeclare() throws Exception
+    {
+        setSystemProperty("qpid.declare_exchanges", "false");
+
+        Connection connection = getConnection();
+
+        Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+
+        String EXCHANGE_TYPE = "test.direct";
+        Queue queue = session.createQueue("new.direct://" + EXCHANGE_TYPE + 
"/queue/queue");
+
+        try
+        {
+            session.createConsumer(queue);
+            fail("JMSException should be thrown as the exchange does not 
exist");
+        }
+        catch (JMSException e)
+        {
+            System.err.println(e.getMessage());
+
+            assertTrue(e.getMessage().contains("Exchange " + EXCHANGE_TYPE + " 
does not exist"));
+        }
+    }
+
+}

Modified: qpid/trunk/qpid/java/test-profiles/Excludes
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/Excludes?rev=811472&r1=811471&r2=811472&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/Excludes (original)
+++ qpid/trunk/qpid/java/test-profiles/Excludes Fri Sep  4 16:31:11 2009
@@ -15,3 +15,5 @@
 
org.apache.qpid.server.logging.MemoryMessageStoreLoggingTest#testMessageStoreClose
 
org.apache.qpid.server.logging.DerbyMessageStoreLoggingTest#testMessageStoreClose
 
+// QPID-2081 - the connection close here needs more work
+org.apache.qpid.test.unit.clienta.DynamicQueueExchangeCreateTest#testExchangeDeclare



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

Reply via email to