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 my...@apache.org on 2008/01/17 03:54:05 UTC
svn commit: r612684 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/derbynet/ junit/
Author: myrnavl
Date: Wed Jan 16 18:54:04 2008
New Revision: 612684
URL: http://svn.apache.org/viewvc?rev=612684&view=rev
Log:
DERBY-3088 - improvements to ServerPropertiesTest and related changes - adds
an assertExecJavaCmdAsExpected method to BaseTestCase.java
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java?rev=612684&r1=612683&r2=612684&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java Wed Jan 16 18:54:04 2008
@@ -61,12 +61,13 @@
*/
private void assertSuccessfulPing(String[] pingCmd) throws InterruptedException, IOException {
- InputStream is = Utilities.execJavaCmd(pingCmd, 0);
+/* InputStream is = Utilities.execJavaCmd(pingCmd, 0);
byte[] b = new byte[80];
is.read(b, 0, 80);
String output = new String(b);
assertTrue(output.startsWith("Connection obtained"));
-
+*/
+ assertExecJavaCmdAsExpected(new String[] {"Connection obtained"}, pingCmd, 0);
}
/**
* Execute ping command and verify that it fails with the expected message
@@ -78,12 +79,12 @@
*/
private void assertFailedPing(String[] pingCmd,String expectedMessage) throws InterruptedException, IOException {
- InputStream is = Utilities.execJavaCmd(pingCmd, 1);
+ /*InputStream is = Utilities.execJavaCmd(pingCmd, 1);
byte[] b = new byte[80];
is.read(b, 0, 80);
String output = new String(b);
- assertTrue(output.startsWith(expectedMessage));
-
+ assertTrue(output.startsWith(expectedMessage));*/
+ assertExecJavaCmdAsExpected(new String[] {expectedMessage}, pingCmd, 1);
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.java?rev=612684&r1=612683&r2=612684&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.java Wed Jan 16 18:54:04 2008
@@ -24,32 +24,26 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.InetAddress;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Properties;
-import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.derby.drda.NetworkServerControl;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.BaseTestCase;
import org.apache.derbyTesting.junit.Derby;
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.NetworkServerTestSetup;
import org.apache.derbyTesting.junit.SecurityManagerSetup;
import org.apache.derbyTesting.junit.SupportFilesSetup;
import org.apache.derbyTesting.junit.TestConfiguration;
-import org.apache.derbyTesting.junit.Utilities;
/**
* This test tests the derby.properties, system properties and command line
@@ -98,33 +92,30 @@
public static Test suite()
{
TestSuite suite = new TestSuite("ServerPropertiesTest");
-
- // Server booting requires that we run from the jar files
- // Need derbynet.jar in the classpath!
- // TODO: check - can this be modified to use noSecurityManager
- // for classes?
- // if (!TestConfiguration.loadingFromJars()) { return suite; }
if (!Derby.hasServer()) return suite;
// don't run with JSR169 for 1. this is network server and
// 2. the java executable may be named differently
if (JDBC.vmSupportsJSR169()) return suite;
- // this test doesn't use a client/server setup, instead does the
+ // this fixture doesn't use a client/server setup, instead does the
// relevant starting/stopping inside the test
// Add security manager policy that allows executing java commands
Test setPortPriority = new ServerPropertiesTest("ttestSetPortPriority");
setPortPriority = decorateWithPolicy(setPortPriority);
suite.addTest(setPortPriority);
- // unfinished properties settings. decorateTest add policy file and sets
- // up properties
- suite.addTest(decorateTest("ttestDefaultProperties", getStartupProperties(),
- new String[] {}));
+ // test unfinished properties settings.
+ // decorateTest adds policy file and sets up properties
+ // fixture hits error DRDA_MissingNetworkJar (Cannot find derbynet.jar) so,
+ // only run with jars
+ if (TestConfiguration.loadingFromJars())
+ suite.addTest(decorateTest("ttestDefaultProperties",
+ getStartupProperties(), new String[] {}));
- // The other tests, testToggleTrace (trace on/off),
+ // The other fixtures, testToggleTrace (trace on/off),
// testToggleLogConnections (logconnections on/off) , and
- // testWrongCommands can all use the default setup - with policy
+ // testWrongCommands can all use the default setup with adjusted policy
// need english locale so we can compare command output for those tests
if (!Locale.getDefault().getLanguage().equals("en"))
@@ -458,97 +449,9 @@
* @throws IOException
*/
private void assertSuccessfulCmd(String expectedString, String[] Cmd) throws InterruptedException, IOException {
- InputStream is = Utilities.execJavaCmd(Cmd, 0);
- byte[] b = new byte[80];
- is.read(b, 0, 80);
- String output = new String(b);
- //System.out.println("output: " + output);
- assertTrue(output.startsWith(expectedString));
+ assertExecJavaCmdAsExpected(new String[] {expectedString}, Cmd, 0);
}
- /**
- * Execute command and verify that it completes with
- * an error
- * This method does *not* use Utilities.execJavaCmd, because
- * that one will hang on waitFor() when the usage message needs
- * to get extracted. This is probably DERBY-3251.
- * Note: this method may possibly be extracted
- * be placed in either Utilities or one of the Configuration
- * or Setup classes, but as there is an intermittent problem
- * with it, holding off on that
- * @param expectedString String to compare the resulting output with
- * @param cmd array of java arguments for command
- * @param expectedExitValue expected return value from the command
- * @throws InterruptedException
- * @throws IOException
- */
- private void assertUsageMessage(
- String[] expectedString, String[] cmd, int expectedExitValue)
- throws InterruptedException, IOException {
-
- int totalSize = 3 + cmd.length;
- String[] tcmd = new String[totalSize];
- tcmd[0] = "java";
- tcmd[1] = "-classpath";
- tcmd[2] = BaseTestCase.getSystemProperty("java.class.path");
-
- System.arraycopy(cmd, 0, tcmd, 3, cmd.length);
-
- final String[] command = tcmd;
- Process pr = null;
- try {
- pr = (Process) AccessController
- .doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws IOException {
- Process result = null;
- result = Runtime.getRuntime().exec(command);
- return result;
- }
- });
- } catch (PrivilegedActionException pe) {
- Exception e = pe.getException();
- if (e instanceof IOException)
- throw (IOException) e;
- else
- throw (SecurityException) e;
- }
- InputStream is = pr.getInputStream();
- if ( is == null )
- {
- fail("Unexpectedly receiving no text from the java command");
- }
-
- String output = "";
- try
- {
- char[] ca = new char[1024];
- // Create an InputStreamReader with UTF-8 encoding
- // use default encoding; we're hoping this to be en.
- // if not, it's not going to match the expected string.
- InputStreamReader inStream;
- //inStream = new InputStreamReader(is, "UTF-8");
- inStream = new InputStreamReader(is);
- // keep reading from the stream until all done
- while ((inStream.read(ca, 0, ca.length)) != -1)
- {
- output = output + new String(ca).trim();
- }
- } catch (Exception e) {
- fail("Exception accessing inputstream from javacommand");
- }
-
- // wait until the process exits
- pr.waitFor();
-
- Assert.assertEquals(expectedExitValue, pr.exitValue());
- for (int i=0 ; i<expectedString.length ; i++)
- {
- assertFalse(output.indexOf(expectedString[i]) < 0);
- }
- }
-
-
-
/**
* Test port setting priority
*/
@@ -845,15 +748,15 @@
// we'll assume that we get the full message if we get 'Usage'
// because sometimes, the message gets returned with carriage return,
// and sometimes it doesn't, checking for two different parts...
- assertUsageMessage(new String[]
+ assertExecJavaCmdAsExpected(new String[]
{"No arguments given.", "Usage: "}, cmd, 1);
//Unknown command
cmd = new String[] {nsc, "unknowncmd"};
- assertUsageMessage(new String[]
+ assertExecJavaCmdAsExpected(new String[]
{"Command unknowncmd is unknown.", "Usage: "}, cmd, 0);
// wrong number of arguments
cmd = new String[] {nsc, "ping", "arg1"};
- assertUsageMessage(new String[]
+ assertExecJavaCmdAsExpected(new String[]
{"Invalid number of arguments for command ping.",
"Usage: "}, cmd, 1);
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy?rev=612684&r1=612683&r2=612684&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy Wed Jan 16 18:54:04 2008
@@ -172,6 +172,12 @@
// super-set of the jar permissions for running out of the classes directory
//
grant codeBase "${derbyTesting.codeclasses}" {
+
+ // just add the complete gross policy change for ServerPropertiesTest
+ // execute permission is for 'java', but this can be at a variety of locations.
+ permission java.io.FilePermission "<<ALL FILES>>", "execute";
+ permission java.security.SecurityPermission "getPolicy";
+
// Access all properties using System.getProperties
permission java.util.PropertyPermission "*", "read, write";
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=612684&r1=612683&r2=612684&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Wed Jan 16 18:54:04 2008
@@ -19,6 +19,7 @@
*/
package org.apache.derbyTesting.junit;
+import junit.framework.Assert;
import junit.framework.TestCase;
import java.io.BufferedInputStream;
@@ -27,12 +28,14 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.io.PrintStream;
import java.net.URL;
import java.sql.SQLException;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
@@ -395,6 +398,83 @@
}
});
}
+
+ /**
+ /**
+ * Execute command using 'java' executable and verify that it completes
+ * with expected results
+ * @param expectedString String to compare the resulting output with. May be
+ * null if the output is not expected to be of interest.
+ * @param cmd array of java arguments for command
+ * @param expectedExitValue expected return value from the command
+ * @throws InterruptedException
+ * @throws IOException
+ */
+ public void assertExecJavaCmdAsExpected(
+ String[] expectedString, String[] cmd, int expectedExitValue)
+ throws InterruptedException, IOException {
+
+ int totalSize = 3 + cmd.length;
+ String[] tcmd = new String[totalSize];
+ tcmd[0] = "java";
+ tcmd[1] = "-classpath";
+ tcmd[2] = BaseTestCase.getSystemProperty("java.class.path");
+
+ System.arraycopy(cmd, 0, tcmd, 3, cmd.length);
+
+ final String[] command = tcmd;
+ Process pr = null;
+ try {
+ pr = (Process) AccessController
+ .doPrivileged(new PrivilegedExceptionAction() {
+ public Object run() throws IOException {
+ Process result = null;
+ result = Runtime.getRuntime().exec(command);
+ return result;
+ }
+ });
+ } catch (PrivilegedActionException pe) {
+ Exception e = pe.getException();
+ if (e instanceof IOException)
+ throw (IOException) e;
+ else
+ throw (SecurityException) e;
+ }
+ InputStream is = pr.getInputStream();
+ if ( is == null )
+ {
+ fail("Unexpectedly receiving no text from the java command");
+ }
+
+ String output = "";
+ try
+ {
+ char[] ca = new char[1024];
+ // Create an InputStreamReader with default encoding; we're hoping
+ // this to be en. If not, we may not match the expected string.
+ InputStreamReader inStream;
+ inStream = new InputStreamReader(is);
+ // keep reading from the stream until all done
+ while ((inStream.read(ca, 0, ca.length)) != -1)
+ {
+ output = output + new String(ca).trim();
+ }
+ } catch (Exception e) {
+ fail("Exception accessing inputstream from javacommand");
+ }
+
+ // wait until the process exits
+ pr.waitFor();
+
+ Assert.assertEquals(expectedExitValue, pr.exitValue());
+ if (expectedString != null)
+ {
+ for (int i=0 ; i<expectedString.length ; i++)
+ {
+ assertFalse(output.indexOf(expectedString[i]) < 0);
+ }
+ }
+ }
/**
* Remove the directory and its contents.
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java?rev=612684&r1=612683&r2=612684&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java Wed Jan 16 18:54:04 2008
@@ -225,12 +225,12 @@
final String[] command = new String[ al.size() ];
al.toArray(command);
- /* System.out.println( "XXX server startup command = ");
+ System.out.println( "XXX server startup command = ");
for (int i = 0 ; i < command.length ; i++) {
System.out.print( command[i] + " " );
}
System.out.println();
- */
+
Process serverProcess = (Process) AccessController.doPrivileged
(