You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2008/02/21 21:51:12 UTC

svn commit: r629986 - in /incubator/qpid/trunk/qpid/java: clean-dir client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java module.xml

Author: rhs
Date: Thu Feb 21 12:51:11 2008
New Revision: 629986

URL: http://svn.apache.org/viewvc?rev=629986&view=rev
Log:
modified test harness to clean up data dir when broker crashes

Added:
    incubator/qpid/trunk/qpid/java/clean-dir   (with props)
Modified:
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
    incubator/qpid/trunk/qpid/java/module.xml

Added: incubator/qpid/trunk/qpid/java/clean-dir
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/clean-dir?rev=629986&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/clean-dir (added)
+++ incubator/qpid/trunk/qpid/java/clean-dir Thu Feb 21 12:51:11 2008
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+rm -rf $@; mkdir $@

Propchange: incubator/qpid/trunk/qpid/java/clean-dir
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java?rev=629986&r1=629985&r2=629986&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java Thu Feb 21 12:51:11 2008
@@ -43,6 +43,7 @@
 
     // 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 @@
     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 @@
         }
     }
 
+    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,39 +127,48 @@
             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)
             {
                 // this is expect if the broker started succesfully
+            }
+        }
+    }
+
+    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);
             }
         }
     }

Modified: incubator/qpid/trunk/qpid/java/module.xml
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/module.xml?rev=629986&r1=629985&r2=629986&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/module.xml (original)
+++ incubator/qpid/trunk/qpid/java/module.xml Thu Feb 21 12:51:11 2008
@@ -169,14 +169,18 @@
 
   <condition property="brokerdefault" value="${project.root}/../cpp/src/qpidd --data-dir ${build.data} -t" else="vm">
     <isset property="cpp"/>
-  </condition>  
+  </condition>
 
- <condition property="broker" value="${brokerdefault} --load-module ${store}" else="${brokerdefault}">
+  <condition property="broker" value="${brokerdefault} --load-module ${store} --store-async yes" else="${brokerdefault}">
     <and>
-    	<isset property="store"/>
-    	<isset property="cpp"/>
-    </and>	
-  </condition>  
+      <isset property="store"/>
+      <isset property="cpp"/>
+    </and>
+  </condition>
+
+  <condition property="broker.clean" value="${project.root}/clean-dir ${build.data}">
+    <isset property="cpp"/>
+  </condition>
 
   <condition property="broker.version" value="0-10" else="0-8">
     <isset property="cpp"/>
@@ -184,7 +188,6 @@
 
   <target name="test" depends="compile-tests" if="module.test.src.exists"
           description="execute unit tests">
-    <echo message="=------->>>>>>>>>>>>> ${broker}"/>
     <junit fork="yes" haltonfailure="no" printsummary="on" timeout="600000">
 
       <sysproperty key="amqj.logging.level" value="${amqj.logging.level}"/>
@@ -193,6 +196,7 @@
       <sysproperty key="java.naming.factory.initial" value="${java.naming.factory.initial}"/>
       <sysproperty key="java.naming.provider.url" value="${java.naming.provider.url}"/>
       <sysproperty key="broker" value="${broker}"/>
+      <sysproperty key="broker.clean" value="${broker.clean}"/>
       <sysproperty key="broker.version" value="${broker.version}"/>
 
       <formatter type="plain"/>