db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r396638 - in /db/derby/code/trunk: ./ java/testing/org/apache/derbyTesting/functionTests/suites/ java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ java/testing/org/apache/derbyTesting/functionTests/util/
Date Mon, 24 Apr 2006 18:36:02 GMT
Author: rhillegas
Date: Mon Apr 24 11:36:00 2006
New Revision: 396638

URL: http://svn.apache.org/viewcvs?rev=396638&view=rev
Log:
DERBY-930: Enable autoloading of client drivers now that build 81 of jdk1.6 fixes a problem
with autoloading under the SecurityManager.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
  (with props)
Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/build.xml?rev=396638&r1=396637&r2=396638&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Mon Apr 24 11:36:00 2006
@@ -889,12 +889,13 @@
           append="true"
           message="org/apache/derby/info/DBMS.properties"/>
 
-    <!-- copy license file to lists dir for inclusion in derby.jar -->
+    <!-- copy boilerplate common to derby jar files -->
+    <antcall target="meta-inf-common"/>
 
-    <mkdir dir="${derby.jar.dir}/lists/META-INF"/>
-    <copy todir="${derby.jar.dir}/lists/META-INF">
-      <fileset dir="${basedir}" includes="LICENSE*,NOTICE*,COPYRIGHT*"/>
-    </copy>
+    <!-- declare the embedded driver for autoloading by the JDBC 4 DriverManager -->
+    <antcall target="declare-autoloadable-driver">
+      <param name="driver.name" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+    </antcall>
 
     <!-- the next two targets are orthogonal. Only one will be executed, -->
     <!-- depending on whether or not osgi.jar is available.              -->
@@ -1063,12 +1064,8 @@
       <param name="info.file" value="${out.dir}/org/apache/derby/info/tools.properties"/>
     </antcall>
 
-    <!-- copy license file to lists dir for inclusion in derbytools.jar -->
-
-    <mkdir dir="${derby.jar.dir}/lists/META-INF"/>
-    <copy todir="${derby.jar.dir}/lists/META-INF">
-      <fileset dir="${basedir}" includes="LICENSE*,NOTICE*,COPYRIGHT*"/>
-    </copy>
+    <!-- copy boilerplate common to derby jar files -->
+    <antcall target="meta-inf-common"/>
 
     <delete file="${derby.jar.dir}/derbytools.jar"/>
     <jar destfile="${derby.jar.dir}/derbytools.jar"
@@ -1115,13 +1112,9 @@
       <param name="info.file" value="${out.dir}/org/apache/derby/info/net.properties"/>
     </antcall>
 
-    <!-- copy license file to lists dir for inclusion in derbynet.jar -->
+    <!-- copy boilerplate common to derby jar files -->
+    <antcall target="meta-inf-common"/>
 
-    <mkdir dir="${derby.jar.dir}/lists/META-INF"/>
-    <copy todir="${derby.jar.dir}/lists/META-INF">
-      <fileset dir="${basedir}" includes="LICENSE*,NOTICE*,COPYRIGHT*"/>
-    </copy>
-  	
     <manifest file="${derby.jar.dir}/lists/smfnet.mf">
       <attribute name="Main-Class" value="org.apache.derby.drda.NetworkServerControl"/>
       <attribute name="Class-Path" value="derby.jar"/>
@@ -1174,13 +1167,14 @@
       <param name="info.file" value="${out.dir}/org/apache/derby/info/dnc.properties"/>
     </antcall>
 
-    <!-- copy license file to lists dir for inclusion in derbyclient.jar -->
+    <!-- copy boilerplate common to derby jar files -->
+    <antcall target="meta-inf-common"/>
+
+    <!-- declare the client driver for autoloading by the JDBC 4 DriverManager -->
+    <antcall target="declare-autoloadable-driver">
+      <param name="driver.name" value="org.apache.derby.jdbc.ClientDriver"/>
+    </antcall>
 
