summaryrefslogtreecommitdiff
path: root/java/systests/src
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2009-11-03 15:21:54 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2009-11-03 15:21:54 +0000
commitf9c5304c21332e836ac4f615f2479cec6689f96d (patch)
tree43d2aaeb53ecf636253415e6038a13170db24f82 /java/systests/src
parent5c08385e89afa9a51bfa60d2bf54e8bce87a8a5e (diff)
downloadqpid-python-f9c5304c21332e836ac4f615f2479cec6689f96d.tar.gz
This adds some minor enhancements to our test framework.
It introduces two jvm args "broker.log.interleave" and "broker.log.prefix". broker.log.interleave if set to false, will print the broker output into a separate file. The file name will be in the following format and placed alongside the test output. "%s/TEST-%s.broker.out" Ex. TEST-org.apache.qpid.test.client.failover.FailoverTest.testP2PFailover.out TEST-org.apache.qpid.test.client.failover.FailoverTest.testP2PFailover.broker.out "broker.log.interleave" is set to true in module.xml to default to the current behaviour. "broker.log.prefix" which is set to "BROKER: " in the module.xml will prefix each broker output line. This would help to follow the log files more easily as it would help to distinguish between broker and client output. It would also be handy for grep. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@832452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/systests/src')
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java57
1 files changed, 44 insertions, 13 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
index b7ca40213a..a1fa2c1a0c 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
@@ -50,6 +50,7 @@ import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
@@ -160,7 +161,9 @@ public class QpidTestCase extends TestCase
protected static final String BROKER_READY = "broker.ready";
private static final String BROKER_STOPPED = "broker.stopped";
private static final String TEST_OUTPUT = "test.output";
-
+ private static final String BROKER_LOG_INTERLEAVE = "broker.log.interleave";
+ private static final String BROKER_LOG_PREFIX = "broker.log.prefix";
+
// values
protected static final String JAVA = "java";
protected static final String CPP = "cpp";
@@ -181,9 +184,14 @@ public class QpidTestCase extends TestCase
private Boolean _brokerCleanBetweenTests = Boolean.getBoolean(BROKER_CLEAN_BETWEEN_TESTS);
private String _brokerVersion = System.getProperty(BROKER_VERSION, VERSION_08);
private String _output = System.getProperty(TEST_OUTPUT);
-
+
+ private static String _brokerLogPrefix = System.getProperty(BROKER_LOG_PREFIX,"BROKER: ");
+ protected static boolean _interleaveBrokerLog = Boolean.getBoolean(BROKER_LOG_INTERLEAVE);
+
protected File _outputFile;
-
+
+ protected PrintStream _brokerOutputStream;
+
private Map<Integer, Process> _brokers = new HashMap<Integer, Process>();
private InitialContext _initialContext;
@@ -209,17 +217,18 @@ public class QpidTestCase extends TestCase
}
public void runBare() throws Throwable
- {
+ {
_testName = getClass().getSimpleName() + "." + getName();
String qname = getClass().getName() + "." + getName();
- // Initalise this for each test run
+ // Initialize this for each test run
_env = new HashMap<String, String>();
PrintStream oldOut = System.out;
PrintStream oldErr = System.err;
PrintStream out = null;
PrintStream err = null;
+
boolean redirected = _output != null && _output.length() > 0;
if (redirected)
{
@@ -228,6 +237,16 @@ public class QpidTestCase extends TestCase
err = new PrintStream(String.format("%s/TEST-%s.err", _output, qname));
System.setOut(out);
System.setErr(err);
+
+ if (_interleaveBrokerLog)
+ {
+ _brokerOutputStream = out;
+ }
+ else
+ {
+ _brokerOutputStream = new PrintStream(new FileOutputStream(String
+ .format("%s/TEST-%s.broker.out", _output, qname)), true);
+ }
}
_logger.info("========== start " + _testName + " ==========");
@@ -266,6 +285,10 @@ public class QpidTestCase extends TestCase
System.setOut(oldOut);
err.close();
out.close();
+ if (!_interleaveBrokerLog)
+ {
+ _brokerOutputStream.close();
+ }
}
}
}
@@ -300,20 +323,22 @@ public class QpidTestCase extends TestCase
{
private LineNumberReader in;
+ private PrintStream out;
private String ready;
private CountDownLatch latch;
private boolean seenReady;
private String stopped;
private String stopLine;
- public Piper(InputStream in, String ready)
+ public Piper(InputStream in, PrintStream out, String ready)
{
- this(in, ready, null);
+ this(in, out, ready, null);
}
- public Piper(InputStream in, String ready, String stopped)
+ public Piper(InputStream in, PrintStream out, String ready, String stopped)
{
this.in = new LineNumberReader(new InputStreamReader(in));
+ this.out = out;
this.ready = ready;
this.stopped = stopped;
this.seenReady = false;
@@ -328,9 +353,9 @@ public class QpidTestCase extends TestCase
}
}
- public Piper(InputStream in)
+ public Piper(InputStream in, PrintStream out)
{
- this(in, null);
+ this(in, out, null);
}
public boolean await(long timeout, TimeUnit unit) throws InterruptedException
@@ -352,8 +377,13 @@ public class QpidTestCase extends TestCase
{
String line;
while ((line = in.readLine()) != null)
- {
- System.out.println(line);
+ {
+ if (_interleaveBrokerLog)
+ {
+ line = _brokerLogPrefix + line;
+ }
+ out.println(line);
+
if (latch != null && line.contains(ready))
{
seenReady = true;
@@ -528,6 +558,7 @@ public class QpidTestCase extends TestCase
process = pb.start();
Piper p = new Piper(process.getInputStream(),
+ _brokerOutputStream,
System.getProperty(BROKER_READY),
System.getProperty(BROKER_STOPPED));
@@ -591,7 +622,7 @@ public class QpidTestCase extends TestCase
ProcessBuilder pb = new ProcessBuilder(_brokerClean.split("\\s+"));
pb.redirectErrorStream(true);
Process clean = pb.start();
- new Piper(clean.getInputStream()).start();
+ new Piper(clean.getInputStream(),_brokerOutputStream).start();
clean.waitFor();