Skip to content

Commit 50a8a39

Browse files
committed
Fix
1 parent fc1343f commit 50a8a39

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.hibernate.reactive;
77

8+
import java.util.concurrent.CompletableFuture;
89
import javax.persistence.Entity;
910
import javax.persistence.Id;
1011

@@ -14,6 +15,7 @@
1415

1516
import org.junit.Test;
1617

18+
import io.smallrye.mutiny.Uni;
1719
import io.vertx.core.Context;
1820
import io.vertx.core.Vertx;
1921
import io.vertx.ext.unit.Async;
@@ -53,7 +55,7 @@ public void testPersistWithStage(TestContext testContext) throws Exception {
5355
newContext.runOnContext( event -> test( async, testContext, session
5456
.persist( new Competition( "Cheese Rolling" ) )
5557
.thenCompose( v -> session.flush() )
56-
.handle( (v, e) -> assertExceptionThrown( e ) ) )
58+
.handle( (v, e) -> assertExceptionThrown( e ).join() ) )
5759
);
5860
}
5961

@@ -70,7 +72,7 @@ public void testFindWithStage(TestContext testContext) throws Exception {
7072
// Run test in the new context
7173
newContext.runOnContext( event -> test( async, testContext, session
7274
.find( Competition.class, "Chess boxing" )
73-
.handle( (v, e) -> assertExceptionThrown( e ) ) )
75+
.handle( (v, e) -> assertExceptionThrown( e ).join() ) )
7476
);
7577
}
7678

@@ -88,8 +90,8 @@ public void testOnPersistWithMutiny(TestContext testContext) throws Exception {
8890
newContext.runOnContext( event -> test( async, testContext, session
8991
.persist( new Competition( "Cheese Rolling" ) )
9092
.call( session::flush )
91-
.onItem().failWith( () -> new AssertionError( "No exception thrown" ) )
92-
.onFailure().recoverWithItem( e -> assertExceptionThrown( e ) ) )
93+
.onItemOrFailure()
94+
.transformToUni( (unused, e) -> Uni.createFrom().completionStage( assertExceptionThrown( e ) ) ) )
9395
);
9496
}
9597

@@ -106,22 +108,25 @@ public void testFindWithMutiny(TestContext testContext) throws Exception {
106108
// Run test in the new context
107109
newContext.runOnContext( event -> test( async, testContext, session
108110
.find( Competition.class, "Chess boxing" )
109-
.onItem().failWith( () -> new AssertionError( "No exception thrown" ) )
110-
.onFailure().recoverWithItem( e -> assertExceptionThrown( e ) ) )
111+
.onItemOrFailure()
112+
.transformToUni( (unused, e) -> Uni.createFrom().completionStage( assertExceptionThrown( e ) ) ) )
111113
);
112114
}
113115

114116
// Check that at least one exception has the expected message
115-
private static <T> T assertExceptionThrown(Throwable e) {
117+
private static CompletableFuture<Void> assertExceptionThrown(Throwable e) {
118+
CompletableFuture<Void> result = new CompletableFuture<>();
116119
Throwable t = e;
117120
while ( t != null ) {
118121
if ( t.getClass().equals( IllegalStateException.class )
119122
&& t.getMessage().contains( ERROR_MESSAGE ) ) {
120-
return null;
123+
result.complete( null );
124+
return result;
121125
}
122126
t = t.getCause();
123127
}
124-
throw new AssertionError( "Expected exception not thrown. Exception thrown: " + e );
128+
result.completeExceptionally( new AssertionError( "Expected exception not thrown. Exception thrown: " + e ) );
129+
return result;
125130
}
126131

127132
@Entity

0 commit comments

Comments
 (0)