This is an automated email from the ASF dual-hosted git repository.
chia7712 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new 6f1bd8fc637 KAFKA-18973 gracefully stopping test execution if .git
does not exist (#20703)
6f1bd8fc637 is described below
commit 6f1bd8fc6379a329d8671bed06d38f0ff7852138
Author: Arpit Goyal <[email protected]>
AuthorDate: Wed Oct 22 20:50:16 2025 +0530
KAFKA-18973 gracefully stopping test execution if .git does not exist
(#20703)
The test logic covers three main scenarios:
1. Running from the Kafka Root Directory
Action: The test immediately finds the .git directory.
Result: It uses this location to correctly find the schema file and
runs the test successfully.
2. Running from a Subdirectory
Action: The test searches up the directory tree (e.g., from
generator/ or generator/src/test/java/).
Result: It finds the .git directory at the Kafka root, uses that
root to build the correct path to the schema file, and runs the test
successfully.
3. Running from a Source Release (No Git)
Action: The test searches all the way up the entire directory tree
to the filesystem root.
Result: It never finds the .git directory, and the test skips
gracefully with a message.
Reviewers: Chia-Ping Tsai <[email protected]>
---
.../checker/MetadataSchemaCheckerToolTest.java | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git
a/generator/src/test/java/org/apache/kafka/message/checker/MetadataSchemaCheckerToolTest.java
b/generator/src/test/java/org/apache/kafka/message/checker/MetadataSchemaCheckerToolTest.java
index b1df61a1565..ba435198de2 100644
---
a/generator/src/test/java/org/apache/kafka/message/checker/MetadataSchemaCheckerToolTest.java
+++
b/generator/src/test/java/org/apache/kafka/message/checker/MetadataSchemaCheckerToolTest.java
@@ -27,18 +27,26 @@ import java.nio.file.Paths;
import static
org.apache.kafka.message.checker.CheckerTestUtils.messageSpecStringToTempFile;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class MetadataSchemaCheckerToolTest {
@Test
public void testVerifyEvolutionGit() throws Exception {
- try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
- Path rootKafkaDirectory = Paths.get("").toAbsolutePath();
- while (!Files.exists(rootKafkaDirectory.resolve(".git"))) {
- rootKafkaDirectory = rootKafkaDirectory.getParent();
- if (rootKafkaDirectory == null) {
- throw new RuntimeException("Invalid directory, need to be
within a Git repository");
- }
+ // Try to find the Git root directory
+ Path rootKafkaDirectory = Paths.get("").toAbsolutePath();
+ boolean gitFound = false;
+
+ while (rootKafkaDirectory != null) {
+ if (Files.exists(rootKafkaDirectory.resolve(".git"))) {
+ gitFound = true;
+ break;
}
+ rootKafkaDirectory = rootKafkaDirectory.getParent();
+ }
+
+ assumeTrue(gitFound, "Skipping test - not in a Git repository");
+
+ try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
Path schemaPath =
rootKafkaDirectory.resolve("metadata/src/main/resources/common/metadata/AbortTransactionRecord.json");
MetadataSchemaCheckerTool.run(
// In the CI environment because the CI fetch command only
creates HEAD and refs/remotes/pull/... references.