diff options
| author | Brian S. O'Neill <bronee@gmail.com> | 2009-01-20 05:30:43 +0000 |
|---|---|---|
| committer | Brian S. O'Neill <bronee@gmail.com> | 2009-01-20 05:30:43 +0000 |
| commit | a312d026a3e5f46928050714e94d4d5e52054da3 (patch) | |
| tree | 021402d2e1169f0d36e56211003dfb2e0a637562 /src/test/java/com/amazon/carbonado | |
| parent | 3f0d660904c9ac49694a69f2c77fafca4f9af56d (diff) | |
Ensure that exited transaction cleans up the local scope even when an exception is thrown.
Diffstat (limited to 'src/test/java/com/amazon/carbonado')
| -rw-r--r-- | src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java b/src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java index 360a34d..be43b88 100644 --- a/src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java +++ b/src/test/java/com/amazon/carbonado/txn/TestTransactionManager.java @@ -134,7 +134,41 @@ public class TestTransactionManager extends TestCase { es.shutdown();
}
+ public void testBrokenRollback() throws Exception {
+ TransactionScope<Txn> scope = mTxnMgr.localScope();
+ Transaction txn = scope.enter(null);
+ Txn t = scope.getTxn();
+ t.doFail = true;
+
+ try {
+ txn.exit();
+ fail();
+ } catch (Exception e) {
+ }
+
+ Transaction txn2 = scope.enter(null);
+ Txn t2 = scope.getTxn();
+
+ // If not null, then exception thrown while exiting previous
+ // transaction did not properly clean up. As a result, new transaction
+ // is nested.
+ assertNull(t2.parent);
+ }
+
private static class Txn {
+ final Txn parent;
+
+ volatile boolean doFail;
+
+ Txn(Txn parent) {
+ this.parent = parent;
+ }
+
+ void abort() {
+ if (doFail) {
+ throw new IllegalStateException("fail");
+ }
+ }
}
private static class TM extends TransactionManager<Txn> {
@@ -147,7 +181,7 @@ public class TestTransactionManager extends TestCase { }
protected Txn createTxn(Txn parent, IsolationLevel level) {
- return new Txn();
+ return new Txn(parent);
}
protected boolean commitTxn(Txn txn) {
@@ -155,6 +189,7 @@ public class TestTransactionManager extends TestCase { }
protected void abortTxn(Txn txn) {
+ txn.abort();
}
}
}
|
