db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r450508 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/ master/DerbyNetClient/ tests/derbynet/ util/
Date Wed, 27 Sep 2006 17:10:58 GMT
Author: mikem
Date: Wed Sep 27 10:10:56 2006
New Revision: 450508

URL: http://svn.apache.org/viewvc?view=rev&rev=450508
Log:
DERBY-1878
contributed by Sunitha Kambhampati
patch: derby1878.diff.txt 

 I am attaching the patch (derby1878.diff.txt) to improve some error handling in some of the
network server tests.

 1.The execCmdDumpResults used by the five tests timeslice.java,maxthreads.java,testij.java,runtimeinfo.java,sysinfo.java
suffer from the same problems that was fixed for testProperties.java namely
 -- the outputstream for the sub process's is not flushed out
 -- there is no timeout handling for the ProcessStreamResult
 2.Eliminate duplication of code in these 5 tests for execCmdDumpResults(String[] args) method.
The execCmdDumpResults method basically exec's a new process and then waits for the process
to dump the results. A new utility class - ExecProcUtil is added with execCmdDumpResults that
is generalized to take the necessary input from the tests as well as fixes the issues mentioned
in #1. The OutputStream is flushed out by calling bos.flush and System.out.flush and the timeout
is added for ProcessStreamResult.
 3.Make use of the TimedProcess to kill process if process does not exit within the timeout
period.
 4.TestConnection.java test has some variation of the execCmdDumpResults and it also adds
some testcases into this method. Hence this method in this test is left as is and timeout
handling is added.
 5.testij.out has been updated. The previous master file was eating away the last line that
was written to System.out, but now that the process's streams are flushed properly, the last
line in testij.out test which prints out 'End test'
 is also seen in the output file.

 Also noticed that these tests - like timeslice.java, maxthreads.java all seem to set the
properties for the server and then check if the property is set. The functionality of the
server when these properties is set is not being tested. It will be good to add tests that
test that the functionality itself is working as expected or not. Please note, recently connecting
to server with timeslice options discovered some issues with server (see DERBY-1856). 


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ExecProcUtil.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/testij.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testij.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/maxthreads.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/runtimeinfo.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testconnection.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testij.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/timeslice.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/testij.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/testij.out?view=diff&rev=450508&r1=450507&r2=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/testij.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/testij.out
Wed Sep 27 10:10:56 2006
@@ -56,4 +56,4 @@
 ij(CONNECTION14)> -- just user security mechanism
 connect 'jdbc:derby://xxxFILTERED_HOSTNAMExxx:1527/my-db-name;create=true;user=usr;retrieveMessageText=true';
 ij(CONNECTION15)> connect 'jdbc:derby://xxxFILTERED_HOSTNAMExxx:1527/wombat' USER 'APP';
-ij(CONNECTION16)> 
+ij(CONNECTION16)> End test

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testij.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testij.out?view=diff&rev=450508&r1=450507&r2=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testij.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testij.out
Wed Sep 27 10:10:56 2006
@@ -38,4 +38,4 @@
 ij(CONNECTION6)> -- with no user
 connect 'jdbc:derby:net://xxxFILTERED_HOSTNAMExxx:1527/wombat;create=true:retrieveMessagesFromServerOnGetMessage=true;';
 ERROR (no SQLState): null userid not supported
-ij(CONNECTION6)> 
+ij(CONNECTION6)> End test

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/maxthreads.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/maxthreads.java?view=diff&rev=450508&r1=450507&r2=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/maxthreads.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/maxthreads.java
Wed Sep 27 10:10:56 2006
@@ -30,8 +30,8 @@
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.drda.NetworkServerControl;
 import org.apache.derbyTesting.functionTests.harness.jvm;
