Skip to content

Commit dc91e71

Browse files
mumrahmjsax
authored andcommitted
KAFKA-17587 Refactor test infrastructure (apache#18602)
This patch reorganizes our test infrastructure into three Gradle modules: ":test-common:test-common-internal-api" is now a minimal dependency which exposes interfaces and annotations only. It has one project dependency on server-common to expose commonly used data classes (MetadataVersion, Feature, etc). Since this pulls in server-common, this module is Java 17+. It cannot be used by ":clients" or other Java 11 modules. ":test-common:test-common-util" includes the auto-quarantined JUnit extension. The @flaky annotation has been moved here. Since this module has no project dependencies, we can add it to the Java 11 list so that ":clients" and others can utilize the @flaky annotation ":test-common:test-common-runtime" now includes all of the test infrastructure code (TestKitNodes, etc). This module carries heavy dependencies (core, etc) and so it should not normally be included as a compile-time dependency. In addition to this reorganization, this patch leverages JUnit SPI service discovery so that modules can utilize the integration test framework without depending on ":core". This will allow us to start moving integration tests out of core and into the appropriate sub-module. This is done by adding ":test-common:test-common-runtime" as a testRuntimeOnly dependency rather than as a testImplementation dependency. A trivial example was added to QuorumControllerTest to illustrate this. Reviewers: Ismael Juma <[email protected]>, Chia-Ping Tsai <[email protected]>
1 parent a713d3e commit dc91e71

File tree

126 files changed

+349
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+349
-387
lines changed

.github/scripts/junit.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ class TestSuite:
9191
def clean_test_name(test_name: str) -> str:
9292
cleaned = test_name.strip("\"").rstrip("()")
9393
m = method_matcher.match(cleaned)
94-
return m.group(1)
94+
if m is None:
95+
raise ValueError(f"Could not parse test name '{test_name}'. Expected a valid Java method name.")
96+
else:
97+
return m.group(1)
9598

9699

97100
class TestCatalogExporter:

build.gradle

+55-52
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ext {
6969
gradleVersion = versions.gradle
7070
minClientJavaVersion = 11
7171
minNonClientJavaVersion = 17
72-
modulesNeedingJava11 = [":clients", ":generator", ":streams", ":streams:test-utils", ":streams-scala", ":test-common:test-common-runtime"]
72+
modulesNeedingJava11 = [":clients", ":generator", ":streams", ":streams:test-utils", ":streams-scala", ":test-common:test-common-util"]
7373

7474
buildVersionFileName = "kafka-version.properties"
7575

@@ -160,10 +160,11 @@ ext {
160160
runtimeTestLibs = [
161161
libs.slf4jLog4j2,
162162
libs.junitPlatformLanucher,
163-
project(":test-common:test-common-runtime")
163+
libs.jacksonDatabindYaml,
164+
project(":test-common:test-common-util")
164165
]
165166

166-
log4jRuntimeLibs = [
167+
log4jReleaseLibs = [
167168
libs.slf4jLog4j2,
168169
libs.log4j1Bridge2Api,
169170
libs.jacksonDatabindYaml
@@ -1118,7 +1119,7 @@ project(':core') {
11181119
}
11191120

11201121
dependencies {
1121-
releaseOnly log4jRuntimeLibs
1122+
releaseOnly log4jReleaseLibs
11221123
// `core` is often used in users' tests, define the following dependencies as `api` for backwards compatibility
11231124
// even though the `core` module doesn't expose any public API
11241125
api project(':clients')
@@ -1161,8 +1162,9 @@ project(':core') {
11611162
testImplementation project(':server-common').sourceSets.test.output
11621163
testImplementation project(':storage:storage-api').sourceSets.test.output
11631164
testImplementation project(':server').sourceSets.test.output
1164-
testImplementation project(':test-common')
1165-
testImplementation project(':test-common:test-common-api')
1165+
testImplementation project(':test-common:test-common-runtime')
1166+
testImplementation project(':test-common:test-common-internal-api')
1167+
testImplementation project(':test-common:test-common-util')
11661168
testImplementation libs.bcpkix
11671169
testImplementation libs.mockitoCore
11681170
testImplementation(libs.apacheda) {
@@ -1598,21 +1600,17 @@ project(':group-coordinator') {
15981600
srcJar.dependsOn 'processMessages'
15991601
}
16001602

1601-
project(':test-common') {
1602-
// Test framework stuff. Implementations that support test-common-api
1603+
1604+
project(':test-common:test-common-internal-api') {
1605+
// Interfaces, config classes, and other test APIs. Java 17 only
16031606
base {
1604-
archivesName = "kafka-test-common"
1607+
archivesName = "kafka-test-common-internal-api"
16051608
}
16061609

16071610
dependencies {
1608-
implementation project(':core')
1609-
implementation project(':metadata')
1610-
implementation project(':server')
1611-
implementation project(':raft')
1612-
implementation project(':storage')
1613-
implementation project(':server-common')
1614-
implementation libs.jacksonDatabindYaml
1615-
implementation libs.slf4jApi
1611+
implementation project(':server-common') // Only project dependency allowed
1612+
1613+
implementation libs.junitJupiterApi
16161614

16171615
testImplementation libs.junitJupiter
16181616
testImplementation libs.mockitoCore
@@ -1622,41 +1620,30 @@ project(':test-common') {
16221620
}
16231621

16241622
checkstyle {
1625-
configProperties = checkstyleConfigProperties("import-control-test-common.xml")
1623+
configProperties = checkstyleConfigProperties("import-control-test-common-internal-api.xml")
16261624
}
16271625

16281626
javadoc {
16291627
enabled = false
16301628
}
16311629
}
16321630

1633-
project(':test-common:test-common-api') {
1634-
// Interfaces, config classes, and other test APIs
1631+
project(':test-common:test-common-util') {
1632+
// Runtime-only JUnit extensions for entire project. Java 11 only
16351633
base {
1636-
archivesName = "kafka-test-common-api"
1634+
archivesName = "kafka-test-common-util"
16371635
}
16381636

16391637
dependencies {
1640-
implementation project(':clients')
1641-
implementation project(':core')
1642-
implementation project(':group-coordinator')
1643-
implementation project(':metadata')
1644-
implementation project(':raft')
1645-
implementation project(':server')
1646-
implementation project(':server-common')
1647-
implementation project(':storage')
1648-
implementation project(':test-common')
1638+
implementation libs.junitPlatformLanucher
16491639
implementation libs.junitJupiterApi
1650-
1651-
testImplementation libs.junitJupiter
1652-
testImplementation libs.mockitoCore
1640+
implementation libs.junitJupiter
1641+
implementation libs.slf4jApi
16531642
testImplementation testLog4j2Libs
1654-
1655-
testRuntimeOnly runtimeTestLibs
16561643
}
16571644

16581645
checkstyle {
1659-
configProperties = checkstyleConfigProperties("import-control-test-common-api.xml")
1646+
configProperties = checkstyleConfigProperties("import-control-test-common-util.xml")
16601647
}
16611648

16621649
javadoc {
@@ -1665,21 +1652,36 @@ project(':test-common:test-common-api') {
16651652
}
16661653

16671654
project(':test-common:test-common-runtime') {
1668-
// Runtime-only test code including JUnit extentions
1655+
// Runtime-only JUnit extensions for integration tests. Java 17 only
16691656
base {
16701657
archivesName = "kafka-test-common-runtime"
16711658
}
16721659

16731660
dependencies {
1661+
implementation project(':test-common:test-common-internal-api')
1662+
implementation project(':clients')
1663+
implementation project(':core')
1664+
implementation project(':group-coordinator')
1665+
implementation project(':metadata')
1666+
implementation project(':raft')
1667+
implementation project(':server')
1668+
implementation project(':server-common')
1669+
implementation project(':storage')
1670+
16741671
implementation libs.junitPlatformLanucher
1675-
implementation libs.junitJupiterApi
16761672
implementation libs.junitJupiter
1673+
implementation libs.jacksonDatabindYaml
16771674
implementation libs.slf4jApi
1675+
1676+
testImplementation libs.junitJupiter
1677+
testImplementation libs.mockitoCore
16781678
testImplementation testLog4j2Libs
1679+
1680+
testRuntimeOnly runtimeTestLibs
16791681
}
16801682

16811683
checkstyle {
1682-
configProperties = checkstyleConfigProperties("import-control-test-common-api.xml")
1684+
configProperties = checkstyleConfigProperties("import-control-test-common-runtime.xml")
16831685
}
16841686

16851687
javadoc {
@@ -1707,8 +1709,8 @@ project(':transaction-coordinator') {
17071709
testImplementation libs.junitJupiter
17081710
testImplementation libs.mockitoCore
17091711
testImplementation project(':clients').sourceSets.test.output
1710-
testImplementation project(':test-common')
1711-
testImplementation project(':test-common:test-common-api')
1712+
testImplementation project(':test-common:test-common-runtime')
1713+
testImplementation project(':test-common:test-common-internal-api')
17121714

17131715
testRuntimeOnly runtimeTestLibs
17141716

@@ -1929,6 +1931,7 @@ project(':clients') {
19291931
compileOnly libs.jose4j // for SASL/OAUTHBEARER JWT validation; only used by broker
19301932

19311933

1934+
testImplementation project(':test-common:test-common-util')
19321935
testImplementation libs.bcpkix
19331936
testImplementation libs.jacksonJakartarsJsonProvider
19341937
testImplementation libs.jose4j
@@ -1943,7 +1946,6 @@ project(':clients') {
19431946
testRuntimeOnly libs.jacksonDatabind
19441947
testRuntimeOnly libs.jacksonJDK8Datatypes
19451948
testRuntimeOnly runtimeTestLibs
1946-
testRuntimeOnly log4jRuntimeLibs
19471949

19481950
generator project(':generator')
19491951
}
@@ -2330,7 +2332,8 @@ project(':storage') {
23302332
testImplementation project(':clients').sourceSets.test.output
23312333
testImplementation project(':core')
23322334
testImplementation project(':core').sourceSets.test.output
2333-
testImplementation project(':test-common:test-common-api')
2335+
testImplementation project(':test-common:test-common-internal-api')
2336+
testImplementation project(':test-common:test-common-runtime')
23342337
testImplementation project(':server')
23352338
testImplementation project(':server-common')
23362339
testImplementation project(':server-common').sourceSets.test.output
@@ -2487,7 +2490,7 @@ project(':tools') {
24872490
}
24882491

24892492
dependencies {
2490-
releaseOnly log4jRuntimeLibs
2493+
releaseOnly log4jReleaseLibs
24912494

24922495
implementation project(':clients')
24932496
implementation project(':metadata')
@@ -2519,7 +2522,8 @@ project(':tools') {
25192522
testImplementation project(':server').sourceSets.test.output
25202523
testImplementation project(':core')
25212524
testImplementation project(':core').sourceSets.test.output
2522-
testImplementation project(':test-common:test-common-api')
2525+
testImplementation project(':test-common:test-common-internal-api')
2526+
testImplementation project(':test-common:test-common-runtime')
25232527
testImplementation project(':server-common')
25242528
testImplementation project(':server-common').sourceSets.test.output
25252529
testImplementation project(':connect:api')
@@ -2530,7 +2534,6 @@ project(':tools') {
25302534
testImplementation project(':streams')
25312535
testImplementation project(':streams').sourceSets.test.output
25322536
testImplementation project(':streams:integration-tests').sourceSets.test.output
2533-
testImplementation project(':test-common')
25342537
testImplementation libs.junitJupiter
25352538
testImplementation libs.mockitoCore
25362539
testImplementation libs.mockitoJunitJupiter // supports MockitoExtension
@@ -2711,7 +2714,6 @@ project(':streams') {
27112714

27122715
testRuntimeOnly project(':streams:test-utils')
27132716
testRuntimeOnly runtimeTestLibs
2714-
testRuntimeOnly log4jRuntimeLibs
27152717

27162718
generator project(':generator')
27172719
}
@@ -2902,7 +2904,7 @@ project(':streams:integration-tests') {
29022904
testImplementation project(':storage')
29032905
testImplementation project(':streams').sourceSets.test.output
29042906
testImplementation project(':streams:streams-scala')
2905-
testImplementation project(':test-common')
2907+
testImplementation project(':test-common:test-common-runtime')
29062908
testImplementation project(':tools')
29072909
testImplementation project(':transaction-coordinator')
29082910
testImplementation libs.bcpkix
@@ -3578,14 +3580,15 @@ project(':connect:runtime') {
35783580
testImplementation project(':server')
35793581
testImplementation project(':metadata')
35803582
testImplementation project(':server-common')
3581-
testImplementation project(':test-common')
3583+
testImplementation project(':test-common:test-common-internal-api')
3584+
testImplementation project(':test-common:test-common-util')
3585+
testImplementation project(':test-common:test-common-runtime')
35823586
testImplementation project(':server-common')
35833587
testImplementation project(':server')
35843588
testImplementation project(':group-coordinator')
35853589
testImplementation project(':storage')
35863590
testImplementation project(':connect:test-plugins')
35873591
testImplementation project(':server-common').sourceSets.test.output
3588-
testImplementation project(':test-common:test-common-api')
35893592

35903593
testImplementation libs.jacksonDatabindYaml
35913594
testImplementation libs.junitJupiter
@@ -3699,7 +3702,7 @@ project(':connect:file') {
36993702
testImplementation project(':connect:runtime')
37003703
testImplementation project(':connect:runtime').sourceSets.test.output
37013704
testImplementation project(':core')
3702-
testImplementation project(':test-common')
3705+
testImplementation project(':test-common:test-common-runtime')
37033706
testImplementation project(':server-common').sourceSets.test.output
37043707

37053708
testRuntimeOnly runtimeTestLibs
@@ -3803,7 +3806,7 @@ project(':connect:mirror') {
38033806
testImplementation project(':clients').sourceSets.test.output
38043807
testImplementation project(':connect:runtime').sourceSets.test.output
38053808
testImplementation project(':core')
3806-
testImplementation project(':test-common')
3809+
testImplementation project(':test-common:test-common-runtime')
38073810
testImplementation project(':server')
38083811
testImplementation project(':server-common').sourceSets.test.output
38093812

checkstyle/import-control-coordinator-common.xml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<allow pkg="org.apache.kafka.common.security" />
3838
<allow pkg="org.apache.kafka.common.serialization" />
3939
<allow pkg="org.apache.kafka.common.utils" />
40+
<allow pkg="org.apache.kafka.common.test.api" />
4041

4142
<subpackage name="coordinator">
4243
<subpackage name="common">

checkstyle/import-control-core.xml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<allow pkg="kafka.utils" />
3737
<allow pkg="kafka.serializer" />
3838
<allow pkg="org.apache.kafka.common" />
39+
<allow pkg="org.apache.kafka.common.test.api" />
3940
<allow pkg="org.mockito" class="AssignmentsManagerTest"/>
4041
<allow pkg="org.apache.kafka.server"/>
4142
<allow pkg="org.opentest4j" class="RemoteLogManagerTest"/>

checkstyle/import-control-group-coordinator.xml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<allow pkg="org.apache.kafka.common.utils" />
4646
<allow pkg="org.apache.kafka.common.errors" exact-match="true" />
4747
<allow pkg="org.apache.kafka.common.memory" />
48+
<allow pkg="org.apache.kafka.common.test.api" />
4849

4950
<subpackage name="coordinator">
5051
<subpackage name="group">

checkstyle/import-control-metadata.xml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<allow pkg="org.apache.kafka.common.utils" />
4545
<allow pkg="org.apache.kafka.common.errors" exact-match="true" />
4646
<allow pkg="org.apache.kafka.common.memory" />
47+
<allow pkg="org.apache.kafka.common.test.api" />
4748

4849
<!-- persistent collection factories/non-library-specific wrappers -->
4950
<allow pkg="org.apache.kafka.server.immutable" exact-match="true" />

checkstyle/import-control-server-common.xml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<allow pkg="org.apache.kafka.common.utils" />
4545
<allow pkg="org.apache.kafka.common.errors" exact-match="true" />
4646
<allow pkg="org.apache.kafka.common.memory" />
47+
<allow pkg="org.apache.kafka.common.test.api" />
4748

4849
<!-- persistent collection factories/non-library-specific wrappers -->
4950
<allow pkg="org.apache.kafka.server.immutable" exact-match="true" />

checkstyle/import-control-server.xml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<allow pkg="org.apache.kafka.common.memory" />
4848
<allow pkg="org.apache.kafka.common.network" />
4949
<allow pkg="org.apache.kafka.server.config"/>
50+
<allow pkg="org.apache.kafka.common.test.api" />
5051

5152

5253
<!-- protocol, records and request/response utilities -->

checkstyle/import-control-share-coordinator.xml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<allow pkg="org.apache.kafka.common.security" />
4141
<allow pkg="org.apache.kafka.common.serialization" />
4242
<allow pkg="org.apache.kafka.common.utils" />
43+
<allow pkg="org.apache.kafka.common.test.api" />
4344

4445
<subpackage name="coordinator">
4546
<subpackage name="share">

checkstyle/import-control-storage.xml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<allow pkg="org.apache.kafka.common.errors" exact-match="true" />
4646
<allow pkg="org.apache.kafka.common.memory" />
4747
<allow pkg="org.apache.kafka.common.test" />
48+
<allow pkg="org.apache.kafka.common.test.api" />
4849

4950

5051
<subpackage name="server">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE import-control PUBLIC
2+
"-//Puppy Crawl//DTD Import Control 1.1//EN"
3+
"http://www.puppycrawl.com/dtds/import_control_1_1.dtd">
4+
<!--
5+
Licensed to the Apache Software Foundation (ASF) under one or more
6+
contributor license agreements. See the NOTICE file distributed with
7+
this work for additional information regarding copyright ownership.
8+
The ASF licenses this file to You under the Apache License, Version 2.0
9+
(the "License"); you may not use this file except in compliance with
10+
the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
-->
20+
21+
<import-control pkg="org.apache.kafka">
22+
<!-- no one depends on the server -->
23+
<disallow pkg="kafka" />
24+
25+
<!-- anyone can use public classes -->
26+
<allow pkg="org.apache.kafka.common" exact-match="true" />
27+
<allow pkg="org.apache.kafka.common.security" />
28+
<allow pkg="org.apache.kafka.common.serialization" />
29+
<allow pkg="org.apache.kafka.common.utils" />
30+
<allow pkg="org.apache.kafka.common.errors" exact-match="true" />
31+
<allow pkg="org.apache.kafka.common.memory" />
32+
<allow pkg="org.apache.kafka.common.network" />
33+
<allow pkg="org.apache.kafka.common.test" />
34+
35+
<!-- things from server-common -->
36+
<allow pkg="org.apache.kafka.server.common" />
37+
38+
<allow pkg="java" />
39+
<allow pkg="javax.security" />
40+
<allow pkg="org.junit" />
41+
<allow pkg="org.slf4j" />
42+
43+
</import-control>

0 commit comments

Comments
 (0)