Skip to content

Commit

Permalink
Temp fix for local context
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Feb 3, 2025
1 parent 4b1857b commit df429cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) {

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

private static ContextInternal currentContext() {
return (ContextInternal) Vertx.currentContext();
}

@Override
public <T> T get(Key<T> key) {
final io.vertx.core.Context context = Vertx.currentContext();
final ContextInternal context = currentContext();
if ( context != null ) {
T local = context.getLocal( key );
if ( trace ) LOG.tracef( "Getting value %2$s from context for key %1$s", key, local );
Expand All @@ -63,7 +67,7 @@ public <T> T get(Key<T> key) {

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

@Override
public void execute(Runnable runnable) {
final io.vertx.core.Context currentContext = Vertx.currentContext();
final io.vertx.core.Context currentContext = currentContext();
if ( currentContext == null ) {
if ( trace ) LOG.tracef( "Not in a Vert.x context, checking the VertxInstance service" );
final io.vertx.core.Context newContext = vertxInstance.getVertx().getOrCreateContext();
// Ensure we don't run on the root context, which is globally scoped:
// that could lead to unintentionally share the same session with other streams.
ContextInternal newContextInternal = (ContextInternal) newContext;
final ContextInternal duplicate = newContextInternal.duplicate();

if ( trace ) LOG.tracef( "Using duplicated context from VertxInstance: %s", duplicate );
duplicate.runOnContext( x -> runnable.run() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
import static org.hibernate.reactive.testing.ReactiveAssertions.assertThrown;
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY;
import static org.junit.jupiter.params.provider.Arguments.arguments;
Expand Down Expand Up @@ -126,13 +127,8 @@ context, setupFactory( strategy, type )
validateConf.addAnnotatedClass( BasicTypesTestEntity.class );
// The table mapping this entity shouldn't be in the db
validateConf.addAnnotatedClass( Extra.class );
return setupSessionFactory( validateConf )
.handle( (unused, throwable) -> {
assertThat( throwable )
.isInstanceOf( SchemaManagementException.class )
.hasMessage( errorMessage );
return null;
} );
return assertThrown( SchemaManagementException.class, setupSessionFactory( validateConf ) )
.thenAccept( throwable -> assertThat( throwable ).hasMessage( errorMessage ) );
} )
);
}
Expand Down

0 comments on commit df429cb

Please sign in to comment.