You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2008/10/13 23:29:09 UTC

svn commit: r704259 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/suites/AllPackages.java functionTests/tests/multi/StressMultiTest.java junit/SystemPropertyTestSetup.java

Author: kmarsden
Date: Mon Oct 13 14:29:09 2008
New Revision: 704259

URL: http://svn.apache.org/viewvc?rev=704259&view=rev
Log:
DERBY-1764 Rewrite stress.multi as a JUnit test

enable StressMultiTest.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/multi/StressMultiTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java?rev=704259&r1=704258&r2=704259&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/AllPackages.java Mon Oct 13 14:29:09 2008
@@ -61,6 +61,7 @@
         suite.addTest(org.apache.derbyTesting.functionTests.tests.demo._Suite.suite());
         suite.addTest(org.apache.derbyTesting.functionTests.tests.memory._Suite.suite());
         suite.addTest(org.apache.derbyTesting.functionTests.tests.i18n._Suite.suite());
+        suite.addTest(org.apache.derbyTesting.functionTests.tests.multi.StressMultiTest.suite());
 
         // Suites that are compiled using Java SE 6 target need to
         // be added this way, otherwise creating the suite

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/multi/StressMultiTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/multi/StressMultiTest.java?rev=704259&r1=704258&r2=704259&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/multi/StressMultiTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/multi/StressMultiTest.java Mon Oct 13 14:29:09 2008
@@ -39,8 +39,10 @@
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.BaseTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
 import org.apache.derbyTesting.junit.Decorator;
 import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
@@ -107,23 +109,35 @@
      * Default run is 10 threads for 10 minutes in each mode
      */
     public static Test suite() {
-        Properties sysprops = System.getProperties();
-        sysprops.put("derby.locks.deadlockTimeout", "2");
-        sysprops.put("derby.locks.waitTimeout", "3");
-        sysprops.put("derby.language.logStatementText", "true");
+        Properties dbprops = new Properties();
+        dbprops.put("derby.locks.deadlockTimeout", "2");
+        dbprops.put("derby.locks.waitTimeout", "3");
+
+        Properties sysprops = new Properties();
         sysprops.put("derby.storage.keepTransactionLog", "true");
+        sysprops.put("derby.language.logStatementText", "true");
         sysprops.put("derby.infolog.append", "true");
-
-        TestSuite embedded = new TestSuite("StressMultiTest:embedded");
-        embedded.addTestSuite(StressMultiTest.class);
-
-        TestSuite client = new TestSuite("StressMultiTest:client");
-        client.addTest(TestConfiguration.clientServerDecorator(
-                new TestSuite(StressMultiTest.class)));
-
-        TestSuite encrypted = new TestSuite("StressMultiTest:encrypted");
-        encrypted.addTestSuite(StressMultiTest.class);
-
+        Test embedded = new TestSuite(StressMultiTest.class);
+        embedded = new SystemPropertyTestSetup(embedded,sysprops,true);
+        embedded = new DatabasePropertyTestSetup(embedded,dbprops);
+        // make this a singleUseDatabase so the datbase and 
+        // transaction log will be preserved.
+        embedded = TestConfiguration.singleUseDatabaseDecorator(newCleanDatabase(embedded));
+        // SystemPropertyTestSetup for static properties 
+        // does not work for client because shutting down the
+        // engine causes protocol errors on the client. Run
+        // with -Dderby.storage.keepTransactionLog=true if
+        // you need to save the transaction log for client.
+        Test client = TestConfiguration.clientServerDecorator(
+        		new TestSuite(StressMultiTest.class));
+        client = newCleanDatabase(new DatabasePropertyTestSetup(client,dbprops));
+        Test encrypted = new TestSuite(StressMultiTest.class);
+        // SystemPropertyTestSetup for static properties 
+        // does not work for encrypted databases because the
+        // database has to be rebooted and we don't have access
+        // to the boot password (local to Decorator.encryptedDatabase()
+        // Run with -Dderby.storage.keepTransactionLog=true if you 
+        // need to save the transaction log for encrypted.
         TestSuite unencrypted = new TestSuite("StressMultiTest:unencrypted");
         unencrypted.addTest((embedded));
         unencrypted.addTest((client));
@@ -132,7 +146,7 @@
                 " Threads " + MINUTES + " Minutes");
         suite.addTest(newCleanDatabase(unencrypted));
         //Encrypted uses a different database so it needs its own newCleanDatabase
