Skip to content

Commit df429cb

Browse files
committed
Temp fix for local context
1 parent 4b1857b commit df429cb

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/context/impl/VertxContext.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) {
3636

3737
@Override
3838
public <T> void put(Key<T> key, T instance) {
39-
final io.vertx.core.Context context = Vertx.currentContext();
39+
final ContextInternal context = currentContext();
4040
if ( context != null ) {
4141
if ( trace ) LOG.tracef( "Putting key,value in context: [%1$s, %2$s]", key, instance );
4242
context.putLocal( key, instance );
@@ -47,9 +47,13 @@ public <T> void put(Key<T> key, T instance) {
4747
}
4848
}
4949

50+
private static ContextInternal currentContext() {
51+
return (ContextInternal) Vertx.currentContext();
52+
}
53+
5054
@Override
5155
public <T> T get(Key<T> key) {
52-
final io.vertx.core.Context context = Vertx.currentContext();
56+
final ContextInternal context = currentContext();
5357
if ( context != null ) {
5458
T local = context.getLocal( key );
5559
if ( trace ) LOG.tracef( "Getting value %2$s from context for key %1$s", key, local );
@@ -63,7 +67,7 @@ public <T> T get(Key<T> key) {
6367

6468
@Override
6569
public void remove(Key<?> key) {
66-
final io.vertx.core.Context context = Vertx.currentContext();
70+
final ContextInternal context = currentContext();
6771
if ( context != null ) {
6872
boolean removed = context.removeLocal( key );
6973
if ( trace ) LOG.tracef( "Key %s removed from context: %s", key, removed );
@@ -75,14 +79,15 @@ public void remove(Key<?> key) {
7579

7680
@Override
7781
public void execute(Runnable runnable) {
78-
final io.vertx.core.Context currentContext = Vertx.currentContext();
82+
final io.vertx.core.Context currentContext = currentContext();
7983
if ( currentContext == null ) {
8084
if ( trace ) LOG.tracef( "Not in a Vert.x context, checking the VertxInstance service" );
8185
final io.vertx.core.Context newContext = vertxInstance.getVertx().getOrCreateContext();
8286
// Ensure we don't run on the root context, which is globally scoped:
8387
// that could lead to unintentionally share the same session with other streams.
8488
ContextInternal newContextInternal = (ContextInternal) newContext;
8589
final ContextInternal duplicate = newContextInternal.duplicate();
90+
8691
if ( trace ) LOG.tracef( "Using duplicated context from VertxInstance: %s", duplicate );
8792
duplicate.runOnContext( x -> runnable.run() );
8893
}

hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaValidationTest.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
3535
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
3636
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
37+
import static org.hibernate.reactive.testing.ReactiveAssertions.assertThrown;
3738
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
3839
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY;
3940
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -126,13 +127,8 @@ context, setupFactory( strategy, type )
126127
validateConf.addAnnotatedClass( BasicTypesTestEntity.class );
127128
// The table mapping this entity shouldn't be in the db
128129
validateConf.addAnnotatedClass( Extra.class );
129-
return setupSessionFactory( validateConf )
130-
.handle( (unused, throwable) -> {
131-
assertThat( throwable )
132-
.isInstanceOf( SchemaManagementException.class )
133-
.hasMessage( errorMessage );
134-
return null;
135-
} );
130+
return assertThrown( SchemaManagementException.class, setupSessionFactory( validateConf ) )
131+
.thenAccept( throwable -> assertThat( throwable ).hasMessage( errorMessage ) );
136132
} )
137133
);
138134
}

0 commit comments

Comments
 (0)