db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r431697 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testProperties.java
Date Tue, 15 Aug 2006 20:38:48 GMT
Author: djd
Date: Tue Aug 15 13:38:48 2006
New Revision: 431697

URL: http://svn.apache.org/viewvc?rev=431697&view=rev
Log:
DERBY-1694 Cleanup derbynet/testProperties so that it always handles the output from the processes
it forks.
Not handling the output can lead to hangs according to the javadoc for java.lang.Process.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testProperties.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testProperties.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testProperties.java?rev=431697&r1=431696&r2=431697&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testProperties.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testProperties.java
Tue Aug 15 13:38:48 2006
@@ -23,6 +23,7 @@
 import java.sql.*;
 import java.util.Vector;
 import java.util.Properties;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.BufferedOutputStream;
@@ -111,27 +112,43 @@
 									"-p",
 									"1527"};	
     /**
-	 * Execute the given command and dump the results to standard out
+	 * Execute the given command and optionally wait and dump the results to standard out
 	 *
 	 * @param args	command and arguments
-	 * @param wait  true =wait for completion
+	 * @param wait  true =wait for completion and dump output, false don't wait and
+     * ignore the output.
 	 * @exception Exception
 	 */
 
-	private static void execCmdDumpResults (String[] args) throws Exception
+	private static void execCmdDumpResults (String[] args, boolean wait) throws Exception
 	{
         // We need the process inputstream and errorstream
         ProcessStreamResult prout = null;
         ProcessStreamResult prerr = null;
             
+        System.out.flush();
+        bos.flush();
+        
+        BufferedOutputStream _bos = bos;
+        if (!wait) {
+            // not interested in the output, don't expect a huge amount.
+            // information will just be written to the byte array in
+            // memory and never used.
+            _bos = new BufferedOutputStream(new ByteArrayOutputStream());
+        }
 		// Start a process to run the command
 		Process pr = execCmd(args);
-        prout = new ProcessStreamResult(pr.getInputStream(), bos, null);
-        prerr = new ProcessStreamResult(pr.getErrorStream(), bos, null);
+        prout = new ProcessStreamResult(pr.getInputStream(), _bos, null);
+        prerr = new ProcessStreamResult(pr.getErrorStream(), _bos, null);
+        
+        if (!wait)
+            return;
 
 		// wait until all the results have been processed
 		prout.Wait();
 		prerr.Wait();
+        _bos.flush();
+        System.out.flush();
 
 	}
 
@@ -182,10 +199,8 @@
 			 {portString,"org.apache.derby.drda.NetworkServerControl", cmd};
 		else
 			cmdArr = new String[] {"org.apache.derby.drda.NetworkServerControl", cmd,"-p", portString};
-		if (!wait)
-			execCmd(cmdArr);
-		else 
-			execCmdDumpResults(cmdArr);
+		
+        execCmdDumpResults(cmdArr, wait);
 	}	
 	
 	private static void waitForStart(String portString, int timeToWait) throws Exception
@@ -278,23 +293,23 @@
 
 			//Shutdown the server started by test
 			derbyServerCmd("shutdown","1527");
-			execCmd(startServerCmd);
+            execCmdDumpResults(startServerCmd, false);
 			waitForStart("1527",15000);
 			//check that default properties are used
 			listProperties("1527");
 			
 			//Test trace and logconnections commands
-			execCmdDumpResults(cmdTraceOn);
-			execCmdDumpResults(cmdLogconnectionsOn);
+			execCmdDumpResults(cmdTraceOn, true);
+			execCmdDumpResults(cmdLogconnectionsOn, true);
 			listProperties("1527");
-			execCmdDumpResults(cmdTraceOff);
+			execCmdDumpResults(cmdTraceOff, true);
 			listProperties("1527");
 			derbyServerCmd("shutdown","1527");
 			
 			//Test error conditions in command-line
-			execCmdDumpResults(cmdWithoutArgs);
-			execCmdDumpResults(cmdUnknown);
-			execCmdDumpResults(cmdWithWrongArgNum);
+			execCmdDumpResults(cmdWithoutArgs, true);
+			execCmdDumpResults(cmdUnknown, true);
+			execCmdDumpResults(cmdWithWrongArgNum, true);
 			
 			System.out.println("End test");
 			bos.close();



Mime
View raw message