db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r688103 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/master/ functionTests/master/DerbyNet/ functionTests/suites/ functionTests/tests/derbynet/ junit/
Date Fri, 22 Aug 2008 15:47:08 GMT
Author: myrnavl
Date: Fri Aug 22 08:47:07 2008
New Revision: 688103

URL: http://svn.apache.org/viewvc?rev=688103&view=rev
Log:
DERBY-3829; convert derbynet/sysinfo* to JUnit
  original patch contributed by Erlend Birkenes

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy   (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/sysinfo.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/sysinfo_withproperties.out
    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/sysinfo.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo_sed.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo_withproperties.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo_withproperties.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo_withproperties_derby.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/sysinfo_withproperties_sed.properties
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientRemote.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetRemote.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetUseprocess.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
    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/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientRemote.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientRemote.exclude?rev=688103&r1=688102&r2=688103&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientRemote.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientRemote.exclude Fri Aug 22 08:47:07 2008
@@ -11,8 +11,6 @@
 #     the server machine
 # derbynet/maxthreads - tries to use NetworkServerControl statements
 # derbynet/runtimeinfo - tries to use NetworkServerControl statements
-# derbynet/sysinfo - tries to use NetworkServerControl statements
-# derbynet/sysinfo_withproperties - tries to use NetworkServerControl statements and for the test, server needs to be
 # started with specific property set - DERBY928 for reference 
 # thus not suitable for remote server testing in its current form. - DERBY-928
 # derbynet/timeslice - tries to use NetworkServerControl statements
@@ -26,8 +24,6 @@
 derbynet/dblook_test_net_territory.java
 derbynet/maxthreads.java
 derbynet/runtimeinfo.java
-derbynet/sysinfo.java
-derbynet/sysinfo_withproperties.java
 derbynet/timeslice.java
 derbynet/DerbyNetAutoStart.java
 lang/wisconsin.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude?rev=688103&r1=688102&r2=688103&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude Fri Aug 22 08:47:07 2008
@@ -8,8 +8,6 @@
 # derbynet/dblook_test_net_territory.java - expects different dir structure
 # stress/stress.multi - exits suite
 # derbynet/runtimeinfo.java - different sessions
-# derbynet/sysinfo.java - needs other properties
-# derbynet/sysinfo_withproperties.java - needs other properties
 # following fail for various reasons, many related to not being able to connect:
 #  lang/wisconsin.java
 #  jdbcapi/derbyStress.java
@@ -21,8 +19,6 @@
 derbynet/dblook_test_net.java
 derbynet/dblook_test_net_territory.java
 derbynet/runtimeinfo.java
-derbynet/sysinfo.java
-derbynet/sysinfo_withproperties.java
 stress/stress.multi
 lang/wisconsin.java
 jdbcapi/derbyStress.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetRemote.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetRemote.exclude?rev=688103&r1=688102&r2=688103&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetRemote.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetRemote.exclude Fri Aug 22 08:47:07 2008
@@ -11,11 +11,9 @@
 #     the server machine
 # derbynet/maxthreads - tries to use NetworkServerControl statements
 # derbynet/runtimeinfo - tries to use NetworkServerControl statements
-# derbynet/sysinfo - tries to use NetworkServerControl statements
 # thus not suitable for remote server testing in its current form. - DERBY-928
 # derbynet/timeslice - tries to use NetworkServerControl statements
 # derbynet/DerbyNetAutoStart - tries to start networkserver
-# derbynet/sysinfo_withproperties - tries to use NetworkServerControl statements and test requires server to 
 # be started with a specific property. see DERBY-928 for reference
 # lang/wisconsin - optimization is quite different when running remote server.
 # junitTests/derbyNet/CompatibilityTest.java - tries to start and shutdown the server
@@ -25,8 +23,6 @@
 derbynet/dblook_test_net_territory.java
 derbynet/maxthreads.java
 derbynet/runtimeinfo.java
-derbynet/sysinfo.java
-derbynet/sysinfo_withproperties.java
 derbynet/timeslice.java
 derbynet/DerbyNetAutoStart.java
 lang/wisconsin.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetUseprocess.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetUseprocess.exclude?rev=688103&r1=688102&r2=688103&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetUseprocess.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetUseprocess.exclude Fri Aug 22 08:47:07 2008
@@ -7,8 +7,6 @@
 # derbynet/dblook_test_net.java - fails, test misses properties
 # derbynet/dblook_test_net_territory.java - fails, test misses properties
 # derbynet/runtimeinfo.java - fails with already existing threads (maybe intermittent)
-# derbynet/sysinfo.java - fails because not access to java.class.path
-# derbynet/sysinfo_withproperties.java - fails because not access to java.class.path
 # lang/wisconsin.java - checks depend on dir structure
 # jdbcapi/maxfieldsize.java - fails...??? (but not when run by itself)
 #
@@ -18,7 +16,5 @@
 derbynet/dblook_test_net.java
 derbynet/dblook_test_net_territory.java
 derbynet/runtimeinfo.java
-derbynet/sysinfo.java
-derbynet/sysinfo_withproperties.java
 lang/wisconsin.java
 stress/stress.multi

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall?rev=688103&r1=688102&r2=688103&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall Fri Aug 22 08:47:07 2008
@@ -2,8 +2,6 @@
 derbynet/dblook_test_net_territory.java
 derbynet/DerbyNetAutoStart.java
 derbynet/runtimeinfo.java
-derbynet/sysinfo.java
-derbynet/sysinfo_withproperties.java
 derbynet/testProtocol.java
 lang/holdCursorIJ.sql
 lang/wisconsin.java

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=688103&r1=688102&r2=688103&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 Fri Aug 22 08:47:07 2008
@@ -473,7 +473,7 @@
             "org.apache.derby.drda.NetworkServerControl", "-p",
             String.valueOf(fourthAlternatePort).toString(), 
             "-noSecurityManager", "start"};
