db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1353862 - in /db/derby/code/trunk: ./ java/testing/org/apache/derbyTesting/functionTests/master/ java/testing/org/apache/derbyTesting/functionTests/suites/ java/testing/org/apache/derbyTesting/functionTests/tests/tools/ java/testing/org/ap...
Date Tue, 26 Jun 2012 08:43:19 GMT
Author: kahatlen
Date: Tue Jun 26 08:43:17 2012
New Revision: 1353862

URL: http://svn.apache.org/viewvc?rev=1353862&view=rev
Log:
DERBY-5821: tools/derbyrunjartest.java doesn't use jvmflags

Converted the test to JUnit to allow it to use BaseTestCase's helper
methods for starting sub-processes.

Extended BaseTestCase's helper methods with support for running jar
files with java -jar.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.policy
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/derbyrunjartest.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest_sed.properties
Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbytools.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=1353862&r1=1353861&r2=1353862&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Tue Jun 26 08:43:17 2012
@@ -2752,7 +2752,7 @@ you should not have to do this.
             </instr>
 	</emma>
         <!-- Change the classpath used for junit tests to use the jars instrumented by
EMMA -->
-        <property name="derby.junit.classpath" value="${emma}:${derby.jar.dir}/derbyTesting.jar:${instrumented.jars}/derbyclient.jar:${instrumented.jars}/derbynet.jar:${instrumented.jars}/derbytools.jar"
/>
+        <property name="derby.junit.classpath" value="${emma}:${derby.jar.dir}/derbyTesting.jar:${instrumented.jars}/derbyrun.jar"/>
     </target>
     
     <target name="emma-all" depends="emma-instrumentation,junit-all,emma-report">

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbytools.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbytools.runall?rev=1353862&r1=1353861&r2=1353862&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbytools.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbytools.runall
Tue Jun 26 08:43:17 2012
@@ -1,4 +1,3 @@
 tools/dblook_test.java
 tools/dblook_test_territory.java
-tools/derbyrunjartest.java
 tools/ij.sql
\ No newline at end of file

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/build.xml?rev=1353862&r1=1353861&r2=1353862&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/build.xml
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/build.xml
Tue Jun 26 08:43:17 2012
@@ -135,7 +135,7 @@
   <target name="copyfiles">
     <copy todir="${out.dir}/${derby.testing.functest.dir}/tests/tools">
       <fileset dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/tools"

-        includes="*.jar,*.sql,*.properties"/>  
+        includes="*.jar,*.sql,*.properties,*.policy"/>
     </copy>
   </target> 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.java?rev=1353862&r1=1353861&r2=1353862&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.java
Tue Jun 26 08:43:17 2012
@@ -21,97 +21,128 @@
 
 package org.apache.derbyTesting.functionTests.tests.tools;
 
-import java.io.File;
-import java.io.IOException;
-import java.lang.Process;
-import java.lang.Runtime;
-import java.lang.SecurityException;
 import java.net.URL;
