Skip to content

Commit a7dc0a1

Browse files
committed
[#2768] Update existing test
Now the test will throw an exception if context and connection aren't handled correctly.
1 parent a4c9b67 commit a7dc0a1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/MultithreadedInsertionWithLazyConnectionTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,13 @@ private CompletionStage<Void> storeEntity(Stage.Session s) {
197197
final EntityWithGeneratedId entity = new EntityWithGeneratedId();
198198
entity.name = beforeOperationThread + "__" + localVerticleOperationSequence;
199199

200+
// We are not using transactions on purpose here, because this approach will cause a context switch
201+
// and an assertion error if things aren't handled correctly. See Hibernate Reactive issue #2768:
202+
// https://github.com/hibernate/hibernate-reactive/issues/2768
200203
return s
201-
.withTransaction( t -> s.persist( entity ) )
204+
.persist( entity )
205+
.thenCompose( v -> s.flush() )
206+
.thenAccept( v -> s.clear() )
202207
.thenCompose( v -> beforeOperationThread != Thread.currentThread()
203208
? failedFuture( new IllegalStateException( "Detected an unexpected switch of carrier threads!" ) )
204209
: voidFuture() );

0 commit comments

Comments
 (0)