db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r792001 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/master/ functionTests/suites/ functionTests/tests/derbynet/ junit/
Date Tue, 07 Jul 2009 23:54:21 GMT
Author: kmarsden
Date: Tue Jul  7 23:54:20 2009
New Revision: 792001

URL: http://svn.apache.org/viewvc?rev=792001&view=rev
Log:
DERBY-3834 Convert derbynet/runtimeinfo to JUnit

Contributed by Tiago R. Espinha (tiago at espinhas dot net) based on partial patch contributed
by Erlend Birkenes (erlend at birkenes dot net)


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/LocaleTestSetup.java  
(with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/runtimeinfo.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/runtimeinfo.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/runtimeinfo_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/runtimeinfo_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/derbynetmats.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.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=792001&r1=792000&r2=792001&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
Tue Jul  7 23:54:20 2009
@@ -10,7 +10,6 @@
 # derbynet/dblook_test_net_territory because it tries to search derby.log, which is on
 #     the server machine
 # derbynet/maxthreads - tries to use NetworkServerControl statements
-# derbynet/runtimeinfo - tries to use NetworkServerControl statements
 # 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
@@ -23,7 +22,6 @@
 derbynet/dblook_test_net.java
 derbynet/dblook_test_net_territory.java
 derbynet/maxthreads.java
-derbynet/runtimeinfo.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=792001&r1=792000&r2=792001&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
Tue Jul  7 23:54:20 2009
@@ -7,7 +7,6 @@
 # derbynet/dblook_test_net.java - expects different dir structure
 # derbynet/dblook_test_net_territory.java - expects different dir structure
 # stress/stress.multi - exits suite
-# derbynet/runtimeinfo.java - different sessions
 # following fail for various reasons, many related to not being able to connect:
 #  lang/wisconsin.java
 #  jdbcapi/derbyStress.java
@@ -18,7 +17,6 @@
 derbynet/DerbyNetAutoStart.java
 derbynet/dblook_test_net.java
 derbynet/dblook_test_net_territory.java
-derbynet/runtimeinfo.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=792001&r1=792000&r2=792001&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
Tue Jul  7 23:54:20 2009
@@ -10,7 +10,6 @@
 # derbynet/dblook_test_net_territory because it tries to search derby.log, which is on
 #     the server machine
 # derbynet/maxthreads - tries to use NetworkServerControl statements
-# derbynet/runtimeinfo - 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
@@ -22,7 +21,6 @@
 derbynet/dblook_test_net.java
 derbynet/dblook_test_net_territory.java
 derbynet/maxthreads.java
-derbynet/runtimeinfo.java
 derbynet/timeslice.java
 derbynet/DerbyNetAutoStart.java
 lang/wisconsin.java

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=792001&r1=792000&r2=792001&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
Tue Jul  7 23:54:20 2009
@@ -1,7 +1,6 @@
 derbynet/dblook_test_net.java
 derbynet/dblook_test_net_territory.java
 derbynet/DerbyNetAutoStart.java
-derbynet/runtimeinfo.java
 derbynet/testProtocol.java
 lang/holdCursorIJ.sql
 lang/wisconsin.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall?rev=792001&r1=792000&r2=792001&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall
Tue Jul  7 23:54:20 2009
@@ -1,4 +1,3 @@
 derbynet/dblook_test_net.java
 derbynet/dblook_test_net_territory.java
-derbynet/runtimeinfo.java
 lang/holdCursorIJ.sql

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java?rev=792001&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.java
Tue Jul  7 23:54:20 2009
@@ -0,0 +1,345 @@
+/*
+
+   Derby - Class 
+   org.apache.derbyTesting.functionTests.tests.derbynet.RuntimeInfoTest
+
+   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.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Locale;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.LocaleTestSetup;
+import org.apache.derbyTesting.junit.NetworkServerTestSetup;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ This tests the runtimeinfo command
+ */
+
+public class RuntimeInfoTest extends BaseJDBCTestCase {
+
+	private static String[] RuntimeinfoCmd = new String[] {
+			"org.apache.derby.drda.NetworkServerControl", "runtimeinfo",
+			"-p", String.valueOf(TestConfiguration.getCurrent().getPort()) };
+	private static String[] RuntimeinfoLocaleCmd = new String[] {
+			"-Duser.language=err", "-Duser.country=DE",
+			"org.apache.derby.drda.NetworkServerControl", "runtimeinfo",
+			"-p", String.valueOf(TestConfiguration.getCurrent().getPort()) };
+	
+	private static String POLICY_FILE_NAME=
+    	"functionTests/tests/derbynet/RuntimeInfoTest.policy";
+    private static String TARGET_POLICY_FILE_NAME="runtimeinfo.policy";
+
+    private static Locale englishLocale = new Locale("en","US");
+	private static Locale germanLocale = new Locale("de","DE");
+	
+	/**
+	 * Constructor
+	 * 
+	 * @param name
+	 */
+	public RuntimeInfoTest(String name) {
+		super(name);
+	}
+
+	/**
+	 * Creates a suite with two testcases, with and without some extra 
+	 * system properties.
+	 * 
+	 * @return
+	 */
+	public static Test suite() {
+		TestSuite suite = new TestSuite("RuntimeInfoTest");
+        
+        suite.addTest(decorateTest(englishLocale));
+        suite.addTest(decorateTest(germanLocale));
+		return suite;
+	}	
+	
+	/**
+	 * This is the wrapper that calls the x_tests in order.
+	 * These fixtures rely on the order of the commands being issued.
+	 */
+	public void testRunTests() throws Exception {
+		x_testRuntimeInfoWithActiveConn();
+		x_testRuntimeInfoLocale();
+		x_testRuntimeInfoAfterConnClose();
+	}
+	
+	/**
+	 * Test runtimeinfo
+	 * 
+	 * @throws Exception
+	 */
+	public void x_testRuntimeInfoWithActiveConn() throws Exception {
+		Process p = execJavaCmd(RuntimeinfoCmd);
+		String output = sed(readProcessOutput(p));
+		
+		printIfVerbose("testRuntimeInfo", output);
+		
+		String expectedOutput = ((HashMap)outputs.get(Locale.getDefault())).get("RuntimeInfoWithActiveConn").toString();
+		assertEquals("Output doesn't match", expectedOutput, output);
+	}
+	
+	/**
+	 * Test runtimeinfo w/ foreign (non-English) locale
+	 */
+	public void x_testRuntimeInfoLocale() throws Exception {      
+		Connection conn1 = getConnection();
+		// Now get a couple of connections with some prepared statements
+		Connection conn2 = openDefaultConnection();
+		PreparedStatement ps = prepareAndExecuteQuery(conn1,
+				"SELECT count(*) from sys.systables");
+		PreparedStatement ps2 = prepareAndExecuteQuery(conn1, "VALUES(1)");
+
+		Connection conn3 = openDefaultConnection();
+		PreparedStatement ps3 = prepareAndExecuteQuery(conn2,
+				"SELECT count(*) from sys.systables");
+		PreparedStatement ps4 = prepareAndExecuteQuery(conn2, "VALUES(2)");
+
+		Process p = execJavaCmd(RuntimeinfoLocaleCmd);
+		String output = sed(readProcessOutput(p));
+		
+		printIfVerbose("testRuntimeInfoLocale", output);
+		
+		int matched = 0;
+		String matchString = "\tSYSLH0001\tSELECT count(*) from sys.systables\n	SYSLH0002\tVALUES(1)\n";
+		String invertedMatchString = "\tSYSLH0002\tVALUES(1)\n\tSYSLH0001\tSELECT count(*) from
sys.systables\n";
+		
+		/* The IF clause accomodates for the different order that the result may have */ 
+		matched = output.indexOf(matchString);
+		if (matched == -1) { /* The order was incorrect, try the other one */
+			matched = output.indexOf(invertedMatchString);
+			assertTrue(matched != -1);
+		}
+		
+		matched = 0;
+		matchString = "\tSYSLH0001\tSELECT count(*) from sys.systables\n	SYSLH0002\tVALUES(2)\n";
+		invertedMatchString = "\tSYSLH0002\tVALUES(2)\n\tSYSLH0001\tSELECT count(*) from sys.systables\n";
+		
+		/* Same as above, but with VALUES(2) */ 
+		matched = output.indexOf(matchString);
+		if (matched == -1) { /* The order was incorrect, try the other one */
+			matched = output.indexOf(invertedMatchString);
+			assertTrue(matched != -1);
+		}
+		
+		/* Match the empty session */
+		matched = 0;
+		matchString = ((HashMap)outputs.get(Locale.getDefault())).get("RuntimeInfoLocaleString").toString();
+		
+		assertTrue(output.indexOf(matchString) != -1);
+
+		ps.close();
+		ps2.close();
+		ps3.close();
+		ps4.close();
+		conn1.close();
+		conn2.close();
+		conn3.close();
+
+	}
+
+	/**
+	 * once more after closing the connections 
+	 * - by calling NetworkServerControl.getRuntimeInfo 
+	 * @throws Exception
+	 */
+	public void x_testRuntimeInfoAfterConnClose() throws Exception {
+		// give the network server a second to clean up (DERBY-1455)
+		Thread.sleep(1000);
+
+		String s = NetworkServerTestSetup
+					.getNetworkServerControl(TestConfiguration.getCurrent().getPort())
+					.getRuntimeInfo();
+		s = sed(s);
+		NetworkServerTestSetup.getNetworkServerControl().shutdown();
+		
+		printIfVerbose("testRuntimeInfoMethod", s);
+		
+		String expectedOutput = ((HashMap)outputs.get(Locale.getDefault())).get("RuntimeInfoAfterConnClose").toString();
+		assertEquals("Output doesn't match", expectedOutput, s);
+	}
+
+	public static PreparedStatement prepareAndExecuteQuery(Connection conn,
+			String sql) throws SQLException {
+		PreparedStatement ps = conn.prepareStatement(sql);
+		ResultSet rs = ps.executeQuery();
+		rs.next();
+		return ps;
+	}
+	
+	/**
+     * Replace memory values in the output 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) {
+    	String searchString = ((HashMap)outputs.get(Locale.getDefault())).get("sedMemorySearch").toString();
+    	String replaceString = ((HashMap)outputs.get(Locale.getDefault())).get("sedMemoryReplace").toString();
+		s = s.replaceAll(searchString, replaceString);
+		s = s.trim();
+		return s;
+    }
+    
+    /**
+     * Prints strings to System.out to make it easier to update the tests
+     * when the output changes. BaseTestCase.println() only prints when on VERBOSE
+     * 
+     * @param name just a label to identify the string
+     * @param s the string to be printed
+     */
+    private void printIfVerbose(String name,String s) {
+		println("\n\n>>>" + name + ">>>");
+		println(s);
+		println("<<<" + name + "<<<\n\n");
+    }
+    
+    /**
+     * Construct the name of the server policy file.
+     */
+    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.toURI().toURL().toExternalForm();
+
+            return urlString;
+        }
+        catch (Exception e)
+        {
+            fail(e.getMessage());
+            return null;
+        }
+    }
+	
+	/**
+	 * Decorate a test with SecurityManagerSetup, clientServersuite, and
+	 * SupportFilesSetup.
+	 * 
+	 * @return the decorated test
+	 */
+	private static Test decorateTest(Locale serverLocale) {
+        String policyName = new RuntimeInfoTest("test").makePolicyName();
+
+        Test test = new TestSuite(RuntimeInfoTest.class);
+        
+        test = TestConfiguration.clientServerDecorator(test);
+        
+        /* A single use database must be used to ensure the consistent output.
+         * The output would change whether the test was being ran for the first
+         * or subsequent times. */
+        test = TestConfiguration.singleUseDatabaseDecorator(test);
+        test = new LocaleTestSetup(test, serverLocale);
+        // Install a security manager using the initial policy file.
+        test = new SecurityManagerSetup(test, policyName);
+
+        // Copy over the policy file we want to use.
+        test = new SupportFilesSetup
+            (
+             test,
+             null,
+             new String[] { POLICY_FILE_NAME },
+             null,
+             new String[] { TARGET_POLICY_FILE_NAME}
+             );
+        
+        return test;
+    }
+	
+	private static final HashMap outputs;
+	static {
+		HashMap englishOutputs = new HashMap();
+		englishOutputs.put("RuntimeInfoWithActiveConn",
+				"--- Derby Network Server Runtime Information ---\n" + 
+				"---------- Session Information ---------------\n" + 
+				"Session # :2\n" + 
+				"\n" + 
+				"\n" + 
+				"-------------------------------------------------------------\n" + 
+				"# Connection Threads : 1\n" + 
+				"# Active Sessions : 1\n" + 
+				"# Waiting  Sessions : 0\n" + 
+				"\n" + 
+				"Total Memory : #####	Free Memory : #####");
+		englishOutputs.put("RuntimeInfoAfterConnClose", 
+				"--- Derby Network Server Runtime Information ---\n" + 
+				"---------- Session Information ---------------\n" + 
+				"Session # :8\n" + 
+				"\n" + 
+				"\n" + 
+				"-------------------------------------------------------------\n" + 
+				"# Connection Threads : 4\n" + 
+				"# Active Sessions : 1\n" + 
+				"# Waiting  Sessions : 0\n" + 
+				"\n" + 
+				"Total Memory : #####	Free Memory : #####");
+		englishOutputs.put("sedMemorySearch", "(?m)Memory : [0-9]*");
+		englishOutputs.put("sedMemoryReplace", "Memory : #####");
+		englishOutputs.put("RuntimeInfoLocaleString", "\tStmt ID\t\tSQLText\n\t-------------\t-----------\n\n\n\nSession");
+		
+		HashMap germanOutputs = new HashMap();
+		germanOutputs.put("RuntimeInfoWithActiveConn",
+				"--- Laufzeitinformationen zu Derby Network Server ---\n" + 
+				"---------- Sitzungsinformationen ---------------\n" + 
+				"Sitzungsnummer:2\n" + 
+				"\n" + 
+				"\n" + 
+				"-------------------------------------------------------------\n" + 
+				"Anzahl der Verbindungs-Threads: 1\n" + 
+				"Anzahl der aktiven Sitzungen: 1\n" + 
+				"Anzahl der wartenden Sitzungen: 0\n" + 
+				"\n" + 
+				"Gesamtspeicher: #####	Freier Speicher: #####");
+		germanOutputs.put("RuntimeInfoAfterConnClose", 
+				"--- Laufzeitinformationen zu Derby Network Server ---\n" + 
+				"---------- Sitzungsinformationen ---------------\n" + 
+				"Sitzungsnummer:8\n" + 
+				"\n" + 
+				"\n" + 
+				"-------------------------------------------------------------\n" + 
+				"Anzahl der Verbindungs-Threads: 4\n" + 
+				"Anzahl der aktiven Sitzungen: 1\n" + 
+				"Anzahl der wartenden Sitzungen: 0\n" + 
+				"\n" + 
+				"Gesamtspeicher: #####	Freier Speicher: #####");
+		germanOutputs.put("sedMemorySearch", "Gesamtspeicher: [0-9]*	Freier Speicher: [0-9]*");
+		germanOutputs.put("sedMemoryReplace", "Gesamtspeicher: #####	Freier Speicher: #####");
+		germanOutputs.put("RuntimeInfoLocaleString", "\tAnwsg-ID\t\tSQL-Text\n\t--------------\t------------\n\n\n\nSitzungsnummer");
+		
+		outputs = new HashMap();
+		outputs.put(englishLocale, englishOutputs);
+		outputs.put(germanLocale, germanOutputs);
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy?rev=792001&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/RuntimeInfoTest.policy
Tue Jul  7 23:54:20 2009
@@ -0,0 +1,399 @@
+//
+// *  Derby - Class org.apache.derbyTesting.functionTests.tests.lang.SimpleTest
+// *  
+// * 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";
+};
+
+//
+// super-set of the jar permissions for running out of the classes directory
+//
+grant codeBase "${derbyTesting.codeclasses}" {
+  // 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";
+};
+
+// 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";
+};
+
+// 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";
+    
+    //client side: test execs another jvm with relative path
+  permission java.io.FilePermission "<<ALL FILES>>", "execute";
+};
+
+// 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/RuntimeInfoTest.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=792001&r1=792000&r2=792001&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
Tue Jul  7 23:54:20 2009
@@ -55,6 +55,7 @@
         suite.addTest(SecureServerTest.suite());
         suite.addTest(SysinfoTest.suite());
         suite.addTest(SSLTest.suite());
