db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1066707 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java
Date Thu, 03 Feb 2011 00:20:25 GMT
Author: dag
Date: Thu Feb  3 00:20:25 2011
New Revision: 1066707

URL: http://svn.apache.org/viewvc?rev=1066707&view=rev
Log:
DERBY-4741 Make embedded Derby work reliably in the presence of thread interrupts

Patch derby-4741-testBatchInterrupt-b:

It tests that an interrupt will stop a batch of statements by throwing
08000 just before we execute the next statement in the batch.


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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java?rev=1066707&r1=1066706&r2=1066707&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/InterruptResilienceTest.java
Thu Feb  3 00:20:25 2011
@@ -507,7 +507,6 @@ public class InterruptResilienceTest ext
             // assertTrue(c.isClosed()); // DERBY-4993
             assertTrue(Thread.interrupted());
         }
-
     }
 
     // Test that query if interrupted will get stopped as expected in
@@ -531,4 +530,68 @@ public class InterruptResilienceTest ext
         }
 
     }
+
+
+    // We do the actual test inside a stored procedure so we can test this for
+    // client/server as well, otherwise we would just interrupt the client
+    // thread. This SP correponds to #testInterruptBatch
+    public static void tstInterruptBatch() throws Exception {
+        Connection c = DriverManager.getConnection("jdbc:default:connection");
+        Statement s = c.createStatement();
+        s.executeUpdate("create table tmp(i int)");
+        PreparedStatement ps = c.prepareStatement("insert into tmp values (?)");
+
+        // fill batch:
+        for (int i=0; i < 10; i++) {
+            s.addBatch("insert into tmp values (" + i + ")");
+        }
+
+        s.executeBatch(); // should work OK, since no interrupt present
+
+        // refill batch:
+        for (int i=0; i < 10; i++) {
+            s.addBatch("insert into tmp values (" + i + ")");
+        }
+
+        try {
+            Thread.currentThread().interrupt();
+            s.executeBatch();
+            fail("expected CONN_INTERRUPT");
+        } catch (SQLException e) {
+            assertSQLState("expected CONN_INTERRUPT", "08000", e);
+            // assertTrue(c.isClosed()); // DERBY-4993
+            assertTrue(Thread.interrupted());
+        }
+    }
+
+
+    // Test that batched statements, if interrupted, will get stopped as
+    // expected.
+    public void testInterruptBatch() throws SQLException {
+        Connection c = getConnection();
+        Statement s = createStatement();
+        setAutoCommit(false);
+
+        s.executeUpdate(
+            "create procedure tstInterruptBatch() " +
+            "modifies sql data " +
+            "external name 'org.apache.derbyTesting.functionTests" +
+            ".tests.store.InterruptResilienceTest" +
+            ".tstInterruptBatch' " +
+            "language java parameter style java");
+        try {
+            s.executeUpdate("call tstInterruptBatch()");
+            fail("expected 40XC0 exception");
+        } catch (SQLException e) {
+            assertSQLState("expected 40XC0", "40XC0", e); // dead statement
+            assertTrue(c.isClosed());
+        }
+
+        setAutoCommit(false);
+        s = createStatement();
+        // The table created inside stored routine should be gone:
+        s.executeUpdate("create table tmp(i int)");
+        rollback();
+
+    }
 }



Mime
View raw message