Author: kahatlen
Date: Wed Feb 6 12:49:38 2013
New Revision: 1442937
URL: http://svn.apache.org/viewvc?rev=1442937&view=rev
Log:
DERBY-4480: "No suitable driver found" when attempting to connect while other thread is auto-loading
the driver
Add test case to verify that it does not affect Java 7 and newer.
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrentAutoloadTest.java
(with props)
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?rev=1442937&r1=1442936&r2=1442937&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
Wed Feb 6 12:49:38 2013
@@ -230,6 +230,7 @@ public class AutoloadTest extends BaseJD
suite.addTest(new AutoloadTest(JDBCDriversEmbeddedTest.class));
suite.addTest(new AutoloadTest(JDBCDriversClientTest.class));
suite.addTest(new AutoloadTest(JDBCDriversAllTest.class));
+ suite.addTest(new AutoloadTest(ConcurrentAutoloadTest.class));
// The forked test processes will access the default test database, so
// stop the engine in the main test process to prevent attempts to
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrentAutoloadTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrentAutoloadTest.java?rev=1442937&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrentAutoloadTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrentAutoloadTest.java
Wed Feb 6 12:49:38 2013
@@ -0,0 +1,95 @@
+/*
+
+Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.ConcurrentAutoloadTest
+
+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.jdbcapi;
+
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Test that autoloading works correctly also in the case where it's invoked
+ * from two threads at the same time. This test case must run in a separate
+ * JVM to make sure the driver hasn't already been loaded.
+ */
+public class ConcurrentAutoloadTest extends BaseJDBCTestCase {
+ public ConcurrentAutoloadTest(String name) {
+ super(name);
+ }
+
+ public void testConcurrentAutoloading() throws Exception {
+
+ if (!TestConfiguration.loadingFromJars()) {
+ // Autoloading only happens when running from jars.
+ return;
+ }
+
+ if (!JDBC.vmSupportsJDBC41()) {
+ // Only run this test case on JDBC 4.1 (Java 7) and newer. Although
+ // autoloading is supposed to work on JDBC 4.0 (Java 6) too, there
+ // is a bug on Java 6 that causes problems when autoloading happens
+ // in multiple threads at once. See DERBY-4480.
+ return;
+ }
+
+ TestConfiguration tc = getTestConfiguration();
+ final String url = tc.getJDBCUrl() + ";create=true";
+ final String user = tc.getUserName();
+ final String pw = tc.getUserPassword();
+
+ final List errors = Collections.synchronizedList(new ArrayList());
+
+ Runnable r = new Runnable() {
+ public void run() {
+ try {
+ DriverManager.getConnection(url, user, pw);
+ } catch (Throwable t) {
+ errors.add(t);
+ }
+ }
+ };
+
+ Thread t1 = new Thread(r);
+ Thread t2 = new Thread(r);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ if (!errors.isEmpty()) {
+ if (errors.size() > 1) {
+ // Since we can only link one exception to the assert failure,
+ // print all stack traces if we have multiple errors.
+ for (int i = 0; i < errors.size(); i++) {
+ printStackTrace((Throwable) errors.get(i));
+ }
+ }
+ fail("Thread failed", (Throwable) errors.get(0));
+ }
+ }
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrentAutoloadTest.java
------------------------------------------------------------------------------
svn:eol-style = native
|