-    <mkdir dir="${derby.jar.dir}/lists/META-INF"/>
-    <copy todir="${derby.jar.dir}/lists/META-INF">
-      <fileset dir="${basedir}" includes="LICENSE*,NOTICE*,COPYRIGHT*"/>
-    </copy>
- 	
     <manifest file="${derby.jar.dir}/lists/smfclient.mf">
       	<attribute name="Sealed" value="true"/>
     	<section name="org/apache/derby/jdbc/">
@@ -1254,12 +1248,8 @@
 
   <target name="derbylocalejars" depends="initjars">
  
-    <!-- copy license file to lists dir for inclusion in derbynet.jar -->
-
-    <mkdir dir="${derby.jar.dir}/lists/META-INF"/>
-    <copy todir="${derby.jar.dir}/lists/META-INF">
-      <fileset dir="${basedir}" includes="LICENSE*,NOTICE*,COPYRIGHT*"/>
-    </copy>
+    <!-- copy boilerplate common to derby jar files -->
+    <antcall target="meta-inf-common"/>
 
     <!-- call localejar for each locale -->
 
@@ -1376,6 +1366,36 @@
   <target name="cleanjars" depends="setsanityname">
     <delete dir="${basedir}/jars/${sanity.name}"/>
   </target>
+
+<!-- - - - - - - - - - - - - - targets for populating META-INF  - - - - - - - - - - -
-->
+
+  <!-- copy boilerplate common to derby jar files -->
+
+  <target name="meta-inf-common">
+ 
+    <mkdir dir="${derby.jar.dir}/lists/META-INF"/>
+    <copy todir="${derby.jar.dir}/lists/META-INF">
+      <fileset dir="${basedir}" includes="LICENSE*,NOTICE*,COPYRIGHT*"/>
+    </copy>
+
+  </target>
+
+  <!--
+    Declare the jdbc driver for autoloading under JDBC 4.
+
+    Parameters:
+
+      driver.name   Class name of driver to be autoloaded by JDBC 4 DriverManager
+  -->
+
+  <target name="declare-autoloadable-driver">
+ 
+    <mkdir dir="${derby.jar.dir}/lists/META-INF/services"/>
+    <echo file="${derby.jar.dir}/lists/META-INF/services/java.sql.Driver">${driver.name}
+</echo>
+
+  </target>
+
 
 <!-- =================================================================== -->
 <!--                         Nightly build targets                       -->

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall?rev=396638&r1=396637&r2=396638&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
Mon Apr 24 11:36:00 2006
@@ -11,4 +11,5 @@
 jdbc4/DataSourceTest.junit
 jdbc4/ResultSetMetaDataTest.junit
 jdbc4/EmbeddedBrokeredConnectionWrapperTest.junit