-import java.security.CodeSource;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.Arrays;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+
+/**
+ * Basic tests for exercising the {@code org.apache.derby.iapi.tools.run}
+ * class found in {@code derbyrun.jar}.
+ */
+public class derbyrunjartest extends BaseTestCase {
 
-import org.apache.derbyTesting.functionTests.harness.BackgroundStreamSaver;
-import org.apache.derbyTesting.functionTests.harness.jvm;
+    public derbyrunjartest(String name) {
+        super(name);
+    }
 
-public class derbyrunjartest {
+    public static Test suite() {
+        Class cl = derbyrunjartest.class;
+        return new SecurityManagerSetup(
+                new TestSuite(cl),
+                cl.getName().replace('.', '/') + ".policy",
+                true);
+    }
 
-    public static void main(String[] args) throws Exception
-    {
-        // get location of run class.
-        CodeSource cs = null;
-        try {
-            cs = org.apache.derby.iapi.tools.run.class.getProtectionDomain().getCodeSource();
-        } catch (SecurityException se) {
-            System.out.println("Security exception: " + se.getMessage());
-        }
- 
-        URL result = cs.getLocation();
-        jvm jvm = null;
+    /**
+     * Invoke {@code org.apache.derby.iapi.tools.run} in a sub-process.
+     *
+     * @param toolArgs the arguments to pass to derbyrun.jar
+     * @param output expected lines of output
+     * @param exitCode expected exit code for the command
+     */
+    private void runtool(String[] toolArgs, String[] output, int exitCode)
+            throws Exception {
+        String runClassName = org.apache.derby.iapi.tools.run.class.getName();
+        URL result = SecurityManagerSetup.getURL(runClassName);
         String derbyrunloc = null;
 
         if (result.toString().endsWith(".jar")) {
             derbyrunloc = result.toString().substring(5);
             if (System.getProperty("os.name").startsWith("Windows"))
               derbyrunloc = derbyrunloc.substring(1);
-            jvm = jvm.getJvm("currentjvm"); // ensure compatibility
         }
 
-        String[][] testCommands = new String[][] {
-            {"ij", "--help"},
-            {"sysinfo", "-cp", "help"},
-            {"dblook"},
-            {"server"},
-        };
+        ArrayList cmdArgs = new ArrayList();
 
-        for (int i = 0; i < testCommands.length; i++) {
-            runtool(jvm, derbyrunloc, testCommands[i]);
+        // Invoke java -jar derbyrun.jar if we are running from jars, or
+        // with fully qualified class name if we are running from classes.
+        if (derbyrunloc == null) {
+            cmdArgs.add(runClassName);
+        } else {
+            cmdArgs.add("-jar");
+            cmdArgs.add(derbyrunloc);
         }
-    }
 
-    private static void runtool(jvm jvm, String loc, String[] args)
-        throws IOException
-    {
-        System.out.println(concatenate(args) + ':');
-
-        if (jvm == null) {
-            org.apache.derby.iapi.tools.run.main(args);
-            return;
-        }
+        cmdArgs.addAll(Arrays.asList(toolArgs));
 
-        Vector cmd = jvm.getCommandLine();
-        cmd.addElement("-jar");
-        cmd.addElement(loc);
-        for (int i=0; i < args.length; i++) {
-            cmd.addElement(args[i]);
-        }
-        String command = concatenate((String[]) cmd.toArray(new String[0]));
+        String[] cmd = (String[]) cmdArgs.toArray(new String[cmdArgs.size()]);
+        assertExecJavaCmdAsExpected(output, cmd, exitCode);
+    }
 
-        Process pr = null;
+    public void testIJ() throws Exception {
+        String[] cmd = { "ij", "--help" };
+        String[] output = {
+            "Usage: java org.apache.derby.tools.ij [-p propertyfile] [inputfile]"
+        };
+        runtool(cmd, output, 0);
+    }
 
-        try
-        {
-            pr = Runtime.getRuntime().exec(command);
-            BackgroundStreamSaver saver = 
-                        new BackgroundStreamSaver(pr.getInputStream(), System.out);
-            saver.finish();
-            pr.waitFor();
-            pr.destroy();
-        } catch(Throwable t) {
-            System.out.println("Process exception: " + t.getMessage());
-            if (pr != null)
-            {
-                pr.destroy();
-                pr = null;
-            }
-        }
+    public void testSysinfo() throws Exception {
+        String[] cmd = { "sysinfo", "-cp", "help" };
+        String[] output = {
+            "USAGE: java org.apache.derby.tools.sysinfo -cp [ [ embedded ][ server ][ client]
[ tools ] [ anyClass.class ] ]"
+        };
+        runtool(cmd, output, 0);
     }
 
-    private static String concatenate(String[] args) {
-        StringBuffer buf = new StringBuffer();
-        for (int i = 0; i < args.length; i++) {
-            buf.append(args[i]);
-            if (i + 1 < args.length) buf.append(' ');
-        }
-        return buf.toString();
+    public void testDblook() throws Exception {
+        String[] cmd = { "dblook" };
+        String[] output = {
+            " USAGE:",
+            " java org.apache.derby.tools.dblook -d <sourceDBUrl> [OPTIONS]",
+            " 	where the source URL is the full URL, including the connection protocol",
+            " 	and any connection attributes that might apply.  For example, use",
+            " 	options include:",
+            " 	-z <schemaName> to specify a schema to which the DDL generation",
+            " 	 should be limited.  Only database objects with that schema will have",
+            " 	 their DDL generated.",
+            " 	-t <tableOne> <tableTwo> ... to specify a list of tables for which",
+            " 	 the DDL will be generated; any tables not in the list will be ignored.",
+            " 	-td <value> to specify what should be appended to the end",
+            " 	 of each DDL statement.",
+            "		This defaults to ';'.",
+            " 	-noview to prevent the generation of DDL for views.",
+            " 	-append to keep from overwriting the output files.",
+            " 	-verbose to have error messages printed to the console (in addition",
+            " 	 to the log file).  If not specified, errors will only be printed to the",
+            " 	 log file.",
+            " 	-o <filename> to specify the file name to which the generated DDL",
+            " 	 will be written.",
+            " 		If not specified, default is the console.",
+        };
+        runtool(cmd, output, 0);
+    }
+
+    public void testServer() throws Exception {
+        String[] cmd = { "server" };
+        String[] output = {
+            "Usage: NetworkServerControl <commands> ",
+            "Commands:",
+            "start [-h <host>] [-p <portnumber>] [-noSecurityManager] [-ssl <sslmode>]",
+            "shutdown [-h <host>][-p <portnumber>] [-ssl <sslmode>] [-user
<username>] [-password <password>]",
+            "ping [-h <host>][-p <portnumber>] [-ssl <sslmode>]",
+            "sysinfo [-h <host>][-p <portnumber>] [-ssl <sslmode>]",
+            "runtimeinfo [-h <host>][-p <portnumber>] [-ssl <sslmode>]",
+            "logconnections {on|off} [-h <host>][-p <portnumber>] [-ssl <sslmode>]",
+            "maxthreads <max>[-h <host>][-p <portnumber>] [-ssl <sslmode>]",
+            "timeslice <milliseconds>[-h <host>][-p <portnumber>] [-ssl
<sslmode>]",
+            "trace {on|off} [-s <session id>][-h <host>][-p <portnumber>]
[-ssl <sslmode>]",
+            "tracedirectory <traceDirectory>[-h <host>][-p <portnumber>]
[-ssl <sslmode>]",
+        };
+        runtool(cmd, output, 1);
     }
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.policy?rev=1353862&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.policy
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.policy
Tue Jun 26 08:43:17 2012
@@ -0,0 +1,24 @@
+//
+//   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.
+//
+
+grant codeBase "${derbyTesting.testjar}derbyTesting.jar" {
+  permission java.lang.RuntimePermission "getProtectionDomain";
+};
+
+grant codeBase "${derbyTesting.codeclasses}" {
+  permission java.lang.RuntimePermission "getProtectionDomain";
+};

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/derbyrunjartest.policy
------------------------------------------------------------------------------
    svn:eol-style = native

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=1353862&r1=1353861&r2=1353862&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 Tue Jun
26 08:43:17 2012
@@ -549,6 +549,10 @@ public abstract class BaseTestCase
     public static Process execJavaCmd(
         String jvm, String cp, String[] cmd, final File dir)
             throws IOException {
+
+        // Is this an invocation of a jar file with java -jar ...?
+        final boolean isJarInvocation = cmd.length > 0 && cmd[0].equals("-jar");
+
 	    ArrayList cmdlist = new ArrayList();
         cmdlist.add(jvm == null ? getJavaExecutableName() : jvm);
 	    if (isJ9Platform())
@@ -581,6 +585,13 @@ public abstract class BaseTestCase
             if (cp != null) {
                 cp += File.pathSeparator + getEmmaJar().getPath();
             }
+
+            // DERBY-5821: When starting a sub-process with java -jar, the
+            // classpath argument will be ignored, so we cannot add emma.jar
+            // that way. Add it to the boot classpath instead.
+            if (isJarInvocation) {
+                cmdlist.add("-Xbootclasspath/a:" + getEmmaJar().getPath());
+            }
         }
 
         if (runsWithJaCoCo()) {
@@ -591,8 +602,16 @@ public abstract class BaseTestCase
                     "destfile=" + getJaCoCoOutFile());
         }
 
-	    cmdlist.add("-classpath");
-        cmdlist.add(cp == null ? getSystemProperty("java.class.path") : cp);
+        if (isJarInvocation) {
+            // If -jar is specified, the Java command will ignore the user's
+            // classpath, so don't set it. Fail if an explicit classpath has
+            // been set in addition to -jar, as that's probably a mistake in
+            // the calling code.
+            assertNull("Both -jar and classpath specified", cp);
+        } else {
+            cmdlist.add("-classpath");
+            cmdlist.add(cp == null ? getSystemProperty("java.class.path") : cp);
+        }
 
 	    for (int i =0; i < cmd.length;i++) {
 	        cmdlist.add(cmd[i]);



Mime
View raw message