-        Utilities.execJavaCmd(commandArray);
+        execJavaCmd(commandArray);
         
         if (!canPingServer(fourthAlternatePort, true)) {
             actionResult = "Can not ping server specified with -p";
@@ -486,7 +486,7 @@
                 "org.apache.derby.drda.NetworkServerControl", "-p",
                 String.valueOf(fourthAlternatePort).toString(), 
                 "-noSecurityManager", "shutdown"};
-        Utilities.execJavaCmd(commandArray);
+        execJavaCmd(commandArray);
 
         if (canPingServer(fourthAlternatePort, false)) {
             actionResult = "Can still ping server specified with -p";

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.java?rev=688103&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.java Fri Aug 22 08:47:07 2008
@@ -0,0 +1,314 @@
+/*
+
+   Derby - Class 
+   org.apache.derbyTesting.functionTests.tests.derbynet.SysinfoTest
+
+   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.tests.derbynet;
+
+import java.io.File;
+import java.net.URL;
+import java.security.AccessController;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+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.SystemPropertyTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+	This tests the sysinfo command
+ */
+
+public class SysinfoTest extends BaseJDBCTestCase {
+
+    private static String TARGET_POLICY_FILE_NAME="sysinfo.policy";
+    private String OUTPUT;
+
+    /**
+     * Set to true before adding a test to the suite to add some extra properties.
+     */
+    private static boolean useProperties = false;
+
+
+    /**
+     * Default constructor
+     * @param name
+     */
+    public SysinfoTest(String name) {
+        super(name);
+        /**
+         * Output from sysinfo without the extra properties. 
+         */
+        String OUTPUT1 = 
+            "--------- Derby Network Server Information --------\n" + 
+            "derby.drda.maxThreads=0\n" + 
+            "derby.drda.sslMode=off\n" + 
+            "derby.drda.keepAlive=true\n" + 
+            "derby.drda.minThreads=0\n" + 
+            "derby.drda.portNumber=1527\n" + 
+            "derby.drda.logConnections=false\n" + 
+            "derby.drda.timeSlice=0\n" + 
+            "derby.drda.startNetworkServer=false\n" + 
+            "derby.drda.traceAll=false\n" + 
+            "--------- Derby Information --------\n" + 
+            "------------------------------------------------------\n" + 
+            "----------------- Locale Information -----------------\n" + 
+            "------------------------------------------------------";
+
+        /**
+         * Output by sysinfo with the extra properties.
+         */
+        String OUTPUT2 = 
+            "--------- Derby Network Server Information --------\n" + 
+            "derby.drda.securityMechanism=USER_ONLY_SECURITY\n" + 
+            "derby.drda.maxThreads=0\n" + 
+            "derby.drda.sslMode=off\n" + 
+            "derby.drda.keepAlive=true\n" + 
+            "derby.drda.minThreads=0\n" + 
+            "derby.drda.portNumber=1527\n" + 
+            "derby.drda.logConnections=false\n" + 
+            "derby.drda.timeSlice=0\n" + 
+            "derby.drda.startNetworkServer=false\n" + 
+            "derby.drda.traceAll=false\n" + 
+            "--------- Derby Information --------\n" + 
+            "------------------------------------------------------\n" + 
+            "----------------- Locale Information -----------------\n" + 
+            "------------------------------------------------------";
+
+        if (useProperties)
+            OUTPUT = OUTPUT2;
+        else 
+            OUTPUT = OUTPUT1;
+    }
+
+    /**
+     * Creates a suite with two testcases, with and without some extra 
+     * system properties.
+     * 
+     * @return
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("SysinfoTest");
+
+        // we need to be able to run the server
+        if (!Derby.hasServer()) return suite;
+        // don't run with JSR169 for this is a network server test
+        if (JDBC.vmSupportsJSR169()) return suite;
+
+        useProperties = false;
+        // a call to sysinfo will eventually attempt to load resource 
+        // org.apache.derby.info.DBMS.properties.
+        // If we're using classes, we don't have read permission for the dir.
+        // So, figure out the path & pass the property on so the reference
+        // in the policy file can be resolved.
+        // Note: can't use $derbyTesting.codeclasses as on windows it has
+        // the slashes adjusted.
+        if (!TestConfiguration.loadingFromJars()) {
+            Properties propstmp = new Properties();
+            propstmp.put("sysinfotest.classesdir", findClassDir());
+            suite.addTest(new SystemPropertyTestSetup(decorateTest(), propstmp));
+        }
+        else
+            suite.addTest(decorateTest());
+
+        useProperties = true;
+        Properties props = new Properties();
+        if (!TestConfiguration.loadingFromJars())
+            props.put("sysinfotest.classesdir", findClassDir());
+        props.put("derby.infolog.append","true");
+        props.put("derby.locks.waitTimeout","120");
+        props.put("derby.language.logStatementText","true");
+        //#drda property ,test for it in sysinfo output
+        props.put("derby.drda.securityMechanism","USER_ONLY_SECURITY");
+        suite.addTest(new SystemPropertyTestSetup(decorateTest(), props));
+
+        return suite;
+    }
+
+    private String makePolicyName() {
+        try {
+            String  userDir = getSystemProperty( "user.dir" );
+            String  fileName = userDir + File.separator + 
+            SupportFilesSetup.EXTINOUT + File.separator + TARGET_POLICY_FILE_NAME;
+            File      file = new File( fileName );
+            String  urlString = file.toURL().toExternalForm();
+
+            return urlString;
+        }
+        catch (Exception e) {
+            fail("Unexpected exception caught by " +
+                    "makeServerPolicyName(): " + e );
+            return null;
+        }
+    }
+
+    /**
+     * Decorate a test with SecurityManagerSetup, clientServersuite, and
+     * SupportFilesSetup.
+     * 
+     * @return the decorated test
+     */
+    private static Test decorateTest() {
+        String policyName = new SysinfoTest("test").makePolicyName();
+        Test test = TestConfiguration.clientServerSuite(SysinfoTest.class);
+
+        // Install a security manager using the initial policy file.
+        test = TestConfiguration.singleUseDatabaseDecorator(
+                new SecurityManagerSetup(test, policyName));
+
+        // Copy over the policy file we want to use.
+        String POLICY_FILE_NAME=
+            "functionTests/tests/derbynet/SysinfoTest.policy";
+
+        test = new SupportFilesSetup
+        (
+                test,
+                null,
+                new String[] { POLICY_FILE_NAME },
+                null,
+                new String[] { TARGET_POLICY_FILE_NAME}
+        );
+        return test;
+    }
+
+    /**
+     * Test sysinfo
+     * 
+     * @throws Exception
+     */	
+    public void testSysinfo() throws Exception {
+        String[] SysInfoCmd = 
+            new String[] {"org.apache.derby.drda.NetworkServerControl", "sysinfo"};
+
+        Process p = execJavaCmd(SysInfoCmd);
+        String s = readProcessOutput(p);
+
+        s = sed(s);
+
+        print("testSysinfo", s);
+        assertEquals(OUTPUT,s);
+
+    }
+
+    /**
+     * Test sysinfo by calling NetworkServerControl.getSysinfo()
+     * 
+     * @throws Exception
+     */
+    public void testSysinfoMethod() throws Exception {	
+
+        String s = NetworkServerTestSetup.
+        getNetworkServerControlDefault().getSysinfo();
+        s = sed(s);
+
+        print("testSysinfoMethod", s);
+        assertEquals(OUTPUT, s);
+    }		
+
+    /**
+     * Test sysinfo w/ foreign (non-English) locale.
+     * 
+     * @throws Exception
+     */
+    public void testSysinfoLocale() throws Exception {
+
+        String[] SysInfoLocaleCmd = 
+            new String[] {"-Duser.language=de", "-Duser.country=DE", 
+                "org.apache.derby.drda.NetworkServerControl", "sysinfo"};
+        Process p = execJavaCmd(SysInfoLocaleCmd);
+        String s = readProcessOutput(p);
+        s = sed(s);
+
+        print("testSysinfoLocale", s);
+        assertEquals(OUTPUT, s);
+    }
+
+    /**
+     * Removes lines containing a number of preset words from the given string.
+     * Also trims the string to make it easier to compare.
+     * 
+     * @param s the string to remove lines from
+     * @return the string with the lines removed
+     */
+    private String sed(String s) {
+        /**
+         * Lines containing these strings will be deleted from the output before
+         * asserting that output is correct.
+         */
+        String[] sed = {"Version", "version", "Java", "OS", 
+                "[0-9*].[0-9*].[0-9*]","JRE - JDBC","derby.drda.traceDirectory",
+                "Unable to access Protection Domain","listing properties",
+                "Current Locale",           //Remove these because locale info is
+                "Found support for locale:" //not printed when running from jars..
+        };                          
+
+        for (int i = 0; i < sed.length; i++) {
+            // first, replace \r\n with \n, that's needed if we're on
+            // windows
+            s = s.replaceAll("\r\n", "\n");
+            s = s.replaceAll("(?m)^.*" + sed[i] + ".*\n", "");
+        }
+        s = s.trim();
+        return s;
+    }
+
+    /**
+     * Prints strings to System.out to make it easier to update the tests
+     * when the output changes if derby.tests.debug is true.
+     * 
+     * @param name just a label to identify the string
+     * @param s the string to be printed
+     */
+    private void print(String name,String s) {
+        println("\n\n>>>" + name + ">>>");
+        println(s);
+        println("<<<" + name + "<<<\n\n");
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+        TARGET_POLICY_FILE_NAME = null;
+        OUTPUT = null;
+    }
+
+    private static String findClassDir() {
+        URL url = null;
+        try {
+            final Class cl = Class.forName("org.apache.derbyTesting." +
+                    "functionTests.tests.derbynet.SysinfoTest");
+        url = (URL)
+           AccessController.doPrivileged(new java.security.PrivilegedAction() {
+            public Object run() {
+                return cl.getProtectionDomain().getCodeSource().getLocation();
+            }
+        });
+        } catch (ClassNotFoundException e) {
+            // need catch to silence compiler, but as we're referring to *this*
+            // class, it ok to ignore this.
+        }
+        return url.getPath();
+    }
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy?rev=688103&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SysinfoTest.policy Fri Aug 22 08:47:07 2008
@@ -0,0 +1,411 @@
+//
+// *  Derby - Class org.apache.derbyTesting.functionTests.tests.lang.SysinfoTest
+// *  
+// * 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.
+// *
+
+//
+// Policy file with minimal set of permissions to run derby's
+// functional tests.
+//
+// The test harness sets up four variables used by this policy file
+//
+// derbyTesting.codejar - URL to the jar files when they are in the classpath
+// derbyTesting.codeclasses - URL to the classes directory when it is in the classpath
+//
+// Only one of derbyTesting.codejar and derbyTesting.codeclasses will be valid, the
+// other will be set to a bogus URL like file://unused
+//
+// derbyTesting.codedir - File location of either derbyTesting.codejar or derbyTesting.codeclasses.
+// Only required due to a BUG (see below for more info).
+//
+// derbyTesting.jaxpjar - URL to the jar file containing the JAXP implementation
+//     for XML-based tests (ex. lang/XMLBindingTest.java).
+//
+// derbyTesting.serverhost - Host name or ip where network server is started 
+// derbyTesting.clienthost - specifies the clients ip address/hostName. 
+//     when testing with networkserver on a remote host, this needs to be passed in 
+//     with the NetworkServerControl start command
+
+//
+// Permissions for the embedded engine (derby.jar)
+//
+grant codeBase "${derbyTesting.codejar}derby.jar" {
+  permission java.util.PropertyPermission "derby.*", "read";
+permission java.util.PropertyPermission "derby.storage.jvmInstanceId", 
+      "write"; 
+  // The next two properties are used to determine if the VM is 32 or 64 bit.
+  permission java.util.PropertyPermission "sun.arch.data.model", "read";
+  permission java.util.PropertyPermission "os.arch", "read";
+  permission java.util.PropertyPermission "java.class.path", "read";//sysinfo
+  
+  // unit tests (e.g. store/T_RecoverFullLog) set this property 
+  // (called from derbyTesting.jar through code in derby.jar)
+  permission java.util.PropertyPermission "derbyTesting.unittest.*", "write";
+
+  permission java.lang.RuntimePermission "createClassLoader";
+
+  // permissions so that we can set the context class loader to
+  // null for daemon threads to avoid class loader leak.
+  // DERBY-3745
+  permission java.lang.RuntimePermission "getClassLoader";
+  permission java.lang.RuntimePermission "setContextClassLoader";
+
+  permission java.security.SecurityPermission "getPolicy";
+  
+  permission java.io.FilePermission "${derby.system.home}${/}derby.properties", "read";
+  permission java.io.FilePermission "${derby.system.home}${/}derby.log", "read, write, delete";
+  // [DERBY-2000] The write permission was added to allow creation of the
+  // derby.system.home directory when running tests under a security manager.
+  permission java.io.FilePermission "${derby.system.home}", "read, write";
+  
+  // all databases under derby.system.home 
+  permission java.io.FilePermission "${derby.system.home}${/}-", "read, write, delete";
+
+  // Import/export and other support files from these locations in tests
+  permission java.io.FilePermission "${user.dir}${/}extin${/}-", "read";
+  permission java.io.FilePermission "${user.dir}${/}extinout${/}-", "read,  write, delete";
+  permission java.io.FilePermission "${user.dir}${/}extout${/}-", "read,write";
+  permission java.io.FilePermission "${user.dir}${/}extinout", "read,write";
+  
+  // These permissions are needed to load the JCE for encryption with Sun and IBM JDK131.
+  // JDK14 has the JCE  preloaded
+  permission java.security.SecurityPermission "insertProvider.SunJCE";
+  permission java.security.SecurityPermission "insertProvider.IBMJCE";
+  
+//
+// Permissions needed for JMX based management and monitoring, which is only
+// available for JVMs supporting "platform management", that is J2SE 5.0 or better.
+//
+// Allows this code to create an MBeanServer:
+//
+  permission javax.management.MBeanServerPermission "createMBeanServer";
+//
+// Allows access to Derby's built-in MBeans, within the domain org.apache.derby.
+// Derby must be allowed to register and unregister these MBeans.
+// To fine tune this permission, see the javadoc of javax.management.MBeanPermission
+// or the JMX Instrumentation and Agent Specification.
+//
+  permission javax.management.MBeanPermission "org.apache.derby.*#[org.apache.derby:*]","registerMBean,unregisterMBean";
+//
+// Trusts Derby code to be a source of MBeans and to register these in the MBean server.
+//
+  permission javax.management.MBeanTrustPermission "register";
+
+  // Gives permission for jmx to be used against Derby but
+  // only if JMX authentication is not being used.
+  // In that case the application would need to create
+  // a whole set of fine-grained permissions to allow specific
+  // users access to MBeans and actions they perform.
+  permission org.apache.derby.security.SystemPermission "jmx", "control";
+  permission org.apache.derby.security.SystemPermission "engine", "monitor";
+  permission org.apache.derby.security.SystemPermission "server", "monitor";  
+ 
+  // These permissions are needed when testing code instrumented with EMMA.
+  // They will only be used if the emma.active system property property is set,
+  // which should be set to "" for the permissions to be correct.
+  permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+  permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+  permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+  
+  // These permissions are needed by AssertFailure to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+};
+
+//
+// Permissions for the network server (derbynet.jar)
+//
+grant codeBase "${derbyTesting.codejar}derbynet.jar" {
+  permission java.util.PropertyPermission "java.class.path", "read";//sysinfo
+  
+  // accept is needed for the server accepting connections
+  // connect is needed for ping command (which is in the server jar)
+  permission java.net.SocketPermission "127.0.0.1", "accept,connect";
+  permission java.net.SocketPermission "localhost", "accept,connect";
+  permission java.net.SocketPermission "${derbyTesting.clienthost}", "accept,connect";
+  permission java.net.SocketPermission "${derbyTesting.serverhost}", "accept,connect";
+  // Need to be able to write to trace file for NetworkServerControlApiTest
+  permission java.io.FilePermission "${user.dir}${/}system${/}trace${/}-", "write"; 
+    // Needed for NetworkServerMBean access (see JMX section above)
+  permission org.apache.derby.security.SystemPermission "server", "control,monitor";
+  
+};
+
+//
+// Permissions for the network client (derbyclient.jar)
+//
+grant codeBase "${derbyTesting.clientjar}derbyclient.jar" {
+  permission java.net.SocketPermission "127.0.0.1", "connect,resolve";
+  permission java.net.SocketPermission "localhost", "connect,resolve";
+  permission java.net.SocketPermission "${derbyTesting.serverhost}", "connect,resolve";
+
+  // DERBY-1883: Since some classes that are included in both derby.jar and
+  // derbyclient.jar read properties, derbyclient.jar needs permission to read
+  // derby.* properties to avoid failures when it is listed before derby.jar in
+  // the classpath.
+  permission java.util.PropertyPermission "derby.*", "read";
+
+  // DERBY-2302: derbyclient.jar needs to be able to read the user.dir property in order to
+  // do tracing in that directory. Also, it needs read/write permissions in user.dir in order
+  // to create the trace files in that directory.
+  permission java.util.PropertyPermission "user.dir", "read";
+  permission java.io.FilePermission "${user.dir}${/}-", "read, write"; 
+  
+  // These permissions are needed by AssertFailure to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+
+};
+
+//
+// Permissions for the tools (derbytools.jar)
+// Ideally this would be more secure, for now the
+// focus is on getting the engine & network server secure.
+//
+grant codeBase "${derbyTesting.codejar}derbytools.jar" {
+  // Access all properties using System.getProperties -
+  // ij enumerates the properties in order to open connections
+  // for any property set in ij.connection.* and set protocols
+  // for any property in ij.protocol.*
+  permission java.util.PropertyPermission "*", "read, write";
+  
+  // Read all files under ${user.dir}
+  permission java.io.FilePermission "${user.dir}${/}-", "read";
+  
+  // IjTestCases read, write, and delete ij's output in the extinout dir
+  permission java.io.FilePermission "${user.dir}${/}extinout${/}-", "read, write, delete";
+ 
+  // ij needs permission to read the sql files in this jar
+  permission java.io.FilePermission "${derbyTesting.testjarpath}", "read";
+  
+};
+
+//
+// Permissions for the tests (derbyTesting.jar)
+// We are liberal here, it's not a goal to make the test harness
+// or tests secure.
+//
+grant codeBase "${derbyTesting.testjar}derbyTesting.jar" {
+  // Access all properties using System.getProperties
+  permission java.util.PropertyPermission "*", "read, write";
+  
+  // Access all files under ${user.dir}to write the test directory structure
+  permission java.io.FilePermission "${user.dir}${/}-", "read,write,delete"; 
+
+  // When running with useprocess=false need to install and uninstall
+  // the security manager and allow setIO to change the system err and out
+  // streams. Currently the nist suite runs with useprocess=false.
+  permission java.lang.RuntimePermission "setSecurityManager";
+  permission java.security.SecurityPermission "getPolicy";
+  permission java.lang.RuntimePermission "setIO";  
+
+  // These permissions are needed to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+  
+  // Allow MBeanTest to register the application management MBean.
+  permission javax.management.MBeanServerPermission "createMBeanServer";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.Management#[org.apache.derby:type=Management]","registerMBean,unregisterMBean";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.Management#-[-]", "instantiate";
+  permission javax.management.MBeanTrustPermission "register";
+   
+  // And to find and use Derby's MBeans
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#[org.apache.derby:*]", "getAttribute,invoke";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#-[org.apache.derby:*]", "getMBeanInfo";
+  permission javax.management.MBeanPermission "-#-[-]", "queryNames";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#-[org.apache.derby:*]", "queryNames";
+  
+  // Test code needs this as well for the platform MBeanServer
+  // tests where the testing code is in the stack frame.
+  permission org.apache.derby.security.SystemPermission "jmx", "control";
+  permission org.apache.derby.security.SystemPermission "engine", "monitor";
+  permission org.apache.derby.security.SystemPermission "server", "control,monitor";
+  
+  // These permissions are needed when testing code instrumented with EMMA.
+  permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+  
+  //client side: test execs another jvm with relative path
+  permission java.io.FilePermission "<<ALL FILES>>", "execute";
+};
+
+//
+// super-set of the jar permissions for running out of the classes directory
+//
+grant codeBase "${derbyTesting.codeclasses}" {
+  // for sysinfo test, with classes, we need read access for this...
+  // can't use derbyTesting.codeclasses as it has backslashes on windows
+  permission java.io.FilePermission "${sysinfotest.classesdir}", "read";
+
+  // Access all properties using System.getProperties
+  permission java.util.PropertyPermission "*", "read, write";
+  
+  permission java.util.PropertyPermission "derby.*", "read";
+  permission java.lang.RuntimePermission "createClassLoader";
+
+  // permissions so that we can set the context class loader to
+  // null for daemon threads to avoid class loader leak.
+  // DERBY-3745
+  permission java.lang.RuntimePermission "getClassLoader";
+  permission java.lang.RuntimePermission "setContextClassLoader";
+
+  permission java.security.SecurityPermission "getPolicy";
+   
+  permission java.io.FilePermission "${derby.system.home}${/}derby.properties", "read";
+  permission java.io.FilePermission "${derby.system.home}${/}derby.log", "read, write, delete";
+  permission java.io.FilePermission "${derby.system.home}", "read";
+  permission java.io.FilePermission "${derby.system.home}${/}-", "read, write, delete";
+
+  // combination of client and server side.
+  permission java.net.SocketPermission "127.0.0.1", "accept,connect,resolve";
+  permission java.net.SocketPermission "localhost", "accept,connect,resolve";
+  permission java.net.SocketPermission "${derbyTesting.clienthost}", "accept,connect";
+  permission java.net.SocketPermission "${derbyTesting.serverhost}", "connect,resolve";
+  
+  // Access all files under ${user.dir}to write the test directory structure
+  // Also covers extin, extout and extinout locations
+  permission java.io.FilePermission "${user.dir}${/}-", "read,write,delete"; 
+    
+  // These permissions are needed to load the JCE for encryption with Sun and IBM JDK131.
+  // JDK14 has the JCE  preloaded
+  permission java.security.SecurityPermission "insertProvider.SunJCE";
+  permission java.security.SecurityPermission "insertProvider.IBMJCE";
+
+  // When running with useprocess=false need to install and uninstall
+  // the security manager and allow setIO to change the system err and out
+  // streams. Currently the nist suite runs with useprocess=false.
+  permission java.lang.RuntimePermission "setSecurityManager";
+  permission java.lang.RuntimePermission "setIO"; 
+
+  // These permissions are needed by stress.multi to dump the thread stack
+  // traces upon failure.
+  permission java.lang.RuntimePermission "getStackTrace";
+  permission java.lang.RuntimePermission "modifyThreadGroup";
+  
+    // Allow MBeanTest to register the application management MBean.
+  permission javax.management.MBeanServerPermission "createMBeanServer";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.Management#[org.apache.derby:type=Management]","registerMBean,unregisterMBean";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.Management#-[-]", "instantiate";
+  permission javax.management.MBeanTrustPermission "register";
+  
+  // Allows access to Derby's built-in MBeans, within the domain org.apache.derby.
+  permission javax.management.MBeanPermission "org.apache.derby.*#[org.apache.derby:*]","registerMBean,unregisterMBean";
+  
+   
+  // And to find and use Derby's MBeans
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#[org.apache.derby:*]", "getAttribute,invoke";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#-[org.apache.derby:*]", "getMBeanInfo";
+  permission javax.management.MBeanPermission "-#-[-]", "queryNames";
+  permission javax.management.MBeanPermission "org.apache.derby.mbeans.*#-[org.apache.derby:*]", "queryNames";
+  
+  // Test code needs this as well for the platform MBeanServer
+  // tests where the testing code is in the stack frame.
+  permission org.apache.derby.security.SystemPermission "jmx", "control";
+  permission org.apache.derby.security.SystemPermission "engine", "monitor";
+  permission org.apache.derby.security.SystemPermission "server", "control,monitor";
+  
+  //client side: test execs another jvm with relative path
+  permission java.io.FilePermission "<<ALL FILES>>", "execute";
+};
+
+// JUnit jar file tries to read junit.properties in the user's
+// home directory and seems to require permission to read the
+// property user.home as well.
+// junit.swingui.TestRunner writes to .junitsession on exit.
+grant codeBase "${derbyTesting.junit}" {
+    permission java.util.PropertyPermission "user.home", "read";
+    permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
+    permission java.io.FilePermission "${user.home}${/}.junitsession", "write";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
+  
+    // These permissions are needed when testing code instrumented with EMMA.
+    permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+    permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+    
+    //client side: test execs another jvm with relative path
+    permission java.io.FilePermission "<<ALL FILES>>", "execute";
+};
+
+// Due to a problem running tests/derbynet/CompatibilityTest in the old test
+// harness, permission to read junit.properties is granted to all. This can be 
+// removed when CompatibilityTest is rewritten to conform to our current Junit
+// usage. See DERBY-2076.
+grant {
+    permission java.io.FilePermission "${user.home}${/}junit.properties", "read";
+};
+
+// Ant's junit runner requires setOut to redirect the System output streams
+// to the forked JVM used when running junit tests inside Ant. Ant requires
+// forking the JVM if you want to run tests in a different directory than the
+// current one.
+grant codeBase "${derbyTesting.antjunit}" {
+    permission java.lang.RuntimePermission "setIO";
+
+    // This permission is needed when running the tests using ant 1.7
+    permission java.io.FilePermission "${user.dir}${/}*", "write";
+
+    // These permissions are needed when testing code instrumented with EMMA.
+    permission java.util.PropertyPermission "${emma.active}user.dir", "read";
+    permission java.io.FilePermission "${emma.active}${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "${emma.active}writeFileDescriptor";
+};
+
+// functionTests.tests.lang.RoutineSecurityTest requires this grant
+// to check to see if permissions are granted through generated code
+// through this mechanism.
+grant {
+    permission java.util.PropertyPermission "derbyRoutineSecurityTest.yes", "read";
+    
+
+};
+
+// When inserting XML values that use external DTD's, the JAXP parser
+// needs permission to read the DTD files.  We assume that all DTD
+// files will be copied to extin/ by whichever tests need them.  So
+// grant the JAXP parser permissions to read that directory.
+grant codeBase "${derbyTesting.jaxpjar}" {
+  permission java.io.FilePermission "${user.dir}${/}extin${/}-", "read";
+};
+
+
+// These permissions are needed when testing code instrumented with EMMA.
+// They are all related to writing coverage statistics to a file that by default
+// is named coverage.ec placed in the directory where the test is executed.
+grant codeBase "${derbyTesting.emma}" {
+    permission java.util.PropertyPermission "user.dir", "read";
+    permission java.io.FilePermission "${user.dir}${/}coverage.ec", "read, write";
+    permission java.lang.RuntimePermission "writeFileDescriptor";
+};
+
+// Permissions for package-private tests run from 'classes.pptesting'
+grant codeBase "${derbyTesting.ppcodeclasses}" {
+
+  // Needed for ProtocolTest - allows connection to a server
+  permission java.net.SocketPermission "127.0.0.1", "connect,resolve";
+  permission java.net.SocketPermission "localhost", "connect,resolve";
+  permission java.net.SocketPermission "${derbyTesting.serverhost}", "connect,resolve";
+
+  // Allows reading support files in 'extin'
+  permission java.io.FilePermission "${user.dir}${/}extin${/}-", "read";
+};

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java?rev=688103&r1=688102&r2=688103&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java Fri Aug 22 08:47:07 2008
@@ -53,6 +53,7 @@
         suite.addTest(BadConnectionTest.suite());
         suite.addTest(NetHarnessJavaTest.suite());
         suite.addTest(SecureServerTest.suite());
+        suite.addTest(SysinfoTest.suite());
         suite.addTest(SSLTest.suite());
         suite.addTest(NetIjTest.suite());
         suite.addTest(NSinSameJVMTest.suite());

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=688103&r1=688102&r2=688103&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 Fri Aug 22 08:47:07 2008
@@ -436,87 +436,114 @@
         });
 	}
     