-jdbc4/ParameterMetaDataWrapperTest.junit
\ No newline at end of file
+jdbc4/ParameterMetaDataWrapperTest.junit
+jdbc4/AutoloadTest.junit

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java?rev=396638&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
Mon Apr 24 11:36:00 2006
@@ -0,0 +1,214 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.AutoloadTest
+
+   Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+
+   Licensed 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.
+
+ */
+/**
+ * <p>
+ * This JUnit test verifies the autoloading of the jdbc driver under JDBC4.
+ * This test must be run in its own VM because we want to verify that the
+ * driver was not accidentally loaded by some other test.
+ * </p>
+ *
+ * @author Rick
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbc4;
+
+import java.sql.*;
+import java.util.*;
+import junit.framework.*;
+
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
+
+public	class	AutoloadTest	extends	BaseJDBCTestCase
+{
+	/////////////////////////////////////////////////////////////
+	//
+	//	CONSTANTS
+	//
+	/////////////////////////////////////////////////////////////
+
+	/////////////////////////////////////////////////////////////
+	//
+	//	STATE
+	//
+	/////////////////////////////////////////////////////////////
+
+	private	static	final	String	NONEXISTENT_DATABASE = "nonexistentDatabase";
+	private	static	final	String	DRIVER_LIST = "jdbc.drivers";
+	
+	/////////////////////////////////////////////////////////////
+	//
+	//	CONSTRUCTOR
+	//
+	/////////////////////////////////////////////////////////////
+	
+	public	AutoloadTest( String name ) { super( name ); }
+
+	/////////////////////////////////////////////////////////////
+	//
+	//	ENTRY POINT
+	//
+	/////////////////////////////////////////////////////////////
+
+	/////////////////////////////////////////////////////////////
+	//
+	//	JUnit BEHAVIOR
+	//
+	/////////////////////////////////////////////////////////////
+
+	/////////////////////////////////////////////////////////////
+	//
+	//	TEST ENTRY POINTS
+	//
+	/////////////////////////////////////////////////////////////
+
+	/**
+	 * <p>
+	 * Tests the autoloading of the client driver by JDBC 4. This behavior
+	 * is described in section 10.2.1 of the JDBC 4 spec. The driver is
+	 * autoloaded if we are running under jdk1.6 or later and one of the
+	 * following is true:
+	 * </p>
+	 *
+	 * <ul>
+	 * <li>Classes are being loaded out of the Derby jar files.</li>
+	 * <li>OR the system property jdbc.drivers names the drivers.</li>
+	 * </ul>
+	 */
+	public	void	testAutoloading()
+		throws Exception
+	{
+		//CONFIG.setVerbosity( true );
+		
+		//
+		// We expect that the connection to the database will fail for
+		// one reason or another.
+		//
+		if ( autoloading() )
+		{
+			println( "We ARE autoloading..." );
+
+			//
+			// The DriverManager should have autoloaded the client driver.
+			// This means that the connection request is passed on to the
+			// server. The server then determines that the database does
+			// not exist. This raises a different error depending on whether
+			// we're running embedded or with the Derby client.
+			//
+			if ( usingEmbedded() ) { failToConnect( "XJ004" ); }
+			else { failToConnect( "08004" ); }
+		}
+		else
+		{
+			println( "We are NOT autoloading..." );
+
+			//
+			// We aren't autoloading the driver. The
+			// DriverManager returns the following SQLState.
+			//
+			failToConnect( "08001" );
+		}
+	}
+
+	/**
+	 * <p>
+	 * Verify that we fail to connect to the database for the expected
+	 * reason.
+	 * </p>
+	 */
+	private	void	failToConnect( String expectedSQLState )
+		throws Exception
+	{
+		String			connectionURL = CONFIG.getJDBCUrl( NONEXISTENT_DATABASE );
+		Properties		properties = new Properties();
+		SQLException 	se = null;
+
+		properties.put( "user", CONFIG.getUserName() );
+		properties.put( "password", CONFIG.getUserPassword() );
+
+		try {
+			println( "Attempting to connect with this URL: '" + connectionURL + "'" );
+			
+			DriverManager.getConnection( connectionURL, properties );
+		}
+		catch ( SQLException e ) { se = e; }
+
+		println( "Caught expected SQLException: " + se );
+		
+		assertSQLState( expectedSQLState, expectedSQLState, se );
+	}
+
+	/**
+	 * <p>
+	 * Return true if we expect that the DriverManager will autoload the client driver.
+	 * </p>
+	 */
+	private	boolean	autoloading()
+		throws Exception
+	{
+		//
+		// DriverManager autoloads the client only as of JDBC4.
+		//
+		if ( !CONFIG.supportsJDBC4() )
+		{
+			println( "NOT JDBC4..." );
+			return false;
+		}
+
+		//
+		// The DriverManager will autoload drivers specified by the jdbc.drivers
+		// property. 
+		//
+		if ( CONFIG.getSystemStartupProperty( DRIVER_LIST ) != null )
+		{
+			println( "Drivers list encoded in startup properties..." );
+			return true;
+		}
+
+		//
+		// The DriverManager will also look inside our jar files for
+		// the generated file META-INF/services/java.sql.Driver. This file
+		// will contain the name of the driver to load. So if we are running
+		// this test against Derby jar files, we expect that the driver will
+		// be autoloaded.
+		//
+		// Note that if we run with a security manager, we get permissions
+		// exception at startup when the driver is autoloaded. This exception
+		// is silently swallowed and the result is that the driver is not
+		// loaded even though we expect it to be.
+		//
+		if ( CONFIG.loadingFromJars() )
+		{
+			println( "Loading from jars..." );
+			return true;
+		}
+
+		//
+		// OK, we've run out of options. We do not expect that the driver
+		// will be autoloaded.
+		//
+
+		println( "None of the above. Not autoloading..." );
+		
+		return false;
+	}
+
+}
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java?rev=396638&r1=396637&r2=396638&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
Mon Apr 24 11:36:00 2006
@@ -20,8 +20,8 @@
 package org.apache.derbyTesting.functionTests.util;
 
 import java.sql.*;
