-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-7944: Improve Suppress test coverage #6382
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
Changes from all commits
63c4d7b
efb4407
a724897
5ad02ea
48dabcd
7420fd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,16 +32,19 @@ | |
| import org.apache.kafka.streams.kstream.KTable; | ||
| import org.apache.kafka.streams.kstream.Materialized; | ||
| import org.apache.kafka.streams.kstream.Produced; | ||
| import org.apache.kafka.streams.kstream.Suppressed; | ||
| import org.apache.kafka.streams.kstream.Suppressed.BufferConfig; | ||
| import org.apache.kafka.streams.kstream.TimeWindows; | ||
| import org.apache.kafka.streams.kstream.Windowed; | ||
| import org.apache.kafka.streams.state.Stores; | ||
| import org.apache.kafka.streams.state.WindowStore; | ||
| import org.apache.kafka.test.TestUtils; | ||
|
|
||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.Properties; | ||
|
|
||
| import static org.apache.kafka.streams.kstream.Suppressed.untilWindowCloses; | ||
|
|
||
| public class SmokeTestClient extends SmokeTestUtil { | ||
|
|
||
| private final String name; | ||
|
|
@@ -113,7 +116,7 @@ private KafkaStreams createKafkaStreams(final Properties props) { | |
| final Topology build = getTopology(); | ||
| final KafkaStreams streamsClient = new KafkaStreams(build, getStreamsConfig(props)); | ||
| streamsClient.setStateListener((newState, oldState) -> { | ||
| System.out.printf("%s: %s -> %s%n", name, oldState, newState); | ||
| System.out.printf("%s %s: %s -> %s%n", name, Instant.now(), oldState, newState); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this while debugging the smoke test. Printing the time allows us to correlate events across test nodes and with the test logs.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice find! |
||
| if (oldState == KafkaStreams.State.REBALANCING && newState == KafkaStreams.State.RUNNING) { | ||
| started = true; | ||
| } | ||
|
|
@@ -149,24 +152,22 @@ public Topology getTopology() { | |
| .withRetention(Duration.ofHours(25)) | ||
| ); | ||
|
|
||
| minAggregation | ||
| .toStream() | ||
| .filterNot((k, v) -> k.key().equals("flush")) | ||
| .map((key, value) -> new KeyValue<>(key.toString(), value)) | ||
| .to("min-raw", Produced.with(stringSerde, intSerde)); | ||
| streamify(minAggregation, "min-raw"); | ||
|
|
||
| minAggregation | ||
| .suppress(Suppressed.untilWindowCloses(Suppressed.BufferConfig.unbounded())) | ||
| .toStream() | ||
| .filterNot((k, v) -> k.key().equals("flush")) | ||
| .map((key, value) -> new KeyValue<>(key.toString(), value)) | ||
| .to("min-suppressed", Produced.with(stringSerde, intSerde)); | ||
| streamify(minAggregation.suppress(untilWindowCloses(BufferConfig.unbounded())), "min-suppressed"); | ||
|
|
||
| minAggregation | ||
| .toStream(new Unwindow<>()) | ||
| .filterNot((k, v) -> k.equals("flush")) | ||
| .to("min", Produced.with(stringSerde, intSerde)); | ||
|
|
||
| final KTable<Windowed<String>, Integer> smallWindowSum = groupedData | ||
| .windowedBy(TimeWindows.of(Duration.ofSeconds(2)).advanceBy(Duration.ofSeconds(1)).grace(Duration.ofSeconds(30))) | ||
| .reduce((l, r) -> l + r); | ||
|
|
||
| streamify(smallWindowSum, "sws-raw"); | ||
| streamify(smallWindowSum.suppress(untilWindowCloses(BufferConfig.unbounded())), "sws-suppressed"); | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a "small window sum" stream to the topology, which does a "normal" windowed computation. The exact data production timing is non-deterministic, so we can't verify the results, but we can verify that there is exactly one result per windowed key in the suppressed stream |
||
| final KTable<String, Integer> minTable = builder.table( | ||
| "min", | ||
| Consumed.with(stringSerde, intSerde), | ||
|
|
@@ -250,4 +251,12 @@ public Topology getTopology() { | |
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
| private static void streamify(final KTable<Windowed<String>, Integer> windowedTable, final String topic) { | ||
| windowedTable | ||
| .toStream() | ||
| .filterNot((k, v) -> k.key().equals("flush")) | ||
| .map((key, value) -> new KeyValue<>(key.toString(), value)) | ||
| .to(topic, Produced.with(stringSerde, intSerde)); | ||
| } | ||
| } | ||
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.
More stable and future-proof test setup code. I needed this because I added a second test here, which I've since removed.
Leaving this change, though, so we won't have to waste time debugging again next time we try to add a test.