sashapolo commented on code in PR #7610:
URL: https://github.com/apache/ignite-3/pull/7610#discussion_r2847037629


##########
modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMetaTest.java:
##########
@@ -277,4 +279,145 @@ void 
testTruncatePrefixRemovesAllEntriesWhenKeptAfterLast() {
         assertThat(groupMeta.indexMeta(19), is(nullValue()));
         assertThat(groupMeta.firstLogIndexInclusive(), is(-1L));
     }
+
+    @Test
+    void testOnIndexCompacted() {
+        var meta1 = new IndexFileMeta(1, 50, 0, new FileProperties(0));
+        var meta2 = new IndexFileMeta(50, 100, 42, new FileProperties(1));
+        var meta3 = new IndexFileMeta(100, 150, 84, new FileProperties(2));
+
+        var groupMeta = new GroupIndexMeta(meta1);
+        groupMeta.addIndexMeta(meta2);
+        groupMeta.addIndexMeta(meta3);
+
+        var compactedMeta2 = new IndexFileMeta(50, 100, 42, new 
FileProperties(1, 1));
+        groupMeta.onIndexCompacted(new FileProperties(1), compactedMeta2);
+
+        assertThat(groupMeta.indexMeta(1), is(meta1));
+        assertThat(groupMeta.indexMeta(50), is(compactedMeta2));
+        assertThat(groupMeta.indexMeta(100), is(meta3));
+    }
+
+    @Test
+    void testOnIndexRemoved() {
+        var meta1 = new IndexFileMeta(1, 50, 0, new FileProperties(0));
+        var meta2 = new IndexFileMeta(50, 100, 42, new FileProperties(1));
+        var meta3 = new IndexFileMeta(100, 150, 84, new FileProperties(2));
+
+        var groupMeta = new GroupIndexMeta(meta1);
+        groupMeta.addIndexMeta(meta2);
+        groupMeta.addIndexMeta(meta3);
+
+        groupMeta.onIndexRemoved(new FileProperties(1));
+
+        assertThat(groupMeta.indexMeta(1), is(meta1));
+        assertThat(groupMeta.indexMeta(50), is(nullValue()));
+        assertThat(groupMeta.indexMeta(99), is(nullValue()));
+        assertThat(groupMeta.indexMeta(100), is(meta3));
+        assertThat(groupMeta.lastLogIndexExclusive(), is(150L));
+    }
+
+    @Test
+    void testOnIndexCompactedWithMultipleBlocks() {
+        // meta1 is in block 0.
+        var meta1 = new IndexFileMeta(1, 100, 0, new FileProperties(0));
+        var groupMeta = new GroupIndexMeta(meta1);
+
+        // meta2 overlaps meta1, creating a second block in the deque.
+        var meta2 = new IndexFileMeta(42, 100, 42, new FileProperties(1));
+        groupMeta.addIndexMeta(meta2);
+
+        // meta3 is added to the second block (consecutive to meta2).
+        var meta3 = new IndexFileMeta(100, 200, 84, new FileProperties(2));
+        groupMeta.addIndexMeta(meta3);
+
+        // Compact meta1 from the older block.
+        var compactedMeta1 = new IndexFileMeta(1, 100, 0, new 
FileProperties(0, 1));
+        groupMeta.onIndexCompacted(new FileProperties(0), compactedMeta1);
+
+        assertThat(groupMeta.indexMeta(1), is(compactedMeta1));
+        assertThat(groupMeta.indexMeta(42), is(meta2));
+        assertThat(groupMeta.indexMeta(100), is(meta3));
+
+        // Compact meta3 from the newer block.
+        var compactedMeta3 = new IndexFileMeta(100, 200, 84, new 
FileProperties(2, 1));
+        groupMeta.onIndexCompacted(new FileProperties(2), compactedMeta3);
+
+        assertThat(groupMeta.indexMeta(1), is(compactedMeta1));
+        assertThat(groupMeta.indexMeta(42), is(meta2));
+        assertThat(groupMeta.indexMeta(100), is(compactedMeta3));
+    }
+
+    @Test
+    void testOnIndexRemovedWithMultipleBlocks() {
+        var meta1 = new IndexFileMeta(1, 50, 0, new FileProperties(0));
+        var meta1b = new IndexFileMeta(50, 100, 42, new FileProperties(1));
+
+        var groupMeta = new GroupIndexMeta(meta1);
+        groupMeta.addIndexMeta(meta1b);
+
+        var meta2 = new IndexFileMeta(42, 100, 42, new FileProperties(2));
+        groupMeta.addIndexMeta(meta2);
+
+        var meta3 = new IndexFileMeta(100, 150, 84, new FileProperties(3));
+        groupMeta.addIndexMeta(meta3);
+
+        groupMeta.onIndexRemoved(new FileProperties(2));
+
+        assertThat(groupMeta.indexMeta(42), is(meta1));

Review Comment:
   See my answer above. In general, I agree, going to make the contract more 
strict



-- 
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