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=1cafe1cde7ae02b78dfcbd344e463f5e3548e725;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 2f78dc7..13ab0ae 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/AggregationTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/AggregationTopologyTest.java @@ -21,7 +21,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 @@ -161,8 +162,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); } }