db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1303693 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi: AutoloadTest.java _Suite.java
Date Thu, 22 Mar 2012 09:11:03 GMT
Author: kahatlen
Date: Thu Mar 22 09:11:03 2012
New Revision: 1303693

URL: http://svn.apache.org/viewvc?rev=1303693&view=rev
Log:
DERBY-5664: Include driver tests in jdbcapi suite

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java?rev=1303693&r1=1303692&r2=1303693&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
Thu Mar 22 09:11:03 2012
@@ -30,6 +30,7 @@ import java.sql.Statement;
 import javax.sql.DataSource;
 import java.util.Enumeration;
 
+import junit.extensions.TestSetup;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -40,6 +41,7 @@ import org.apache.derbyTesting.junit.JDB
 import org.apache.derbyTesting.junit.JDBCDataSource;
 import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.SpawnedProcess;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
@@ -52,9 +54,34 @@ import org.apache.derbyTesting.junit.Tes
  * driver was not accidentally loaded by some other test.
  */
 public class AutoloadTest extends BaseJDBCTestCase
-{		
+{
+    private Class spawnedTestClass;
+
 	public	AutoloadTest( String name ) { super( name ); }
 
+    /**
+     * Create a test case that runs this test in a separate JVM.
+     *
+     * @param wrapper a test class that decorates {@code AutoloadTest} with the
+     * desired configuration
+     */
+    private AutoloadTest(Class wrapper) {
+        this("spawnProcess");
+        spawnedTestClass = wrapper;
+    }
+
+    /**
+     * Get the name of the test case.
+     */
+    public String getName() {
+        String name = super.getName();
+        if (spawnedTestClass != null) {
+            // Append the name of the class that decorates the test case to
+            // make it easier to see which configuration it runs under.
+            name += ":" + spawnedTestClass.getSimpleName();
+        }
+        return name;
+    }
     
     /**
      * Only run a test if the driver will be auto-loaded.
@@ -178,6 +205,58 @@ public class AutoloadTest extends BaseJD
         return suite;
     }
 
+    /**
+     * <p>
+     * Generate the full suite of autoload tests. Each test will be started
+     * in its own JVM so that we know that the driver hasn't been loaded
+     * accidentally by another test.
+     * </p>
+     *
+     * <p>
+     * The test suite runs {@code AutoloadTest} in the following
+     * configurations:
+     * </p>
+     *
+     * <ul>
+     * <li>No jdbc.drivers property</li>
+     * <li>jdbc.drivers property specifying embedded driver</li>
+     * <li>jdbc.drivers property specifying client driver</li>
+     * <li>jdbc.drivers property specifying both drivers</li>
+     * </ul>
+     */
+    static Test fullAutoloadSuite() {
+        TestSuite suite = new TestSuite("AutoloadTest:All");
+        suite.addTest(new AutoloadTest(AutoloadTest.class));
+        suite.addTest(new AutoloadTest(JDBCDriversEmbeddedTest.class));
+        suite.addTest(new AutoloadTest(JDBCDriversClientTest.class));
+        suite.addTest(new AutoloadTest(JDBCDriversAllTest.class));
+
+        // The forked test processes will access the default test database, so
+        // stop the engine in the main test process to prevent attempts to
+        // double-boot the database.
+        return new TestSetup(suite) {
+            protected void setUp() {
+                TestConfiguration.getCurrent().shutdownEngine();
+            }
+        };
+    }
+
+    /**
+     * Run {@code AutoloadTest} in a separate JVM.
+     */
+    public void spawnProcess() throws Exception {
+        String[] cmd = {
+            "junit.textui.TestRunner", spawnedTestClass.getName()
+        };
+
+        SpawnedProcess proc =
+            new SpawnedProcess(execJavaCmd(cmd), spawnedTestClass.getName());
+
+        if (proc.complete() != 0) {
+            fail(proc.getFailMessage("Test process failed"));
+        }
+    }
+
 	// ///////////////////////////////////////////////////////////
 	//
 	// TEST ENTRY POINTS

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java?rev=1303693&r1=1303692&r2=1303693&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
Thu Mar 22 09:11:03 2012
@@ -168,6 +168,9 @@ public class _Suite extends BaseTestCase
             // XA and ConnectionPool Datasource are not available with
             // JSR169 so can't run InternationalConnectTest. 
             suite.addTest(InternationalConnectTest.suite());
+
+            // Test requires java.sql.DriverManager
+            suite.addTest(AutoloadTest.fullAutoloadSuite());
         }
 
         return suite;



Mime
View raw message