Skip to content

fix(QTDI-2284): fix junit resources cleanup#1179

Open
thboileau wants to merge 5 commits intomasterfrom
tboileau/QTDI-2284_junit_cleanup_issue
Open

fix(QTDI-2284): fix junit resources cleanup#1179
thboileau wants to merge 5 commits intomasterfrom
tboileau/QTDI-2284_junit_cleanup_issue

Conversation

@thboileau
Copy link
Contributor

Requirements

  • Any code change adding any logic MUST be tested through a unit test executed with the default build
  • Any API addition MUST be done with a documentation update if relevant

Why this PR is needed?

What does this PR adds (design/code thoughts)?

.get(ComponentManager.AllServices.class)
.getServices();
Injector.class.cast(services.get(Injector.class)).inject(instance);
((Injector) services.get(Injector.class)).inject(instance);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intellij asked me to do so

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless change

}

interface Local<T> {
protected interface Local<T> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

@thboileau thboileau changed the title Tboileau/qtdi 2284 junit cleanup issue fix(QTDI-2284): fix junit resources cleanup Mar 11, 2026
@thboileau thboileau requested review from Copilot and undx March 11, 2026 16:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BaseComponentsHandler cleanup logic (centralize JSON-B close and avoid NPE on repeated close() 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.

Comment on lines +23 to +41
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;
}
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 204 to 205
* IMPORTANT: don't forget to consume all the streams to ensure the underlying
* { @see org.talend.sdk.component.runtime.input.Input} is closed.
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
* 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.

Copilot uses AI. Check for mistakes.
}

interface Local<T> {
protected interface Local<T> {
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
protected interface Local<T> {
interface Local<T> {

Copilot uses AI. Check for mistakes.
thboileau and others added 3 commits March 11, 2026 17:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@thboileau thboileau requested review from ypiel-talend and removed request for undx March 12, 2026 10:41
Copy link
Contributor

@ypiel-talend ypiel-talend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 minor remark

.get(ComponentManager.AllServices.class)
.getServices();
Injector.class.cast(services.get(Injector.class)).inject(instance);
((Injector) services.get(Injector.class)).inject(instance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants