Created `TimeWindow` explicitly to further simplify/clearfy the test
authorKai Moritz <kai@juplo.de>
Mon, 8 Jul 2024 12:19:11 +0000 (14:19 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 8 Jul 2024 12:19:11 +0000 (14:19 +0200)
src/test/java/de/juplo/kafka/wordcount/counter/AggregationTopologyTest.java

index 94935be..024f8e4 100644 (file)
@@ -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<String> 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);
   }
 }