Skip to content

Commit d0b3a8a

Browse files
blafondDavideD
authored andcommitted
#1365 Add test case for ReactiveSession#clear
Signed-off-by: blafond <blafond@redhat.com>
1 parent c20a117 commit d0b3a8a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ private static String nameFromResult(List<Object> rowSet) {
5656
}
5757
}
5858

59+
@Test
60+
public void sessionClear(TestContext context) {
61+
final GuineaPig guineaPig = new GuineaPig( 81, "Perry" );
62+
test(
63+
context,
64+
getMutinySessionFactory().withSession( session -> session
65+
.persist( guineaPig )
66+
.invoke( session::clear )
67+
// If the previous clear doesn't work, this will cause a duplicated entity exception
68+
.chain( () -> session.persist( guineaPig ) )
69+
.call( session::flush )
70+
.chain( () -> session.createQuery( "FROM GuineaPig", GuineaPig.class )
71+
// By not using .find() we check that there is only one entity in the db with getSingleResult()
72+
.getSingleResult() )
73+
.invoke( result -> assertThatPigsAreEqual( context, guineaPig, result ) )
74+
)
75+
);
76+
}
77+
5978
@Test
6079
public void reactiveWithTransactionStatelessSession(TestContext context) {
6180
final GuineaPig guineaPig = new GuineaPig( 61, "Mr. Peanutbutter" );

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ public void reactiveFind(TestContext context) {
7676
);
7777
}
7878

79+
@Test
80+
public void sessionClear(TestContext context) {
81+
final GuineaPig guineaPig = new GuineaPig( 81, "Perry" );
82+
test(
83+
context,
84+
getSessionFactory().withSession( session -> session
85+
.persist( guineaPig )
86+
.thenAccept( v -> session.clear() )
87+
// If the previous clear doesn't work, this will cause a duplicated entity exception
88+
.thenCompose( v -> session.persist( guineaPig ) )
89+
.thenCompose( v -> session.flush() )
90+
.thenCompose( v -> session.createQuery( "FROM GuineaPig", GuineaPig.class )
91+
// By not using .find() we check that there is only one entity in the db with getSingleResult()
92+
.getSingleResult() )
93+
.thenAccept( result -> assertThatPigsAreEqual( context, guineaPig, result ) )
94+
)
95+
);
96+
}
97+
7998
@Test
8099
public void reactiveWithTransactionSession(TestContext context) {
81100
final GuineaPig guineaPig = new GuineaPig( 61, "Mr. Peanutbutter" );

0 commit comments

Comments
 (0)