Skip to content

MINOR: Move client test utilities to test fixtures and resolve shadow jar conflicts#22201

Merged
chia7712 merged 6 commits into
apache:trunkfrom
soarez:minor-testsslutils-to-fixtures
May 5, 2026
Merged

MINOR: Move client test utilities to test fixtures and resolve shadow jar conflicts#22201
chia7712 merged 6 commits into
apache:trunkfrom
soarez:minor-testsslutils-to-fixtures

Conversation

@soarez

@soarez soarez commented May 4, 2026

Copy link
Copy Markdown
Member

This change moves TestSslUtils, TestUtils and accessory classes from the
test classpath in clients to test fixtures, allowing other modules to
use these classes for testing without having to include all of the test
classpath for clients.

For further details on the context and purpose of this change, check
these threads:
#20376 (comment)
#22193 (comment)

Reviewers: Chia-Ping Tsai chia7712@gmail.com

This change moves TestSslUtils, TestUtils and accessory classes from the
test classpath in clients to test fixtures, allowing other modules to
use these classes for testing without having to include all of the test
classpath for clients.

For further details on the context and purpose of this change, check
these threads:
apache#20376 (comment)
apache#22193 (comment)
@github-actions github-actions Bot added core Kafka Broker kraft build Gradle build or GitHub Actions clients labels May 4, 2026
Comment thread build.gradle
shadowed
}

// java-test-fixtures creates dependencies testImplementation -> testFixturesApi -> (main artifact)

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.

This is definitely a magic workaround... I noticed there are several issues discussing this behavior

gradle/gradle#19946
gradle/gradle#11696

Anyway, good job finding this approach!

Comment thread build.gradle Outdated

apply plugin: 'java-library'

// Resolve conflict between testFixtures and shadow in :clients.

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.

Could you add a comment referencing the "magic workaround" in the clients project?

Comment thread build.gradle Outdated
@@ -1120,6 +1139,7 @@ project(':core') {
implementation libs.re2j

testImplementation project(':clients').sourceSets.test.output

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.

It would be great if we could remove all references to project(':clients').sourceSets.test.output. We could move the classes used across modules to the test-fixtures folder. WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All such references were removed and disallowed - adding them now triggers a build error.

@chia7712 chia7712 left a comment

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.

LGTM

*/
package org.apache.kafka.clients.admin;

public class KafkaAdminClientInternalFactory {

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.

Exposing a package-private method through this 'factory' feels very hacky. I'll submit a PR to move the specific test from core to clients-integration-test so we can close this door for good.

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.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FailureInjectingTimeoutProcessorFactory extends KafkaAdminClient.TimeoutProcessorFactory {

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.

similar to KafkaAdminClientInternalFactory, which can be moved out of testfixtures.

Comment thread build.gradle
config.dependencies.each { dep ->
if (dep instanceof FileCollectionDependency) {
dep.files.files.each { file ->
if (file.absolutePath.endsWith('/clients/build/classes/java/test')) {

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.

Nice catch. Right now it only rejects client test code, but since other modules still depend on other's test code, this will eventually result in all test scopes being rejected as we clean them up. A beautiful world! 😄

@chia7712 chia7712 changed the title MINOR: Move TestSslUtils to client test fixtures MINOR: Move client test utilities to test fixtures and resolve shadow jar conflicts May 5, 2026
@chia7712
chia7712 merged commit 3b6c838 into apache:trunk May 5, 2026
35 of 37 checks passed
airlock-confluentinc Bot pushed a commit to confluentinc/common-docker that referenced this pull request May 7, 2026
apache/kafka#22201 (3b6c838) moved org.apache.kafka.test.TestUtils
out of clients' regular test sources and into testFixtures, so the
class is no longer in kafka-clients-<v>-test.jar but in the new
kafka-clients-<v>-test-fixtures.jar instead. Add the test-fixtures
classifier dependency so ClusterWaitTest compiles again.

(Earlier attempt swapped the import to
org.apache.kafka.common.test.TestUtils from kafka-test-common-runtime,
but that class is package-private — its javadoc redirects callers to
org.apache.kafka.test.TestUtils. CI confirmed this with: "TestUtils
is not public in org.apache.kafka.common.test; cannot be accessed
from outside package".)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
airlock-confluentinc Bot pushed a commit to confluentinc/common-docker that referenced this pull request May 7, 2026
Drop the dependency on org.apache.kafka.test.TestUtils#waitForCondition
and inline an equivalent polling loop. Test scope only.

apache/kafka#22201 (3b6c838) moved TestUtils out of kafka-clients'
test classifier jar into testFixtures. Two attempts to keep using an
upstream TestUtils failed:

  1. Switching to org.apache.kafka.common.test.TestUtils (in
     kafka-test-common-runtime) — that class is package-private; CI
     reported "TestUtils is not public in org.apache.kafka.common.test;
     cannot be accessed from outside package".

  2. Adding kafka-clients with classifier=test-fixtures so the original
     class is back on the test classpath — Confluent's CodeArtifact
     does not publish that classifier ("kafka-clients:jar:test-fixtures
     :8.4.0-81-ccs (absent)").

Inlining is small, self-contained, and robust to future upstream
test-utility refactors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread build.gradle
compileOnly libs.jacksonJDK8Datatypes
compileOnly libs.jose4j // for SASL/OAUTHBEARER JWT validation; only used by broker

testFixturesApi project(':test-common:test-common-util')

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.

What do you think about using testFixturesImplementation instead? It provides better isolation for our dependencies.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Addressed in #22243

@omkreddy

Copy link
Copy Markdown
Contributor

@soarez I see that we are not publishing kafka-clients-test-fixtures-4.4.0-SNAPSHOT.jar. I wanted to know if there is a specific reason for this. The reason I’m asking is that there are downstream projects that depend on these test utilities, so it would be useful to publish them.

cc @chia7712

@chia7712

Copy link
Copy Markdown
Member

@omkreddy thanks for pointing that out. The test-fixtures jar definitely needs to be published. We’ll file a patch for it shortly.

@soarez

soarez commented May 13, 2026

Copy link
Copy Markdown
Member Author

No, I didn’t think of downstream dependencies. It does make sense to publish it. And I see there’s already a patch! Thanks @majialoong

omkreddy pushed a commit that referenced this pull request May 13, 2026
See #22201 (comment) .
This change add `testFixturesJar` to the published artifacts.

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Ken Huang
Comment thread build.gradle
dep instanceof ProjectDependency && dep.name == project.name
}
dependencies {
testFixturesApi files(sourceSets.main.output.classesDirs)

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.

We should revisit those tests instead of hacking the dependencies. The test code in the clients module should NOT depend on io.opentelemetry, and that can be addressed by moving the io.opentelemetry-related code to ClientTelemetryUtils. It is not perfect, but it's better than a hack in build.gradle

chia7712 pushed a commit that referenced this pull request Jul 2, 2026
See the discussion:
#22201 (comment)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Comment thread build.gradle

testImplementation project(':clients')
testImplementation project(':clients').sourceSets.test.output
testImplementation testFixtures(project(':clients'))

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.

Seeing that tools depends on the testFixtures(project(':clients')), the testImplementation libs.bcpkix could be deleted from tools module.

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.

We will file a minor patch for it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @chia7712,
I've opened #22868 to address this. PTAL when you have time, thanks!

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 consumer core Kafka Broker kraft streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants