From: Kai Moritz Date: Mon, 8 Jul 2024 12:19:11 +0000 (+0200) Subject: Created `TimeWindow` explicitly to further simplify/clearfy the test X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=66bf6ab006e8c5988e797de867c7d4cb283eb6b2;p=demos%2Fkafka%2Fwordcount Created `TimeWindow` explicitly to further simplify/clearfy the test --- diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/AggregationTopologyTest.java b/src/test/java/de/juplo/kafka/wordcount/counter/AggregationTopologyTest.java index 94935be..024f8e4 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/AggregationTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/AggregationTopologyTest.java @@ -23,7 +23,8 @@ import static org.assertj.core.api.Assertions.assertThat; @Slf4j public class AggregationTopologyTest { - static final TimeWindows WINDOWS = TimeWindows.ofSizeWithNoGrace(Duration.ofSeconds(10)); + static final Duration WINDOW_SIZE = Duration.ofSeconds(10); + static final TimeWindows WINDOWS = TimeWindows.ofSizeWithNoGrace(WINDOW_SIZE); @Test @@ -164,8 +165,9 @@ public class AggregationTopologyTest Windowed windowFor(int second) { - Instant time = Instant.ofEpochSecond(second); - long timestamp = time.toEpochMilli(); - return new Windowed<>(KEY, WINDOWS.windowsFor(timestamp).values().stream().findFirst().get()); + Instant startTime = Instant.ofEpochSecond(second); + Instant endTime = startTime.plus(WINDOW_SIZE); + TimeWindow window = new TimeWindow(startTime.toEpochMilli(), endTime.toEpochMilli()); + return new Windowed<>(KEY, window); } }