db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1041339 - in /db/derby/code/branches/10.7: ./ java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java
Date Thu, 02 Dec 2010 11:46:46 GMT
Author: kahatlen
Date: Thu Dec  2 11:46:46 2010
New Revision: 1041339

URL: http://svn.apache.org/viewvc?rev=1041339&view=rev
Log:
DERBY-3258: 'Unexpected row count: expected:<0> but was:<3>' in testReleaseCompileLocks

Merged fix from trunk (revision 1041338).

Modified:
    db/derby/code/branches/10.7/   (props changed)
    db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java

Propchange: db/derby/code/branches/10.7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec  2 11:46:46 2010
@@ -1 +1 @@
-/db/derby/code/trunk:1035603,1036769,1038813,1039084,1039268,1040658
+/db/derby/code/trunk:1035603,1036769,1038813,1039084,1039268,1040658,1041338

Modified: db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java?rev=1041339&r1=1041338&r2=1041339&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java
(original)
+++ db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ReleaseCompileLocksTest.java
Thu Dec  2 11:46:46 2010
@@ -68,7 +68,13 @@ public class ReleaseCompileLocksTest ext
 	    	"parameter style java language java external name " +
 	    	"'org.apache.derbyTesting.functionTests.util.StaticInitializers." +
 	    	"InsertInStaticInitializer.getANumber' no sql");
-        
+
+        stmt.execute("CREATE PROCEDURE WAIT_FOR_POST_COMMIT() "
+                + "LANGUAGE JAVA EXTERNAL NAME "
+                + "'org.apache.derbyTesting.functionTests.util."
+                + "T_Access.waitForPostCommitToFinish' "
+                + "PARAMETER STYLE JAVA");
+
         stmt.close();
         commit();
 	}
@@ -115,9 +121,9 @@ public class ReleaseCompileLocksTest ext
     			JDBC.assertFullResultSet(stmt.executeQuery(
             		"select count(*) from sys.systables where " +
             		"CAST(tablename AS VARCHAR(128)) = 'SYSCONGLOMERATES'"), new String[][] {{"1"}});
-    			
 
-                JDBC.assertEmpty(stmt.executeQuery("select TYPE, MODE, TABLENAME, LOCKNAME,
STATE from syscs_diag.lock_table order by 1"));
+
+        assertNoLocks(stmt);
 		commit();
 
 		stmt.execute("drop table t1");
@@ -137,24 +143,25 @@ public class ReleaseCompileLocksTest ext
         		"select count(*) from sys.systables where " +
         		"CAST(tablename AS VARCHAR(128)) = 'SYSCONGLOMERATES'"), new String[][] {{"1"}});
 			
-                JDBC.assertEmpty(stmt.executeQuery("select TYPE, MODE, TABLENAME, LOCKNAME,
STATE from syscs_diag.lock_table order by 1"));
+        assertNoLocks(stmt);
 
 		JDBC.assertEmpty(stmt.executeQuery("select * from t1"));
 		stmt.execute("drop table t1");
 		commit();
-	
-		JDBC.assertEmpty(stmt.executeQuery("select TYPE, MODE, TABLENAME, LOCKNAME, STATE from
syscs_diag.lock_table order by 1"));
+
+        assertNoLocks(stmt);
 		commit();
 
 		stmt.execute("create table test_tab (x int)");
 		stmt.executeUpdate("insert into test_tab values (1)");
 		commit();
 
-		JDBC.assertSingleValueResultSet(stmt.executeQuery("select count(*) from syscs_diag.lock_table"),
"0");
+        assertNoLocks(stmt);
 		JDBC.assertSingleValueResultSet(stmt.executeQuery("select count(*) from sys.sysviews"),
"0");
-		JDBC.assertSingleValueResultSet(stmt.executeQuery("select count(*) from syscs_diag.lock_table"),
"0");
+        assertNoLocks(stmt);
 		stmt.execute("insert into test_tab values (2)");
 
+        waitForPostCommit(stmt);
                 ResultSet rs = stmt.executeQuery("select TYPE, MODE, TABLENAME, LOCKNAME,
STATE from syscs_diag.lock_table order by 1");
 		
 		String expectedValues[][] = {{"ROW", "X", "TEST_TAB", "(1,8)", "GRANT" }, {"TABLE", "IX",
"TEST_TAB", "Tablelock","GRANT"}};
@@ -188,9 +195,10 @@ public class ReleaseCompileLocksTest ext
 		ps.setCursorName("cursor1");
 		ps.setInt(1, 1);
 
-		JDBC.assertSingleValueResultSet(stmt.executeQuery("select count(*) from syscs_diag.lock_table"),
"0");
+        assertNoLocks(stmt);
 		ps.executeUpdate();
-		
+
+        waitForPostCommit(stmt);
 		rs = stmt.executeQuery("select TYPE, MODE, TABLENAME, LOCKNAME, STATE from syscs_diag.lock_table
order by 1");
 		String expectedValues1[][] = {{"ROW", "X", "TEST_TAB", "(1,7)", "GRANT" }, {"TABLE", "IX",
"TEST_TAB", "Tablelock","GRANT"}};
                 JDBC.assertFullResultSet(rs, expectedValues1);
@@ -204,7 +212,7 @@ public class ReleaseCompileLocksTest ext
 
 		ps = prepareStatement("select * from t where c1 = ? and c2 = ?");
 		ps.setCursorName("ps");
-		JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
+        assertNoLocks(stmt);
 
 		
 		stmt.execute("create table x(c1 int)");
@@ -213,7 +221,7 @@ public class ReleaseCompileLocksTest ext
 
 		ps = prepareStatement("insert into t values (3,2)");
 		ps.setCursorName("pi");
-		JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
+        assertNoLocks(stmt);
 		commit();
 
 
@@ -223,7 +231,7 @@ public class ReleaseCompileLocksTest ext
 
 		ps = prepareStatement("update t set c2 = c1, c1 = c2");
 		ps.setCursorName("p1");
-		JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
+        assertNoLocks(stmt);
 		commit();
 
 		
@@ -233,7 +241,7 @@ public class ReleaseCompileLocksTest ext
 
 		ps = prepareStatement("delete from t");
 		ps.setCursorName("p1");
-		JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
+        assertNoLocks(stmt);
 		commit();
 		
 		stmt.execute("create trigger update_of_t after update on t for each row values 2");
@@ -242,12 +250,33 @@ public class ReleaseCompileLocksTest ext
 	
 		ps = prepareStatement("update t set c2=2 where c1=2");
 		ps.setCursorName("pu");
-		JDBC.assertEmpty(stmt.executeQuery("select * from syscs_diag.lock_table"));
+        assertNoLocks(stmt);
 		commit();
 
 		rs.close();
 		ps.close();
 		stmt.close();
        }
-       
+
+    /**
+     * Assert that the lock table is empty.
+     * @param stmt the statement to use for querying the lock table
+     */
+    private void assertNoLocks(Statement stmt) throws SQLException {
+        // First make sure there are no locks held by the post-commit worker
+        // thread (DERBY-3258).
+        waitForPostCommit(stmt);
+
+        // Then verify that the lock table is empty.
+        JDBC.assertEmpty(
+                stmt.executeQuery("SELECT * FROM SYSCS_DIAG.LOCK_TABLE"));
+    }
+
+    /**
+     * Wait for post commit to finish.
+     * @param stmt the statement to use for invoking WAIT_FOR_POST_COMMIT
+     */
+    private void waitForPostCommit(Statement stmt) throws SQLException {
+        stmt.execute("CALL WAIT_FOR_POST_COMMIT()");
+    }
 }



Mime
View raw message