diff options
| author | Rajith Muditha Attapattu <rajith@apache.org> | 2010-05-06 21:17:21 +0000 |
|---|---|---|
| committer | Rajith Muditha Attapattu <rajith@apache.org> | 2010-05-06 21:17:21 +0000 |
| commit | 0836956c41a0d535f37c6d17674e89b23532ba65 (patch) | |
| tree | 6301cfaf2d0216ab00688dedfc4102eccd96f51b /qpid/java | |
| parent | 5bee9733abc18405f6e4f8e059e7fd1487b5ae38 (diff) | |
| download | qpid-python-0836956c41a0d535f37c6d17674e89b23532ba65.tar.gz | |
Modified the testHeartbeat method to use an external script to start & stop the broker.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@941934 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
5 files changed, 65 insertions, 12 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java index 7f6267c210..d08eee3e83 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java @@ -26,6 +26,7 @@ import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import javax.jms.Connection; @@ -294,11 +295,33 @@ public class AMQConnectionTest extends QpidTestCase Process process = null; int port = getPort(0); + String pid = null; try { + // close the connection and shutdown the broker started by QpidTest _connection.close(); - System.setProperty("qpid.heartbeat", "1"); - Connection con = getConnection(); + stopBroker(port); + + System.setProperty("qpid.heartbeat", "1"); + + // in case this broker gets stuck, atleast the rest of the tests will not fail. + port = port + 200; + String startCmd = getBrokerCommand(port); + + // start a broker using a script + ProcessBuilder pb = new ProcessBuilder(System.getProperty("broker.start")); + pb.redirectErrorStream(true); + + Map<String, String> env = pb.environment(); + env.put("BROKER_CMD",startCmd); + env.put("BROKER_READY",System.getProperty(BROKER_READY)); + + Process startScript = pb.start(); + startScript.waitFor(); + startScript.destroy(); + + Connection con = + new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:" + port + "'"); final AtomicBoolean lock = new AtomicBoolean(false); String cmd = "/usr/bin/pgrep -f " + port; @@ -306,7 +329,7 @@ public class AMQConnectionTest extends QpidTestCase 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(); + pid = reader.readLine(); try { Integer.parseInt(pid); @@ -351,18 +374,15 @@ public class AMQConnectionTest extends QpidTestCase 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(); - } + Process killScript = Runtime.getRuntime().exec(System.getProperty("broker.kill") + " " + pid); + killScript.waitFor(); + killScript.destroy(); cleanBroker(); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java index 54628ab4b8..020b598279 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -469,7 +469,7 @@ public class QpidTestCase extends TestCase } } - private String getBrokerCommand(int port) throws MalformedURLException + protected String getBrokerCommand(int port) throws MalformedURLException { return _broker .replace("@PORT", "" + port) diff --git a/qpid/java/test-profiles/default.testprofile b/qpid/java/test-profiles/default.testprofile index dfc92f1e19..43b9c68d43 100644 --- a/qpid/java/test-profiles/default.testprofile +++ b/qpid/java/test-profiles/default.testprofile @@ -6,6 +6,8 @@ broker=vm broker.clean=${test.profiles}/clean-dir ${build.data} ${project.root}/build/work/derbyDB broker.ready=Listening on TCP port broker.config=${project.root}/build/etc/config-systests.xml +broker.start=${test.profiles}/start-broker +broker.kill=${test.profiles}/kill-broker max_prefetch=1000 qpid.dest_syntax=BURL diff --git a/qpid/java/test-profiles/kill-broker b/qpid/java/test-profiles/kill-broker index e31d3811b3..8078fa755e 100755 --- a/qpid/java/test-profiles/kill-broker +++ b/qpid/java/test-profiles/kill-broker @@ -21,5 +21,6 @@ # # - +kill -CONT $1 kill -9 $1 +rm /tmp/broker.log diff --git a/qpid/java/test-profiles/start-broker b/qpid/java/test-profiles/start-broker new file mode 100755 index 0000000000..1dc9cd4336 --- /dev/null +++ b/qpid/java/test-profiles/start-broker @@ -0,0 +1,30 @@ + +#!/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. +# +# + +# The entire broker command is passed as an argument. + +waitfor() { until grep -a -l "$2" $1 >/dev/null 2>&1 ; do sleep 1 ; done ; } + +sh $BROKER_CMD --log-to-file /tmp/broker.log & +waitfor /tmp/broker.log $BROKER_READY + |
