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


##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java:
##########
@@ -244,12 +251,19 @@
         RocksDBSessionTest.class,
         RocksDBCountersTest.class,
         RocksDBTableQueryByIdsTest.class,
+        RocksDBStdSessionsLifecycleTest.class,
+        RocksDBIteratorPoolTest.class,
+
+        /* memory */
+        MemoryAllocateTest.class,

Review Comment:
   [P2] Scale down and clean up allocation tests before registering them
   
   This registration makes the ordinary unit suite run testNettyAllocate(), 
which requests a real 1-GiB direct ByteBuf and never releases its three 
buffers, and testOnHeapAllocate(), which creates a real 1-GiB byte array. The 
forceAllocate implementations call directBuffer((int) size) and new byte[(int) 
size], so this introduces a >1-GiB heap requirement and a 1-GiB 
direct-memory request even when the allocator is correct. A unit-test fork 
capped at 1 GiB or less cannot pass the heap allocation. Please use a small 
temporary manager limit and small boundary allocations, restore the prior 
settings, and release every ByteBuf in finally before enabling this class.
   
   Reviewed head: a46e8226c2902ed298477935d55d435a23008c2c. This is 
source-level analysis; I did not independently execute this scenario.



##########
hugegraph-store/hg-store-test/src/main/java/org/apache/hugegraph/store/rocksdb/SessionOperatorTest.java:
##########
@@ -0,0 +1,268 @@
+/*
+ * 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.store.rocksdb;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hugegraph.rocksdb.access.DBStoreException;
+import org.apache.hugegraph.rocksdb.access.RocksDBSession;
+import org.apache.hugegraph.rocksdb.access.RocksDBSession.BackendColumn;
+import org.apache.hugegraph.rocksdb.access.ScanIterator;
+import org.apache.hugegraph.rocksdb.access.SessionOperator;
+import org.apache.hugegraph.rocksdb.access.SessionOperatorImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class SessionOperatorTest extends BaseRocksDbTest {
+
+    private static final String TABLE = "tbl";
+    private static final String GRAPH = "op-graph";
+
+    @Rule
+    public TemporaryFolder folder = new TemporaryFolder();
+
+    private ExecutorService prober;
+    private String dataPath;
+    private RocksDBSession session;
+    private int probes;
+
+    private static byte[] b(String s) {
+        return s.getBytes(StandardCharsets.UTF_8);
+    }
+
+    private static List<String> keys(ScanIterator it) {
+        List<String> keys = new ArrayList<>();
+        try {
+            while (it.hasNext()) {
+                BackendColumn col = it.next();
+                keys.add(new String(col.name, StandardCharsets.UTF_8));
+            }
+        } finally {
+            it.close();
+        }
+        return keys;
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        this.prober = Executors.newSingleThreadExecutor(r -> {
+            Thread t = new Thread(r, "cf-lock-prober");
+            t.setDaemon(true);
+            return t;
+        });
+        this.dataPath = this.folder.newFolder("data").getAbsolutePath();
+        this.session = new RocksDBSession(hConfig, this.dataPath, GRAPH, 0);
+        this.session.checkTable(TABLE);
+    }
+
+    @After
+    public void tearDown() {
+        if (this.session != null) {
+            this.session.close();
+        }
+        this.prober.shutdownNow();

Review Comment:
   [P2] Make teardown safe when the read-lock probe times out
   
   If commit/rollback leaves the read lock held, which assertCfLockReleased() 
is specifically intended to detect, its future.get() times out but JUnit still 
calls this teardown. RocksDBSession.close() then reaches shutdown(), whose 
writeLock().lock() runs on the test thread while that thread still owns the 
read lock acquired by prepare(). ReentrantReadWriteLock cannot perform that 
upgrade, so the test hangs instead of reporting the 10-second failure, and 
shutdownNow() is never reached. Release any outstanding read-lock holds owned 
by the test thread and let the probe finish before closing the session; merely 
moving shutdownNow() will not interrupt writeLock().lock().
   
   Reviewed head: a46e8226c2902ed298477935d55d435a23008c2c. This is 
source-level analysis; I did not independently execute this scenario.



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