summaryrefslogtreecommitdiff
path: root/qpid/java/client/src
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2008-02-21 20:51:11 +0000
committerRafael H. Schloming <rhs@apache.org>2008-02-21 20:51:11 +0000
commit7e83529e9cef60441fa9cd297ffce485e57b3fc2 (patch)
tree79bb4c7f889ee0204d9f433f089790f469b32ec4 /qpid/java/client/src
parentf054d72c87c3646042c2d4ee91a44fe30523594e (diff)
downloadqpid-python-7e83529e9cef60441fa9cd297ffce485e57b3fc2.tar.gz
modified test harness to clean up data dir when broker crashes
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@629986 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src')
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java84
1 files changed, 62 insertions, 22 deletions
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java b/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
index 084137b38e..60b1b70d67 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
@@ -43,6 +43,7 @@ public class QpidTestCase extends TestCase
// system properties
private static final String BROKER = "broker";
+ private static final String BROKER_CLEAN = "broker.clean";
private static final String BROKER_VERSION = "broker.version";
// values
@@ -52,6 +53,7 @@ public class QpidTestCase extends TestCase
private static final String VERSION_010 = "0-10";
private String _broker = System.getProperty(BROKER, VM);
+ private String _brokerClean = System.getProperty(BROKER_CLEAN, null);
private String _brokerVersion = System.getProperty(BROKER_VERSION, VERSION_08);
private Process _brokerProcess;
@@ -82,6 +84,35 @@ public class QpidTestCase extends TestCase
}
}
+ private static final class Piper extends Thread
+ {
+
+ private InputStream in;
+
+ public Piper(InputStream in)
+ {
+ this.in = in;
+ }
+
+ public void run()
+ {
+ try
+ {
+ byte[] buf = new byte[4*1024];
+ int n;
+ while ((n = in.read(buf)) != -1)
+ {
+ System.out.write(buf, 0, n);
+ }
+ }
+ catch (IOException e)
+ {
+ // this seems to happen regularly even when
+ // exits are normal
+ }
+ }
+ }
+
public void startBroker() throws Exception
{
if (_broker.equals(VM))
@@ -96,34 +127,15 @@ public class QpidTestCase extends TestCase
pb.redirectErrorStream(true);
_brokerProcess = pb.start();
- new Thread()
- {
- private InputStream in = _brokerProcess.getInputStream();
-
- public void run()
- {
- try
- {
- byte[] buf = new byte[4*1024];
- int n;
- while ((n = in.read(buf)) != -1)
- {
- System.out.write(buf, 0, n);
- }
- }
- catch (IOException e)
- {
- // this seems to happen regularly even when
- // exits are normal
- }
- }
- }.start();
+ new Piper(_brokerProcess.getInputStream()).start();
Thread.sleep(1000);
try
{
int exit = _brokerProcess.exitValue();
+ _logger.info("broker aborted: " + exit);
+ cleanBroker();
throw new RuntimeException("broker aborted: " + exit);
}
catch (IllegalThreadStateException e)
@@ -133,6 +145,34 @@ public class QpidTestCase extends TestCase
}
}
+ public void cleanBroker()
+ {
+ if (_brokerClean != null)
+ {
+ _logger.info("clean: " + _brokerClean);
+
+ try
+ {
+ ProcessBuilder pb = new ProcessBuilder(_brokerClean.split("\\s+"));
+ pb.redirectErrorStream(true);
+ Process clean = pb.start();
+ new Piper(clean.getInputStream()).start();
+
+ clean.waitFor();
+
+ _logger.info("clean exited: " + clean.exitValue());
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
public void stopBroker() throws Exception
{
_logger.info("stopping broker: " + _broker);