MINOR: Move client test utilities to test fixtures and resolve shadow jar conflicts#22201
Conversation
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)
| shadowed | ||
| } | ||
|
|
||
| // java-test-fixtures creates dependencies testImplementation -> testFixturesApi -> (main artifact) |
There was a problem hiding this comment.
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!
|
|
||
| apply plugin: 'java-library' | ||
|
|
||
| // Resolve conflict between testFixtures and shadow in :clients. |
There was a problem hiding this comment.
Could you add a comment referencing the "magic workaround" in the clients project?
| @@ -1120,6 +1139,7 @@ project(':core') { | |||
| implementation libs.re2j | |||
|
|
|||
| testImplementation project(':clients').sourceSets.test.output | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
All such references were removed and disallowed - adding them now triggers a build error.
| */ | ||
| package org.apache.kafka.clients.admin; | ||
|
|
||
| public class KafkaAdminClientInternalFactory { |
There was a problem hiding this comment.
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.
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class FailureInjectingTimeoutProcessorFactory extends KafkaAdminClient.TimeoutProcessorFactory { |
There was a problem hiding this comment.
similar to KafkaAdminClientInternalFactory, which can be moved out of testfixtures.
| config.dependencies.each { dep -> | ||
| if (dep instanceof FileCollectionDependency) { | ||
| dep.files.files.each { file -> | ||
| if (file.absolutePath.endsWith('/clients/build/classes/java/test')) { |
There was a problem hiding this comment.
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! 😄
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>
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>
| compileOnly libs.jacksonJDK8Datatypes | ||
| compileOnly libs.jose4j // for SASL/OAUTHBEARER JWT validation; only used by broker | ||
|
|
||
| testFixturesApi project(':test-common:test-common-util') |
There was a problem hiding this comment.
What do you think about using testFixturesImplementation instead? It provides better isolation for our dependencies.
|
@omkreddy thanks for pointing that out. The test-fixtures jar definitely needs to be published. We’ll file a patch for it shortly. |
|
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 |
See #22201 (comment) . This change add `testFixturesJar` to the published artifacts. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Ken Huang
| dep instanceof ProjectDependency && dep.name == project.name | ||
| } | ||
| dependencies { | ||
| testFixturesApi files(sourceSets.main.output.classesDirs) |
There was a problem hiding this comment.
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
See the discussion: #22201 (comment) Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
|
|
||
| testImplementation project(':clients') | ||
| testImplementation project(':clients').sourceSets.test.output | ||
| testImplementation testFixtures(project(':clients')) |
There was a problem hiding this comment.
Seeing that tools depends on the testFixtures(project(':clients')), the testImplementation libs.bcpkix could be deleted from tools module.
There was a problem hiding this comment.
We will file a minor patch for it
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