Skip to content

Commit 08d0afe

Browse files
committed
[#2139] Add test for upsert with batching
1 parent 5742b0d commit 08d0afe

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

+63-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hibernate.cfg.AvailableSettings;
1010
import org.hibernate.cfg.Configuration;
1111
import org.hibernate.reactive.BaseReactiveTest;
12+
import org.hibernate.reactive.annotations.EnabledFor;
1213
import org.hibernate.reactive.stage.Stage;
1314
import org.hibernate.reactive.testing.SqlStatementTracker;
1415

@@ -28,6 +29,7 @@
2829

2930
import static java.util.concurrent.TimeUnit.MINUTES;
3031
import static org.assertj.core.api.Assertions.assertThat;
32+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL;
3133

3234
/**
3335
* Test the stateless session actually execute the operations in batch.
@@ -87,7 +89,7 @@ protected void addServices(StandardServiceRegistryBuilder builder) {
8789
}
8890

8991
private static boolean filter(String s) {
90-
String[] accepted = { "insert ", "update ", "delete " };
92+
String[] accepted = { "merge ", "insert ", "update ", "delete " };
9193
for ( String valid : accepted ) {
9294
if ( s.toLowerCase().startsWith( valid ) ) {
9395
return true;
@@ -96,6 +98,66 @@ private static boolean filter(String s) {
9698
return false;
9799
}
98100

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

0 commit comments

Comments
 (0)