db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1136844 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/IndexSplitDeadlockTest.java
Date Fri, 17 Jun 2011 11:23:53 GMT
Author: kahatlen
Date: Fri Jun 17 11:23:53 2011
New Revision: 1136844

URL: http://svn.apache.org/viewvc?rev=1136844&view=rev
Log:
DERBY-5278: AssertionFailedError in IndexSplitDeadlockTest.testBTreeForwardScan_fetchRows_resumeAfterWait_unique_split()

Made synchronization between threads more reliable with wait/notify instead of sleep.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/IndexSplitDeadlockTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/IndexSplitDeadlockTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/IndexSplitDeadlockTest.java?rev=1136844&r1=1136843&r2=1136844&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/IndexSplitDeadlockTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/IndexSplitDeadlockTest.java
Fri Jun 17 11:23:53 2011
@@ -359,6 +359,13 @@ public class IndexSplitDeadlockTest exte
         }
         commit();
 
+        // Object used for synchronization between the main thread and the
+        // helper thread. The main thread should increment the value to tell
+        // the helper thread that it's ready to start the index scan. The
+        // helper thread should increment it to tell the main thread that it
+        // has locked row 40 and is ready to insert more values.
+        final int[] syncObject = new int[1];
+
         // Lock a row on the first page in a different thread to stop the
         // index scan. Then split the first leaf by inserting many values
         // less than zero.
@@ -368,11 +375,24 @@ public class IndexSplitDeadlockTest exte
                 Statement s = conn.createStatement();
                 s.executeUpdate("update t set x = x where x = 40");
                 s.close();
-                // Give the index scan time to start and position on
-                // the row we have locked. (Give it two seconds, since the
-                // main thread sleeps for one second first before it starts
-                // the index scan.)
-                Thread.sleep(2000);
+
+                synchronized (syncObject) {
+                    // Tell the main thread that we've locked the row and that
+                    // it can go ahead with the index scan.
+                    syncObject[0]++;
+                    syncObject.notifyAll();
+
+                    // Wait here until the main thread is actually ready to
+                    // start the scan.
+                    while (syncObject[0] < 2) {
+                        syncObject.wait();
+                    }
+                }
+
+                // The main thread is ready to start the index scan. Give it a
+                // second to get to the row we have locked.
+                Thread.sleep(1000L);
+
                 // Split the first leaf
                 PreparedStatement ps = conn.prepareStatement(
                         "insert into t values ?");
@@ -385,13 +405,24 @@ public class IndexSplitDeadlockTest exte
             }
         });
 
-        // Give the other thread time to obtain the lock
-        Thread.sleep(1000);
+        // Prepare the index scan.
+        PreparedStatement scan = prepareStatement(
+                "select * from t --DERBY-PROPERTIES constraint=C");
+
+        synchronized (syncObject) {
+            // Tell the helper thread we're ready to start the scan.
+            syncObject[0]++;
+            syncObject.notifyAll();
+
+            // Wait until the helper thread has obtained the lock.
+            while (syncObject[0] < 2) {
+                syncObject.wait();
+            }
+        }
 
         // Perform an index scan. Will be blocked for a while when fetching
-        // the row where x=100, but should be able to resume the scan.
-        ResultSet rs = s.executeQuery(
-                "select * from t --DERBY-PROPERTIES constraint=C");
+        // the row where x=40, but should be able to resume the scan.
+        ResultSet rs = scan.executeQuery();
         for (int i = 0; i < 300; i++) {
             assertTrue(rs.next());
             assertEquals(i, rs.getInt(1));



Mime
View raw message