+        suite.addTest(RuntimeInfoTest.suite());
         suite.addTest(NetIjTest.suite());
         suite.addTest(NSinSameJVMTest.suite());
         suite.addTest(NetworkServerControlClientCommandTest.suite());

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/LocaleTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/LocaleTestSetup.java?rev=792001&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/LocaleTestSetup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/LocaleTestSetup.java Tue
Jul  7 23:54:20 2009
@@ -0,0 +1,69 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.junit.LocaleTestSetup
+ *
+ * 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.junit;
+
+import java.security.AccessController;
+import java.util.Locale;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+/**
+ * This decorator allows the usage of different locales on the tests
+ */
+public class LocaleTestSetup extends TestSetup {
+	private Locale oldLocale;
+	private Locale newLocale;
+	
+	public LocaleTestSetup(Test test, Locale newLocale) {
+		super(test);
+		
+		oldLocale = Locale.getDefault();
+		this.newLocale = newLocale;
+	}
+	
+	/**
+	 * Set up the new locale for the test
+	 */
+	protected void setUp() {
+		AccessController.doPrivileged
+        (new java.security.PrivilegedAction() {
+            public Object run() {
+            	Locale.setDefault(newLocale);
+                return null;
+            }
+        }
+        );
+	}
+	
+	/**
+	 * Revert the locale back to the old one
+	 */
+	protected void tearDown() {
+		AccessController.doPrivileged
+        (new java.security.PrivilegedAction() {
+            public Object run() {
+            	Locale.setDefault(oldLocale);
+                return null;
+            }
+        }
+        );
+	}
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/LocaleTestSetup.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=792001&r1=792000&r2=792001&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
Tue Jul  7 23:54:20 2009
@@ -613,7 +613,7 @@
     {
         if ( !t.getClass().getName().equals( "java.lang.Exception" ) ) { return false; }
         
-        return ( t.getMessage().startsWith( "DRDA_NoIO.S:Could not connect to Derby Network
Server" ) );
+        return ( t.getMessage().startsWith( "DRDA_NoIO.S:" ) );
     }
     
     // return true if this is a drda error



Mime
View raw message