From 134fb24da17b023fba1a55d5d60e1ac0580f145e Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 13 May 2008 15:55:00 +0000 Subject: QPID-1053: updated QpidTestCase to check against broker output to ensure the broker is actually listening before the test attempts to connect; the text checked for is controlled by the broker.ready system property, appropriate values have been added to the cpp profiles git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@655927 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/testutil/QpidTestCase.java | 56 ++++++++++++++++++---- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'java/client') diff --git a/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java b/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java index 2f4a0e6b04..145b4da268 100644 --- a/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java +++ b/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java @@ -23,9 +23,10 @@ import junit.framework.TestResult; import javax.jms.Connection; import javax.naming.InitialContext; import java.io.*; -import java.util.List; import java.util.ArrayList; +import java.util.List; import java.util.StringTokenizer; +import java.util.concurrent.CountDownLatch; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.AMQConnection; @@ -105,6 +106,7 @@ public class QpidTestCase extends TestCase private static final String BROKER = "broker"; private static final String BROKER_CLEAN = "broker.clean"; private static final String BROKER_VERSION = "broker.version"; + private static final String BROKER_READY = "broker.ready"; // values private static final String VM = "vm"; @@ -162,22 +164,49 @@ public class QpidTestCase extends TestCase private static final class Piper extends Thread { - private InputStream in; + private LineNumberReader in; + private String ready; + private CountDownLatch latch; + + public Piper(InputStream in, String ready) + { + this.in = new LineNumberReader(new InputStreamReader(in)); + this.ready = ready; + if (this.ready != null && !this.ready.equals("")) + { + this.latch = new CountDownLatch(1); + } + else + { + this.latch = null; + } + } public Piper(InputStream in) { - this.in = in; + this(in, null); + } + + public void await() throws InterruptedException + { + if (latch != null) + { + latch.await(); + } } public void run() { try { - byte[] buf = new byte[4*1024]; - int n; - while ((n = in.read(buf)) != -1) + String line; + while ((line = in.readLine()) != null) { - System.out.write(buf, 0, n); + System.out.println(line); + if (latch != null && line.contains(ready)) + { + latch.countDown(); + } } } catch (IOException e) @@ -185,6 +214,13 @@ public class QpidTestCase extends TestCase // this seems to happen regularly even when // exits are normal } + finally + { + if (latch != null) + { + latch.countDown(); + } + } } } @@ -202,9 +238,11 @@ public class QpidTestCase extends TestCase pb.redirectErrorStream(true); _brokerProcess = pb.start(); - new Piper(_brokerProcess.getInputStream()).start(); + Piper p = new Piper(_brokerProcess.getInputStream(), + System.getProperty(BROKER_READY)); - Thread.sleep(1000); + p.start(); + p.await(); try { -- cgit v1.2.1