db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r354523 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store: OnlineBackup.java OnlineBackupTest1.java
Date Tue, 06 Dec 2005 19:47:38 GMT
Author: mikem
Date: Tue Dec  6 11:47:31 2005
New Revision: 354523

URL: http://svn.apache.org/viewcvs?rev=354523&view=rev
Log:
DERBY-239, fixing onlinebackuptest1.

committing on behalf of Suresh Thalamati.

This pacth  fixes store/onlineBackupTest1.java failure on non-windows envirorment.   Problem
 was  unlogged operations thread and insert thread are working on the  same connection. Test
was failing becuase  insert thread  was committing the unlogged operation that was suppose
to block the backup. 
This pacth modified the test , so that  these threads works on different conenctions, 
 

 Test passed on Windows XP and Linuix. 


Modified:
    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

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=354523&r1=354522&r2=354523&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
Tue Dec  6 11:47:31 2005
@@ -19,10 +19,11 @@
  */
 
 package org.apache.derbyTesting.functionTests.tests.store;
-import java.sql.DriverManager;
 import java.sql.Connection;
 import java.sql.CallableStatement;
 import java.sql.SQLException;
+import java.util.Properties;
+import org.apache.derbyTesting.functionTests.util.TestUtil;
 
 /**
  * This class provides  functionalty for tests to perform 
@@ -65,7 +66,7 @@
 	 * Backup the database
 	 */
 	void performBackup() throws SQLException {
-		Connection conn = DriverManager.getConnection("jdbc:derby:"+ dbName);
+        Connection conn = getConnection(dbName , "");
 		CallableStatement backupStmt = 	
 			conn.prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)");
 		backupStmt.setString(1, backupPath);
@@ -126,7 +127,7 @@
 	 * @return     <tt>true</tt> if backup is running.
 	 *             <tt>false</tt> otherwise.
 	 */
-	public boolean isRunning() {
+	public synchronized boolean isRunning() {
 		return beginBackup;
 	}
 	
@@ -135,23 +136,45 @@
 	 * @param  newDbName   name of the database to be created.
 	 */
 	public void createFromBackup(String newDbName) throws SQLException {
-		Connection conn = 
-			DriverManager.getConnection("jdbc:derby:"+ newDbName + ";" +  
-										"createFrom=" + backupPath + "/" + 
-										dbName);
-		conn.close();
-	}
+		
+        Connection conn = getConnection(newDbName,  
+                                        "createFrom=" +
+                                        backupPath + "/" + 
+                                        dbName);
+        conn.close();
+        
+    }
 
 	
-	/**
-	 * Restore the  database from the backup copy taken earlier.
-	 */
-	public void restoreFromBackup() throws SQLException {
-		Connection conn = 
-			DriverManager.getConnection("jdbc:derby:"+ dbName + ";" +
-										"restoreFrom=" + backupPath + "/" + 
-										dbName);
+    /**
+     * Restore the  database from the backup copy taken earlier.
+     */
+    public void restoreFromBackup() throws SQLException {
+       
+        Connection conn = 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 
+    {
+        Properties prop = new Properties();
+        prop.setProperty("databaseName", databaseName);
+        prop.setProperty("connectionAttributes", connAttrs);
+        Connection 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=354523&r1=354522&r2=354523&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
Tue Dec  6 11:47:31 2005
@@ -24,8 +24,9 @@
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.DriverManager;
 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
@@ -77,13 +78,17 @@
 		backup.waitForBackupToBegin();
 		logMessage("BACKUP STARTED");
 
-		// run some dml actions in another thread
-		DatabaseActions dmlActions = new DatabaseActions(DatabaseActions.DMLACTIONS, conn);
+        // run some dml actions in another thread
+        Connection dmlConn = getConnection();
+        DatabaseActions dmlActions = 
+            new DatabaseActions(DatabaseActions.DMLACTIONS, dmlConn);
 		Thread dmlThread = new Thread(dmlActions, "DML_THREAD");
 		dmlThread.start();
 
-		// run some DDL create/drop tables in another thread
-		DatabaseActions ddlActions = new DatabaseActions(DatabaseActions.CREATEDROPS, conn);
+        // run some DDL create/drop tables in another thread
+        Connection ddlConn = getConnection();
+		DatabaseActions ddlActions = 
+            new DatabaseActions(DatabaseActions.CREATEDROPS, ddlConn);
 		Thread ddlThread = new Thread(ddlActions, "DDL_THREAD");
 		ddlThread.start();
 
@@ -105,6 +110,11 @@
 		ddlActions.stopActivity();
 		dmlThread.join();
 		ddlThread.join();
+        
+        // close the connections.
+        conn.close();
+        dmlConn.close();
+        ddlConn.close() ;
 
 		//shutdown the test db 
 		shutdown(TEST_DATABASE_NAME);
@@ -125,7 +135,7 @@
 	 * @param  dbName  consistency checks are performed on this database.
 	 */
 	void runConsistencyChecker(String dbName) throws SQLException {
-		Connection conn = DriverManager.getConnection("jdbc:derby:" + dbName);
+        Connection conn = getConnection();
 		Statement stmt = conn.createStatement();
 		stmt.execute("values SYSCS_UTIL.SYSCS_CHECK_TABLE('APP',  'EMP')");
 		//TO DO : Consistency check all the tables including the system tables. 
@@ -143,8 +153,7 @@
 
 		try{
 			// shutdown 
-			Connection conn = 
-				DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true");
+            TestUtil.shutdownUsingDataSource(TEST_DATABASE_NAME);
 		}catch(SQLException se){
 			if (se.getSQLState() != null && se.getSQLState().equals("08006"))
 				System.out.println("database shutdown properly");
@@ -152,6 +161,18 @@
 				dumpSQLException(se);
 		}
 	}
+
+    /*
+     * get connection to the test database
+     */
+    Connection getConnection() throws SQLException 
+    {
+        Properties prop = new Properties();
+        prop.setProperty("databaseName", TEST_DATABASE_NAME);
+        Connection conn = TestUtil.getDataSourceConnection(prop);
+        return conn;
+    }
+
 
 	/**
 	 * Write message to the standard output.



Mime
View raw message