-import javax.sql.DataSource;
 import java.util.Properties;
+import javax.sql.DataSource;
 import javax.sql.ConnectionPoolDataSource;
 import javax.sql.XADataSource;
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java?rev=396638&r1=396637&r2=396638&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
Mon Apr 24 11:36:00 2006
@@ -19,10 +19,11 @@
  */
 package org.apache.derbyTesting.functionTests.util;
 
-import java.security.AccessController;
-import java.security.PrivilegedAction;
+import java.security.*;
 import java.util.Properties;
 
+import org.apache.derby.iapi.services.info.JVMInfo;
+
 /**
  * Class which holds information about the configuration of a Test.
  */
@@ -41,6 +42,7 @@
      */
     private TestConfiguration(Properties props) 
         throws NumberFormatException {
+		systemStartupProperties = props;
         dbName = props.getProperty(KEY_DBNAME, DEFAULT_DBNAME);
         userName = props.getProperty(KEY_USER_NAME, DEFAULT_USER_NAME);
         userPassword = props.getProperty(KEY_USER_PASSWORD, 
@@ -73,6 +75,14 @@
     }
 
     /**
+     * Get the given system property as specified at startup.
+     */
+	public	String	getSystemStartupProperty( String key )
+	{
+		return systemStartupProperties.getProperty( key );
+	}
+
+    /**
      * Get the system properties in a privileged block.
      *
      * @return the system properties.
@@ -176,6 +186,11 @@
     }
     
     /**
+     * Set the verbosity, i.e., whether debug statements print.
+     */
+    public void	setVerbosity( boolean isChatty )	{ isVerbose = isChatty; }
+    
+    /**
      * Return verbose flag.
      *
      * @return verbose flag.
@@ -184,9 +199,39 @@
         return isVerbose;
     }
     
+ 	/**
+ 	 * <p>
+	 * Return true if the client supports JDBC4, i.e., if the VM level is at
+	 * least 1.6.
+	 * </p>
+	 */
+	public	boolean	supportsJDBC4()
+	{
+		if ( JVMInfo.JDK_ID >= JVMInfo.J2SE_16 ) { return true; }
+		else { return false; }
+	}
+
+	/**
+	 * <p>
+	 * Return true if we classes are being loaded from jar files. For the time
+	 * being, this simply tests that the JVMInfo class (common to the client and
+	 * the server) comes out of a jar file.
+	 * </p>
+	 */
+	public	boolean	loadingFromJars()
+	{
+		//
+		// jvm.java sets this property to the build jar directory
+		// if we are using derbyTesting.jar.
+		//
+		
+		return ( !UNUSED.equals( getSystemStartupProperty( "derbyTesting.codejar" ) ) );
+	}
+
     /**
      * Immutable data members in test configuration
      */
+	private	final Properties systemStartupProperties;
     private final String dbName;
     private final String url;
     private final String userName; 
@@ -194,7 +239,7 @@
     private final int port;
     private final String hostName;
     private final JDBCClient jdbcClient;
-    private final boolean isVerbose;
+    private boolean isVerbose;
     
     /**
      * Default values for configurations
@@ -216,5 +261,10 @@
     private final static String KEY_HOSTNAME = "hostName";
     private final static String KEY_PORT = "port";
     private final static String KEY_VERBOSE = "derby.tests.debug";
+
+    /**
+     * Possible values of system properties.
+     */
+    private final static String UNUSED = "file://unused/";
 
 }



Mime
View raw message