db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1060832 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/engine/LockInterruptTest.java junit/BaseTestCase.java
Date Wed, 19 Jan 2011 14:57:43 GMT
Author: dag
Date: Wed Jan 19 14:57:42 2011
New Revision: 1060832

URL: http://svn.apache.org/viewvc?rev=1060832&view=rev
Log:
DERBY-4967 Handle interrupt received while waiting for database lock

Patch derby-4967-locking-4 which makes the existing test
LockInterruptTest assert that the interrupt flag is set when we see
08000 (CONN_INTERRUPT) - in accordance with the behavior we expect
after DERBY-4741. The assert is skipped on Solaris/Sun Java <= 1.6
unless the flag -XX:-UseVMInterruptibleIO is used.


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/LockInterruptTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/LockInterruptTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/LockInterruptTest.java?rev=1060832&r1=1060831&r2=1060832&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/LockInterruptTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/LockInterruptTest.java
Wed Jan 19 14:57:42 2011
@@ -108,6 +108,16 @@ public class LockInterruptTest extends B
         }
         assertSQLState(INTERRUPTED, (SQLException) e1);
 
+        if (hasInterruptibleIO()) {
+            println("Skipping assert for t1.InterruptFlagSetOnThrow due " +
+                    " to interruptible IO.");
+            println("This is default on Solaris/Sun Java <= 1.6, use " +
+                    "-XX:-UseVMInterruptibleIO if available.");
+            // The flag will may get swallowed
+        } else {
+            assertTrue(t1.InterruptFlagSetOnThrow);
+        }
+
         // The second thread should be able to complete successfully.
         Throwable e2 = t2.throwable;
         if (e2 != null) {
@@ -137,6 +147,7 @@ public class LockInterruptTest extends B
         private final PreparedStatement ps;
 
         private Throwable throwable;
+        private boolean InterruptFlagSetOnThrow;
         private long elapsedTime;
 
         private Waiter() throws SQLException {
@@ -149,6 +160,7 @@ public class LockInterruptTest extends B
                 runWaiter();
             } catch (Throwable t) {
                 throwable = t;
+                InterruptFlagSetOnThrow = interrupted(); // clears also
             }
         };
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1060832&r1=1060831&r2=1060832&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Wed Jan
19 14:57:42 2011
@@ -37,6 +37,8 @@ import java.io.OutputStream;
 import java.io.Reader;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.io.InterruptedIOException;
+import java.io.RandomAccessFile;
 import java.net.URL;
 import java.sql.SQLException;
 import java.security.AccessController;
@@ -590,7 +592,63 @@ public abstract class BaseTestCase
         return "Sun Microsystems Inc.".equals(vendor) ||
                 "Oracle Corporation".equals(vendor);
     }
-    
+
+    /**
+     * Check if we have old style (before Sun Java 1.7) Solaris interruptible
+     * IO. On Sun Java 1.5 >= update 22 and Sun Java 1.6 this can be disabled
+     * with Java option {@code -XX:-UseVMInterruptibleIO}. On Sun Java 1.7 it
+     * is by default disabled.
+     *
+     * @return true if we have old style interruptible IO
+     */
+    public static final boolean hasInterruptibleIO()
+            throws Exception {
+
+
+        boolean interruptibleIO = false;
+
+        try {
+            AccessController.doPrivileged(
+                new PrivilegedExceptionAction() {
+                    public Object run() throws
+                        IOException, InterruptedIOException {
+
+                        TestConfiguration curr = TestConfiguration.getCurrent();
+
+                        String sysHome = getSystemProperty("derby.system.home");
+
+                        StringBuffer arbitraryRAFFileName = new StringBuffer();
+
+                        arbitraryRAFFileName.append(sysHome);
+                        arbitraryRAFFileName.append(File.separatorChar);
+                        arbitraryRAFFileName.append("derby.log");
+
+                        RandomAccessFile f = new RandomAccessFile(
+                            arbitraryRAFFileName.toString(), "r");
+
+                        try {
+                            Thread.currentThread().interrupt();
+                            f.read();
+                        } finally {
+                            Thread.interrupted(); // clear flag
+                            f.close();
+                        }
+
+                        return null;
+                    }});
+        } catch (PrivilegedActionException e) {
+            if (e.getCause() instanceof InterruptedIOException) {
+                interruptibleIO = true;
+            } else {
+                throw e;
+            }
+
+        }
+
+        return interruptibleIO;
+    }
+
+
     public static final boolean isIBMJVM() {
         return ("IBM Corporation".equals(
                 getSystemProperty("java.vendor")));



Mime
View raw message