You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2011/11/17 09:54:37 UTC
svn commit: r1203113 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests:
derbynet/SecureServerTest.java jdbc4/Driver40UnbootedTest.java
Author: kahatlen
Date: Thu Nov 17 08:54:37 2011
New Revision: 1203113
URL: http://svn.apache.org/viewvc?rev=1203113&view=rev
Log:
DERBY-5504: Use execJavaCmd() in SecureServerTest and Driver40UnbootedTest
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Driver40UnbootedTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java?rev=1203113&r1=1203112&r2=1203113&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java Thu Nov 17 08:54:37 2011
@@ -22,34 +22,22 @@
package org.apache.derbyTesting.functionTests.tests.derbynet;
import java.io.File;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
-import java.util.Properties;
+import java.util.Arrays;
-import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.derbyTesting.junit.BaseTestCase;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.Derby;
import org.apache.derbyTesting.junit.NetworkServerTestSetup;
import org.apache.derbyTesting.junit.SecurityManagerSetup;
-import org.apache.derbyTesting.junit.ServerSetup;
import org.apache.derbyTesting.junit.SpawnedProcess;
import org.apache.derbyTesting.junit.SupportFilesSetup;
-import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
import org.apache.derbyTesting.junit.TestConfiguration;
import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
-import org.apache.derby.drda.NetworkServerControl;
-
/**
* This Junit test class tests whether the server comes up under a security
* manager as expected.
@@ -363,7 +351,8 @@ public class SecureServerTest extends Ba
private void disableTracing() throws Exception {
- String traceOffOutput = runServerCommand( "trace off" );
+ String traceOffOutput = runServerCommand(
+ new String[] { "trace", "off" });
println( "Output for trace off command:\n\n" + traceOffOutput );
@@ -373,13 +362,14 @@ public class SecureServerTest extends Ba
private void setTraceDirectory() throws Exception {
- String traceDirectoryOutput = runServerCommand( "tracedirectory trace" );
+ String traceDirectoryOutput = runServerCommand(
+ new String[] { "tracedirectory", "trace" });
println( "Output for tracedirectory trace command:\n\n" + traceDirectoryOutput );
if ( traceDirectoryOutput.indexOf( "Trace directory changed to trace." ) < 0 )
{ fail( "Unexpected output in setting trace directory:" + traceDirectoryOutput ); }
- String pingOutput = runServerCommand( "ping" );
+ String pingOutput = runServerCommand( new String[] { "ping" } );
if (pingOutput.indexOf("Connection obtained for host:") < 0)
{ fail ("Failed ping after changing trace directory: " + pingOutput);}
@@ -412,7 +402,8 @@ public class SecureServerTest extends Ba
private void runsysinfo()
throws Exception
{
- String sysinfoOutput = runServerCommand( "sysinfo" );
+ String sysinfoOutput = runServerCommand(
+ new String[] { "sysinfo" } );
if ( sysinfoOutput.indexOf( "Security Exception:" ) > -1 )
{ fail( "Security exceptions in sysinfo output:\n\n:" + sysinfoOutput ); }
@@ -421,7 +412,8 @@ public class SecureServerTest extends Ba
private void enableTracing()
throws Exception
{
- String traceOnOutput = runServerCommand( "trace on" );
+ String traceOnOutput = runServerCommand(
+ new String[] { "trace", "on" } );
println( "Output for trace on command:\n\n" + traceOnOutput );
@@ -460,42 +452,24 @@ public class SecureServerTest extends Ba
* Run a NetworkServerControl command.
* </p>
*/
- private String runServerCommand( String commandSpecifics )
+ private String runServerCommand( String[] commandSpecifics )
throws Exception
{
String portNumber = Integer.toString( getTestConfiguration().getPort() );
- StringBuffer buffer = new StringBuffer();
- String classpath = getSystemProperty( "java.class.path" );
-
- buffer.append( getJavaExecutableName() + " -classpath " );
- buffer.append( classpath );
- buffer.append( " -Demma.verbosity.level=silent");
- buffer.append( " org.apache.derby.drda.NetworkServerControl -p " + portNumber + " " + commandSpecifics );
- final String command = buffer.toString();
+ ArrayList cmdList = new ArrayList();
+ cmdList.add("-Demma.verbosity.level=silent");
+ cmdList.add("org.apache.derby.drda.NetworkServerControl");
+ cmdList.add("-p");
+ cmdList.add(portNumber);
+ cmdList.addAll(Arrays.asList(commandSpecifics));
- println( "Server command is " + command );
+ String[] cmd = (String[]) cmdList.toArray(commandSpecifics);
- Process serverProcess = (Process) AccessController.doPrivileged
- (
- new PrivilegedAction()
- {
- public Object run()
- {
- Process result = null;
- try {
- result = Runtime.getRuntime().exec( command );
- } catch (Exception ex) {
- ex.printStackTrace();
- }
-
- return result;
- }
- }
- );
+ Process serverProcess = execJavaCmd(cmd);
SpawnedProcess spawned = new SpawnedProcess(serverProcess,
- commandSpecifics);
+ cmdList.toString());
// Ensure it completes without failures.
assertEquals(0, spawned.complete(false));
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Driver40UnbootedTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Driver40UnbootedTest.java?rev=1203113&r1=1203112&r2=1203113&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Driver40UnbootedTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Driver40UnbootedTest.java Thu Nov 17 08:54:37 2011
@@ -23,7 +23,6 @@ package org.apache.derbyTesting.function
import java.sql.Driver;
import java.sql.DriverManager;
-import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import junit.framework.Test;
@@ -139,19 +138,12 @@ public class Driver40UnbootedTest extend
{
if ( !getTestConfiguration().loadingFromJars() ) { return ; }
- StringBuffer buffer = new StringBuffer();
- String classpath = getSystemProperty( "java.class.path" );
+ String[] command = {
+ "-Demma.verbosity.level=silent",
+ getClass().getName()
+ };
- buffer.append( getJavaExecutableName() + " -classpath " );
- buffer.append( classpath );
- buffer.append( " -Demma.verbosity.level=silent ");
- buffer.append( getClass().getName() );
-
- final String command = buffer.toString();
-
- println( "Server command is " + command );
-
- Process process = Runtime.getRuntime().exec( command );
+ Process process = execJavaCmd(command);
SpawnedProcess spawned = new SpawnedProcess( process, "UnbootedTest" );