From 1cafe1cde7ae02b78dfcbd344e463f5e3548e725 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 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); } } -- 2.20.1