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 fu...@apache.org on 2006/03/16 00:33:21 UTC

svn commit: r386216 - in /db/derby/code/trunk/java/testing: ./ org/apache/derbyTesting/functionTests/tests/lang/ org/apache/derbyTesting/functionTests/tests/store/ org/apache/derbyTesting/functionTests/util/

Author: fuzzylogic
Date: Wed Mar 15 15:33:17 2006
New Revision: 386216

URL: http://svn.apache.org/viewcvs?rev=386216&view=rev
Log:
DERBY-949: Clean up tests to use common method to get connection.

Committed for Myrna Van Lunteren <m....@gmail.com>

Modified:
    db/derby/code/trunk/java/testing/README.htm
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/closed.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/logStream.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest1.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest3.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDurabilityProperty.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/backupRestore1.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java

Modified: db/derby/code/trunk/java/testing/README.htm
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/README.htm?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/README.htm (original)
+++ db/derby/code/trunk/java/testing/README.htm Wed Mar 15 15:33:17 2006
@@ -1210,7 +1210,7 @@
   <li>
     <p style="margin-bottom: 0in;">create the test file (e.g.
 newfunctest.java or newfunctest.sql) in the appropriate tests
-subdirectory </p>
+subdirectory</p>
   </li>
   <li>
     <p style="margin-bottom: 0in;">list any files needed that are not
@@ -1239,7 +1239,42 @@
     <p style="margin-bottom: 0in;">run the test again. Investigate if
 any differences need to be masked out using a test specific
 sed.properties file (e.g. newfunctest_sed.properties). If so, ensure
-this is added to copyfiles.ant. </p>
+this is added to copyfiles.ant.</p>
+  </li>
+</ul>
+<ul>
+  <li>
+    <p>ensure the test cleans up any testobjects created. This is
+important for running the tests in suites with a remote server, or with
+useprocess=false, because
+in those cases, tests run against databases in the same
+directory.&nbsp; Even if you do not anticipate your test to run in
+those configurations, it makes good practice.&nbsp;You may also want to
+protect your test from other tests leaving things behind by removing
+them before running also. The class
+org.apache.derbyTesting.functionTests.util.TestUtil has a cleanUpTest
+method that may be useful.</p>
+  </li>
+  <li>
+    <p>ensure that connections can be made with all supported jvms.
+This
+includes the J2ME/CDC/JSR169 configuration, which only has
+java.sql.Datasource available, no java.sql.DriverManager. One can use
+the method ij.startJBMS() to get an appropriate connection, or
+TestUtil.getConnection() if one needs to specify connection properties
+different from what is defined in the &lt;test&gt;_app.properties file.
+For instance, to shutdown a database one can use:</p>
+  </li>
+</ul>
+<div style="margin-left: 80px;">TestUtil.getConnection("wombat","shutdown=true");</div>
+<ul>
+  <ul>
+  </ul>
+  <li>
+    <p style="margin-bottom: 0in;">ensure the test does not have hard
+coded 'localhost' for network
+connections. Instead, use the method TestUtil.getHostName() to find if
+a hostName was specified for remote server testing.</p>
   </li>
   <li>
     <p style="margin-bottom: 0in;">add the test to a specific

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/closed.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/closed.java?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/closed.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/closed.java Wed Mar 15 15:33:17 2006
@@ -21,7 +21,6 @@
 package org.apache.derbyTesting.functionTests.tests.lang;
 
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.Statement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -29,7 +28,6 @@
 import java.sql.DatabaseMetaData;
 import java.sql.SQLException;
 import java.sql.SQLWarning;
-import java.util.Properties;
 
 import org.apache.derby.tools.ij;
 import org.apache.derby.tools.JDBCDisplayUtil;
@@ -61,23 +59,6 @@
 			// make the initial connection.
 			ij.getPropertyArg(args);
 			conn = ij.startJBMS();
