Skip to content

Commit 01ebf2c

Browse files
committed
[#2768] Test batching with ProxyConnection
1 parent dd2457e commit 01ebf2c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
99
import org.hibernate.cfg.AvailableSettings;
1010
import org.hibernate.cfg.Configuration;
11+
import org.hibernate.reactive.mutiny.Mutiny;
1112
import org.hibernate.reactive.mutiny.impl.MutinySessionImpl;
1213
import org.hibernate.reactive.mutiny.impl.MutinyStatelessSessionImpl;
1314
import org.hibernate.reactive.pool.BatchingConnection;
1415
import org.hibernate.reactive.pool.ReactiveConnection;
1516
import org.hibernate.reactive.pool.impl.SqlClientConnection;
17+
import org.hibernate.reactive.stage.Stage;
1618
import org.hibernate.reactive.stage.impl.StageSessionImpl;
1719
import org.hibernate.reactive.stage.impl.StageStatelessSessionImpl;
1820
import org.hibernate.reactive.testing.SqlStatementTracker;
@@ -85,6 +87,56 @@ protected void assertConnectionIsLazy(ReactiveConnection connection, boolean sta
8587
.isEqualTo( org.hibernate.reactive.pool.impl.SqlClientPool.class.getName() + "$ProxyConnection" );
8688
}
8789

90+
@Test
91+
public void testBatchingWithPersistAllAndProxyConnection(VertxTestContext context) {
92+
Stage.Session session = getSessionFactory().createSession();
93+
test( context, session
94+
.persist(
95+
new GuineaPig( 11, "One" ),
96+
new GuineaPig( 22, "Two" ),
97+
new GuineaPig( 33, "Three" )
98+
)
99+
// Auto-flush
100+
.thenCompose( v -> session
101+
.createSelectionQuery( "select name from GuineaPig", String.class )
102+
.getResultList()
103+
.thenAccept( names -> {
104+
assertThat( names ).containsExactlyInAnyOrder( "One", "Two", "Three" );
105+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 );
106+
// Parameters are different for different dbs, so we cannot do an exact match
107+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) )
108+
.startsWith( "insert into pig (name,version,id) values " );
109+
sqlTracker.clear();
110+
} )
111+
)
112+
);
113+
}
114+
115+
@Test
116+
public void testBatchingWithPersistAllAndProxyConnectionAndMutiny(VertxTestContext context) {
117+
Mutiny.Session session = getMutinySessionFactory().createSession();
118+
test( context, session
119+
.persistAll(
120+
new GuineaPig( 11, "One" ),
121+
new GuineaPig( 22, "Two" ),
122+
new GuineaPig( 33, "Three" )
123+
)
124+
// Auto-flush
125+
.chain( v -> session
126+
.createSelectionQuery( "select name from GuineaPig", String.class )
127+
.getResultList()
128+
.invoke( names -> {
129+
assertThat( names ).containsExactlyInAnyOrder( "One", "Two", "Three" );
130+
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 1 );
131+
// Parameters are different for different dbs, so we cannot do an exact match
132+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) )
133+
.startsWith( "insert into pig (name,version,id) values " );
134+
sqlTracker.clear();
135+
} )
136+
)
137+
);
138+
}
139+
88140
@Test
89141
public void testBatchingWithPersistAll(VertxTestContext context) {
90142
test( context, openSession().thenCompose( s -> s

0 commit comments

Comments
 (0)