fix(QTDI-2284): fix junit resources cleanup#1179
Conversation
| .get(ComponentManager.AllServices.class) | ||
| .getServices(); | ||
| Injector.class.cast(services.get(Injector.class)).inject(instance); | ||
| ((Injector) services.get(Injector.class)).inject(instance); |
There was a problem hiding this comment.
Intellij asked me to do so
| } | ||
|
|
||
| interface Local<T> { | ||
| protected interface Local<T> { |
There was a problem hiding this comment.
Intellij detected that the interface Local is used with a protected variable. Hence it's better to make this class protected as well
protected static final Local<State> STATE = loadStateHolder();
There was a problem hiding this comment.
Pull request overview
This PR aims to fix JUnit-related resource cleanup in component-runtime-junit, making the embedded component manager shutdown safer (notably when closed multiple times) and adding a regression test.
Changes:
- Bump the project’s JUnit 5 version property.
- Update
BaseComponentsHandlercleanup logic (centralize JSON-B close and avoid NPE on repeatedclose()calls). - Add a unit test validating that the embedded manager can be closed twice without leaving state behind.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
pom.xml |
Updates the JUnit 5 version property used across the build. |
component-runtime-testing/component-runtime-junit/src/main/java/org/talend/sdk/component/junit/BaseComponentsHandler.java |
Makes embedded manager cleanup more robust; adds State.cleanUp() and adjusts shutdown behavior; minor doc/formatting tweaks. |
component-runtime-testing/component-runtime-junit/src/main/java/org/talend/sdk/component/junit5/ComponentExtension.java |
Minor Javadoc grammar fix. |
component-runtime-testing/component-runtime-junit/src/test/java/org/talend/sdk/component/junit/BaseComponentHandlerTest.java |
Adds regression coverage for double-close behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...ent-runtime-junit/src/test/java/org/talend/sdk/component/junit/BaseComponentHandlerTest.java
Outdated
Show resolved
Hide resolved
| public class BaseComponentHandlerTest { | ||
|
|
||
| @Test | ||
| void canCloseTheEmbeddedManagerTwice() { | ||
| final MyBaseComponentsHandler myBaseComponentsHandler = new MyBaseComponentsHandler("org.talend.sdk.component.junit"); | ||
| final BaseComponentsHandler.EmbeddedComponentManager start = myBaseComponentsHandler.start(); | ||
|
|
||
| assertNotNull(BaseComponentsHandler.STATE.get()); | ||
| start.close(); | ||
| assertNull(BaseComponentsHandler.STATE.get()); | ||
| start.close(); | ||
| assertNull(BaseComponentsHandler.STATE.get()); | ||
| } | ||
|
|
||
| private static class MyBaseComponentsHandler extends BaseComponentsHandler { | ||
| public MyBaseComponentsHandler(final String packageName) { | ||
| this.packageName = packageName; | ||
| } | ||
| } |
There was a problem hiding this comment.
Naming: BaseComponentHandlerTest/MyBaseComponentsHandler look like typos/inconsistencies (missing the 's' from BaseComponentsHandler). Renaming the test class and helper to match the production type name would make the intent clearer.
| * IMPORTANT: don't forget to consume all the streams to ensure the underlying | ||
| * { @see org.talend.sdk.component.runtime.input.Input} is closed. |
There was a problem hiding this comment.
The Javadoc says callers must "consume all the streams", but this method returns a single Stream. This wording is misleading and should be corrected back to singular (or rephrased) to match the actual API contract.
| * IMPORTANT: don't forget to consume all the streams to ensure the underlying | |
| * { @see org.talend.sdk.component.runtime.input.Input} is closed. | |
| * IMPORTANT: don't forget to consume the returned stream to ensure the | |
| * underlying {@link org.talend.sdk.component.runtime.input.Input} is closed. |
| } | ||
|
|
||
| interface Local<T> { | ||
| protected interface Local<T> { |
There was a problem hiding this comment.
Local was changed from package-private to protected, which expands the API surface of BaseComponentsHandler to subclasses in other packages. Since there are no in-repo usages of BaseComponentsHandler.Local, consider keeping it package-private unless an external use-case requires this visibility change.
| protected interface Local<T> { | |
| interface Local<T> { |
...ent-runtime-junit/src/test/java/org/talend/sdk/component/junit/BaseComponentHandlerTest.java
Outdated
Show resolved
Hide resolved
...ponent-runtime-junit/src/main/java/org/talend/sdk/component/junit/BaseComponentsHandler.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| .get(ComponentManager.AllServices.class) | ||
| .getServices(); | ||
| Injector.class.cast(services.get(Injector.class)).inject(instance); | ||
| ((Injector) services.get(Injector.class)).inject(instance); |
Requirements
Why this PR is needed?
What does this PR adds (design/code thoughts)?