From 43ce2231324c46b81a5f660e4f815c942a14e449 Mon Sep 17 00:00:00 2001 From: Romain Grecourt Date: Wed, 26 Feb 2025 01:32:45 -0800 Subject: [PATCH] Remove GlobalServiceRegistry context qualifier constants (#9827) Remove the following (unreleased) constants to minimize temporary API surface of 4.2.0 - GlobalServiceRegistry.STATIC_CONTEXT_CLASSIFIER - GlobalServiceRegistry.CONTEXT_CLASSIFIER --- .../testing/testng/HelidonTestNgListener.java | 5 ++- .../junit5/TestGlobalServiceRegistry.java | 2 +- .../testng/TestGlobalServiceRegistry.java | 2 +- .../registry/GlobalServiceRegistry.java | 35 +++---------------- .../testing/junit5/TestJunitExtension.java | 4 +-- 5 files changed, 10 insertions(+), 38 deletions(-) diff --git a/microprofile/testing/testng/src/main/java/io/helidon/microprofile/testing/testng/HelidonTestNgListener.java b/microprofile/testing/testng/src/main/java/io/helidon/microprofile/testing/testng/HelidonTestNgListener.java index a3427f4ae37..a8eb3566625 100644 --- a/microprofile/testing/testng/src/main/java/io/helidon/microprofile/testing/testng/HelidonTestNgListener.java +++ b/microprofile/testing/testng/src/main/java/io/helidon/microprofile/testing/testng/HelidonTestNgListener.java @@ -40,7 +40,6 @@ import io.helidon.microprofile.testing.HelidonTestInfo.MethodInfo; import io.helidon.microprofile.testing.HelidonTestScope; import io.helidon.microprofile.testing.Proxies; -import io.helidon.service.registry.GlobalServiceRegistry; import io.helidon.service.registry.ServiceRegistry; import io.helidon.service.registry.ServiceRegistryManager; @@ -302,10 +301,10 @@ private Context staticContext(Class testClass) { .build(); // self-register, so this context is used even if the current context is some child of it - context.register(GlobalServiceRegistry.STATIC_CONTEXT_CLASSIFIER, context); + context.register("helidon-registry-static-context", context); // supply registry - context.supply(GlobalServiceRegistry.CONTEXT_QUALIFIER, ServiceRegistry.class, + context.supply("helidon-registry", ServiceRegistry.class, () -> ServiceRegistryManager.create().registry()); return context; diff --git a/microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestGlobalServiceRegistry.java b/microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestGlobalServiceRegistry.java index c1d6a69d381..7e7ee043cda 100644 --- a/microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestGlobalServiceRegistry.java +++ b/microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestGlobalServiceRegistry.java @@ -69,7 +69,7 @@ void firstTest() { assertThat(INSTANCES.size(), is(1)); assertThat(INSTANCES.iterator().next(), is(not(System.identityHashCode(Contexts.globalContext() - .get(GlobalServiceRegistry.CONTEXT_QUALIFIER, ServiceRegistry.class) + .get("helidon-registry", ServiceRegistry.class) .orElse(null))))); } diff --git a/microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestGlobalServiceRegistry.java b/microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestGlobalServiceRegistry.java index b348e887f15..cb622d51fcd 100644 --- a/microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestGlobalServiceRegistry.java +++ b/microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestGlobalServiceRegistry.java @@ -69,7 +69,7 @@ void firstTest() { assertThat(INSTANCES.size(), is(1)); assertThat(INSTANCES.iterator().next(), is(not(System.identityHashCode(Contexts.globalContext() - .get(GlobalServiceRegistry.CONTEXT_QUALIFIER, ServiceRegistry.class) + .get("helidon-registry", ServiceRegistry.class) .orElse(null))))); } diff --git a/service/registry/src/main/java/io/helidon/service/registry/GlobalServiceRegistry.java b/service/registry/src/main/java/io/helidon/service/registry/GlobalServiceRegistry.java index 408568a4bce..d5b57c3ef84 100644 --- a/service/registry/src/main/java/io/helidon/service/registry/GlobalServiceRegistry.java +++ b/service/registry/src/main/java/io/helidon/service/registry/GlobalServiceRegistry.java @@ -25,36 +25,9 @@ import io.helidon.common.context.Contexts; /** - * Represents an application wide service registry. - *

- * The registry instance is shared through {@link io.helidon.common.context.Context}, using the current context - * to obtain a context with classifier {@link #STATIC_CONTEXT_CLASSIFIER}. If such a context is found, the - * registry instance is obtained/stored there. If the context does not exist, the - * {@link io.helidon.common.context.Contexts#globalContext()} is used to store the value. - *

- * The first option is designed for testing, to make sure the global registry is only "global" for a single test class. - * The second option is the default for application runtime, where we intend to share the registry as a proper, static - * singleton instance. - *

- * Helidon testing libraries support this approach and correctly configure appropriate context for each execution. + * Application wide service registry backed by {@link io.helidon.common.context.Context}. */ public final class GlobalServiceRegistry { - /** - * Classifier used to register a context that is to serve as the context that holds the - * global registry instance. - *

- * This is to allow testing in parallel, where we need the global registry instance restricted to a single test. - *

- * In normal application runtime we use {@link io.helidon.common.context.Contexts#globalContext()}. - */ - public static final Object STATIC_CONTEXT_CLASSIFIER = new Object(); - - /** - * Classifier used to register the global service registry. - * - * @see #STATIC_CONTEXT_CLASSIFIER - */ - public static final Object CONTEXT_QUALIFIER = new Object(); private static final ReadWriteLock RW_LOCK = new ReentrantReadWriteLock(); @@ -137,7 +110,7 @@ public static ServiceRegistry registry(Supplier registrySupplie public static ServiceRegistry registry(ServiceRegistry newGlobalRegistry) { RW_LOCK.writeLock().lock(); try { - context().register(CONTEXT_QUALIFIER, newGlobalRegistry); + context().register("helidon-registry", newGlobalRegistry); } finally { RW_LOCK.writeLock().unlock(); } @@ -150,14 +123,14 @@ private static Context context() { // this is the context we expect to get (and set global instances) return Contexts.context() .orElse(globalContext) - .get(STATIC_CONTEXT_CLASSIFIER, Context.class) + .get("helidon-registry-static-context", Context.class) .orElse(globalContext); } private static Optional current() { RW_LOCK.readLock().lock(); try { - return context().get(CONTEXT_QUALIFIER, ServiceRegistry.class); + return context().get("helidon-registry", ServiceRegistry.class); } finally { RW_LOCK.readLock().unlock(); } diff --git a/testing/junit5/src/main/java/io/helidon/testing/junit5/TestJunitExtension.java b/testing/junit5/src/main/java/io/helidon/testing/junit5/TestJunitExtension.java index de23afaee0a..d1a84e2ca04 100644 --- a/testing/junit5/src/main/java/io/helidon/testing/junit5/TestJunitExtension.java +++ b/testing/junit5/src/main/java/io/helidon/testing/junit5/TestJunitExtension.java @@ -204,10 +204,10 @@ protected void initStaticContext(ExtensionContext.Store store, ExtensionContext .build(); // self-register, so this context is used even if the current context is some child of it - context.register(GlobalServiceRegistry.STATIC_CONTEXT_CLASSIFIER, context); + context.register("helidon-registry-static-context", context); // supply registry - context.supply(GlobalServiceRegistry.CONTEXT_QUALIFIER, ServiceRegistry.class, () -> { + context.supply("helidon-registry", ServiceRegistry.class, () -> { var manager = ServiceRegistryManager.create(); var registry = manager.registry(); store.put(ServiceRegistryManager.class, (CloseableResource) manager::shutdown);