You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2016/10/05 09:46:50 UTC
[5/8] isis git commit: ISIS-1508: makes the clean up functionality
within IsisTransactionRule (as used by integ tests) more robust to a badly
behaving test.
ISIS-1508: makes the clean up functionality within IsisTransactionRule (as used by integ tests) more robust to a badly behaving test.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/89886e0c
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/89886e0c
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/89886e0c
Branch: refs/heads/maint-1.13.1
Commit: 89886e0c1743f66d625078200071928d1975e9a6
Parents: f3f53f6
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Sep 30 09:03:59 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Sep 30 09:11:32 2016 +0100
----------------------------------------------------------------------
.../IntegrationTestAbstract.java | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/89886e0c/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java
index c9ee2ea..935577d 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java
@@ -39,6 +39,7 @@ import org.apache.isis.applib.services.scratchpad.Scratchpad;
import org.apache.isis.applib.services.sessmgmt.SessionManagementService;
import org.apache.isis.applib.services.wrapper.WrapperFactory;
import org.apache.isis.applib.services.xactn.TransactionService;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
import org.apache.isis.core.specsupport.scenarios.ScenarioExecution;
import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
@@ -214,6 +215,10 @@ public abstract class IntegrationTestAbstract {
isft.endTran();
isft.nextSession();
} catch(final Throwable e) {
+
+ // if test failed to clean up after itself, then take care of it here.
+ endTransactionTilDone();
+
isft.nextSession();
final List<Throwable> causalChain = Throwables.getCausalChain(e);
// if underlying cause is an applib-defined exception, throw that rather than Isis' wrapper exception
@@ -226,6 +231,21 @@ public abstract class IntegrationTestAbstract {
throw e;
}
}
+
+ protected void endTransactionTilDone() {
+ IsisTransactionManager tranMgr = isft.getIsisSessionFactory().getCurrentSession()
+ .getPersistenceSession().getTransactionManager();
+ int count = 0;
+ while(tranMgr.getTransactionLevel() > 0 &&
+ count++ < 10 // just in case, to prevent an infinite loop...
+ ) {
+ try {
+ tranMgr.endTransaction();
+ } catch(Exception ignore) {
+ // ignore
+ }
+ }
+ }
};
}
}