GH-150 - Scenario now execute stimulus within new transaction.

To make sure that we trigger transactional event listeners from Scenario based integration tests, we trigger stimulus executions using transactions configured to require a new transaction. This makes sure that Scenarios work in integration tests using @Transactional, of course circumventing the default rollback behavior of those transactions. There's no other way to implement this as we *need* to commit a transaction to trigger the delivery of transaction-bound events.

Fixed a bug in the handling of Scenario.stimulus(Supplier<T>) as for this, the Supplier handed into the method had not been executed transactionally at all.
This commit is contained in:
Oliver Drotbohm
2023-02-26 20:26:53 +01:00
parent 47a8a7fa77
commit ce264aaf96
4 changed files with 45 additions and 30 deletions

View File

@@ -120,6 +120,10 @@ scenario.stimulate(() -> someBean.someMethod(…)).…
----
Both the event publication and bean invocation will happen within a transaction callback to make sure the given event or any ones published during the bean invocation will be delivered to transactional event listeners.
Note, that this will require a *new* transaction to be started, no matter whether the test case is already running inside a transaction or not.
In other words, state changes of the database triggered by the stimulus will *never* be rolled back and have to be cleaned up manually.
See the `….andCleanup(…)` methods for that purpose.
The resulting object can now get the execution customized though the generic `….customize(…)` method or specialized ones for common use cases like setting a timeout (`….waitAtMost(…)`).
The setup phase will be concluded by defining the actual expectation of the outcome of the stimulus.