Skip to content

Commit 2acd894

Browse files
committed
[#2139] Add test for upsert with batching
1 parent 55ed2a1 commit 2acd894

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
99
import org.hibernate.cfg.Configuration;
1010
import org.hibernate.reactive.BaseReactiveTest;
11+
import org.hibernate.reactive.annotations.EnabledFor;
1112
import org.hibernate.reactive.testing.SqlStatementTracker;
1213

1314
import org.junit.jupiter.api.BeforeEach;
@@ -26,6 +27,7 @@
2627

2728
import static java.util.concurrent.TimeUnit.MINUTES;
2829
import static org.assertj.core.api.Assertions.assertThat;
30+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL;
2931

3032
/**
3133
* Test the stateless session actually execute the operations in batch.
@@ -85,7 +87,7 @@ protected void addServices(StandardServiceRegistryBuilder builder) {
8587
}
8688

8789
private static boolean filter(String s) {
88-
String[] accepted = { "insert ", "update ", "delete " };
90+
String[] accepted = { "merge ", "insert ", "update ", "delete " };
8991
for ( String valid : accepted ) {
9092
if ( s.toLowerCase().startsWith( valid ) ) {
9193
return true;
@@ -94,6 +96,66 @@ private static boolean filter(String s) {
9496
return false;
9597
}
9698

99+
@Test
100+
@EnabledFor(POSTGRESQL)
101+
public void testMutinyMergeUpsertAll(VertxTestContext context) {
102+
test( context, getMutinySessionFactory()
103+
.withStatelessTransaction( s -> s.upsertAll( PIGS ) )
104+
.invoke( () -> assertSqlLogTracker( "merge into pig as t using (.*)" ) )
105+
.chain( () -> Uni.createFrom().completionStage( assertExpectedResult( PIGS ) ) )
106+
);
107+
}
108+
109+
@Test
110+
@EnabledFor(POSTGRESQL)
111+
public void testMutinyMergeUpsertAllWithBatchSize(VertxTestContext context) {
112+
test( context, getMutinySessionFactory()
113+
.withStatelessTransaction( s -> s.upsertAll( 10, PIGS ) )
114+
.invoke( () -> assertSqlLogTracker( "merge into pig as t using (.*)" ) )
115+
.chain( () -> Uni.createFrom().completionStage( assertExpectedResult( PIGS ) ) )
116+
);
117+
}
118+
119+
@Test
120+
@EnabledFor(POSTGRESQL)
121+
public void testMutinyMergeUpsertMultiple(VertxTestContext context) {
122+
test( context, getMutinySessionFactory()
123+
.withStatelessTransaction( s -> s.upsertMultiple( List.of( PIGS ) ) )
124+
.invoke( () -> assertSqlLogTracker( "merge into pig as t using (.*)" ) )
125+
.chain( () -> Uni.createFrom().completionStage( assertExpectedResult( PIGS ) ) )
126+
);
127+
}
128+
129+
@Test
130+
@EnabledFor(POSTGRESQL)
131+
public void testStageMergeUpsertAll(VertxTestContext context) {
132+
test( context, getSessionFactory()
133+
.withStatelessTransaction( s -> s.upsertAll( PIGS ) )
134+
.thenRun( () -> assertSqlLogTracker( "merge into pig as t using (.*)" ) )
135+
.thenCompose( v -> assertExpectedResult( PIGS ) )
136+
);
137+
}
138+
139+
@Test
140+
@EnabledFor(POSTGRESQL)
141+
public void testStageMergeUpsertAllWithBatchSize(VertxTestContext context) {
142+
test( context, getSessionFactory()
143+
.withStatelessTransaction( s -> s.upsertAll( 10, PIGS ) )
144+
.thenRun(() -> assertSqlLogTracker( "merge into pig as t using (.*)" ) )
145+
.thenCompose( v -> assertExpectedResult( PIGS ) )
146+
);
147+
}
148+
149+
@Test
150+
@EnabledFor(POSTGRESQL)
151+
public void testStageMergeUpsertMultiple(VertxTestContext context) {
152+
test( context, getSessionFactory()
153+
.withStatelessTransaction( s -> s.upsertMultiple( List.of( PIGS ) ) )
154+
.thenRun( () -> assertSqlLogTracker( "merge into pig as t using (.*)" ) )
155+
.thenCompose( v -> assertExpectedResult( PIGS ) )
156+
);
157+
}
158+
97159
@Test
98160
public void testMutinyBatchingInsert(VertxTestContext context) {
99161
test( context, getMutinySessionFactory()

0 commit comments

Comments
 (0)