db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r1294805 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/store/OCRecoveryTest.java junit/BaseTestCase.java junit/TestConfiguration.java
Date Tue, 28 Feb 2012 20:02:34 GMT
Author: myrnavl
Date: Tue Feb 28 20:02:34 2012
New Revision: 1294805

URL: http://svn.apache.org/viewvc?rev=1294805&view=rev
Log:
DERBY-5382; Convert existing harness recovery tests to JUnit tests
  Adjusting OCRecoveryTest to create the database in the first launched method.
  Modifying TestConfiguration to this end to look for a property 
    'derby.tests.defaultDatabaseName'
  which can get passed on in a new BaseTestCase method 
  ((assertLaunchedJUnitTestMethod(String, String)). 

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OCRecoveryTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OCRecoveryTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OCRecoveryTest.java?rev=1294805&r1=1294804&r2=1294805&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OCRecoveryTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OCRecoveryTest.java
Tue Feb 28 20:02:34 2012
@@ -30,7 +30,6 @@ import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.BaseTestCase;
-import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 public class OCRecoveryTest extends BaseJDBCTestCase {
@@ -55,25 +54,31 @@ public class OCRecoveryTest extends Base
     {
         Test test = TestConfiguration.embeddedSuite(
                         OCRecoveryTest.class);
-        return new CleanDatabaseTestSetup(test);
+        // using a singleUseDatabaseDecorator which should not create
+        // the database until the first connection is made
+        return TestConfiguration.singleUseDatabaseDecorator(test,
+            "OCRecoveryDB");
     }
 
     public void testOCRecovery() throws Exception
     {
-        setAutoCommit(false);
-
-        TestConfiguration.getCurrent().shutdownDatabase();
+        
         // Now call forked processes - each of these will do something,
         // then *not* shutdown, forcing the next one to recover the
         // database.
+        // Pass in the name of the database to be used.
         assertLaunchedJUnitTestMethod("org.apache.derbyTesting." +
-                "functionTests.tests.store.OCRecoveryTest.launchOCRecovery_1");
+                "functionTests.tests.store.OCRecoveryTest.launchOCRecovery_1",
+                "OCRecoveryDB");
         assertLaunchedJUnitTestMethod("org.apache.derbyTesting." +
-                "functionTests.tests.store.OCRecoveryTest.launchOCRecovery_2");
+                "functionTests.tests.store.OCRecoveryTest.launchOCRecovery_2",
+                "OCRecoveryDB");
         assertLaunchedJUnitTestMethod("org.apache.derbyTesting." +
-                "functionTests.tests.store.OCRecoveryTest.launchOCRecovery_3");
+                "functionTests.tests.store.OCRecoveryTest.launchOCRecovery_3",
+                "OCRecoveryDB");
         assertLaunchedJUnitTestMethod("org.apache.derbyTesting." +
-                "functionTests.tests.store.OCRecoveryTest.launchOCRecovery_4");
+                "functionTests.tests.store.OCRecoveryTest.launchOCRecovery_4",
+                "OCRecoveryDB");
     }
 
     public void launchOCRecovery_1() throws Exception
@@ -81,6 +86,9 @@ public class OCRecoveryTest extends Base
         // setup to test restart recovery of online compress.  Real work
         // is done in next method launchOCRecovery_2 which will run restart
         // recovery on the work done in this step.
+        // open a connection to the database, this should create the db
+        getConnection();
+        setAutoCommit(false);        
         createAndLoadTable(tableName, true, 5000, 0);
         Statement st = createStatement();
         st.executeUpdate("DELETE FROM " + tableName);

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=1294805&r1=1294804&r2=1294805&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Tue Feb
28 20:02:34 2012
@@ -880,6 +880,25 @@ public abstract class BaseTestCase
         testLaunchMethod };
         assertExecJavaCmdAsExpected(new String[] { "OK (1 test)" }, cmd, 0);
     }
+    
+    /**
+     * assert a method from an executing test
+     *
+     * @param testLaunchMethod
+     *            complete pathname of the method to be executed
+     * @param databaseName
+     *            name of the database to be used
+     * @throws Exception
+     */
+    public static void assertLaunchedJUnitTestMethod(String testLaunchMethod,
+            String databaseName)
+            throws Exception 
+    {
+        String[] cmd = new String[] { 
+                "-Dderby.tests.defaultDatabaseName=" + databaseName, 
+                "junit.textui.TestRunner", "-m", testLaunchMethod };
+        assertExecJavaCmdAsExpected(new String[] { "OK (1 test)" }, cmd, 0);
+    }
 
     private static String traceClientType() {
        if (TestConfiguration.getCurrent().getJDBCClient().isEmbedded()) {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=1294805&r1=1294804&r2=1294805&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Tue Feb 28 20:02:34 2012
@@ -1093,7 +1093,14 @@ public final class TestConfiguration {
      *
      */
     private TestConfiguration() {
-        this.defaultDbName = DEFAULT_DBNAME;
+        // Check for possibly passed in DatabaseName
+        // this is used in OCRecoveryTest
+        String propDefDbName = getSystemProperties().getProperty(
+                "derby.tests.defaultDatabaseName");
+        if (propDefDbName != null)
+            this.defaultDbName = propDefDbName;
+        else
+            this.defaultDbName=DEFAULT_DBNAME;
         usedDbNames.add(DEFAULT_DBNAME);
         logicalDbMapping.put(DEFAULT_DBNAME, DEFAULT_DBNAME);
         this.userName = DEFAULT_USER_NAME;



Mime
View raw message