Skip to content

[GSoC 2026] Kafka Streams runner — KafkaStreamsTestRunner test harness#39211

Open
junaiddshaukat wants to merge 1 commit into
apache:feat/18479-kafka-streams-runner-skeletonfrom
junaiddshaukat:feat/ks-test-runner
Open

[GSoC 2026] Kafka Streams runner — KafkaStreamsTestRunner test harness#39211
junaiddshaukat wants to merge 1 commit into
apache:feat/18479-kafka-streams-runner-skeletonfrom
junaiddshaukat:feat/ks-test-runner

Conversation

@junaiddshaukat

@junaiddshaukat junaiddshaukat commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

First part of the testing-infra sub-issue (#39192): a reusable KafkaStreamsTestRunner that removes the translate + drive boilerplate every test repeated, and is the foundation for Create support and the first @ValidatesRunner tests (the next two parts).

  • run(Pipeline) translates + drives through a TopologyTestDriver, and
    auto-discovers internal repartition topics (both a sink and a source, via
    TopologyDescription) and round-trips them to quiescence — generalising the
    manual repartition loop GroupByKeyTest used to do by hand.
  • translate() / streamsConfig() / leafProcessorName() for tests that need
    the Topology (to attach a capture processor before driving).
  • testOptions() for the EMBEDDED harness + a unique app id.

Migrates 4 tests onto it; ChainedExecutableStageTest keeps its explicit
translate because it asserts on the prepared proto's ExecutableStage count.

Testing

Test-only change, no runner behaviour change. :check green, 36 tests.

Refs #39192
cc @je-ik

First part of the testing-infra sub-issue: extract the translate + drive
boilerplate every runner test repeated into a reusable KafkaStreamsTestRunner.

- run(Pipeline): translate + drive through a TopologyTestDriver, and — since the
  driver does not loop a low-level sink topic back into its source — auto-discover
  internal repartition topics (those that appear as both a sink and a source, via
  TopologyDescription) and round-trip them to quiescence. This generalises the
  manual repartition loop GroupByKeyTest did by hand.
- translate(Pipeline) / streamsConfig(Pipeline) / leafProcessorName(Topology) for
  tests that need the Topology to attach a capture processor before driving.
- testOptions(): the EMBEDDED harness + a unique application id.

Migrate GroupByKeyTest and ExecutableStageTranslatorTest to run(), and
WatermarkPropagationTest and KafkaStreamsRunnerTest to translate()/streamsConfig().
ChainedExecutableStageTest keeps its explicit translate because it asserts on the
prepared pipeline proto's ExecutableStage count. Test-only; no runner behaviour
change.

Refs apache#39192
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a reusable test harness, KafkaStreamsTestRunner, for the Kafka Streams runner. The primary goal is to abstract away the repetitive setup involved in translating and driving Beam pipelines through TopologyTestDriver. By automating the management of internal repartition topics and providing consistent test options, this change simplifies the testing infrastructure and improves maintainability for future runner tests.

Highlights

  • New Test Harness: Introduced the KafkaStreamsTestRunner utility to centralize pipeline translation and execution logic, significantly reducing boilerplate code in integration tests.
  • Automated Repartition Handling: Implemented automatic discovery and round-tripping of internal repartition topics within the test harness, simplifying tests that involve GroupByKey.
  • Test Migration: Refactored existing integration tests (KafkaStreamsRunnerTest, ExecutableStageTranslatorTest, GroupByKeyTest, and WatermarkPropagationTest) to utilize the new KafkaStreamsTestRunner.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces KafkaStreamsTestRunner, a reusable test harness that simplifies Beam pipeline translation and execution using TopologyTestDriver in Kafka Streams runner tests. It refactors several test classes (KafkaStreamsRunnerTest, ExecutableStageTranslatorTest, GroupByKeyTest, and WatermarkPropagationTest) to eliminate redundant boilerplate. Feedback on the new test runner includes: ensuring leafProcessorName is deterministic by verifying only a single leaf processor exists, adding a null check for topicSet() on source nodes to prevent potential NullPointerExceptions, and optimizing roundTripInternalTopics by instantiating TestInputTopic and TestOutputTopic outside of the loop.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +119 to +128
public static String leafProcessorName(Topology topology) {
for (TopologyDescription.Subtopology subtopology : topology.describe().subtopologies()) {
for (TopologyDescription.Node node : subtopology.nodes()) {
if (node instanceof TopologyDescription.Processor && node.successors().isEmpty()) {
return node.name();
}
}
}
throw new IllegalStateException("no leaf processor found in topology");
}

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.

medium

The iteration order of subtopology.nodes() (which returns a Set) is not guaranteed to be deterministic. If a topology contains multiple leaf processors (processors with no successors), leafProcessorName will return whichever leaf it encounters first, which could lead to non-deterministic test failures. Collecting all leaf processors and asserting that exactly one exists makes the test harness more robust and deterministic.

  public static String leafProcessorName(Topology topology) {
    List<String> leaves = new java.util.ArrayList<>();
    for (TopologyDescription.Subtopology subtopology : topology.describe().subtopologies()) {
      for (TopologyDescription.Node node : subtopology.nodes()) {
        if (node instanceof TopologyDescription.Processor && node.successors().isEmpty()) {
          leaves.add(node.name());
        }
      }
    }
    if (leaves.isEmpty()) {
      throw new IllegalStateException("no leaf processor found in topology");
    }
    if (leaves.size() > 1) {
      throw new IllegalStateException("multiple leaf processors found in topology: " + leaves);
    }
    return leaves.get(0);
  }

Comment on lines +141 to +143
} else if (node instanceof TopologyDescription.Source) {
sourceTopics.addAll(((TopologyDescription.Source) node).topicSet());
}

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.