-    /**
+	/**
+	 * 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 {
+
+	    Process pr = execJavaCmd(cmd);
+	    String output = readProcessOutput(pr);
+	    int exitValue = pr.exitValue();
+
+	    Assert.assertEquals(expectedExitValue, exitValue);
+	    if (expectedString != null) {
+	        for (int i = 0; i < expectedString.length; i++) {
+	            assertFalse(output.indexOf(expectedString[i]) < 0);
+	        }
+	    }
+	}
+
+
+	/**
+	 * Execute a java command and return the process.
+	 * The caller should decide what to do with the process, if anything,
+	 * typical activities would be to do a pr.waitFor, or to
+	 * get a getInputStream or getErrorStream
+	 * Note, that for verifying the output of a Java process, there is
+	 * assertExecJavaCmdAsExpected
+	 * 
+	 * @param cmd array of java arguments for command
+	 * @return the process that was started
+	 * @throws IOException
+	 */
+	public Process execJavaCmd(String[] cmd) throws 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;
+	    }
+	    return pr;
+	}
+   
    /**
-    * 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
+    * Reads output from a process and returns it as a string.
+    * This will block until the process terminates.
+    * 
+    * @param pr a running process
+    * @return output of the process
     * @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
-           int charsRead;
-           while ((charsRead = inStream.read(ca, 0, ca.length)) != -1)
-           {
-               output = output + new String(ca, 0, charsRead);
-           }
-       } catch (Exception e) {
-           fail("Exception accessing inputstream from javacommand", e);
-       }
-       
-       // wait until the process exits
-       pr.waitFor();
-       
-       Assert.assertEquals(expectedExitValue, pr.exitValue());
-       if (expectedString != null)
-       {
-           for (int i=0 ; i<expectedString.length ; i++)
-           {
-               if (output.indexOf(expectedString[i]) == -1) {
-                   fail("Didn't find expected string: " + expectedString[i] +
-                        "\nFull output from the command:\n" + output);
-               }
-           }
-       }
-   }
-    
+   public String readProcessOutput(Process pr) throws InterruptedException {
+		InputStream is = pr.getInputStream();
+		if (is == null) {
+			fail("Unexpectedly receiving no text from the process");
+		}
+
+		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
+		    int charsRead;
+		    while ((charsRead = inStream.read(ca, 0, ca.length)) != -1)
+		    {
+		        output = output + new String(ca, 0, charsRead);
+		    }
+		} catch (Exception e) {
+		    fail("Exception accessing inputstream from process", e);
+		}
+
+		// wait until the process exits
+		pr.waitFor();
+		
+		return output;
+	}
+   
     /**
      * Remove the directory and its contents.
      * @param path Path of the directory

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java?rev=688103&r1=688102&r2=688103&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java Fri Aug 22 08:47:07 2008
@@ -153,51 +153,6 @@
                     System.out.println("};\n");
             }
         }
-        /**
-         * Execute a java command and return the process.
-         * The caller should decide what to do with the process, if anything,
-         * typical activities would be to do a pr.waitFor, or to
-         * get a getInputStream or getErrorStream
-         * Note, that for verifying the output of a Java process, there is
-         * BaseTestCase.assertExecJavaCmdAsExpected
-         * 
-         * @param args
-         * @return the Process 
-         * @throws InterruptedException
-         */
-        public static Process execJavaCmd(String[] args) throws IOException, InterruptedException {
-            
-            int totalSize = 3 + args.length;
-            String[] cmd = new String[totalSize];
-            cmd[0] = "java";
-            cmd[1] = "-classpath";
-            cmd[2] = BaseTestCase.getSystemProperty("java.class.path");
-                    
-            System.arraycopy(args, 0, cmd, 3, args.length);
-            
-            final String[] command = cmd;
-            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;
-            }
-            
-            return pr;
-        }
         
     /**
      * Calls the public method <code>getInfo</code> of the sysinfo tool within



Mime
View raw message