From 66bf6ab006e8c5988e797de867c7d4cb283eb6b2 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 8 Jul 2024 14:19:11 +0200 Subject: [PATCH] Created `TimeWindow` explicitly to further simplify/clearfy the test --- .../wordcount/counter/AggregationTopologyTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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); } } -- 2.20.1