Skip to content

Commit 3e4ecc0

Browse files
blafondgavinking
andauthored
Added test for #877 BatchingConnection use-case (#925)
Co-authored-by: Gavin King <[email protected]>
1 parent a11ea01 commit 3e4ecc0

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinySessionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.hibernate.reactive.logging.impl.Log;
1919
import org.hibernate.reactive.logging.impl.LoggerFactory;
2020
import org.hibernate.reactive.mutiny.Mutiny;
21+
import org.hibernate.reactive.pool.ReactiveConnection;
2122
import org.hibernate.reactive.session.Criteria;
2223
import org.hibernate.reactive.session.ReactiveSession;
2324

@@ -84,6 +85,10 @@ public <T> T getReference(Class<T> entityClass, Object id) {
8485
return delegate.getReference( entityClass, id );
8586
}
8687

88+
public ReactiveConnection getReactiveConnection() {
89+
return delegate.getReactiveConnection();
90+
}
91+
8792
@Override
8893
public <T> T getReference(T entity) {
8994
return delegate.getReference( delegate.getEntityClass(entity), delegate.getEntityId(entity) );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/impl/StageSessionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.hibernate.reactive.engine.ReactiveActionQueue;
1818
import org.hibernate.reactive.logging.impl.Log;
1919
import org.hibernate.reactive.logging.impl.LoggerFactory;
20+
import org.hibernate.reactive.pool.ReactiveConnection;
2021
import org.hibernate.reactive.session.Criteria;
2122
import org.hibernate.reactive.session.ReactiveSession;
2223
import org.hibernate.reactive.stage.Stage;
@@ -76,6 +77,10 @@ public <T> CompletionStage<T> unproxy(T association) {
7677
return stage( v -> delegate.reactiveFetch(association, true) );
7778
}
7879

80+
public ReactiveConnection getReactiveConnection() {
81+
return delegate.getReactiveConnection();
82+
}
83+
7984
@Override
8085
public <T> T getReference(Class<T> entityClass, Object id) {
8186
//it's important that this method does not hit the database!

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
package org.hibernate.reactive;
77

88
import io.vertx.ext.unit.TestContext;
9+
910
import org.hibernate.LockMode;
1011
import org.hibernate.cfg.AvailableSettings;
1112
import org.hibernate.cfg.Configuration;
1213
import org.hibernate.reactive.common.AffectedEntities;
14+
import org.hibernate.reactive.mutiny.Mutiny;
15+
import org.hibernate.reactive.mutiny.impl.MutinySessionImpl;
16+
import org.hibernate.reactive.pool.BatchingConnection;
1317
import org.hibernate.reactive.stage.Stage;
18+
import org.hibernate.reactive.stage.impl.StageSessionImpl;
1419

1520
import org.junit.After;
1621
import org.junit.Test;
@@ -26,6 +31,7 @@
2631
import java.util.concurrent.CompletionException;
2732
import java.util.concurrent.CompletionStage;
2833

34+
import static org.assertj.core.api.Assertions.assertThat;
2935
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
3036

3137
public class ReactiveSessionTest extends BaseReactiveTest {
@@ -700,6 +706,28 @@ public void testBatching(TestContext context) {
700706
);
701707
}
702708

709+
@Test
710+
public void testBatchingConnection() {
711+
Stage.Session session = getSessionFactory().openSession();
712+
try {
713+
assertThat(((StageSessionImpl)session).getReactiveConnection()).isInstanceOf( BatchingConnection.class );
714+
}
715+
finally {
716+
closeSession( session );
717+
}
718+
}
719+
720+
@Test
721+
public void testBatchingConnectionMutiny() {
722+
Mutiny.Session session = getMutinySessionFactory().openSession();
723+
try {
724+
assertThat(((MutinySessionImpl)session).getReactiveConnection() ).isInstanceOf( BatchingConnection.class );
725+
}
726+
finally {
727+
closeSession( session );
728+
}
729+
}
730+
703731
@Test
704732
public void testSessionWithNativeAffectedEntities(TestContext context) {
705733
GuineaPig pig = new GuineaPig(3,"Rorshach");

0 commit comments

Comments
 (0)