-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4.x: Global instance handling change (and relevant changes to testing) #9193
base: main
Are you sure you want to change the base?
Conversation
9c2ce06
to
7cf06c1
Compare
service/registry/src/main/java/io/helidon/service/registry/GlobalServiceRegistry.java
Outdated
Show resolved
Hide resolved
common/common/src/main/java/io/helidon/common/GlobalInstances.java
Outdated
Show resolved
Hide resolved
testing/testing/src/main/java/io/helidon/testing/TestConfig.java
Outdated
Show resolved
Hide resolved
…, yet support testing Refactored existing global instances to use it
EnumMapperProvider as a proper service Support for existing instance descriptor, to be able to register custom instances during tests (even for types that do not have a service descriptor) + fixed appropriate code in registry, which used Set instead of List Fixed typo in registry module info
… will work nicely once Helidon Service Inject is introduced
- sets up registry with appropriate configuration (through annotations, test source, or static methods) - resets global instances when test class is done
…nces (ClassToInstanceStore)
This also binds the current context to the test class that is executed, making parallel testing a possibility.
3491e58
to
213eb55
Compare
.../src/main/java/io/helidon/metrics/providers/micrometer/MicrometerMetricsFactoryProvider.java
Show resolved
Hide resolved
common/context/src/main/java/io/helidon/common/context/ContextValue.java
Outdated
Show resolved
Hide resolved
…entation. Also removed the no-op, as it is no longer needed
Using a more specific classifier.
common/context/src/main/java/io/helidon/common/context/ContextSingleton.java
Outdated
Show resolved
Hide resolved
common/context/src/main/java/io/helidon/common/context/ContextSingleton.java
Outdated
Show resolved
Hide resolved
common/context/src/main/java/io/helidon/common/context/ContextSingleton.java
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Set a configuration key and value. | ||
* This method CANNOT override an existing key, as such keys are already in the config snapshot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FAQ topic candidate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even need this method ?
This looks like a hack that we aren't using, at least in this pull request.
One should be able to use this instead:
@TestConfig.Source
static ConfigSource config() {
var config = TestConfigSource.create();
onPseudoEvent(() -> config.set("foo", "bar"));
return config;
}
testing/testing/src/main/java/io/helidon/testing/TestRegistry.java
Outdated
Show resolved
Hide resolved
…stry.java Co-authored-by: Daniel Kec <[email protected]>
* | ||
* @return instance of a test config source. | ||
*/ | ||
public static TestConfigSource create() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should provide another variant that takes a initial map.
E.g.
TestConfigSource.create(Map.of("foo", "bar"));
|
||
/** | ||
* Set a configuration key and value. | ||
* This method CANNOT override an existing key, as such keys are already in the config snapshot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even need this method ?
This looks like a hack that we aren't using, at least in this pull request.
One should be able to use this instead:
@TestConfig.Source
static ConfigSource config() {
var config = TestConfigSource.create();
onPseudoEvent(() -> config.set("foo", "bar"));
return config;
}
*/ | ||
public final class ContextSingleton<T> { | ||
/** | ||
* Classifier used to register a context that is to serve as the static context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classifier used to register contexts as "singleton" capable.
/** | ||
* Classifier used to register a context that is to serve as the static context. | ||
*/ | ||
public static final String STATIC_CONTEXT_CLASSIFIER = "helidon-singleton-context"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContextSingleton.CLASSIFIER
is better than
ContextSingleton.STATIC_CONTEXT_CLASSIFIER
At the very least we should not use "static", so either SINGLETON_CONTEXT_CLASSIFIER
, CONTEXT_CLASSIFIER
or just CLASSIFIER
.
Resolves #9186
ContextValue
that usesContext
as the "backing" storeContextValue
ContextValue
either uses the test context, orglobal
context; this is achieved through a context registered under a known qualifier, to make sure it all works even when running in child contextIntroduction of new test annotations
configuration setup using annotations for Helidon SE (through service registry)
static configuration update (if value was not yet read, and is not provided by existing config sources)
introduction of new JUnit5 annotation + extension (resets global instances)
Fix security's ClassToInstanceStore (discovered an issue while copying some ideas to GlobalInstances)
Add support for ExistingInstanceDescriptor to service registry (for testing purposes - bind an instance without a service descriptor)
Testing JUnit extensions now extend the new extension, so all tests inherit the "nice" behavior of global instances SE testing now supports ServiceRegistry (and is ready for future setup using Helidon Inject)