qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject svn commit: r941553 - in /qpid/trunk/qpid/java: client/src/main/java/org/apache/qpid/client/ systests/src/main/java/org/apache/qpid/test/unit/client/ systests/src/main/java/org/apache/qpid/test/utils/ test-profiles/
Date Thu, 06 May 2010 00:10:08 GMT
Author: rajith
Date: Thu May  6 00:10:07 2010
New Revision: 941553

URL: http://svn.apache.org/viewvc?rev=941553&view=rev
Log:
The heartbeat wasn't being set properly and these mistakes went uncaught due to lack of proper
test.
I have added a test case to AMQConnectionTest called testHeartBeat.
This test fails once in a while even when I have an external script to clean the broker instance.
It seems once it's wedged with kill -STOP, it somestimes doesn't get cleaned up properly with
kill -9.
Despite the occasional failure, I think it's worth to have this test as a lot of our users
rely on heartbeat functionality.

Added:
    qpid/trunk/qpid/java/test-profiles/kill-broker   (with props)
Modified:
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java?rev=941553&r1=941552&r2=941553&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
(original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
Thu May  6 00:10:07 2010
@@ -396,7 +396,7 @@ public class AMQConnectionDelegate_0_10 
         {
             heartbeat = Integer.getInteger(ClientProperties.HEARTBEAT,ClientProperties.HEARTBEAT_DEFAULT);
         } 
-        return 0;
+        return heartbeat;
     }
     
     protected org.apache.qpid.transport.Connection getQpidConnection()

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java?rev=941553&r1=941552&r2=941553&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java
Thu May  6 00:10:07 2010
@@ -20,6 +20,16 @@
  */
 package org.apache.qpid.test.unit.client;
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.jms.Connection;
+import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
@@ -37,6 +47,8 @@ import org.apache.qpid.client.AMQTopic;
 import org.apache.qpid.configuration.ClientProperties;
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.test.utils.QpidTestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class AMQConnectionTest extends QpidTestCase
 {
@@ -45,6 +57,7 @@ public class AMQConnectionTest extends Q
     private static AMQQueue _queue;
     private static QueueSession _queueSession;
     private static TopicSession _topicSession;
+    protected static final Logger _logger = LoggerFactory.getLogger(AMQConnectionTest.class);
 
     protected void setUp() throws Exception
     {
@@ -262,6 +275,98 @@ public class AMQConnectionTest extends Q
         }
     }
     
+    /**
+     * Test Strategy : Kill -STOP the broker and see
+     * if the client terminates the connection with a
+     * read timeout.
+     * The broker process is cleaned up in the test itself
+     * and avoids using process.waitFor() as it hangs. 
+     */
+    public void testHeartBeat() throws Exception
+    {
+       boolean windows = 
+            ((String) System.getProperties().get("os.name")).matches("(?i).*windows.*");
+ 
+       if (!isCppBroker() || windows)
+       {
+           return;
+       }
+       
+       Process process = null;
+       int port = getPort(0);
+       try
+       {
+           _connection.close();
+           System.setProperty("qpid.heartbeat", "1");           
+           Connection con = getConnection();
+           final AtomicBoolean lock = new AtomicBoolean(false);
+           
+           String cmd = "/usr/bin/pgrep -f " + port;
+           process = Runtime.getRuntime().exec("/bin/bash");
+           LineNumberReader reader = new LineNumberReader(new InputStreamReader(process.getInputStream()));
+           PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(process.getOutputStream())),
true); 
+           out.println(cmd); 
+           String pid = reader.readLine();
+           try
+           {
+               Integer.parseInt(pid);
+           }
+           catch (NumberFormatException e) 
+           {
+               // Error! try to read further to gather the error msg.
+               String line;
+               _logger.debug(pid);
+               while ((line = reader.readLine()) != null )
+               {
+                   _logger.debug(line);
+               }
+               throw new Exception( "Unable to get the brokers pid " + pid);
+           }
+           _logger.debug("pid : " + pid);
+           
+           con.setExceptionListener(new ExceptionListener(){
+               
+               public void onException(JMSException e)
+               {
+                   synchronized(lock) {
+                       lock.set(true);
+                       lock.notifyAll();
+                  }
+               }           
+           });   
+
+           out.println("kill -STOP " + pid);           
+           
+           synchronized(lock){
+               lock.wait(2500);
+           }
+           out.close();
+           reader.close();
+           assertTrue("Client did not terminate the connection, check log for details",lock.get());
+       }
+       catch(Exception e)
+       {
+           throw e;
+       }
+       finally
+       {
+           System.setProperty("qpid.heartbeat", "");
+           if (process != null)
+           {
+               process.destroy();
+           }
+           
+           Runtime.getRuntime().exec(System.getProperty("broker.kill"));
+           
+           Process brokerProcess = _brokers.remove(port);
+           if (process != null)
+           {
+               brokerProcess.destroy();
+           }
+           cleanBroker();
+       }
+    }
+    
     public static junit.framework.Test suite()
     {
         return new junit.framework.TestSuite(AMQConnectionTest.class);

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java?rev=941553&r1=941552&r2=941553&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
Thu May  6 00:10:07 2010
@@ -201,7 +201,7 @@ public class QpidTestCase extends TestCa
 
     protected PrintStream _brokerOutputStream;
 
-    private Map<Integer, Process> _brokers = new HashMap<Integer, Process>();
+    protected Map<Integer, Process> _brokers = new HashMap<Integer, Process>();
 
     private InitialContext _initialContext;
     protected AMQConnectionFactory _connectionFactory;
@@ -453,7 +453,7 @@ public class QpidTestCase extends TestCa
         return getPort(0);
     }
 
-    private int getPort(int port)
+    protected int getPort(int port)
     {
         if (_broker.equals(VM))
         {

Added: qpid/trunk/qpid/java/test-profiles/kill-broker
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/kill-broker?rev=941553&view=auto
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/kill-broker (added)
+++ qpid/trunk/qpid/java/test-profiles/kill-broker Thu May  6 00:10:07 2010
@@ -0,0 +1,25 @@
+
+#!/bin/bash
+#
+# 
+# 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.
+# 
+#
+
+
+kill -9 $1

Propchange: qpid/trunk/qpid/java/test-profiles/kill-broker
------------------------------------------------------------------------------
    svn:executable = *



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


Mime
View raw message