forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hibernate Reactive Panache: fix WithSessionOnDemand implementation
- fixes quarkusio#35568
- Loading branch information
Showing
3 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ent/src/test/java/io/quarkus/hibernate/reactive/panache/test/WithSessionOnDemandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.hibernate.reactive.panache.test; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.hibernate.reactive.mutiny.Mutiny.Session; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.hibernate.reactive.panache.Panache; | ||
import io.quarkus.hibernate.reactive.panache.common.WithSessionOnDemand; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.vertx.RunOnVertxContext; | ||
import io.quarkus.test.vertx.UniAsserter; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class WithSessionOnDemandTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root.addClasses(MrBean.class, MyEntity.class)); | ||
|
||
@Inject | ||
MrBean bean; | ||
|
||
@RunOnVertxContext | ||
@Test | ||
public void testSharedSession(UniAsserter asserter) { | ||
asserter.assertEquals(() -> bean.ping(), "true"); | ||
} | ||
|
||
@Unremovable | ||
@ApplicationScoped | ||
static class MrBean { | ||
|
||
@WithSessionOnDemand | ||
Uni<String> ping() { | ||
Uni<Session> s1 = Panache.getSession(); | ||
Uni<Session> s2 = Panache.getSession(); | ||
// Test that both unis receive the same session | ||
return s1.chain(s1Val -> s2.map(s2Val -> "" + (s1Val == s2Val))); | ||
} | ||
|
||
} | ||
} |