Skip to content

Commit

Permalink
Added test for #877 BatchingConnection use-case (#925)
Browse files Browse the repository at this point in the history
Co-authored-by: Gavin King <[email protected]>
  • Loading branch information
blafond and gavinking authored Aug 3, 2021
1 parent a11ea01 commit 3e4ecc0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.logging.impl.LoggerFactory;
import org.hibernate.reactive.mutiny.Mutiny;
import org.hibernate.reactive.pool.ReactiveConnection;
import org.hibernate.reactive.session.Criteria;
import org.hibernate.reactive.session.ReactiveSession;

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

public ReactiveConnection getReactiveConnection() {
return delegate.getReactiveConnection();
}

@Override
public <T> T getReference(T entity) {
return delegate.getReference( delegate.getEntityClass(entity), delegate.getEntityId(entity) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.reactive.engine.ReactiveActionQueue;
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.logging.impl.LoggerFactory;
import org.hibernate.reactive.pool.ReactiveConnection;
import org.hibernate.reactive.session.Criteria;
import org.hibernate.reactive.session.ReactiveSession;
import org.hibernate.reactive.stage.Stage;
Expand Down Expand Up @@ -76,6 +77,10 @@ public <T> CompletionStage<T> unproxy(T association) {
return stage( v -> delegate.reactiveFetch(association, true) );
}

public ReactiveConnection getReactiveConnection() {
return delegate.getReactiveConnection();
}

@Override
public <T> T getReference(Class<T> entityClass, Object id) {
//it's important that this method does not hit the database!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
package org.hibernate.reactive;

import io.vertx.ext.unit.TestContext;

import org.hibernate.LockMode;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.reactive.common.AffectedEntities;
import org.hibernate.reactive.mutiny.Mutiny;
import org.hibernate.reactive.mutiny.impl.MutinySessionImpl;
import org.hibernate.reactive.pool.BatchingConnection;
import org.hibernate.reactive.stage.Stage;
import org.hibernate.reactive.stage.impl.StageSessionImpl;

import org.junit.After;
import org.junit.Test;
Expand All @@ -26,6 +31,7 @@
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

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

public class ReactiveSessionTest extends BaseReactiveTest {
Expand Down Expand Up @@ -700,6 +706,28 @@ public void testBatching(TestContext context) {
);
}

@Test
public void testBatchingConnection() {
Stage.Session session = getSessionFactory().openSession();
try {
assertThat(((StageSessionImpl)session).getReactiveConnection()).isInstanceOf( BatchingConnection.class );
}
finally {
closeSession( session );
}
}

@Test
public void testBatchingConnectionMutiny() {
Mutiny.Session session = getMutinySessionFactory().openSession();
try {
assertThat(((MutinySessionImpl)session).getReactiveConnection() ).isInstanceOf( BatchingConnection.class );
}
finally {
closeSession( session );
}
}

@Test
public void testSessionWithNativeAffectedEntities(TestContext context) {
GuineaPig pig = new GuineaPig(3,"Rorshach");
Expand Down

0 comments on commit 3e4ecc0

Please sign in to comment.