|
17 | 17 | import org.junit.jupiter.api.BeforeEach;
|
18 | 18 | import org.junit.jupiter.api.Test;
|
19 | 19 |
|
| 20 | +import io.smallrye.mutiny.Uni; |
20 | 21 | import io.vertx.junit5.Timeout;
|
21 | 22 | import io.vertx.junit5.VertxTestContext;
|
22 | 23 | import jakarta.persistence.Entity;
|
|
32 | 33 | import static java.util.concurrent.TimeUnit.MINUTES;
|
33 | 34 | import static org.assertj.core.api.Assertions.assertThat;
|
34 | 35 | import static org.hibernate.reactive.testing.ReactiveAssertions.assertThrown;
|
| 36 | +import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture; |
35 | 37 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
36 | 38 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
37 | 39 |
|
@@ -61,6 +63,31 @@ public void populateDB(VertxTestContext context) {
|
61 | 63 | test( context, getSessionFactory().withTransaction( session -> session.persist( artemisia, liuto, sev ) ) );
|
62 | 64 | }
|
63 | 65 |
|
| 66 | + @Test |
| 67 | + public void testLazyInitializationExceptionWithTransactionWithMutiny(VertxTestContext context) { |
| 68 | + test( context, assertThrown( LazyInitializationException.class, getMutinySessionFactory() |
| 69 | + .withSession( ms -> ms |
| 70 | + .createSelectionQuery( "from Artist", Artist.class ) |
| 71 | + .getSingleResult() ) |
| 72 | + .call( artist -> getMutinySessionFactory().withTransaction( s -> Uni.createFrom() |
| 73 | + // .size should throw LazyInitializationException |
| 74 | + .item( artist.getPaintings().size() ) ) ) |
| 75 | + ) |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testLazyInitializationExceptionWithTransactionWithStage(VertxTestContext context) { |
| 81 | + test( context, assertThrown( LazyInitializationException.class, getSessionFactory() |
| 82 | + .withSession( ss -> ss |
| 83 | + .createSelectionQuery( "from Artist", Artist.class ) |
| 84 | + .getSingleResult() ) |
| 85 | + .thenCompose( artist -> getSessionFactory() |
| 86 | + .withTransaction( s -> completedFuture( artist.getPaintings().size() ) ) ) |
| 87 | + ) |
| 88 | + ); |
| 89 | + } |
| 90 | + |
64 | 91 | @Test
|
65 | 92 | public void testLazyInitializationExceptionWithMutiny(VertxTestContext context) {
|
66 | 93 | test( context, assertThrown( LazyInitializationException.class, openMutinySession()
|
|
0 commit comments