diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2008-05-13 15:55:00 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2008-05-13 15:55:00 +0000 |
| commit | 134fb24da17b023fba1a55d5d60e1ac0580f145e (patch) | |
| tree | 2c83a3a812751d4ac005fe04a65f202b05ba1bb0 /java/client/src/test | |
| parent | e00d795537664f2aabe03bb0e764dadc73f00df3 (diff) | |
| download | qpid-python-134fb24da17b023fba1a55d5d60e1ac0580f145e.tar.gz | |
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
Diffstat (limited to 'java/client/src/test')
| -rw-r--r-- | java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java | 56 |
1 files changed, 47 insertions, 9 deletions
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 { |
