qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r627157 - in /incubator/qpid/trunk/qpid/java/client/src: main/java/org/apache/qpidity/nclient/Client.java test/java/org/apache/qpid/test/unit/client/connection/ConnectionCloseTest.java
Date Tue, 12 Feb 2008 22:26:29 GMT
Author: rhs
Date: Tue Feb 12 14:26:26 2008
New Revision: 627157

URL: http://svn.apache.org/viewvc?rev=627157&view=rev
Log:
added a test for message send followed by immediate connection close; fixed connection close
handshaking

Added:
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionCloseTest.java
  (with props)
Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java?rev=627157&r1=627156&r2=627157&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/nclient/Client.java
Tue Feb 12 14:26:26 2008
@@ -16,6 +16,7 @@
 import org.apache.qpidity.transport.Channel;
 import org.apache.qpidity.transport.Connection;
 import org.apache.qpidity.transport.ConnectionClose;
+import org.apache.qpidity.transport.ConnectionCloseOk;
 import org.apache.qpidity.transport.ConnectionDelegate;
 import org.apache.qpidity.transport.ConnectionEvent;
 import org.apache.qpidity.transport.ProtocolHeader;
@@ -33,6 +34,9 @@
     private ClosedListener _closedListner;
     private final Lock _lock = new ReentrantLock();
     private static Logger _logger = LoggerFactory.getLogger(Client.class);
+    private Condition closeOk;
+    private boolean closed = false;
+
     /**
      *
      * @return returns a new connection to the broker.
@@ -45,6 +49,7 @@
     public void connect(String host, int port,String virtualHost,String username, String
password) throws QpidException
     {
         Condition negotiationComplete = _lock.newCondition();
+        closeOk = _lock.newCondition();
         _lock.lock();
 
         ConnectionDelegate connectionDelegate = new ConnectionDelegate()
@@ -76,6 +81,21 @@
                 }
             }
 
+            @Override public void connectionCloseOk(Channel context, ConnectionCloseOk struct)
+            {
+                _lock.lock();
+                try
+                {
+                    closed = true;
+                    this.receivedClose = true;
+                    closeOk.signalAll();
+                }
+                finally
+                {
+                    _lock.unlock();
+                }
+            }
+
             @Override public void connectionClose(Channel context, ConnectionClose connectionClose)
             {
                 ErrorCode errorCode = ErrorCode.get(connectionClose.getReplyCode());
@@ -179,6 +199,24 @@
     {
         Channel ch = _conn.getChannel(0);
         ch.connectionClose(0, "client is closing", 0, 0);
+        _lock.lock();
+        try
+        {
+            try {
+                while (!closed)
+                {
+                    closeOk.await();
+                }
+            }
+            catch (InterruptedException e)
+            {
+                // do nothing
+            }
+        }
+        finally
+        {
+            _lock.unlock();
+        }
         _conn.close();
     }
 

Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionCloseTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionCloseTest.java?rev=627157&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionCloseTest.java
(added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionCloseTest.java
Tue Feb 12 14:26:26 2008
@@ -0,0 +1,72 @@
+/*
+ *
+ * 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.connection;
+
+import org.apache.qpid.testutil.QpidTestCase;
+import org.apache.qpidity.transport.util.Logger;
+
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+/**
+ * ConnectionCloseTest
+ *
+ */
+
+public class ConnectionCloseTest extends QpidTestCase
+{
+
+    private static final Logger log = Logger.get(ConnectionCloseTest.class);
+
+    public void testSendReceiveClose() throws Exception
+    {
+        for (int i = 0; i < 500; i++)
+        {
+            if ((i % 10) == 0)
+            {
+                log.warn("%d messages sent and received", i);
+            }
+
+            Connection receiver = getConnection();
+            receiver.start();
+            Session rssn = receiver.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Queue queue = rssn.createQueue("connection-close-test-queue");
+            MessageConsumer cons = rssn.createConsumer(queue);
+
+            Connection sender = getConnection();
+            sender.start();
+            Session sssn = sender.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageProducer prod = sssn.createProducer(queue);
+            prod.send(sssn.createTextMessage("test"));
+            sender.close();
+
+            TextMessage m = (TextMessage) cons.receive(2000);
+            assertNotNull("message was lost", m);
+            assertEquals(m.getText(), "test");
+            receiver.close();
+        }
+    }
+
+}

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



Mime
View raw message