-        suite.addTest(Decorator.encryptedDatabase(newCleanDatabase(encrypted)));
+        suite.addTest(Decorator.encryptedDatabase(new DatabasePropertyTestSetup(newCleanDatabase(encrypted),dbprops)));
 
         return suite;
     }
@@ -163,24 +177,26 @@
         THREADS = threads;
         MINUTES = minutes;
         
-        Properties sysprops = System.getProperties();
-        sysprops.put("derby.locks.deadlockTimeout", "2");
-        sysprops.put("derby.locks.waitTimeout", "3");
-        sysprops.put("derby.language.logStatementText", "true");
+        Properties dbprops = new Properties();
+        dbprops.put("derby.locks.deadlockTimeout", "2");
+        dbprops.put("derby.locks.waitTimeout", "3");
+        dbprops.put("derby.language.logStatementText", "true");
+        dbprops.put("derby.storage.keepTransactionLog", "true");
+        Properties sysprops = new Properties();
         sysprops.put("derby.storage.keepTransactionLog", "true");
+        sysprops.put("derby.language.logStatementText", "true");
         sysprops.put("derby.infolog.append", "true");
-
-        TestSuite embedded = new TestSuite("StressMultiTest:embedded, " + THREADS +
-            " Threads " + MINUTES + " Minutes");
-        embedded.addTestSuite(StressMultiTest.class);
-        
-        return newCleanDatabase(embedded);
+        Test embedded = new TestSuite(StressMultiTest.class);
+        embedded = new SystemPropertyTestSetup(embedded,sysprops,true);
+        embedded = new DatabasePropertyTestSetup(embedded,dbprops);
+        embedded = TestConfiguration.singleUseDatabaseDecorator(newCleanDatabase(embedded));
+        return embedded;
     }
     
     /*
      * Create a CleanDatabaseTestSetup that sets up the testdatabase.
      */
-    private static Test newCleanDatabase(TestSuite s) {
+    private static Test newCleanDatabase(Test s) {
         return new CleanDatabaseTestSetup(s) {
         /**
          * Creates the database objects used in the test cases.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java?rev=704259&r1=704258&r2=704259&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java Mon Oct 13 14:29:09 2008
@@ -36,6 +36,7 @@
 	
 	protected Properties newValues;
 	private Properties oldValues;
+	private boolean staticProperties;
 	
 	/**
 	 * Create a test decorator that sets and restores the passed
@@ -45,14 +46,31 @@
 	 * @param newValues properties to be set
 	 */
 	public SystemPropertyTestSetup(Test test,
-			Properties newValues)
+			Properties newValues,
+			boolean staticProperties)
 	{
 		super(test);
 		this.newValues = newValues;
 		this.oldValues = new Properties();
+		this.staticProperties = staticProperties;
 	}
 
 	/**
+	 * Create a test decorator that sets and restores 
+	 * System properties.  Do not shutdown engine after
+	 * setting properties
+	 * @param test
+	 * @param newValues
+	 */
+	public SystemPropertyTestSetup(Test test,
+			Properties newValues)
+	{
+		super(test);
+		this.newValues = newValues;
+		this.oldValues = new Properties();
+		this.staticProperties = false;
+	}
+	/**
 	 * For each property store the current value and
 	 * replace it with the new value, unless there is no change.
 	 */
@@ -60,6 +78,9 @@
     throws java.lang.Exception
     {
     	setProperties(newValues);
+    	// shutdown engine so static properties take effect
+    	if (staticProperties)
+    		TestConfiguration.getCurrent().shutdownEngine();
     }
 
     /**
@@ -78,6 +99,9 @@
        	}
     	// and then reset nay old values
     	setProperties(oldValues);
+    	// shutdown engine to restore any static properties
+    	if (staticProperties)
+    		TestConfiguration.getCurrent().shutdownEngine();
         newValues = null;
         oldValues = null;
     }