-
Notifications
You must be signed in to change notification settings - Fork 15.3k
KAFKA-19871: Add a TopologyTestDriverBuilder, deprecate old constructors #22673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mjsax
merged 6 commits into
apache:trunk
from
sebastienviale:KAFKA-19871-Multipartition-TTDriver-Add-Builder
Jul 1, 2026
+188
−54
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bcc377f
KAFKA-19871: Add a TopologyTestDriverBuilder, deprecate old constructors
sebastienviale a0ba3d9
KAFKA-19871: Add a TopologyTestDriverBuilder, deprecate old constructors
sebastienviale d3a10db
KAFKA-19871: Add a TopologyTestDriverBuilder, deprecate old constructors
sebastienviale efd3c7c
KAFKA-19871: Add a TopologyTestDriverBuilder, deprecate old constructors
sebastienviale 71f9575
KAFKA-19871: Add a TopologyTestDriverBuilder, deprecate old constructors
sebastienviale 9a10ce9
KAFKA-19871: Add a TopologyTestDriverBuilder, deprecate old constructors
sebastienviale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriverBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.streams; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.Properties; | ||
|
|
||
| /** | ||
| * Fluent builder for a {@link TopologyTestDriver}. | ||
| * | ||
| * <p>This is the entry point for constructing a {@link TopologyTestDriver}. | ||
| * Configure the builder and call {@link #build()}. | ||
| * The {@link TopologyTestDriver} constructors remain functional but are deprecated in favor of | ||
| * this builder.</p> | ||
| * | ||
| * <pre>{@code | ||
| * TopologyTestDriver driver = new TopologyTestDriverBuilder(topology) | ||
| * .withConfig(props) | ||
| * .withInitialWallClockTime(Instant.ofEpochMilli(0)) | ||
| * .build(); | ||
| * }</pre> | ||
| */ | ||
| public class TopologyTestDriverBuilder { | ||
|
mjsax marked this conversation as resolved.
|
||
|
|
||
| private final Topology topology; | ||
| private Properties config = new Properties(); | ||
|
mjsax marked this conversation as resolved.
|
||
| private Optional<Instant> initialWallClockTime = Optional.empty(); | ||
|
|
||
| /** | ||
| * Start building a driver for the given topology. | ||
| * | ||
| * @param topology the topology to be tested | ||
| */ | ||
| public TopologyTestDriverBuilder(final Topology topology) { | ||
| this.topology = Objects.requireNonNull(topology, "topology cannot be null"); | ||
| } | ||
|
|
||
| /** | ||
| * Set the configuration passed to the driver. Optional; defaults to empty {@link Properties}. | ||
| * | ||
| * @param config the configuration for the topology | ||
| * @return this builder | ||
| */ | ||
| public TopologyTestDriverBuilder withConfig(final Properties config) { | ||
| this.config = Objects.requireNonNull(config, "config cannot be null"); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the initial value of the driver's internally mocked wall-clock time. Optional; defaults to | ||
| * the current system time. | ||
| * | ||
| * @param initialWallClockTime the initial mocked wall-clock time | ||
| * @return this builder | ||
| */ | ||
| public TopologyTestDriverBuilder withInitialWallClockTime(final Instant initialWallClockTime) { | ||
| this.initialWallClockTime = Optional.ofNullable(initialWallClockTime); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Build the driver: construct it and apply all declared topic partition counts. | ||
| * | ||
| * @return a ready-to-use {@link TopologyTestDriver} | ||
| */ | ||
| public TopologyTestDriver build() { | ||
| return new TopologyTestDriver( | ||
| topology.internalTopologyBuilder, | ||
| config, | ||
| initialWallClockTime.map(Instant::toEpochMilli).orElseGet(System::currentTimeMillis)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For single-partition mode, should we set
1?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, in the KIP it is specified that single-partition mode will carry partition 0.
In that case, all existing tests that compare a
TestRecordviaequals()/equalTo()against an expected record built from a partition-less constructor will fail (e.g. the test below), since the expected record defaults to partition-1while the actual output record would now carry0.For example:
kafka/streams/test-utils/src/test/java/org/apache/kafka/streams/TestTopicsTest.java
Lines 268 to 282 in 4a2edef
If we change it to 0 now, we'll need to update all the affected tests by using
equalsIgnorePartition(). We can do that now in this PR, or in a follow-up PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, I did mean
0of course...But your point about breaking existing tests is crucial. In the end, it does not only affect our tests in
kafka.gitbut all existing user tests, too, and we should not break them. So I think we better keep-1and update the KIP accordingly, and explain why-1is necessary for single-partition mode to preserve backward compatiblity?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the KIP in the TestRecord class changes and Compatibility, Deprecation, and Migration Plan sections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Thanks.
Can you send a shote note to the VOTE thread for the KIP, calling out this small change. It's best practice to call out small changes (no need to re-vote of course for such a small change).