You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2012/06/28 13:58:19 UTC

svn commit: r1354960 [1/3] - in /db/derby/code/trunk/java/testing: ./ org/apache/derbyTesting/functionTests/tests/compatibility/ org/apache/derbyTesting/functionTests/tests/compatibility/helpers/ org/apache/derbyTesting/junit/

Author: kristwaa
Date: Thu Jun 28 11:58:16 2012
New Revision: 1354960

URL: http://svn.apache.org/viewvc?rev=1354960&view=rev
Log:
DERBY-2076: Rewrite junitTests/derbyNet/CompatibilityTest to conform to current JUnit usage

Initial check-in of the modernized compatibilty test.
Most of the supporting code is new, the tests themselves are copied from the
old-style test (with modifications).
See package.html for an intro, and note the usage of ReleaseRepository.
If you are already specifying derbyTesting.oldReleasePath no action is needed,
otherwise you must create the release repository (check out the release jar
repos) at the default location $HOME/.derbyTestingReleases.
Main entry point is the _Suite class (run with JUnit).

Note that both the server being tested and the clients tested are run in
separate JVM processes.
VersionedNetworkServerTestSetup controls the server process.
ClientCompatibiltyRunControl control the client process.
VersionCombinationConfigurator generates the version combinations according to
the requested configuration.
ClientCompatibiltySuite defines the suite of tests being run for each client.

Patch file: derby-2076-1b-initial.diff

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/AbstractCompatibilityTest.java
      - copied, changed from r1354909, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilitySuite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilitySuite.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/JDBCDriverTest.java
      - copied, changed from r1354909, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/VersionCombinationConfigurator.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/VersionCombinationConfigurator.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/VersionedNetworkServerTestSetup.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/_Suite.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/_SuiteDevFull.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/_SuiteOld.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/_SuiteOldFull.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/build.xml   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/helpers/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/helpers/DummyBlob.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/helpers/DummyClob.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/package.html   (with props)
Modified:
    db/derby/code/trunk/java/testing/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/build.xml?rev=1354960&r1=1354959&r2=1354960&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/build.xml (original)
+++ db/derby/code/trunk/java/testing/build.xml Thu Jun 28 11:58:16 2012
@@ -62,6 +62,7 @@
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/util"/> 
     <ant dir="${derby.testing.src.dir}/${derby.testing.unittest.dir}"/> 
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/multi/stress"/>
+    <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/compatibility"/>
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/junitTests/compatibility"/> 
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/junitTests/derbyNet"/>
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/jdbcapi"/> 

Copied: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/AbstractCompatibilityTest.java (from r1354909, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilitySuite.java)
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/AbstractCompatibilityTest.java?p2=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/AbstractCompatibilityTest.java&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilitySuite.java&r1=1354909&r2=1354960&rev=1354960&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilitySuite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/AbstractCompatibilityTest.java Thu Jun 28 11:58:16 2012
@@ -1,6 +1,6 @@
 /*
 
-   Derby - Class org.apache.derbyTesting.functionTests.tests.compatibility.CompatibilitySuite
+   Derby - Class org.apache.derbyTesting.functionTests.tests.compatibility.AbstractCompatibilityTest
 
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -18,163 +18,97 @@
    limitations under the License.
 
  */
+package org.apache.derbyTesting.functionTests.tests.compatibility;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.DerbyVersion;
+import org.apache.derbyTesting.junit.Version;
+
 /**
- * <p>
- * This is the JUnit suite verifying compatibility of Derby clients and
- * servers across Derby version levels and supported VMs. When you want
- * to add a new class of tests to this suite, just add the classname to
- * the accumulator in suite().
- * </p>
- *
+ * Abstract test case with common functionality often required when writing
+ * JDBC client driver compatibility tests.
  */
