edoardocomar commented on code in PR #15910:
URL: https://github.com/apache/kafka/pull/15910#discussion_r1608522984


##########
connect/mirror/src/test/java/org/apache/kafka/connect/mirror/OffsetSyncStoreTest.java:
##########
@@ -155,6 +154,58 @@ public void testPastOffsetTranslation() {
         }
     }
 
+    // this test has been wriiten knowing the exact offsets syncs stored
+    @Test
+    public void testPastOffsetTranslationWithoutInitializationReadToEnd() {
+        final int maxOffsetLag = 10;
+
+        FakeOffsetSyncStore store = new FakeOffsetSyncStore() {
+            @Override
+            void backingStoreStart() {
+                for (int offset = 0; offset <= 1000; offset += maxOffsetLag) {
+                    sync(tp, offset, offset);
+                    assertSparseSyncInvariant(this, tp);
+                }
+            }
+        };
+
+        store.start(false);
+
+        // After starting but before seeing new offsets
+        assertTranslationsNearby(store, 400, 480, 0);
+        assertTranslationsNearby(store, 500, 720, 480);
+        assertTranslationsNearby(store, 1000, 1000, 990);
+
+        for (int offset = 1000; offset <= 10000; offset += maxOffsetLag) {
+            store.sync(tp, offset, offset);
+            assertSparseSyncInvariant(store, tp);
+        }
+
+        // After seeing new offsets, 1000 was kicked out of the store, so
+        // 1000 can only be traslated to 1, only previously stored offset is 0
+        assertTranslationsNearby(store, 1000, 3840, 0);
+
+        // We can translate offsets between the latest startup offset and the 
latest offset with variable precision
+        // Older offsets are less precise and translation ends up farther apart
+        assertTranslationsNearby(store, 3840, 3840, 0);
+        assertTranslationsNearby(store, 7680, 7680, 3840);
+        assertTranslationsNearby(store, 8640, 8640, 7680);
+        assertTranslationsNearby(store, 9120, 9120, 8640);
+        assertTranslationsNearby(store, 9600, 9600, 9120);
+        assertTranslationsNearby(store, 9840, 9840, 9600);
+        assertTranslationsNearby(store, 9900, 9900, 9840);
+        assertTranslationsNearby(store, 9960, 9960, 9900);
+        assertTranslationsNearby(store, 9990, 9990, 9960);
+        assertTranslationsNearby(store, 10000, 10000, 9990);

Review Comment:
   brilliant suggestion!



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to