Skip to content

MINOR: Rewrite ClientOAuthIntegrationTest from Scala to Java#22520

Open
m1a2st wants to merge 9 commits into
apache:trunkfrom
m1a2st:MINOR-migration-ClientOAuthIntegrationTest
Open

MINOR: Rewrite ClientOAuthIntegrationTest from Scala to Java#22520
m1a2st wants to merge 9 commits into
apache:trunkfrom
m1a2st:MINOR-migration-ClientOAuthIntegrationTest

Conversation

@m1a2st

@m1a2st m1a2st commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Rewite ClientOAuthIntegrationTest and move to clients-integration-tests
module

Reviewers: Chia-Ping Tsai chia7712@gmail.com

@github-actions github-actions Bot added core Kafka Broker build Gradle build or GitHub Actions clients triage PRs from the community labels Jun 9, 2026
@m1a2st m1a2st force-pushed the MINOR-migration-ClientOAuthIntegrationTest branch from aca2c65 to 7fe8b5f Compare June 10, 2026 13:54
private static final String ATTACH_LISTENER_THREAD_PREFIX = "Attach Listener";
private static final String PROCESS_REAPER_THREAD_PREFIX = "process reaper";
private static final String RMI_THREAD_PREFIX = "RMI";
private static final String MOCK_WEB_SERVER_THREAD_PREFIX = "MockWebServer";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you mind sharing the reasoning with us?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

MockOAuth2Server library internally uses OkHttp's MockWebServer, which spawns threads with the "MockWebServer" prefix. These threads may not be fully terminated by the time the thread leak check runs after each test, causing false-positive thread leak detection failures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it an existing issue from before? Did you observe it just because the new framework has stricter constraints?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is an existing issue. The original Scala version extended IntegrationTestHarness which does not have thread leak detection. After migrating to the new @ClusterTest framework, the ClusterTestExtensions automatically performs thread leak checking in afterEach(), which exposed the MockWebServer threads that were not fully terminated after mockOAuthServer.shutdown(). So the leak was always there, but the stricter constraints of the new framework made it visible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the explanation. Would you mind adding a comment for it? It would be good to point out which test spawn those threads.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure, addressed it!

@github-actions github-actions Bot removed the triage PRs from the community label Jun 11, 2026
// internally) in ClientOAuthIntegrationTest.
private static final String MOCK_WEB_SERVER_THREAD_PREFIX = "MockWebServer";
private static final String KEEP_ALIVE_TIMER_THREAD_PREFIX = "Keep-Alive-Timer";
private static final String POOL_THREAD_PREFIX = "pool-";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pool- is a bit too common I guess. Would you mind using a more specific name instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I tried to find a more specific name, but the leaked threads are named pool-N-thread-M, which is the default name produced by Executors.defaultThreadFactory().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Executors.defaultThreadFactory().

Could you share the code with me? It looks like a real leak?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The test error log is

Thread leak detected: pool-11-thread-1, pool-10-thread-1, pool-8-thread-1
Expected :true
Actual   :false
<Click to see difference>

org.opentest4j.AssertionFailedError: Thread leak detected: pool-11-thread-1, pool-10-thread-1, pool-8-thread-1 ==> expected: <true> but was: <false>
	at org.apache.kafka.common.test.junit.ClusterTestExtensions.afterEach(ClusterTestExtensions.java:192)
	at java.base/java.util.Optional.ifPresent(Optional.java:178)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

test.log

m1a2st added 3 commits June 25, 2026 21:54
# Conflicts:
#	core/src/test/scala/integration/kafka/api/ClientOAuthIntegrationTest.scala
#	test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/junit/ClusterTestExtensions.java
threads.stream().map(t -> {
return t.getThreadGroup().getName() + "/" + t.getName();
}).collect(Collectors.joining(", ")));
threads.stream().map(Thread::getName).collect(Collectors.joining(", ")));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need those changes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is unrelated to this patch. I have reverted it.

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

Labels

build Gradle build or GitHub Actions clients core Kafka Broker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants