showuon commented on a change in pull request #11227:
URL: https://github.com/apache/kafka/pull/11227#discussion_r695758175



##########
File path: 
streams/src/test/java/org/apache/kafka/streams/state/internals/CachingPersistentWindowStoreTest.java
##########
@@ -297,6 +297,186 @@ public void shouldPutFetchRangeFromCache() {
         }
     }
 
+    @Test
+    public void shouldPutFetchRangeFromCacheForNullKeyFrom() {
+        cachingStore.put(bytesKey("a"), bytesValue("a"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("b"), bytesValue("b"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("c"), bytesValue("c"), DEFAULT_TIMESTAMP + 
10L);
+        cachingStore.put(bytesKey("d"), bytesValue("d"), DEFAULT_TIMESTAMP + 
20L);
+        cachingStore.put(bytesKey("e"), bytesValue("e"), DEFAULT_TIMESTAMP + 
20L);
+
+        try (final KeyValueIterator<Windowed<Bytes>, byte[]> iterator =
+                 cachingStore.fetch(null, bytesKey("d"), 
ofEpochMilli(DEFAULT_TIMESTAMP), ofEpochMilli(DEFAULT_TIMESTAMP + 20L))) {
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("a"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "a");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("b"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "b");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("c"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 10L, DEFAULT_TIMESTAMP + 10L + WINDOW_SIZE)),
+                "c");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("d"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "d");
+            assertFalse(iterator.hasNext());
+        }
+    }
+
+    @Test
+    public void shouldPutFetchRangeFromCacheForNullKeyTo() {
+        cachingStore.put(bytesKey("a"), bytesValue("a"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("b"), bytesValue("b"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("c"), bytesValue("c"), DEFAULT_TIMESTAMP + 
10L);
+        cachingStore.put(bytesKey("d"), bytesValue("d"), DEFAULT_TIMESTAMP + 
20L);
+        cachingStore.put(bytesKey("e"), bytesValue("e"), DEFAULT_TIMESTAMP + 
20L);
+
+        try (final KeyValueIterator<Windowed<Bytes>, byte[]> iterator =
+                 cachingStore.fetch(bytesKey("b"), null, 
ofEpochMilli(DEFAULT_TIMESTAMP), ofEpochMilli(DEFAULT_TIMESTAMP + 20L))) {
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("b"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "b");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("c"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 10L, DEFAULT_TIMESTAMP + 10L + WINDOW_SIZE)),
+                "c");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("d"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "d");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("e"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "e");
+            assertFalse(iterator.hasNext());
+        }
+    }
+
+    @Test
+    public void shouldPutFetchRangeFromCacheForNullKeyFromKeyTo() {
+        cachingStore.put(bytesKey("a"), bytesValue("a"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("b"), bytesValue("b"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("c"), bytesValue("c"), DEFAULT_TIMESTAMP + 
10L);
+        cachingStore.put(bytesKey("d"), bytesValue("d"), DEFAULT_TIMESTAMP + 
20L);
+        cachingStore.put(bytesKey("e"), bytesValue("e"), DEFAULT_TIMESTAMP + 
20L);
+
+        try (final KeyValueIterator<Windowed<Bytes>, byte[]> iterator =
+                 cachingStore.fetch(null, null, 
ofEpochMilli(DEFAULT_TIMESTAMP), ofEpochMilli(DEFAULT_TIMESTAMP + 20L))) {
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("a"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "a");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("b"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "b");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("c"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 10L, DEFAULT_TIMESTAMP + 10L + WINDOW_SIZE)),
+                "c");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("d"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "d");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("e"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "e");
+            assertFalse(iterator.hasNext());
+        }
+    }
+
+    @Test
+    public void shouldPutBackwardFetchRangeFromCacheForNullKeyFrom() {
+        cachingStore.put(bytesKey("a"), bytesValue("a"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("b"), bytesValue("b"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("c"), bytesValue("c"), DEFAULT_TIMESTAMP + 
10L);
+        cachingStore.put(bytesKey("d"), bytesValue("d"), DEFAULT_TIMESTAMP + 
20L);
+        cachingStore.put(bytesKey("e"), bytesValue("e"), DEFAULT_TIMESTAMP + 
20L);
+
+        try (final KeyValueIterator<Windowed<Bytes>, byte[]> iterator =
+                 cachingStore.backwardFetch(null, bytesKey("c"), 
ofEpochMilli(DEFAULT_TIMESTAMP), ofEpochMilli(DEFAULT_TIMESTAMP + 20L))) {
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("c"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 10L, DEFAULT_TIMESTAMP + 10L + WINDOW_SIZE)),
+                "c");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("b"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "b");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("a"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "a");
+            assertFalse(iterator.hasNext());
+        }
+    }
+
+    @Test
+    public void shouldPutBackwardFetchRangeFromCacheForNullKeyTo() {
+        cachingStore.put(bytesKey("a"), bytesValue("a"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("b"), bytesValue("b"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("c"), bytesValue("c"), DEFAULT_TIMESTAMP + 
10L);
+        cachingStore.put(bytesKey("d"), bytesValue("d"), DEFAULT_TIMESTAMP + 
20L);
+        cachingStore.put(bytesKey("e"), bytesValue("e"), DEFAULT_TIMESTAMP + 
20L);
+
+        try (final KeyValueIterator<Windowed<Bytes>, byte[]> iterator =
+                 cachingStore.backwardFetch(bytesKey("c"), null, 
ofEpochMilli(DEFAULT_TIMESTAMP), ofEpochMilli(DEFAULT_TIMESTAMP + 20L))) {
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("e"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "e");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("d"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "d");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("c"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 10L, DEFAULT_TIMESTAMP + 10L + WINDOW_SIZE)),
+                "c");
+            assertFalse(iterator.hasNext());
+        }
+    }
+
+    @Test
+    public void shouldPutBackwardFetchRangeFromCacheForNullKeyFromKeyTo() {
+        cachingStore.put(bytesKey("a"), bytesValue("a"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("b"), bytesValue("b"), DEFAULT_TIMESTAMP);
+        cachingStore.put(bytesKey("c"), bytesValue("c"), DEFAULT_TIMESTAMP + 
10L);
+        cachingStore.put(bytesKey("d"), bytesValue("d"), DEFAULT_TIMESTAMP + 
20L);
+        cachingStore.put(bytesKey("e"), bytesValue("e"), DEFAULT_TIMESTAMP + 
20L);
+
+        try (final KeyValueIterator<Windowed<Bytes>, byte[]> iterator =
+                 cachingStore.backwardFetch(null, null, 
ofEpochMilli(DEFAULT_TIMESTAMP), ofEpochMilli(DEFAULT_TIMESTAMP + 20L))) {
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("e"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "e");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("d"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 20L, DEFAULT_TIMESTAMP + 20L + WINDOW_SIZE)),
+                "d");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("c"), new TimeWindow(DEFAULT_TIMESTAMP 
+ 10L, DEFAULT_TIMESTAMP + 10L + WINDOW_SIZE)),
+                "c");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("b"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "b");
+            verifyWindowedKeyValue(
+                iterator.next(),
+                new Windowed<>(bytesKey("a"), new 
TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)),
+                "a");
+            assertFalse(iterator.hasNext());

Review comment:
       Updated. Thanks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to