-			
-			
-			String url = new String();
-			try{
-				url = conn.getMetaData().getURL();
-			}
-			catch (NoSuchMethodError msme)
-			{
-				// DatabaseMetaData.getURL not present - correct for JSR169
-				if(!TestUtil.HAVE_DRIVER_CLASS)
-					jsr169_test = true;
-				else
-					passed = false;
-				
-			} catch (Throwable err) {
-			    System.out.println("%%getURL() gave the exception: " + err);
-			}
 
 			passed = testDerby62(conn) && passed;
 
@@ -100,11 +81,11 @@
 
 			// shutdown the database
 			System.out.println("Test database shutdown ...");
-			passed = shutdownTest(url, url + ";shutdown=true", "wombat");
+			passed = shutdownTest("wombat", "shutdown=true");
 
 			// shutdown the system
 			System.out.println("Test system shutdown ...");
-			passed = shutdownTest(url, "jdbc:derby:;shutdown=true", "");
+			passed = shutdownTest("", "shutdown=true");
 			
 
 
@@ -119,28 +100,15 @@
 		System.out.println("Test closed finished");
 	}
 
-	static boolean shutdownTest(String url, String shutdownUrl, String databaseName) throws SQLException {
+	static boolean shutdownTest(String databaseName, String shutdownString) throws SQLException {
+	//	static boolean shutdownTest(String databaseName, String shutdownString) throws SQLException, IllegalAccessException, ClassNotFoundException, InstantiationException {
 
 		boolean passed = true;
 
-		Connection c1;
-		Connection c2;
-		Connection c3a;
-		Connection c3b;
-		
-		if(!jsr169_test) {
-			c1 = DriverManager.getConnection(url);
-			c2 = DriverManager.getConnection(url);
-			c3a = DriverManager.getConnection(url);
-			c3b = DriverManager.getConnection(url);
-		} else {
-			Properties prop = new Properties();
-			prop.setProperty("databaseName", "wombat");
-			c1 = TestUtil.getDataSourceConnection(prop);
-			c2 = TestUtil.getDataSourceConnection(prop);
-			c3a = TestUtil.getDataSourceConnection(prop);
-			c3b = TestUtil.getDataSourceConnection(prop);
-		}
+		Connection c1 = TestUtil.getConnection("wombat",null);
+		Connection c2 = TestUtil.getConnection("wombat",null);
+		Connection c3a = TestUtil.getConnection("wombat",null);
+		Connection c3b = TestUtil.getConnection("wombat",null);
 		
 		try {
 			c3a.createStatement().execute("DROP TABLE CLOSED.LOCKME");
@@ -173,10 +141,7 @@
 
 		SQLException s = null;
 		try {
-			if(!jsr169_test) 
-				DriverManager.getConnection(shutdownUrl);
-			else 
-				TestUtil.shutdownUsingDataSource(databaseName);
+			TestUtil.getConnection(databaseName, shutdownString); 
 		} catch (SQLException sqle) {
 			s = sqle;
 		}
@@ -200,12 +165,12 @@
 
 		if (!c1.isClosed()) {
 			passed = false;
-			System.out.println("FAIL -- connection not shutdown " + shutdownUrl);
+			System.out.println("FAIL -- connection not shutdown " + databaseName + ";" + shutdownString);
 			c1.close();
 		}
 		if (!c2.isClosed()) {
 			passed = false;
-			System.out.println("FAIL -- active connection not shutdown " + shutdownUrl);
+			System.out.println("FAIL -- active connection not shutdown " + databaseName + ";" + shutdownString);
 			c2.close();
 		}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/logStream.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/logStream.java?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/logStream.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/logStream.java Wed Mar 15 15:33:17 2006
@@ -26,7 +26,6 @@
 import org.apache.derby.tools.ij;
 import org.apache.derby.tools.JDBCDisplayUtil;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
-import java.util.Properties;
 
 /**
  * Demonstrate subselect behavior with prepared statement. 
@@ -54,22 +53,11 @@
 		System.out.println("derby.log has content ?  " + (derbyLog.length() > 0));
 
 		System.out.println("SHUTDOWN Derby");
-		if(TestUtil.HAVE_DRIVER_CLASS){
-			try {
-				DriverManager.getConnection("jdbc:derby:;shutdown=true");
-				System.out.println("FAIL - shutdown returned connection");
-			} catch (SQLException sqle) {
-				System.out.println("SHUTDOWN :" + sqle.getMessage());
-			}
-		}
-		else{	
-			//Call helper method which shuts down Derby using Datasource
-			try {
-				TestUtil.shutdownUsingDataSource("");
-				System.out.println("FAIL - shutdown returned connection");
-			} catch (SQLException sqle) {
-				System.out.println("SHUTDOWN :" + sqle.getMessage());
-			}
+		try {
+			TestUtil.getConnection("","shutdown=true");
+			System.out.println("FAIL - shutdown returned connection");
+		} catch (SQLException sqle) {
+			System.out.println("SHUTDOWN :" + sqle.getMessage());
 		}
 
 		System.out.println("derby.log exists ?       " + derbyLog.exists());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackup.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackup.java?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackup.java Wed Mar 15 15:33:17 2006
@@ -21,9 +21,7 @@
 package org.apache.derbyTesting.functionTests.tests.store;
 import java.sql.Connection;
 import java.sql.CallableStatement;
-import java.sql.DriverManager;
 import java.sql.SQLException;
-import java.util.Properties;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
 
 /**
@@ -77,7 +75,7 @@
 	 * Backup the database
 	 */
 	void performBackup() throws SQLException {
-        Connection conn = getConnection(dbName , "");
+		Connection conn = TestUtil.getConnection(dbName , "");
 		CallableStatement backupStmt = 	
 			conn.prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)");
 		backupStmt.setString(1, backupPath);
@@ -161,7 +159,7 @@
 	 */
 	public void createFromBackup(String newDbName) throws SQLException {
 		
-        Connection conn = getConnection(newDbName,  
+        Connection conn = TestUtil.getConnection(newDbName,  
                                         "createFrom=" +
                                         backupPath + "/" + 
                                         dbName);
@@ -175,36 +173,11 @@
      */
     public void restoreFromBackup() throws SQLException {
        
-        Connection conn = getConnection(dbName,  
+        Connection conn = TestUtil.getConnection(dbName,  
                                         "restoreFrom=" +
                                         backupPath + "/" + 
                                         dbName);
 
 		conn.close();
-    }
-
-    
-    /**
-     * Get connection to the given database.
-     *
-     * @param databaseName the name of the database 
-	 * @param connAttrs  connection Attributes.
-     *
-     */
-    private Connection getConnection(String databaseName, 
-                                     String connAttrs) 
-        throws SQLException 
-    {
-    	Connection conn;
-    	if(TestUtil.HAVE_DRIVER_CLASS)
-			conn = DriverManager.getConnection("jdbc:derby:" + databaseName 
-												+ ";" + connAttrs );
-    	else {
-	    	Properties prop = new Properties();
-	        prop.setProperty("databaseName", databaseName);
-	        prop.setProperty("connectionAttributes", connAttrs);
-	        conn = TestUtil.getDataSourceConnection(prop);
-    	}
-        return conn;
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest1.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest1.java?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest1.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest1.java Wed Mar 15 15:33:17 2006
@@ -20,14 +20,12 @@
 
 package org.apache.derbyTesting.functionTests.tests.store;
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.Statement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import org.apache.derby.tools.ij;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
-import java.util.Properties;
 
 /*
  * This class tests online backup when dml/ddl actions
@@ -93,13 +91,13 @@
 		Thread backupThread = new Thread(backup, "BACKUP");
         
         // run some dml actions in another thread
-        Connection dmlConn = getConnection();
+        Connection dmlConn = TestUtil.getConnection(TEST_DATABASE_NAME, null);
         DatabaseActions dmlActions = 
             new DatabaseActions(DatabaseActions.DMLACTIONS, dmlConn);
 		Thread dmlThread = new Thread(dmlActions, "DML_THREAD");
         
         // run some DDL create/drop tables in another thread
-        Connection ddlConn = getConnection();
+        Connection ddlConn = TestUtil.getConnection(TEST_DATABASE_NAME, null);
         
         DatabaseActions ddlActions = 
             new DatabaseActions(DatabaseActions.CREATEDROPS, ddlConn);
@@ -169,7 +167,7 @@
 	 * @param  dbName  consistency checks are performed on this database.
 	 */
 	void runConsistencyChecker(String dbName) throws SQLException {
-        Connection conn = getConnection();
+        Connection conn = TestUtil.getConnection(dbName, null);
 		Statement stmt = conn.createStatement();
 		stmt.execute("values SYSCS_UTIL.SYSCS_CHECK_TABLE('APP',  'EMP')");
         //check the data in the EMP table.
@@ -191,10 +189,7 @@
 
 		try{
 			//shutdown
-			if(TestUtil.HAVE_DRIVER_CLASS)
-				DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true");
-			else 
-				TestUtil.shutdownUsingDataSource(dbName);
+			TestUtil.getConnection(dbName, "shutdown=true");
 		}catch(SQLException se){
 			if (se.getSQLState() != null && se.getSQLState().equals("08006"))
 				System.out.println("database shutdown properly");
@@ -202,23 +197,6 @@
 				dumpSQLException(se);
 		}
 	}
-
-    /*
-     * get connection to the test database
-     */
-    Connection getConnection() throws SQLException 
-    {
-    	Connection conn;
-    	if(TestUtil.HAVE_DRIVER_CLASS)
-			conn = DriverManager.getConnection("jdbc:derby:" + TEST_DATABASE_NAME );
-    	else {
-	    	Properties prop = new Properties();
-	        prop.setProperty("databaseName", TEST_DATABASE_NAME);
-	        conn = TestUtil.getDataSourceConnection(prop);
-    	}
-        return conn;
-    }
-
 
 	/**
 	 * Write message to the standard output.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest3.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest3.java?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest3.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/OnlineBackupTest3.java Wed Mar 15 15:33:17 2006
@@ -20,14 +20,12 @@
 
 package org.apache.derbyTesting.functionTests.tests.store;
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.Statement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import org.apache.derby.tools.ij;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
-import java.util.Properties;
 
 /*
  * This class tests online backup when jar actions
@@ -107,10 +105,7 @@
 
         try{
             //shutdown
-            if(TestUtil.HAVE_DRIVER_CLASS)
-                DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true");
-            else 
-                TestUtil.shutdownUsingDataSource(dbName);
+            TestUtil.getConnection(dbName, "shutdown=true");
         }catch(SQLException se){
             if (se.getSQLState() != null && se.getSQLState().equals("08006"))
                 System.out.println("database shutdown properly");
@@ -119,23 +114,6 @@
         }
     }
 
-    /*
-     * get connection to the test database
-     */
-    Connection getConnection() throws SQLException 
-    {
-        Connection conn;
-        if(TestUtil.HAVE_DRIVER_CLASS)
-            conn = DriverManager.getConnection("jdbc:derby:" + TEST_DATABASE_NAME );
-        else {
-            Properties prop = new Properties();
-            prop.setProperty("databaseName", TEST_DATABASE_NAME);
-            conn = TestUtil.getDataSourceConnection(prop);
-        }
-        return conn;
-    }
-
-
     /**
      * Write message to the standard output.
      */
@@ -171,10 +149,10 @@
      */
     void installJarTest() throws Exception{
         logMessage("Begin Install Jar Test");
-        Connection conn1 = getConnection();
+        Connection conn1 = TestUtil.getConnection(TEST_DATABASE_NAME, null);
         conn1.setAutoCommit(false);
         Statement conn1_stmt = conn1.createStatement();
-        Connection conn2 = getConnection();
+        Connection conn2 = TestUtil.getConnection(TEST_DATABASE_NAME, null);
         conn2.setAutoCommit(false);
         Statement conn2_stmt = conn2.createStatement();
 
@@ -310,7 +288,7 @@
         // restore the database from the backup and run some checks 
         backup.restoreFromBackup();
         logMessage("Restored From the Backup");
-        Connection conn = getConnection();
+        Connection conn = TestUtil.getConnection(TEST_DATABASE_NAME, null);
         Statement stmt = conn.createStatement();
         logMessage("No of rows in table t1: " + countRows(conn, "T1"));
         logMessage("No of rows in table customer: " + 
@@ -346,10 +324,10 @@
      */
     void removeJarTest() throws Exception{
         logMessage("Begin Remove Jar Test");
-        Connection conn1 = getConnection();
+        Connection conn1 = TestUtil.getConnection(TEST_DATABASE_NAME, null);
         conn1.setAutoCommit(false);
         Statement conn1_stmt = conn1.createStatement();
-        Connection conn2 = getConnection();
+        Connection conn2 = TestUtil.getConnection(TEST_DATABASE_NAME, null);
         conn2.setAutoCommit(false);
         Statement conn2_stmt = conn2.createStatement();
         try {
@@ -491,7 +469,7 @@
         // restore the database from the backup and run some checks 
         backup.restoreFromBackup();
         logMessage("Restored From the Backup");
-        Connection conn = getConnection();
+        Connection conn = TestUtil.getConnection(TEST_DATABASE_NAME, null);
         Statement stmt = conn.createStatement();
         logMessage("No of rows in table t1: " + countRows(conn, "T1"));
         logMessage("No of rows in table customer: " + 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDurabilityProperty.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDurabilityProperty.java?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDurabilityProperty.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDurabilityProperty.java Wed Mar 15 15:33:17 2006
@@ -124,11 +124,7 @@
 
         try {
             conn.close();
-            if(TestUtil.HAVE_DRIVER_CLASS) {
-                DriverManager.getConnection("jdbc:derby:;shutdown=true");
-            } else {
-            	TestUtil.shutdownUsingDataSource("");
-            }
+            TestUtil.getConnection("","shutdown=true");
         } catch (SQLException sqle) {
             if ("XJ015".equals(sqle.getSQLState())) {
             }// ok database shutdown

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/backupRestore1.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/backupRestore1.java?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/backupRestore1.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/backupRestore1.java Wed Mar 15 15:33:17 2006
@@ -27,7 +27,6 @@
 
 import java.sql.CallableStatement;
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -35,7 +34,6 @@
 import org.apache.derby.tools.ij;
 import org.apache.derby.tools.JDBCDisplayUtil;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
-import java.util.Properties;
 
 /**
  * Test of backup restore through java program JDBC calls.
@@ -123,13 +121,7 @@
 		//shutdown the database ..
 		try{
 			//shutdown
-			//Need to use if loop because DataSource does not work with j9_13.
-			//javax.naming.Referenceable class is not available in j9_13
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				Connection conn = DriverManager.getConnection("jdbc:derby:wombat;shutdown=true");
-			} else { 
-				TestUtil.shutdownUsingDataSource("wombat");
-			}
+			TestUtil.getConnection("wombat", "shutdown=true");
 		}catch(SQLException se){
 				if (se.getSQLState() != null && se.getSQLState().equals("08006"))
 					System.out.println("database shutdown properly");
@@ -141,17 +133,8 @@
 
 		System.out.println("testing rollforward recovery");
 		try{
-			Connection conn;
 			//perform rollforward recovery and do some inserts again
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				conn = DriverManager.getConnection(
-				  "jdbc:derby:wombat;rollForwardRecoveryFrom=extinout/mybackup/wombat");
-			} else {
-				Properties prop = new Properties();
-				prop.setProperty("databaseName","wombat");
-				prop.setProperty("connectionAttributes", "rollForwardRecoveryFrom=extinout/mybackup/wombat");
-				conn = TestUtil.getDataSourceConnection(prop);
-			}
+			Connection conn = TestUtil.getConnection("wombat", "rollForwardRecoveryFrom=extinout/mybackup/wombat");
 			//run consistenct checker
 			Statement stmt = conn.createStatement();
 			stmt.execute("VALUES (ConsistencyChecker())");
@@ -165,12 +148,7 @@
 
             conn.commit();
 			conn.close();
-			
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				conn = DriverManager.getConnection("jdbc:derby:wombat;shutdown=true");
-			} else {
-				TestUtil.shutdownUsingDataSource("wombat");
-			}
+			TestUtil.getConnection("wombat", "shutdown=true");
 		}
         catch( SQLException se)
         {
@@ -188,14 +166,7 @@
 		RandomAccessFile rfs = null;
 		boolean alreadyShutdown = false;
 		try{
-			Connection conn;
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				conn = DriverManager.getConnection("jdbc:derby:wombat");
-			} else {
-				Properties prop = new Properties();
-				prop.setProperty("databaseName","wombat");
-				conn = TestUtil.getDataSourceConnection(prop);
-			}
+			Connection conn = TestUtil.getConnection("wombat", null);
 								
 			//just open to a file in existing backup, so that rename will fail on
 			//next backup
@@ -209,11 +180,7 @@
             backupStmt.execute();
             backupStmt.close();
 			conn.close();
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				conn = DriverManager.getConnection("jdbc:derby:wombat;shutdown=true");
-			} else {
-				TestUtil.shutdownUsingDataSource("wombat");
-			}
+			TestUtil.getConnection("wombat", "shutdown=true");
 		}catch(SQLException se)
 		{
 			if (se.getSQLState() != null && se.getSQLState().equals("XSRS4"))
@@ -238,11 +205,7 @@
 		{
 			try{
 				//shutdown 
-				if(TestUtil.HAVE_DRIVER_CLASS) {
-					Connection conn = DriverManager.getConnection("jdbc:derby:wombat;shutdown=true");
-				} else {
-					TestUtil.shutdownUsingDataSource("wombat");
-				}
+				TestUtil.getConnection("wombat", "shutdown=true");
 			}catch(SQLException se){
 				if (se.getSQLState() != null && se.getSQLState().equals("08006"))
 					System.out.println("database shutdown properly");
@@ -258,27 +221,15 @@
 			//close the earlier opened file in backup dir
 			if(rfs != null )
 				rfs.close();
-			
-			Connection conn;
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				conn = DriverManager.getConnection("jdbc:derby:wombat;restoreFrom=extinout/mybackup/wombat");
-			} else {
-				Properties prop = new Properties();
-				prop.setProperty("databaseName","wombat");
-				prop.setProperty("connectionAttributes","restoreFrom=extinout/mybackup/wombat");
-				conn = TestUtil.getDataSourceConnection(prop);
-			}
+
+			Connection conn = TestUtil.getConnection("wombat", "restoreFrom=extinout/mybackup/wombat");
 			
 			//run consistenct checker
 			Statement stmt = conn.createStatement();
 			stmt.execute("VALUES (ConsistencyChecker())");
 			conn.close();
 			//shutdown the backup db;
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				conn = DriverManager.getConnection("jdbc:derby:wombat;shutdown=true");
-			} else {
-				TestUtil.shutdownUsingDataSource("wombat");
-			}
+			TestUtil.getConnection("wombat", "shutdown=true");
 		}catch(SQLException se)
 		{
 			if (se.getSQLState() != null && se.getSQLState().equals("08006"))
@@ -291,14 +242,7 @@
 
 		//now take a backup again , just to make all is well in the system.
 		try{
-			Connection conn;
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				conn = DriverManager.getConnection("jdbc:derby:wombat");
-			} else {
-				Properties prop = new Properties();
-				prop.setProperty("databaseName","wombat");
-				conn = TestUtil.getDataSourceConnection(prop);
-			}
+			Connection conn = TestUtil.getConnection("wombat", null);
 			
             CallableStatement backupStmt = conn.prepareCall(
                 "CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)");
@@ -309,11 +253,7 @@
 			Statement stmt = conn.createStatement();
 			stmt.execute("VALUES (ConsistencyChecker())");
 			conn.close();
-			if(TestUtil.HAVE_DRIVER_CLASS) {
-				conn = DriverManager.getConnection("jdbc:derby:wombat;shutdown=true");
-			} else {
-				TestUtil.shutdownUsingDataSource("wombat");
-			}
+			TestUtil.getConnection("wombat", "shutdown=true");
 		}catch(SQLException se)
 		{
 			if (se.getSQLState() != null && se.getSQLState().equals("08006"))

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java?rev=386216&r1=386215&r2=386216&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java Wed Mar 15 15:33:17 2006
@@ -750,26 +750,66 @@
      * @throws InstantiationException on failure to load driver.
      * @throws IllegalAccessException on failure to load driver.
      */
-    public static Connection getConnection(String databaseName, 
-    									   String connAttrs) 
-    	throws SQLException, ClassNotFoundException, 
-				InstantiationException, IllegalAccessException {
-    	
-    	Connection conn;
-    	if(TestUtil.HAVE_DRIVER_CLASS) {
-    		String driver = "org.apache.derby.jdbc.EmbeddedDriver";
-    		Class.forName(driver).newInstance();
-    		conn = DriverManager.getConnection("jdbc:derby:" + databaseName 
-												+ ";" + connAttrs );
+    public static Connection getConnection(String databaseName, String connAttrs)
+    	throws SQLException {
+        try {
+            Connection conn;
+            if(TestUtil.HAVE_DRIVER_CLASS) {
+                // following is like loadDriver(), but
+                // that method throws Exception, we want finer granularity
+                String driverName;
+                int framework = getFramework();
+                switch (framework)
+                {
+                    case EMBEDDED_FRAMEWORK:
+                        driverName =  "org.apache.derby.jdbc.EmbeddedDriver";
+                        break;
+                    case DERBY_NET_FRAMEWORK:
+                    case OLD_NET_FRAMEWORK:				
+                    case DB2JCC_FRAMEWORK:				
+                        driverName = "com.ibm.db2.jcc.DB2Driver";
+                        break;
+                    case DERBY_NET_CLIENT_FRAMEWORK:
+                        driverName = "org.apache.derby.jdbc.ClientDriver";
+                        break;
+                    default:
+                        driverName =  "org.apache.derby.jdbc.EmbeddedDriver";
+                        break;
+                } 
+                // q: do we need a privileged action here, like in loadDriver?
+                Class.forName(driverName).newInstance();
+				
+                String url = getJdbcUrlPrefix() + databaseName;
+                if (connAttrs != null) url += ";" + connAttrs;
+                if (framework == DERBY_NET_FRAMEWORK)
+                {
+                    if (( connAttrs == null) || ((connAttrs != null) && (connAttrs.indexOf("user") < 0)))
+                        url += ":" + "user=me;password=mine;retrieveMessagesFromServerOnGetMessage=true;";
+                }
+                conn = DriverManager.getConnection(url);
+    	    }
+    	    else {
+    		    //Use DataSource for JSR169
+	    	    Properties prop = new Properties();
+	            prop.setProperty("databaseName", databaseName);
+    		    if (connAttrs != null)
+	                prop.setProperty("connectionAttributes", connAttrs);
+	            conn = getDataSourceConnection(prop);
+    	    }
+            return conn;
+    	} catch (ClassNotFoundException cnfe) { 
+		    System.out.println("FAILure: Class not found!");
+		    cnfe.printStackTrace();
+		    return null;
+    	} catch (InstantiationException inste) {
+    		System.out.println("FAILure: Cannot instantiate class");
+    		inste.printStackTrace();
+    		return null;
+    	} catch (IllegalAccessException ille) {
+    		System.out.println("FAILure: Not allowed to use class");
+    		ille.printStackTrace();
+    		return null;
     	}
-    	else {
-    		//Use DataSource for JSR169
-	    	Properties prop = new Properties();
-	        prop.setProperty("databaseName", databaseName);
-	        prop.setProperty("connectionAttributes", connAttrs);
-	        conn = getDataSourceConnection(prop);
-    	}
-        return conn;
     }
     
     public static Connection getDataSourceConnection (Properties prop) throws SQLException {