+abstract class AbstractCompatibilityTest
+        extends BaseJDBCTestCase
+{
+    /////////////////////////////////////////////////////////////
+    //
+    //    CONSTANTS
+    //
+    /////////////////////////////////////////////////////////////
+
+    public static final String SERVER_VERSION_FUNCTION = "getVMVersion";
+
+    private static final String VERSION_PROPERTY = "java.version";
+
+    /////////////////////////////////////////////////////////////
+    //
+    //    STATE
+    //
+    /////////////////////////////////////////////////////////////
+
+    private static Version _clientVMLevel;        // level of client-side vm
+    private static Version _serverVMLevel;        // level of server vm
+    private static DerbyVersion _driverLevel;     // client rev level
 
-package org.apache.derbyTesting.functionTests.tests.junitTests.compatibility;
+    public AbstractCompatibilityTest(String name) {
+        super(name);
+    }
 
-import java.sql.*;
-import java.util.*;
+    /////////////////////////////////////////////////////////////
+    //
+    //    PUBLIC BEHAVIOR
+    //
+    /////////////////////////////////////////////////////////////
 
-import junit.framework.*;
+    public DerbyVersion getServerVersion() throws SQLException {
+        return getServerVersion(getConnection());
+    }
 
-import org.apache.derbyTesting.functionTests.util.DerbyJUnitTest;
+    /**
+     * <p>
+     * Get the version of the server.
+     * </p>
+     */
+    protected static DerbyVersion getServerVersion(Connection con)
+            throws SQLException {
+        return DerbyVersion.parseVersionString(
+                con.getMetaData().getDatabaseProductVersion());
+    }
 
-public	class	CompatibilitySuite	extends	DerbyJUnitTest
-{
-	/////////////////////////////////////////////////////////////
-	//
-	//	CONSTANTS
-	//
-	/////////////////////////////////////////////////////////////
-
-	// Supported versions of Derby.
-	public	static	final	Version	DRB_10_0 = new Version( 10, 0 );
-	public	static	final	Version	DRB_10_1 = new Version( 10, 1 );
-	public	static	final	Version	DRB_10_2 = new Version( 10, 2 );
-	public	static	final	Version	DRB_10_3 = new Version( 10, 3 );
-	public	static	final	Version	DRB_10_4 = new Version( 10, 4 );
-	public	static	final	Version	DRB_10_5 = new Version( 10, 5 );
-	public	static	final	Version	DRB_10_6 = new Version( 10, 6 );
-	public	static	final	Version	DRB_10_7 = new Version( 10, 7 );
-
-	public	static	final	String	SERVER_VERSION_FUNCTION = "getVMVersion";
-	
-	private	static	final			String	VERSION_PROPERTY = "java.version";
-
-	private	static	final			int		EXPECTED_CLIENT_COUNT = 1;
-
-	/////////////////////////////////////////////////////////////
-	//
-	//	STATE
-	//
-	/////////////////////////////////////////////////////////////
-
-	private	static	Driver		_driver;				// the corresponding jdbc driver
-	private	static	Version		_clientVMLevel;			// level of client-side vm
-	private	static	Version		_serverVMLevel;			// level of server vm
-	private	static	Version		_driverLevel;			// client rev level
-	private	static	Version		_serverLevel;			// server rev level
-
-	/////////////////////////////////////////////////////////////
-	//
-	//	JUnit BEHAVIOR
-	//
-	/////////////////////////////////////////////////////////////
-
-	/**
-	 * <p>
-	 * JUnit boilerplate which adds as test cases all public methods
-	 * whose names start with the string "test" in the named classes.
-	 * When you want to add a new class of tests, just wire it into
-	 * this suite.
-	 * </p>
-	 */
-	public static Test suite()
-	{
-		TestSuite	testSuite = new TestSuite();
-
-		testSuite.addTestSuite( JDBCDriverTest.class );
-
-		return testSuite;
-	}
-
-
-	/////////////////////////////////////////////////////////////
-	//
-	//	ENTRY POINT
-	//
-	/////////////////////////////////////////////////////////////
-
-	/**
-	 * <p>
-	 * Run JDBC compatibility tests using either the specified client or
-	 * the client that is visible
-	 * on the classpath. If there is more than one client on the classpath,
-	 * exits with an error.
-	 * </p>
-	 *
-	 * <ul>
-	 * <li>arg[ 0 ] = required name of database to connect to</li>
-	 * <li>arg[ 1 ] = optional driver to use. if not specified, we'll look for a
-	 *                client on the classpath</li>
-	 * </ul>
-	 */
-	public static void main( String args[] )
-		throws Exception
-	{
-		int			exitStatus = FAILURE_EXIT;
-		
-		if (
-			   parseDebug() &&
-			   parseArgs( args ) &&
-			   parseVMLevel() &&
-			   findClient() &&
-			   findServer()
-		   )
-		{		
-			Test t = suite(); 
-			println("CompatibilitySuite.main() will run suite with  " 
-				+ t.countTestCases() + " testcases.");
-
-			TestResult	result = junit.textui.TestRunner.run( t );
-			
-			exitStatus = result.errorCount() + result.failureCount();
-		}
-
-		Runtime.getRuntime().exit( exitStatus );
-	}
-
-	/////////////////////////////////////////////////////////////
-	//
-	//	PUBLIC BEHAVIOR
-	//
-	/////////////////////////////////////////////////////////////
-	
-	/**
-	 * <p>
-	 * Get the version of the server.
-	 * </p>
-	 */
-	public	Version	getServerVersion() { return _serverLevel; }
-
-	/**
-	 * <p>
-	 * Get the version of the client.
-	 * </p>
-	 */
-	public	Version	getDriverVersion() { return _driverLevel; }
-
-	/**
-	 * <p>
-	 * Get the vm level of the server.
-	 * </p>
-	 */
-	public	static	Version	getServerVMVersion()	{ return _serverVMLevel; }
-
-	/**
-	 * <p>
-	 * Get the vm level of the client.
-	 * </p>
-	 */
-	public	Version	getClientVMVersion() { return _clientVMLevel; }
+    /**
+     * <p>
+     * Get the version of the client.
+     * </p>
+     */
+    public DerbyVersion getDriverVersion()
+            throws SQLException {
+        if (_driverLevel == null) {
+            _driverLevel = DerbyVersion.parseVersionString(
+                    getConnection().getMetaData().getDriverVersion());
+        }
+        return _driverLevel;
+    }
+
+    /**
+     * <p>
+     * Get the vm level of the server.
+     * </p>
+     */
+    public    static    Version    getServerVMVersion()    { return _serverVMLevel; }
+
+    /**
+     * <p>
+     * Get the vm level of the client.
+     * </p>
+     */
+    public    Version    getClientVMVersion() { return _clientVMLevel; }
 
     /**
      * <p>
@@ -182,351 +116,329 @@ public	class	CompatibilitySuite	extends	
      * </p>
      */
     public boolean serverSupportsUDTs()
+            throws SQLException {
+        return serverSupportsUDTs(getConnection());
+    }
+
+    public static boolean serverSupportsUDTs(Connection con)
+            throws SQLException {
+        return getServerVersion(con).atLeast( DerbyVersion._10_6 );
+    }
+
+    /////////////////////////////////////////////////////////////
+    //
+    //    DATABASE-SIDE FUNCTIONS
+    //
+    /////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Get the vm level of the server.
+     * </p>
+     */
+    public    static    String    getVMVersion()
+    {
+        return System.getProperty( VERSION_PROPERTY );
+    }
+
+    // POTENTIALLY TEMPORARY METHODS - CLEANUP LATER
+
+    /**
+     * <p>
+     * Assert two objects are equal, allowing nulls to be equal.
+     * </p>
+     */
+    public    void    compareObjects( String message, Object left, Object right )
+            throws SQLException
+    {
+        message = message + "\n\t expected = " + left + "\n\t actual = " + right;
+
+        if ( left == null )
+        {
+            assertNull( message, right );
+        }
+        else
+        {
+            assertNotNull( message, right );
+
+            if ( left instanceof byte[] ) { compareBytes( message, left, right ); }
+            else if ( left instanceof java.util.Date ) { compareDates( message, left, right ); }
+            else { assertTrue( message, left.equals( right ) ); }
+        }
+    }
+
+    /**
+     * <p>
+     * Assert two byte arrays are equal, allowing nulls to be equal.
+     * </p>
+     */
+    public    void    compareBytes( String message, Object left, Object right )
     {
-        return getServerVersion().atLeast( DRB_10_6 );
+        if ( left == null )    { assertNull( message, right ); }
+        else { assertNotNull( right ); }
+
+        if ( !(left instanceof byte[] ) ) { fail( message ); }
+        if ( !(right instanceof byte[] ) ) { fail( message ); }
+
+        byte[]    leftBytes = (byte[]) left;
+        byte[]    rightBytes = (byte[]) right;
+        int        count = leftBytes.length;
+
+        assertEquals( message, count, rightBytes.length );
+
+        for ( int i = 0; i < count; i++ )
+        {
+            assertEquals( message + "[ " + i + " ]", leftBytes[ i ], rightBytes[ i ] );
+        }
+    }
+
+    /**
+     * <p>
+     * Assert two Dates are equal, allowing nulls to be equal.
+     * </p>
+     */
+    public    void    compareDates( String message, Object left, Object right )
+    {
+        if ( left == null )    { assertNull( message, right ); }
+        else { assertNotNull( right ); }
+
+        if ( !(left instanceof java.util.Date ) ) { fail( message ); }
+        if ( !(right instanceof java.util.Date ) ) { fail( message ); }
+
+        assertEquals( message, left.toString(), right.toString() );
+    }
+
+    /**
+     * <p>
+     * Read a column from a ResultSet given its column name and expected jdbc
+     * type. This method is useful if you are want to verify the getXXX() logic
+     * most naturally fitting the declared SQL type.
+     * </p>
+     */
+    private static final int JDBC_BOOLEAN = 16;
+    protected    Object    getColumn( ResultSet rs, String columnName, int jdbcType )
+        throws SQLException
+    {
+        Object        retval = null;
+
+        switch( jdbcType )
+        {
+            case JDBC_BOOLEAN:
+                retval = Boolean.valueOf(rs.getBoolean(columnName));
+                break;
+
+            case Types.BIGINT:
+                retval = new Long( rs.getLong( columnName ) );
+                break;
+
+            case Types.BLOB:
+                retval = rs.getBlob( columnName );
+                break;
+
+            case Types.CHAR:
+            case Types.LONGVARCHAR:
+            case Types.VARCHAR:
+                retval = rs.getString( columnName );
+                break;
+
+            case Types.BINARY:
+            case Types.LONGVARBINARY:
+            case Types.VARBINARY:
+                retval = rs.getBytes( columnName );
+                break;
+
+            case Types.CLOB:
+                retval = rs.getClob( columnName );
+                break;
+
+            case Types.DATE:
+                retval = rs.getDate( columnName );
+                break;
+
+            case Types.DECIMAL:
+            case Types.NUMERIC:
+                retval = rs.getBigDecimal( columnName );
+                break;
+
+            case Types.DOUBLE:
+                retval = new Double( rs.getDouble( columnName ) );
+                break;
+
+            case Types.REAL:
+                retval = new Float( rs.getFloat( columnName ) );
+                break;
+
+            case Types.INTEGER:
+                retval = new Integer( rs.getInt( columnName ) );
+                break;
+
+            case Types.SMALLINT:
+                retval = new Short( rs.getShort( columnName ) );
+                break;
+
+            case Types.TIME:
+                retval = rs.getTime( columnName );
+                break;
+
+            case Types.TIMESTAMP:
+                retval = rs.getTimestamp( columnName );
+                break;
+
+            default:
+                fail( "Unknown jdbc type " + jdbcType + " used to retrieve column: " + columnName );
+                break;
+        }
+
+        if ( rs.wasNull() ) { retval = null; }
+
+        return retval;
     }
 
-	/////////////////////////////////////////////////////////////
-	//
-	//	DATABASE-SIDE FUNCTIONS
-	//
-	/////////////////////////////////////////////////////////////
-	
-	/**
-	 * <p>
-	 * Get the vm level of the server.
-	 * </p>
-	 */
-	public	static	String	getVMVersion()
-	{
-		return System.getProperty( VERSION_PROPERTY );
-	}
-
-	/////////////////////////////////////////////////////////////
-	//
-	//	MINIONS
-	//
-	/////////////////////////////////////////////////////////////
-	
-	///////////////////
-	//
-	//	GENERAL MINIONS
-	//
-	///////////////////
-	
-	//////////////////////////
-	//
-	//	INITIALIZATION MINIONS
-	//
-	//////////////////////////
-	
-	//
-	// Initialize client settings based on the client found.
-	// Return true if one and only one client found, false otherwise.
-	// We allow for the special case when we're running the embedded client
-	// off the current compiled class tree rather than off product jars.
-	//
-	static	boolean	findClient()
-		throws Exception
-	{
-		//
-		// The client may have been specified on the command line.
-		// In that case, we don't bother looking for a client on
-		// the classpath.
-		//
-		if ( getClientSettings() != null ) { faultInDriver( getClientSettings() ); }
-		else
-		{
-			int		legalCount = LEGAL_CLIENTS.length;
-			int		foundCount = 0;
-
-			for ( int i = 0; i < legalCount; i++ )
-			{
-				String[]	candidate = LEGAL_CLIENTS[ i ];
-
-				if ( faultInDriver( candidate ) )
-				{
-					setClient( candidate );
-					foundCount++;
-				}
-			}
-
-			if ( foundCount != EXPECTED_CLIENT_COUNT )
-			{
-				throw new Exception( "Wrong number of drivers: " + foundCount );
-			}
-		}
-
-		// Now make sure that the JDBC driver is what we expect
-
-		try {
-			_driver = DriverManager.getDriver( getClientSettings()[ DATABASE_URL ] );
-			_driverLevel = new Version( _driver.getMajorVersion(), _driver.getMinorVersion() );
-		}
-		catch (SQLException e)
-		{
-			printStackTrace( e );
-			
-			throw new Exception
-				( "Driver doesn't understand expected URL: " + getClientSettings()[ DATABASE_URL ] );
-		}
-
-		println
-			(
-			    "Driver " + _driver.getClass().getName() +
-				" Version = " + _driverLevel
-			);
-		
-		return true;
-	}
-
-	//
-	// Initialize server settings. Assumes that you have called
-	// findClient().
-	//
-	static	boolean	findServer()
-		throws Exception
-	{
-		try {
-			Connection			conn = getConnection();
-			DatabaseMetaData	dmd = conn.getMetaData();
-			String				dbProductVersion = dmd.getDatabaseProductVersion();
-
-			_serverLevel = new Version( dbProductVersion );
-			
-			parseServerVMVersion( conn );
-		}
-		catch (Exception e)
-		{
-			printStackTrace( e );
-			
-			throw new Exception( "Error lookup up server info: " + e.getMessage() );
-		}
-		
-		println( "Server Version = " + _serverLevel );
-
-		return true;
-	}
-
-	static	boolean	parseVMLevel()
-		throws Exception
-	{
-		String				vmVersion = getVMVersion();
-
-		try {
-			_clientVMLevel = new Version( vmVersion );
-		}
-		catch (NumberFormatException e)
-		{
-			throw new Exception( "Badly formatted vm version: " + vmVersion );
-		}
-
-		println( "VM Version = " + _clientVMLevel );
-
-		return true;
-	}
-
-	static	boolean	parseArgs( String args[] )
-		throws Exception
-	{
-		if ( ( args == null ) || (args.length == 0 ) )
-		{ throw new Exception( "Missing database name." ); }
-		
-		setDatabaseName( args[ 0 ] );
-
-		if ( (args.length > 1) && !"".equals( args[ 1 ] ) )
-		{
-			String	desiredClientName = args[ 1 ];
-			int		count = LEGAL_CLIENTS.length;
-
-			for ( int i = 0; i < count; i++ )
-			{
-				String[]	candidate = LEGAL_CLIENTS[ i ];
-
-				if ( desiredClientName.equals( candidate[ DRIVER_NAME ] ) )
-				{
-					setClient( candidate );
-					break;
-				}
-			}
-
-			if ( getClientSettings() == null )
-			{
-				throw new Exception
-					( "Could not find client " + desiredClientName + " on the classpath." );
-			}
-		}
-			
-		return true;
-	}
-
-	/**
-	 * <p>
-	 * Get the vm level of the server.
-	 * </p>
-	 */
-	static	void	parseServerVMVersion( Connection conn )
-		throws SQLException
-	{
-		dropFunction( conn, SERVER_VERSION_FUNCTION );
-
-		PreparedStatement	ps = prepare
-			(
-			    conn,
-				"create function " + SERVER_VERSION_FUNCTION + "() returns varchar(50)\n" +
-				"parameter style java no sql language java\n" +
-				"external name 'org.apache.derbyTesting.functionTests.tests.junitTests.compatibility.CompatibilitySuite.getVMVersion'"
-			);
-		ps.execute();
-		close( ps );
-
-		ps = prepare
-			(
-			    conn,
-				"values " + SERVER_VERSION_FUNCTION + "()"
-			);
-
-		ResultSet	rs = ps.executeQuery();
-		rs.next();
-		String		rawVersion = rs.getString( 1 );
-		close( rs );
-		close( ps );
-
-		_serverVMLevel = new Version( rawVersion );
-			
-		println( "Server VM Version = " + _serverVMLevel );
-	}
-
-	///////////////
-	//
-	//	SQL MINIONS
-	//
-	///////////////
-
-	/////////////////////////////////////////////////////////////
-	//
-	//	INNER CLASSES
-	//
-	/////////////////////////////////////////////////////////////
-
-	/**
-	 * <p>
-	 * This helper class exposes an entry point for creating an empty database.
-	 * </p>
-	 */
-	public	static	final	class	Creator
-	{
-		private	static	CompatibilitySuite	_driver = new CompatibilitySuite();
-		
-		/**
-		 * <p>
-		 * Wait for server to come up, then create the database.
-		 * </p>
-		 *
-		 * <ul>
-		 * <li>args[ 0 ] = name of database to create.</li>
-		 * </ul>
-		 */
-		public	static	void	main( String[] args )
-			throws Exception
-		{
-			String		databaseName = args[ 0 ];
-
-			CompatibilitySuite.findClient();
-			
-			_driver.createDB( databaseName );
-		}
-		
-	}
-
-	/**
-	 * <p>
-	 * A class for storing a major and minor version number. This class
-	 * assumes that more capable versions compare greater than less capable versions.
-	 * </p>
-	 */
-	public	static	final	class	Version	implements	Comparable
-	{
-		private	int	_major;
-		private	int	_minor;
-
-		public	Version( int major, int minor )
-		{
-			constructorMinion( major, minor );
-		}
-
-		public	Version( String desc )
-			throws NumberFormatException
-		{
-			StringTokenizer		tokens = new StringTokenizer( desc, "." );
-
-			constructorMinion
-				(
-				    java.lang.Integer.parseInt( tokens.nextToken() ),
-					java.lang.Integer.parseInt( tokens.nextToken() )
-				);
-		}
-
-		private	void	constructorMinion( int major, int minor )
-		{
-			_major = major;
-			_minor = minor;
-		}
-
-		/**
-		 * <p>
-		 * Returns true if this Version is at least as advanced
-		 * as that Version.
-		 * </p>
-		 */
-		public	boolean	atLeast( Version that )
-		{
-			return this.compareTo( that ) > -1;
-		}
-
-
-		////////////////////////////////////////////////////////
-		//
-		//	Comparable BEHAVIOR
-		//
-		////////////////////////////////////////////////////////
-
-		public	int	compareTo( Object other )
-		{
-			if ( other == null ) { return -1; }
-			if ( !( other instanceof Version ) ) { return -1; }
-
-			Version	that = (Version) other;
-
-			if ( this._major < that._major ) { return -1; }
-			if ( this._major > that._major ) { return 1; }
-
-			return this._minor - that._minor;
-		}
-
-		////////////////////////////////////////////////////////
-		//
-		//	Object OVERLOADS
-		//
-		////////////////////////////////////////////////////////
-		
-		public	String	toString()
-		{
-			return Integer.toString( _major ) + '.' + Integer.toString( _minor );
-		}
-
-		public	boolean	equals( Object other )
-		{
-			return (compareTo( other ) == 0);
-		}
-
-		public	int	hashCode()
-		{
-			return _major ^ _minor;
-		}
-		
-	}
+    /**
+     * <p>
+     * Stuff a PreparedStatement parameter given its 1-based parameter position
+     * and expected jdbc type. This method is useful for testing the setXXX()
+     * methods most natural for a declared SQL type.
+     * </p>
+     */
+    protected    void    setParameter( PreparedStatement ps, int param, int jdbcType, Object value )
+        throws SQLException
+    {
+        if ( value == null )
+        {
+            ps.setNull( param, jdbcType );
+
+            return;
+        }
+
+        switch( jdbcType )
+        {
+            case JDBC_BOOLEAN:
+                ps.setBoolean( param, ((Boolean) value ).booleanValue() );
+                break;
+
+            case Types.BIGINT:
+                ps.setLong( param, ((Long) value ).longValue() );
+                break;
+
+            case Types.BLOB:
+                ps.setBlob( param, ((java.sql.Blob) value ) );
+                break;
+
+            case Types.CHAR:
+            case Types.LONGVARCHAR:
+            case Types.VARCHAR:
+                ps.setString( param, ((String) value ) );
+                break;
+
+            case Types.BINARY:
+            case Types.LONGVARBINARY:
+            case Types.VARBINARY:
+                ps.setBytes( param, (byte[]) value );
+                break;
+
+            case Types.CLOB:
+                ps.setClob( param, ((java.sql.Clob) value ) );
+                break;
+
+            case Types.DATE:
+                ps.setDate( param, ((java.sql.Date) value ) );
+                break;
+
+            case Types.DECIMAL:
+            case Types.NUMERIC:
+                ps.setBigDecimal( param, ((java.math.BigDecimal) value ) );
+                break;
+
+            case Types.DOUBLE:
+                ps.setDouble( param, ((Double) value ).doubleValue() );
+                break;
+
+            case Types.REAL:
+                ps.setFloat( param, ((Float) value ).floatValue() );
+                break;
+
+            case Types.INTEGER:
+                ps.setInt( param, ((Integer) value ).intValue() );
+                break;
+
+            case Types.SMALLINT:
+                ps.setShort( param, ((Short) value ).shortValue() );
+                break;
+
+            case Types.TIME:
+                ps.setTime( param, (java.sql.Time) value );
+                break;
+
+            case Types.TIMESTAMP:
+                ps.setTimestamp( param, (java.sql.Timestamp) value );
+                break;
+
+            default:
+                fail( "Unknown jdbc type: " + jdbcType );
+                break;
+        }
 
-	
+    }
+    /**
+     * <p>
+     * Drop a function regardless of whether it exists. If the function does not
+     * exist, don't log an error unless
+     * running in debug mode. This method is to be used for reinitializing
+     * a schema in case a previous test run failed to clean up after itself.
+     * Do not use this method if you need to verify that the function really exists.
+     * </p>
+     */
+    protected    void    dropFunction(String name )
+    {
+        dropSchemaObject(FUNCTION, name, false );
+    }
+
+    /**
+     * <p>
+     * Drop a procedure regardless of whether it exists. If the procedure does
+     * not exist, don't log an error unless
+     * running in debug mode. This method is to be used for reinitializing
+     * a schema in case a previous test run failed to clean up after itself.
+     * Do not use this method if you need to verify that the procedure really exists.
+     * </p>
+     */
+    protected    void    dropProcedure(String name )
+    {
+        dropSchemaObject(PROCEDURE, name, false );
+    }
+
+    /**
+     * <p>
+     * Drop a UDT regardless of whether it exists. If the UDT does
+     * not exist, don't log an error unless
+     * running in debug mode. This method is to be used for reinitializing
+     * a schema in case a previous test run failed to clean up after itself.
+     * Do not use this method if you need to verify that the UDT really exists.
+     * </p>
+     */
+    protected    void    dropUDT(String name )
+    {
+        dropSchemaObject(TYPE, name, true );
+    }
+
+    protected    void    dropSchemaObject(String genus, String objectName, boolean restrict )
+    {
+        try {
+            String text = "drop " + genus + " " + objectName;
+            if ( restrict ) { text = text + " restrict"; }
+            PreparedStatement ps = prepareStatement(text );
+
+            ps.execute();
+            ps.close();
+        }
+        catch (SQLException e)
+        {
+        }
+
+    }
 
+    private    static    final    String    FUNCTION = "function";
+    private    static    final    String    PROCEDURE = "procedure";
+    private    static    final    String    TYPE = "type";
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java?rev=1354960&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilityRunControl.java Thu Jun 28 11:58:16 2012
@@ -0,0 +1,125 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.compatibility.ClientCompatibilityRunControl
+
+   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.compatibility;
+
+import java.io.File;
+import java.net.URL;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.DerbyDistribution;
+import org.apache.derbyTesting.junit.DerbyVersion;
+import org.apache.derbyTesting.junit.SpawnedProcess;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Spawns the JVM process running the compatibility tests for the given client
+ * version.
+ */
+public class ClientCompatibilityRunControl
+        extends BaseJDBCTestCase {
+
+    static final String LOB_TESTING_PROP = "derby.tests.compat.testLOBs";
+
+    /** The descriptive name of the test case. */
+    private final String realName;
+    /** The Derby client to use. */
+    private final DerbyDistribution clientDist;
+    /** The Derby version we expect to connect to. */
+    private final DerbyVersion serverVersion;
+    /** Path to the testing code to use (typically from trunk). */
+    private final String testingPath;
+
+    /**
+     * Creates a control object for the given client version.
+     *
+     * @param client the Derby client to use
+     * @param testingPath path to the testing code to use (typically
+     *      {@literal derbyTesting.jar} from trunk)
+     * @param serverVersion the expected server version
+     */
+    public ClientCompatibilityRunControl(DerbyDistribution client,
+                                         String testingPath,
+                                         DerbyVersion serverVersion) {
+        super("testClient");
+        this.clientDist = client;
+        this.testingPath = testingPath;
+        this.serverVersion = serverVersion;
+        this.realName = "combination(client " + client.getVersion().toString() +
+                " <> server " + serverVersion.toString() + ")";
+    }
+
+    @Override
+    public String getName() {
+        return realName;
+    }
+
+    /**
+     * Runs the client compatibility test suite with the client driver in a
+     * separate JVM.
+     * <p>
+     * The server is expected to be running already.
+     */
+    public void testClient()
+            throws Exception {
+        boolean testLOBs = Boolean.parseBoolean(
+                getSystemProperty(LOB_TESTING_PROP));
+        // Fork the client test with a minimal classpath.
+        String classpath = clientDist.getDerbyClientJarPath() +
+                File.pathSeparator + testingPath +
+                File.pathSeparator + getJUnitURL().getPath();
+        // If we are running the LOB tests we also need derby.jar, because the
+        // test code being run references classes from the iapi package.
+        // This may also happen for the non-LOB tests in the future.
+        if (testLOBs) {
+            classpath += File.pathSeparator + clientDist.getDerbyEngineJarPath();
+        }
+
+        String[] cmd = new String[] {
+            "-Dderby.tests.compat.expectedClient=" +
+                clientDist.getVersion().toString(),
+            "-Dderby.tests.compat.expectedServer=" +
+                serverVersion.toString(),
+            "-Dderby.tests.compat.testLOBs=" +
+                testLOBs,
+            "-Dderby.tests.basePort=" +
+                TestConfiguration.getBasePort(),
+            "junit.textui.TestRunner",
+            "org.apache.derbyTesting.functionTests.tests." +
+                "compatibility.ClientCompatibilitySuite"
+        };
+        Process proc = execJavaCmd(null, classpath, cmd, null);
+
+        SpawnedProcess spawned = new SpawnedProcess(proc, realName);
+        int exitCode = spawned.complete(30*60*1000); // 30 minutes
+        assertTrue(spawned.getFailMessage("client VM failed: "), exitCode == 0);
+        println(spawned.getFullServerOutput());
+    }
+
+	/**
+	 * Returns the URL of the JUnit classes.
+     *
+     * @return A URL.
+	 */
+    private static URL getJUnitURL() {
+        return VersionCombinationConfigurator.getClassURL(
+                junit.framework.TestCase.class);
+	}
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilitySuite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilitySuite.java?rev=1354960&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilitySuite.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/compatibility/ClientCompatibilitySuite.java Thu Jun 28 11:58:16 2012
@@ -0,0 +1,55 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.compatibility.ClientCompatibilitySuite
+
+   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.compatibility;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derbyTesting.functionTests.tests.jdbcapi.Compat_BlobClob4BlobTest;
+import org.apache.derbyTesting.junit.BaseTestCase;
+
+/**
+ * Returns the test suite run by each client in the compatibility test.
+ * <p>
+ * This is where one would add the tests from a new test class to be included
+ * in the compatibility suite.
+ */
+public class ClientCompatibilitySuite
+        extends BaseTestCase {
+
+    public ClientCompatibilitySuite(String name) {
+        super(name);
+        throw new IllegalStateException(
+                "use ClientCompatibilitySuite.suite() instead");
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Client compatibility suite");
+        suite.addTest(JDBCDriverTest.suite());
+        // Adding the LOB suite adds around 5 minutes to each client-server
+        // combination. There are also errors and/or failures when run with
+        // clients older than 10.5, at least for some server versions.
+        if (Boolean.parseBoolean(getSystemProperty(
+                ClientCompatibilityRunControl.LOB_TESTING_PROP))) {
+            suite.addTest(Compat_BlobClob4BlobTest.suite());
+        }
+        return suite;
+    }
+}

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