-import org.apache.derbyTesting.functionTests.harness.ProcessStreamResult;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
+import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
 import org.apache.derby.tools.ij;
 
 /**
@@ -59,51 +59,7 @@
 	private static  NetworkServerControl server;
 	private static String host;
 	private static int port = 1527;
-	/**
-	 * Execute the given command and dump the results to standard out
-	 *
-	 * @param args	command and arguments
-	 * @exception Exception
-	 */
-
-	private static void execCmdDumpResults (String[] args) throws Exception
-	{
-        // We need the process inputstream and errorstream
-        ProcessStreamResult prout = null;
-        ProcessStreamResult prerr = null;
-            
-        StringBuffer sb = new StringBuffer();
-            
-        for (int i = 0; i < args.length; i++)
-        {
-            sb.append(args[i] + " ");                    
-        }
-        System.out.println(sb.toString());
-		int totalSize = vCmd.size() + args.length;
-		String serverCmd[] = new String[totalSize];
-		int i;
-		for (i = 0; i < vCmd.size(); i++)
-		{
-			serverCmd[i] = (String)vCmd.elementAt(i);
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
-		int j = 0;
-		for (; i < totalSize; i++)
-		{
-			serverCmd[i] = args[j++];
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
- 
-		// Start a process to run the command
-		Process pr = Runtime.getRuntime().exec(serverCmd);
-        prout = new ProcessStreamResult(pr.getInputStream(), bos, null);
-        prerr = new ProcessStreamResult(pr.getErrorStream(), bos, null);
-
-		// wait until all the results have been processed
-		prout.Wait();
-		prerr.Wait();
-
-	}
+   
 	private static void checkMaxThreads( int value)
 		throws Exception
 	{
@@ -139,22 +95,22 @@
 			 ************************************************************/
 			System.out.println("Testing maxthreads");
 			//test maxthreads 0
-			execCmdDumpResults(maxthreadsCmd1);	
+			ExecProcUtil.execCmdDumpResults(maxthreadsCmd1,vCmd,bos);	
 			checkMaxThreads(0);
 			//test maxthreads -1 
-			execCmdDumpResults(maxthreadsCmd2);	
+			ExecProcUtil.execCmdDumpResults(maxthreadsCmd2,vCmd,bos);	
 			checkMaxThreads(0);	//default is currently 0
 			//test maxthreads -12 - should error
-			execCmdDumpResults(maxthreadsCmd3);	
+			ExecProcUtil.execCmdDumpResults(maxthreadsCmd3,vCmd,bos);	
 			checkMaxThreads(0);
 			//test maxthreads 2147483647 - should work
-			execCmdDumpResults(maxthreadsCmd4);	
+			ExecProcUtil.execCmdDumpResults(maxthreadsCmd4,vCmd,bos);	
 			checkMaxThreads(2147483647);
 			//test maxthreads 9000 - should work
-			execCmdDumpResults(maxthreadsCmd5);	
+			ExecProcUtil.execCmdDumpResults(maxthreadsCmd5,vCmd,bos);	
 			checkMaxThreads(9000);
 			//test maxthreads with invalid value (NumberFormatException)
-			execCmdDumpResults(maxthreadsCmd6);	
+			ExecProcUtil.execCmdDumpResults(maxthreadsCmd6,vCmd,bos);	
 			// try the same values using the callable interface
 			//test maxthreads 0
 			server.setMaxThreads(0);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/runtimeinfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/runtimeinfo.java?view=diff&rev=450508&r1=450507&r2=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/runtimeinfo.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/runtimeinfo.java
Wed Sep 27 10:10:56 2006
@@ -29,10 +29,10 @@
 import java.io.BufferedOutputStream;
 
 import org.apache.derbyTesting.functionTests.harness.jvm;
-import org.apache.derbyTesting.functionTests.harness.ProcessStreamResult;
 import org.apache.derby.drda.NetworkServerControl;
 import org.apache.derby.tools.ij;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
+import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
 import org.apache.derby.tools.JDBCDisplayUtil;
 
 /**
@@ -50,54 +50,7 @@
 		"runtimeinfo"};
 	private static String[] RuntimeinfoLocaleCmd = new String[] {"-Duser.language=err",
 		"-Duser.country=DE", "org.apache.derby.drda.NetworkServerControl", "runtimeinfo"};
-
-	/**
-	 * Execute the given command and dump the results to standard out
-	 *
-	 * @param args	command and arguments
-	 * @exception Exception
-	 */
-
-	private static void execCmdDumpResults (String[] args) throws Exception
-	{
-        // We need the process inputstream and errorstream
-        ProcessStreamResult prout = null;
-        ProcessStreamResult prerr = null;
-   		bos = null;         
-        StringBuffer sb = new StringBuffer();
-            
-        for (int i = 0; i < args.length; i++)
-        {
-            sb.append(args[i] + " ");                    
-        }
-        System.out.println(sb.toString());
-		int totalSize = vCmd.size() + args.length;
-		String serverCmd[] = new String[totalSize];
-		int i;
-		for (i = 0; i < vCmd.size(); i++)
-		{
-			serverCmd[i] = (String)vCmd.elementAt(i);
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
-		int j = 0;
-		for (; i < totalSize; i++)
-		{
-			serverCmd[i] = args[j++];
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
- 
-		// Start a process to run the command
-		Process pr = Runtime.getRuntime().exec(serverCmd);
-        bos = new BufferedOutputStream(System.out, 1024);
-        prout = new ProcessStreamResult(pr.getInputStream(), bos, null);
-        prerr = new ProcessStreamResult(pr.getErrorStream(), bos, null);
-
-		// wait until all the results have been processed
-		prout.Wait();
-		prerr.Wait();
-
-	}
-
+    
 
 
 	public static void main (String args[]) throws Exception
@@ -111,12 +64,14 @@
 		{
 			ij.getPropertyArg(args);
 			Connection conn1 = ij.startJBMS();
+            bos = new BufferedOutputStream(System.out, 1024);
+
 			
 			/************************************************************
 			 *  Test runtimeinfo
 			 ************************************************************/
 			System.out.println("Testing Runtimeinfo");
-			execCmdDumpResults(RuntimeinfoCmd);	
+			ExecProcUtil.execCmdDumpResults(RuntimeinfoCmd,vCmd,bos);	
 			System.out.println("End test");
 			
 			// Now get a couple of connections with some prepared statements
@@ -133,7 +88,7 @@
 			 *  Test runtimeinfo w/ foreign (non-English) locale
 			 ************************************************************/
 			System.out.println("Testing Runtimeinfo (locale)");
-			execCmdDumpResults(RuntimeinfoLocaleCmd);	
+			ExecProcUtil.execCmdDumpResults(RuntimeinfoLocaleCmd,vCmd,bos);	
 			System.out.println("End test (locale)");
 			ps.close();
 			ps2.close();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo.java?view=diff&rev=450508&r1=450507&r2=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo.java
Wed Sep 27 10:10:56 2006
@@ -29,7 +29,7 @@
 import java.net.InetAddress;
 
 import org.apache.derbyTesting.functionTests.harness.jvm;
-import org.apache.derbyTesting.functionTests.harness.ProcessStreamResult;
+import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
 import org.apache.derby.drda.NetworkServerControl;
 import org.apache.derby.tools.ij;
 
@@ -49,54 +49,6 @@
 	private static String[] SysInfoLocaleCmd = new String[] {"-Duser.language=err",
 		"-Duser.country=DE", "org.apache.derby.drda.NetworkServerControl", "sysinfo"};
 
-	/**
-	 * Execute the given command and dump the results to standard out
-	 *
-	 * @param args	command and arguments
-	 * @exception Exception
-	 */
-
-	private static void execCmdDumpResults (String[] args) throws Exception
-	{
-        // We need the process inputstream and errorstream
-        ProcessStreamResult prout = null;
-        ProcessStreamResult prerr = null;
-   		bos = null;         
-        StringBuffer sb = new StringBuffer();
-            
-        for (int i = 0; i < args.length; i++)
-        {
-            sb.append(args[i] + " ");                    
-        }
-        System.out.println(sb.toString());
-		int totalSize = vCmd.size() + args.length;
-		String serverCmd[] = new String[totalSize];
-		int i;
-		for (i = 0; i < vCmd.size(); i++)
-		{
-			serverCmd[i] = (String)vCmd.elementAt(i);
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
-		int j = 0;
-		for (; i < totalSize; i++)
-		{
-			serverCmd[i] = args[j++];
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
- 
-		// Start a process to run the command
-		Process pr = Runtime.getRuntime().exec(serverCmd);
-        bos = new BufferedOutputStream(System.out, 1024);
-        prout = new ProcessStreamResult(pr.getInputStream(), bos, null);
-        prerr = new ProcessStreamResult(pr.getErrorStream(), bos, null);
-
-		// wait until all the results have been processed
-		prout.Wait();
-		prerr.Wait();
-
-	}
-
-
     /*
      * Test calling server's sysinfo 
      * 
@@ -112,11 +64,13 @@
 		try
 		{
 			Connection conn1 = ij.startJBMS();
+            bos = new BufferedOutputStream(System.out, 1024);
+
 			/************************************************************
 			 *  Test sysinfo
 			 ************************************************************/
 			System.out.println("Testing Sysinfo");
-			execCmdDumpResults(SysInfoCmd);	
+			ExecProcUtil.execCmdDumpResults(SysInfoCmd,vCmd,bos);	
 			System.out.println("End test");
 			
 			/************************************************************
@@ -133,7 +87,7 @@
 			 *  Test sysinfo w/ foreign (non-English) locale
 			 ************************************************************/
 			System.out.println("Testing Sysinfo (locale)");
-			execCmdDumpResults(SysInfoLocaleCmd);	
+			ExecProcUtil.execCmdDumpResults(SysInfoLocaleCmd,vCmd,bos);	
 			System.out.println("End test (locale)");
 
 			bos.close();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testconnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testconnection.java?view=diff&rev=450508&r1=450507&r2=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testconnection.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testconnection.java
Wed Sep 27 10:10:56 2006
@@ -65,6 +65,15 @@
     private static  BufferedOutputStream bos = null;
     
     /**
+     * For each new exec process done as part of this test, set 
+     * timeout for ProcessStreamResult after which the thread that 
+     * handles the streams for the process exits.  Timeout is in minutes. 
+     * Note: timeout handling will only come into effect when 
+     * ProcessStreamResult#Wait() is called
+     */
+    private static String timeoutMinutes = "2";
+    
+    /**
 	 * Execute the given command and dump the results to standard out
 	 *
 	 * @param args	command and arguments
@@ -144,8 +153,8 @@
  
 		// Start a process to run the command
 		Process pr = Runtime.getRuntime().exec(serverCmd);
-        prout = new ProcessStreamResult(pr.getInputStream(), bos, null);
-        prerr = new ProcessStreamResult(pr.getErrorStream(), bos, null);
+        prout = new ProcessStreamResult(pr.getInputStream(), bos, timeoutMinutes);
+        prerr = new ProcessStreamResult(pr.getErrorStream(), bos, timeoutMinutes);
 
 		// wait until all the results have been processed
 		prout.Wait();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testij.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testij.java?view=diff&rev=450508&r1=450507&r2=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testij.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testij.java
Wed Sep 27 10:10:56 2006
@@ -33,9 +33,9 @@
 import java.io.FileNotFoundException;
 
 import org.apache.derbyTesting.functionTests.harness.jvm;
-import org.apache.derbyTesting.functionTests.harness.ProcessStreamResult;
 import org.apache.derbyTesting.functionTests.harness.Sed;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
+import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
 
 import org.apache.derby.drda.NetworkServerControl;
 
@@ -55,7 +55,7 @@
 	private static String clientSqlFile="testclientij.sql";
 	private static String altExtinDir;
 	private static boolean useAltExtinDir=false;
-	
+    
 	private static void execCmd (String[] args) throws Exception
 	{
 		int totalSize = vCmd.size() + args.length;
@@ -77,55 +77,6 @@
 		Process pr = Runtime.getRuntime().exec(serverCmd);
 		pr.waitFor();		// make sure this is executed first
 	}
-	/**
-	 * Execute the given command and dump the results to standard out
-	 *
-	 * @param args	command and arguments
-	 * @exception Exception
-	 */
-
-	private static void execCmdDumpResults (String[] args) throws Exception
-	{
-        // We need the process inputstream and errorstream
-        ProcessStreamResult prout = null;
-        ProcessStreamResult prerr = null;
-        BufferedOutputStream bos = null;
-            
-        StringBuffer sb = new StringBuffer();
-            
-        for (int i = 0; i < args.length; i++)
-        {
-            sb.append(args[i] + " ");                    
-        }
-        System.out.println(sb.toString());
-		int totalSize = vCmd.size() + args.length;
-		String serverCmd[] = new String[totalSize];
-		int i;
-		for (i = 0; i < vCmd.size(); i++)
-		{
-			serverCmd[i] = (String)vCmd.elementAt(i);
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
-		int j = 0;
-		for (; i < totalSize; i++)
-		{
-			serverCmd[i] = args[j++];
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
- 
-		// Start a process to run the command
-		Process pr = Runtime.getRuntime().exec(serverCmd);
-        bos = new BufferedOutputStream(System.out, 1024);
-        prout = new ProcessStreamResult(pr.getInputStream(), bos, null);
-        prerr = new ProcessStreamResult(pr.getErrorStream(), bos, null);
-
-		// wait until all the results have been processed
-		prout.Wait();
-		prerr.Wait();
-
-		bos.close();
-
-	}
 	
     public static void massageSqlFile (String hostName, String fileName) throws Exception
{
         // only called if hostName is *not* localhost. 
@@ -173,6 +124,7 @@
 		sep =  System.getProperty("file.separator");
 		try
 		{
+            BufferedOutputStream bos = new BufferedOutputStream(System.out, 1024);
 			/************************************************************
 			 *  Test comments in front of select's doesn't cause problems
 			 ************************************************************/
@@ -189,16 +141,16 @@
 				if (!hostName.equals("localhost")) 
 					massageSqlFile(hostName,jccSqlFile);
 				if (useAltExtinDir)	
-					execCmdDumpResults(new String[]{IjCmd,(altExtinDir + sep + SqlDir + sep + jccSqlFile)});
-				execCmdDumpResults(new String[]{IjCmd,(SqlDir + sep + jccSqlFile)});
+					ExecProcUtil.execCmdDumpResults(new String[]{IjCmd,(altExtinDir + sep + SqlDir + sep
+ jccSqlFile)},vCmd,bos);
+				ExecProcUtil.execCmdDumpResults(new String[]{IjCmd,(SqlDir + sep + jccSqlFile)},vCmd,bos);
 			} else {   // Derby Client
 				// use clientSqlFile
 				if(!hostName.equals("localhost")) {
 					massageSqlFile(hostName,clientSqlFile);
 				if (useAltExtinDir)	
-					execCmdDumpResults(new String[]{IjCmd,(altExtinDir + sep + SqlDir + sep + clientSqlFile)});
+					ExecProcUtil.execCmdDumpResults(new String[]{IjCmd,(altExtinDir + sep + SqlDir + sep
+ clientSqlFile)},vCmd,bos);
 				}
-				execCmdDumpResults(new String[]{IjCmd,(SqlDir + sep + clientSqlFile)});
+				ExecProcUtil.execCmdDumpResults(new String[]{IjCmd,(SqlDir + sep + clientSqlFile)},vCmd,bos);
 			}
 			System.out.println("End test");
 		}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/timeslice.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/timeslice.java?view=diff&rev=450508&r1=450507&r2=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/timeslice.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/timeslice.java
Wed Sep 27 10:10:56 2006
@@ -30,8 +30,8 @@
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.drda.NetworkServerControl;
 import org.apache.derbyTesting.functionTests.harness.jvm;
-import org.apache.derbyTesting.functionTests.harness.ProcessStreamResult;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
+import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
 import org.apache.derby.tools.ij;
 
 /**
@@ -59,51 +59,7 @@
 	private static  NetworkServerControl server;
 	private static String host;
 	private static int port = 1527;
-	/**
-	 * Execute the given command and dump the results to standard out
-	 *
-	 * @param args	command and arguments
-	 * @exception Exception
-	 */
-
-	private static void execCmdDumpResults (String[] args) throws Exception
-	{
-        // We need the process inputstream and errorstream
-        ProcessStreamResult prout = null;
-        ProcessStreamResult prerr = null;
-            
-        StringBuffer sb = new StringBuffer();
-            
-        for (int i = 0; i < args.length; i++)
-        {
-            sb.append(args[i] + " ");                    
-        }
-        System.out.println(sb.toString());
-		int totalSize = vCmd.size() + args.length;
-		String serverCmd[] = new String[totalSize];
-		int i;
-		for (i = 0; i < vCmd.size(); i++)
-		{
-			serverCmd[i] = (String)vCmd.elementAt(i);
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
-		int j = 0;
-		for (; i < totalSize; i++)
-		{
-			serverCmd[i] = args[j++];
-		//	System.out.println("serverCmd["+i+"]: "+serverCmd[i]);
-		}
- 
-		// Start a process to run the command
-		Process pr = Runtime.getRuntime().exec(serverCmd);
-        prout = new ProcessStreamResult(pr.getInputStream(), bos, null);
-        prerr = new ProcessStreamResult(pr.getErrorStream(), bos, null);
-
-		// wait until all the results have been processed
-		prout.Wait();
-		prerr.Wait();
-
-	}
+    
 	private static void checkTimeSlice( int value)
 		throws Exception
 	{
@@ -135,22 +91,22 @@
 			 ************************************************************/
 			System.out.println("Testing timeslice");
 			//test timeslice 0
-			execCmdDumpResults(timesliceCmd1);	
+			ExecProcUtil.execCmdDumpResults(timesliceCmd1,vCmd,bos);	
 			checkTimeSlice(0);
 			//test timeslice -1 
-			execCmdDumpResults(timesliceCmd2);	
+			ExecProcUtil.execCmdDumpResults(timesliceCmd2,vCmd,bos);	
 			checkTimeSlice(0);	//default is currently 0
 			//test timeslice -12 - should error
-			execCmdDumpResults(timesliceCmd3);	
+			ExecProcUtil.execCmdDumpResults(timesliceCmd3,vCmd,bos);	
 			checkTimeSlice(0);
 			//test timeslice 2147483647 - should work
-			execCmdDumpResults(timesliceCmd4);	
+			ExecProcUtil.execCmdDumpResults(timesliceCmd4,vCmd,bos);	
 			checkTimeSlice(2147483647);
 			//test timeslice 9000 - should work
-			execCmdDumpResults(timesliceCmd5);	
+			ExecProcUtil.execCmdDumpResults(timesliceCmd5,vCmd,bos);	
 			checkTimeSlice(9000);
 			//test timeslice with invlaid value - NumberFormatException
-			execCmdDumpResults(timesliceCmd6);
+			ExecProcUtil.execCmdDumpResults(timesliceCmd6,vCmd,bos);
 			//test callable interface
 			//test timeslice 0
 			server.setTimeSlice(0);

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ExecProcUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ExecProcUtil.java?view=auto&rev=450508
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ExecProcUtil.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ExecProcUtil.java
Wed Sep 27 10:10:56 2006
@@ -0,0 +1,107 @@
+/*
+ 
+ Derby - Class org.apache.derbyTesting.functionTests.util.ExecProcUtil
+ 
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ 
+ */
+package org.apache.derbyTesting.functionTests.util;
+
+import org.apache.derbyTesting.functionTests.harness.ProcessStreamResult;
+import org.apache.derbyTesting.functionTests.harness.TimedProcess;
+import java.util.Vector;
+import java.io.BufferedOutputStream;
+/**
+ * Utility class to hold helper methods to exec new processes
+ */
+public class ExecProcUtil {
+    
+    /**
+     * For each new exec process done, set 
+     * timeout for ProcessStreamResult after which the thread that 
+     * handles the streams for the process exits.  Timeout is in minutes. 
+     * Note: timeout handling will only come into effect when 
+     * ProcessStreamResult#Wait() is called
+     */
+    private static String timeoutMinutes = "2";
+    
+    /**
+     * timeout in seconds for the processes spawned.
+     */
+    private static int timeoutSecondsForProcess = 180;
+    
+    /**
+     * Execute the given command and dump the results to standard out
+     *
+     * @param args  command and arguments
+     * @param vCmd  java command line arguments.
+     * @param bos  buffered stream (System.out) to dump results to.
+     * @exception Exception
+     */
+    public static void execCmdDumpResults(String[] args, Vector vCmd,
+            BufferedOutputStream bos) throws Exception {
+        // We need the process inputstream and errorstream
+        ProcessStreamResult prout = null;
+        ProcessStreamResult prerr = null;
+
+        StringBuffer sb = new StringBuffer();
+
+        for (int i = 0; i < args.length; i++) {
+            sb.append(args[i] + " ");
+        }
+        System.out.println(sb.toString());
+        int totalSize = vCmd.size() + args.length;
+        String serverCmd[] = new String[totalSize];
+
+        int i = 0;
+        for (i = 0; i < vCmd.size(); i++)
+            serverCmd[i] = (String) vCmd.elementAt(i);
+
+        for (int j = 0; i < totalSize; i++)
+            serverCmd[i] = args[j++];
+
+        System.out.flush();
+        bos.flush();
+
+        // Start a process to run the command
+        Process pr = Runtime.getRuntime().exec(serverCmd);
+
+        // TimedProcess, kill process if process doesnt finish in a certain 
+        // amount of time
+        TimedProcess tp = new TimedProcess(pr);
+        prout = new ProcessStreamResult(pr.getInputStream(), bos,
+                timeoutMinutes);
+        prerr = new ProcessStreamResult(pr.getErrorStream(), bos,
+                timeoutMinutes);
+
+        // wait until all the results have been processed
+        boolean outTimedOut = prout.Wait();
+        boolean errTimedOut = prerr.Wait();
+        
+        // wait for this process to terminate, upto a wait period
+        // of 'timeoutSecondsForProcess'
+        // if process has already been terminated, this call will 
+        // return immediately.
+        tp.waitFor(timeoutSecondsForProcess);
+        pr = null;
+        
+        if (outTimedOut || errTimedOut)
+            System.out.println(" Reading from process streams timed out.. ");
+
+        System.out.flush();
+    }
+    
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ExecProcUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message