Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 73741 invoked from network); 7 Jun 2007 22:13:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Jun 2007 22:13:51 -0000 Received: (qmail 59099 invoked by uid 500); 7 Jun 2007 22:13:54 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 59074 invoked by uid 500); 7 Jun 2007 22:13:54 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 59060 invoked by uid 99); 7 Jun 2007 22:13:54 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2007 15:13:54 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2007 15:13:50 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id EAAE01A981A; Thu, 7 Jun 2007 15:13:29 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r545332 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java Date: Thu, 07 Jun 2007 22:13:29 -0000 To: derby-commits@db.apache.org From: djd@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070607221329.EAAE01A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: djd Date: Thu Jun 7 15:13:25 2007 New Revision: 545332 URL: http://svn.apache.org/viewvc?view=rev&rev=545332 Log: DERBY-1952 Add a check to the AutoloadTest that indicates in a somewhat non-internal way that Derby's embedded engine was actually booted in not. Will replace the use of internal apis and checking for a NPE in the jdbc4 version of the test. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.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?view=diff&rev=545332&r1=545331&r2=545332 ============================================================================== --- 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 Jun 7 15:13:25 2007 @@ -24,6 +24,7 @@ import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; +import java.util.Enumeration; import junit.framework.Test; import junit.framework.TestSuite; @@ -33,6 +34,7 @@ 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.TestConfiguration; /** @@ -59,42 +61,54 @@ boolean embeddedAutoLoad = false; boolean clientAutoLoad = false; + boolean jdbc4Autoload = false; if (JDBC.vmSupportsJDBC4() && TestConfiguration.loadingFromJars()) { - // test client & embedded - embeddedAutoLoad = true; - clientAutoLoad = true; - } - else - { - // Simple test to see if the driver class is - // in the value. Could get fancy and see if it is - // correctly formatted but not worth it. - - try { - String jdbcDrivers = getSystemProperty("jdbc.drivers"); - if (jdbcDrivers == null) - jdbcDrivers = ""; - - embeddedAutoLoad = jdbcDrivers - .indexOf("org.apache.derby.jdbc.EmbeddedDriver") != -1; - - clientAutoLoad = jdbcDrivers - .indexOf("org.apache.derby.jdbc.ClientDriver") != -1; - - } catch (SecurityException se) { - // assume there is no autoloading if - // we can't read the value of jdbc.drivers. - } + // test client & embedded,but the JDBC 4 auto boot is not + // a full boot of the engine. Thus while there is no + // need to explicitly load the driver, the embedded engine + // does not start up. Unlike when the embedded driver is + // put in jdbc.drivers. + + jdbc4Autoload = true; } + + + // Simple test to see if the driver class is + // in the value. Could get fancy and see if it is + // correctly formatted but not worth it. + + try { + String jdbcDrivers = getSystemProperty("jdbc.drivers"); + if (jdbcDrivers == null) + jdbcDrivers = ""; + + embeddedAutoLoad = jdbcDrivers + .indexOf("org.apache.derby.jdbc.EmbeddedDriver") != -1; + + clientAutoLoad = jdbcDrivers + .indexOf("org.apache.derby.jdbc.ClientDriver") != -1; + + } catch (SecurityException se) { + // assume there is no autoloading if + // we can't read the value of jdbc.drivers. + } + - if (embeddedAutoLoad || clientAutoLoad) + if (jdbc4Autoload || embeddedAutoLoad || clientAutoLoad) { TestSuite suite = new TestSuite("AutoloadTest"); - if (embeddedAutoLoad) + + if (jdbc4Autoload && !embeddedAutoLoad) + { + suite.addTest(SecurityManagerSetup.noSecurityManager( + new AutoloadTest("testEmbeddedNotStarted"))); + } + + if (jdbc4Autoload || embeddedAutoLoad) suite.addTest(baseAutoLoadSuite("embedded")); - if (clientAutoLoad) + if (jdbc4Autoload || clientAutoLoad) suite.addTest( TestConfiguration.clientServerDecorator( baseAutoLoadSuite("client"))); @@ -106,6 +120,7 @@ // not loaded implicitly by some other means. TestSuite suite = new TestSuite("AutoloadTest: no autoloading expected"); + suite.addTest(new AutoloadTest("testEmbeddedNotStarted")); suite.addTest(new AutoloadTest("noloadTestNodriverLoaded")); suite.addTest(TestConfiguration.clientServerDecorator( new AutoloadTest("noloadTestNodriverLoaded"))); @@ -129,8 +144,14 @@ suite.addTest(new AutoloadTest("testAutoNetworkServerBoot")); } - + suite.addTest(new AutoloadTest("testSuccessfulConnect")); + + if ("embedded".equals(which)) { + suite.addTest(SecurityManagerSetup.noSecurityManager( + new AutoloadTest("testEmbeddedStarted"))); + } + suite.addTest(new AutoloadTest("testUnsuccessfulConnect")); suite.addTest(new AutoloadTest("testExplicitLoad")); return suite; @@ -150,7 +171,7 @@ { String protocol = getTestConfiguration().getJDBCClient().getUrlBase(); - + Driver driver = DriverManager.getDriver(protocol); assertNotNull("Expected registered driver", driver); } @@ -272,6 +293,60 @@ { String jdbcDrivers = getSystemProperty("jdbc.drivers"); return jdbcDrivers.indexOf("org.apache.derby.jdbc.EmbeddedDriver") != -1; + } + + /** + * Test indirect artifiacts through public apis that + * the embedded engine has not been started. + */ + + public void testEmbeddedNotStarted() + { + assertFalse(hasDerbyThreadGroup()); + } + + /** + * Check the test(s) we use to determine if the embedded driver + * is not up indicate the opposite once the driver has been + * fully booted. + * + */ + public void testEmbeddedStarted() + { + assertTrue(hasDerbyThreadGroup()); + } + + /** + * Return true if a ThreadGroup exists that has a name + * starting with derby. + * @return + */ + private boolean hasDerbyThreadGroup() { + ThreadGroup tg = Thread.currentThread().getThreadGroup(); + + while (tg.getParent() != null) + { + tg = tg.getParent(); + } + + // estimate of groups + ThreadGroup[] allGroups = new ThreadGroup[tg.activeGroupCount()]; + int actual; + for (;;) + { + actual = tg.enumerate(allGroups, true); + if (actual < allGroups.length) + break; + // just double the size + allGroups = new ThreadGroup[allGroups.length * 2]; + } + + for (int i = 0; i < actual; i++) + { + if (allGroups[i].getName().startsWith("derby.")) + return true; + } + return false; } }