medium

If a source node in the topology is configured using a Pattern instead of a set of topic names, topicSet() will return null. Calling sourceTopics.addAll(null) will throw a NullPointerException. Adding a null check before calling addAll prevents potential crashes when pattern-based sources are used.

        } else if (node instanceof TopologyDescription.Source) {
          Set<String> topics = ((TopologyDescription.Source) node).topicSet();
          if (topics != null) {
            sourceTopics.addAll(topics);
          }
        }

Comment on lines +151 to +175
private static void roundTripInternalTopics(TopologyTestDriver driver, Set<String> topics) {
for (int round = 0; round < MAX_ROUND_TRIPS; round++) {
boolean progressed = false;
for (String topic : topics) {
TestOutputTopic<byte[], byte[]> out =
driver.createOutputTopic(
topic, new ByteArrayDeserializer(), new ByteArrayDeserializer());
List<TestRecord<byte[], byte[]>> records = out.readRecordsToList();
if (records.isEmpty()) {
continue;
}
progressed = true;
TestInputTopic<byte[], byte[]> in =
driver.createInputTopic(topic, new ByteArraySerializer(), new ByteArraySerializer());
for (TestRecord<byte[], byte[]> record : records) {
in.pipeInput(record);
}
}
if (!progressed) {
return;
}
}
throw new IllegalStateException(
"Internal topics did not reach quiescence after " + MAX_ROUND_TRIPS + " round trips");
}

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.

medium

Creating TestInputTopic and TestOutputTopic instances inside the round-trip loop on every iteration is inefficient as it repeatedly allocates new objects and performs lookups in TopologyTestDriver's internal maps. Instantiating them once outside the loop improves performance and reduces overhead.

  private static void roundTripInternalTopics(TopologyTestDriver driver, Set<String> topics) {
    java.util.Map<String, TestOutputTopic<byte[], byte[]>> outputs = new java.util.HashMap<>();
    java.util.Map<String, TestInputTopic<byte[], byte[]>> inputs = new java.util.HashMap<>();
    for (String topic : topics) {
      outputs.put(
          topic,
          driver.createOutputTopic(
              topic, new ByteArrayDeserializer(), new ByteArrayDeserializer()));
      inputs.put(
          topic,
          driver.createInputTopic(topic, new ByteArraySerializer(), new ByteArraySerializer()));
    }

    for (int round = 0; round < MAX_ROUND_TRIPS; round++) {
      boolean progressed = false;
      for (String topic : topics) {
        TestOutputTopic<byte[], byte[]> out = outputs.get(topic);
        List<TestRecord<byte[], byte[]>> records = out.readRecordsToList();
        if (records.isEmpty()) {
          continue;
        }
        progressed = true;
        TestInputTopic<byte[], byte[]> in = inputs.get(topic);
        for (TestRecord<byte[], byte[]> record : records) {
          in.pipeInput(record);
        }
      }
      if (!progressed) {
        return;
      }
    }
    throw new IllegalStateException(
        "Internal topics did not reach quiescence after " + MAX_ROUND_TRIPS + " round trips");
  }

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @kennknowles added as fallback since no labels match configuration

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@je-ik je-ik self-requested a review July 3, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant