You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2009/11/03 16:21:54 UTC

svn commit: r832452 - in /qpid/trunk/qpid/java: module.xml systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java

Author: rajith
Date: Tue Nov  3 15:21:54 2009
New Revision: 832452

URL: http://svn.apache.org/viewvc?rev=832452&view=rev
Log:
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.


Modified:
    qpid/trunk/qpid/java/module.xml
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java

Modified: qpid/trunk/qpid/java/module.xml
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/module.xml?rev=832452&r1=832451&r2=832452&view=diff
==============================================================================
--- qpid/trunk/qpid/java/module.xml (original)
+++ qpid/trunk/qpid/java/module.xml Tue Nov  3 15:21:54 2009
@@ -60,6 +60,8 @@
   <property name="module.release.bz2"  location="${module.release}/${module.namever}.tar.bz2"/>
 
   <property name="module.genpom.args"  value=""/>
+  <property name="broker.log.prefix" value="BROKER: "/> 
+  <property name="broker.log.interleave" value="true"/>
 
   <property name="module.qpid.jar"     location="${module.release.lib}/qpid-all.jar"/>
   <basename property="qpid.jar.name"  file="${module.qpid.jar}"/>
@@ -276,6 +278,7 @@
       <sysproperty key="broker.stopped" value="${broker.stopped}" />
       <sysproperty key="broker.config" value="${broker.config}" />
       <sysproperty key="test.output" value="${module.results}"/>
+
       <syspropertyset>
         <propertyref prefix="test"/>
       </syspropertyset>
@@ -284,7 +287,11 @@
       </syspropertyset>
       <syspropertyset>
         <propertyref prefix="javax.net.ssl"/>
+      </syspropertyset>  
+      <syspropertyset>
+         <propertyref prefix="broker"/>
       </syspropertyset>
+      
       <sysproperty key="max_prefetch" value ="${max_prefetch}"/>
       <sysproperty key="example.plugin.target" value="${project.root}/build/lib/plugins"/>
       <sysproperty key="QPID_EXAMPLE_HOME" value="${qpid.home}"/>
@@ -526,6 +533,7 @@
   </target>
 
   <target name="cover-test" depends="instrument">
+
     <mkdir dir="${build.coveragereport}" />
     <junit fork="yes" forkmode="once" maxmemory="${test.mem}" reloading="no"
            haltonfailure="${haltonfailure}" haltonerror="${haltonerror}"
@@ -543,9 +551,14 @@
       <sysproperty key="broker.version" value="${broker.version}"/>
       <sysproperty key="broker.ready" value="${broker.ready}" />
       <sysproperty key="test.output" value="${module.results}"/>
+
       <syspropertyset>
         <propertyref prefix="test"/>
       </syspropertyset>
+      <syspropertyset>
+          <propertyref prefix="broker"/>
+      </syspropertyset>
+
       <sysproperty key="max_prefetch" value ="${max_prefetch}"/>
       <sysproperty key="example.plugin.target" value="${project.root}/build/lib/plugins"/>
       <sysproperty key="QPID_EXAMPLE_HOME" value="${project.root}/build"/>

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java?rev=832452&r1=832451&r2=832452&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java Tue Nov  3 15:21:54 2009
@@ -50,6 +50,7 @@
 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 @@
     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 @@
     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 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 @@
             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 @@
                 System.setOut(oldOut);
                 err.close();
                 out.close();
+                if (!_interleaveBrokerLog)
+                { 	
+                	_brokerOutputStream.close();
+                }
             }
         }
     }
@@ -300,20 +323,22 @@
     {
 
         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 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 @@
             {
                 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 @@
             process = pb.start();
 
             Piper p = new Piper(process.getInputStream(),
+            		            _brokerOutputStream,
                                 System.getProperty(BROKER_READY),
                                 System.getProperty(BROKER_STOPPED));
 
@@ -591,7 +622,7 @@
                 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();
 



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org