You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/09/30 17:17:35 UTC
[isis] branch master updated: ISIS-2033: verify each test runs in
its own interaction context
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 17b6f67 ISIS-2033: verify each test runs in its own interaction context
17b6f67 is described below
commit 17b6f6739354c6cf6410061af26afe863b393f5f
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Sep 30 19:17:27 2020 +0200
ISIS-2033: verify each test runs in its own interaction context
---
.../commons/InteractionBoundaryProbe.java | 30 +++++++++++++++-------
.../entitychangemetrics/ChangedObjectsTest.java | 20 +++++++++------
2 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/regressiontests/stable/src/test/java/org/apache/isis/testdomain/commons/InteractionBoundaryProbe.java b/regressiontests/stable/src/test/java/org/apache/isis/testdomain/commons/InteractionBoundaryProbe.java
index 2d20f0e..360019c 100644
--- a/regressiontests/stable/src/test/java/org/apache/isis/testdomain/commons/InteractionBoundaryProbe.java
+++ b/regressiontests/stable/src/test/java/org/apache/isis/testdomain/commons/InteractionBoundaryProbe.java
@@ -81,18 +81,30 @@ public class InteractionBoundaryProbe implements TransactionScopeListener {
return kvStoreForTesting.getCounter(InteractionBoundaryProbe.class, "txEnded");
}
- // -- ASSERTIONS
+ // -- ASSERTIONS (INTERACTIONAL)
- public static void assertTransactional(KVStoreForTesting kvStoreForTesting, Runnable runnable) {
+ public static void assertInteractional(KVStoreForTesting kvStoreForTesting, Runnable runnable) {
+ assertInteractional(kvStoreForTesting, ()->{ runnable.run(); return null; });
+ }
+
+ public static <T> T assertInteractional(KVStoreForTesting kvStoreForTesting, Supplier<T> supplier) {
- final long txStartCountBefore = totalTransactionsStarted(kvStoreForTesting);
- final long txEndCountBefore = totalTransactionsEnded(kvStoreForTesting);
- runnable.run();
- final long txStartCountAfter = totalTransactionsStarted(kvStoreForTesting);
- final long txEndCountAfter = totalTransactionsEnded(kvStoreForTesting);
+ final long iaStartCountBefore = totalInteractionsStarted(kvStoreForTesting);
+ final long iaEndCountBefore = totalInteractionsEnded(kvStoreForTesting);
+ val result = supplier.get();
+ final long iaStartCountAfter = totalInteractionsStarted(kvStoreForTesting);
+ final long iaEndCountAfter = totalInteractionsEnded(kvStoreForTesting);
- Assertions.assertEquals(1, txStartCountAfter - txStartCountBefore);
- Assertions.assertEquals(1, txEndCountAfter - txEndCountBefore);
+ Assertions.assertEquals(1, iaStartCountAfter - iaStartCountBefore);
+ Assertions.assertEquals(1, iaEndCountAfter - iaEndCountBefore);
+
+ return result;
+ }
+
+ // -- ASSERTIONS (TRANSACTIONAL)
+
+ public static void assertTransactional(KVStoreForTesting kvStoreForTesting, Runnable runnable) {
+ assertTransactional(kvStoreForTesting, ()->{ runnable.run(); return null; });
}
public static <T> T assertTransactional(KVStoreForTesting kvStoreForTesting, Supplier<T> supplier) {
diff --git a/regressiontests/stable/src/test/java/org/apache/isis/testdomain/entitychangemetrics/ChangedObjectsTest.java b/regressiontests/stable/src/test/java/org/apache/isis/testdomain/entitychangemetrics/ChangedObjectsTest.java
index e0b91e5..134197f 100644
--- a/regressiontests/stable/src/test/java/org/apache/isis/testdomain/entitychangemetrics/ChangedObjectsTest.java
+++ b/regressiontests/stable/src/test/java/org/apache/isis/testdomain/entitychangemetrics/ChangedObjectsTest.java
@@ -88,16 +88,20 @@ class ChangedObjectsTest extends InteractionTestAbstract {
// given
fixtureScripts.runPersona(JdoTestDomainPersona.InventoryWith1Book);
+ // each test runs in its own interaction context (check)
+ val testRunNr = kvStoreForTesting.incrementCounter(ChangedObjectsTest.class, "test-run");
+ assertEquals(testRunNr, InteractionBoundaryProbe.totalInteractionsStarted(kvStoreForTesting));
}
@Test
void wrapperInvocation_shouldSpawnSingleTransaction() {
-
+
// given
- val inventoryManager = factoryService.create(JdoInventoryManager.class);
// spawns its own transactional boundary (check)
val book = assertTransactional(kvStoreForTesting, this::getBookSample);
+ val inventoryManager = factoryService.create(JdoInventoryManager.class);
+
// spawns its own transactional boundary (check)
val product = assertTransactional(kvStoreForTesting,
@@ -108,6 +112,11 @@ class ChangedObjectsTest extends InteractionTestAbstract {
@Test
void actionInteraction_shouldSpawnSingleTransaction() {
+
+ // spawns its own transactional boundary (check)
+ val book = assertTransactional(
+ kvStoreForTesting,
+ this::getBookSample);
val managedAction = startActionInteractionOn(
JdoInventoryManager.class,
@@ -118,10 +127,6 @@ class ChangedObjectsTest extends InteractionTestAbstract {
assertFalse(managedAction.checkVisibility().isPresent()); // is visible
assertFalse(managedAction.checkUsability().isPresent()); // can invoke
- // spawns its own transactional boundary (check)
- val book = assertTransactional(
- kvStoreForTesting,
- this::getBookSample);
val args = managedAction.getInteractionHead()
.getPopulatedParameterValues(_Lists.of(book, 12.));
@@ -133,8 +138,7 @@ class ChangedObjectsTest extends InteractionTestAbstract {
val product = (JdoProduct)either.leftIfAny().getPojo();
- assertEquals(12., product.getPrice(), 1E-3);
-
+ assertEquals(12., product.getPrice(), 1E-3);
}
// -- HELPER