From 582b360c15baa33586f15963931e390f718070f0 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 17 Feb 2010 22:26:51 +0000 Subject: Fix transaction attach/detach test. --- .../amazon/carbonado/txn/TestTransactionManager.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/test/java/com/amazon/carbonado') diff --git a/src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java b/src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java index be43b88..d226e8d 100644 --- a/src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java +++ b/src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java @@ -117,16 +117,23 @@ public class TestTransactionManager extends TestCase { txn2.exit(); + // Thread with txn2 was attached but is inactive, so txn thread can + // steal it. Exiting a top-level transaction implicitly detaches + // it. This can happen if a remote connection is dropped, but the + // thread which is automatically exiting the open transaction isn't the + // one which is attached. Detach is not allowed, so it can only exit. + txn.attach(); + try { - txn.attach(); + txn2.detach(); fail(); } catch (IllegalStateException e) { + // Cannot detach since attach was stolen. Throwing an exception + // here is the correct thing, since it indicates a bug in the + // application. The txn2 thread didn't detach properly and it let + // the txn thread try to get the transaction. } - txn.detach(); - - txn2.detach(); - txn.detach(); txn.attach(); txn.detach(); -- cgit v1.2.3