Skip to content

Commit

Permalink
Added test for hibernate#877 BatchingConnection use-case
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking authored and blafond committed Aug 3, 2021
1 parent b828388 commit fc2f4e1
Show file tree
Hide file tree
Showing 3 changed files with 28 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,17 @@
package org.hibernate.reactive;

import io.vertx.ext.unit.TestContext;
import org.assertj.core.api.Assertions;

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 Down Expand Up @@ -700,6 +706,18 @@ public void testBatching(TestContext context) {
);
}

@Test
public void testBatchingConnection(TestContext context) {
Stage.Session session = getSessionFactory().openSession();
Assertions.assertThat(((StageSessionImpl)session).getReactiveConnection()).isInstanceOf( BatchingConnection.class );
}

@Test
public void testBatchingConnectionMutiny(TestContext context) {
Mutiny.Session session = getMutinySessionFactory().openSession();
Assertions.assertThat(((MutinySessionImpl)session).getReactiveConnection()).isInstanceOf( BatchingConnection.class );
}

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

0 comments on commit fc2f4e1

Please sign in to comment.