imbajin commented on code in PR #2982:
URL: https://github.com/apache/hugegraph/pull/2982#discussion_r3323595551


##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/rocksdb/RocksDBTableQueryByIdsTest.java:
##########
@@ -0,0 +1,361 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.unit.rocksdb;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.id.IdGenerator;
+import org.apache.hugegraph.backend.store.BackendEntry.BackendColumn;
+import org.apache.hugegraph.backend.store.BackendEntry.BackendColumnIterator;
+import org.apache.hugegraph.backend.store.rocksdb.RocksDBSessions;
+import org.apache.hugegraph.backend.store.rocksdb.RocksDBTables;
+import org.apache.hugegraph.testutil.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.rocksdb.RocksDBException;
+
+public class RocksDBTableQueryByIdsTest extends BaseRocksDBUnitTest {
+
+    private static final String DATABASE = "db";
+
+    private TestVertexTable vertexTable;
+    private TestEdgeTable edgeOutTable;
+    private TestEdgeTable edgeInTable;
+
+    @Override
+    @Before
+    public void setup() throws RocksDBException {
+        super.setup();
+        this.vertexTable = new TestVertexTable(DATABASE);
+        this.edgeOutTable = new TestEdgeTable(true, DATABASE);
+        this.edgeInTable = new TestEdgeTable(false, DATABASE);
+        this.rocks.createTable(this.vertexTable.table());
+        this.rocks.createTable(this.edgeOutTable.table());
+        this.rocks.createTable(this.edgeInTable.table());
+    }
+
+    @Test
+    public void testVertexQueryByIdsWithAllExistingIds() {
+        Id id1 = IdGenerator.of("v1");
+        Id id2 = IdGenerator.of("v2");
+        Id id3 = IdGenerator.of("v3");
+
+        this.rocks.session().put(this.vertexTable.table(), id1.asBytes(), 
getBytes("value1"));
+        this.rocks.session().put(this.vertexTable.table(), id2.asBytes(), 
getBytes("value2"));
+        this.rocks.session().put(this.vertexTable.table(), id3.asBytes(), 
getBytes("value3"));
+        this.commit();
+
+        List<Id> ids = Arrays.asList(id1, id2, id3);
+        BackendColumnIterator iter = 
this.vertexTable.queryByIds(this.rocks.session(), ids);
+
+        Map<String, String> results = toResultMap(iter);
+
+        Assert.assertEquals(3, results.size());
+        Assert.assertEquals("value1", results.get("v1"));
+        Assert.assertEquals("value2", results.get("v2"));
+        Assert.assertEquals("value3", results.get("v3"));
+    }
+
+    @Test
+    public void testVertexQueryByIdsWithExistingAndMissingIdsMixed() {
+        Id id1 = IdGenerator.of("v1");
+        Id id2 = IdGenerator.of("v2");
+        Id id3 = IdGenerator.of("v3");
+
+        this.rocks.session().put(this.vertexTable.table(), id1.asBytes(), 
getBytes("value1"));
+        this.rocks.session().put(this.vertexTable.table(), id3.asBytes(), 
getBytes("value3"));
+        this.commit();
+
+        List<Id> ids = Arrays.asList(id1, id2, id3);
+        BackendColumnIterator iter = 
this.vertexTable.queryByIds(this.rocks.session(), ids);
+
+        Map<String, String> results = toResultMap(iter);
+
+        Assert.assertEquals(2, results.size());
+        Assert.assertEquals("value1", results.get("v1"));
+        Assert.assertEquals("value3", results.get("v3"));
+        Assert.assertFalse(results.containsKey("v2"));
+    }
+
+    @Test
+    public void testVertexQueryByIdsDedupsDuplicateIds() {
+        Id id1 = IdGenerator.of("v1");
+        Id id2 = IdGenerator.of("v2");
+
+        this.rocks.session().put(this.vertexTable.table(), id1.asBytes(), 
getBytes("value1"));
+        this.rocks.session().put(this.vertexTable.table(), id2.asBytes(), 
getBytes("value2"));
+        this.commit();
+
+        List<Id> ids = Arrays.asList(id1, id2, id1);
+        BackendColumnIterator iter = 
this.vertexTable.queryByIds(this.rocks.session(), ids);
+
+        Map<String, String> results = toResultMap(iter);

Review Comment:
   This test does not actually protect the duplicate-id behavior because 
`toResultMap()` collapses duplicate rows by key before the assertion. If 
`queryByIds()` regressed and returned `v1, v2, v1`, the map would still contain 
only two entries and this test would pass. Since this PR explicitly 
deduplicates ids before multi-get, please assert the iterator output 
sequence/count directly (for example collect the column names into a list) so 
duplicate backend results would fail the test.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to