RongtongJin commented on code in PR #10418:
URL: https://github.com/apache/rocketmq/pull/10418#discussion_r3457439487


##########
store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java:
##########
@@ -713,4 +713,51 @@ public void 
correctMinOffsetWithEmptyQueueReadAheadOptimizationTest() throws IOE
         consumeQueue.destroy();
         FileUtils.deleteDirectory(tmpDir);
     }
+
+    @Test
+    public void testCorrectMinOffsetAfterAllFilesDeleted() throws IOException {
+        String topic = "T1";
+        int queueId = 0;
+        MessageStoreConfig storeConfig = new MessageStoreConfig();
+        File tmpDir = new File(System.getProperty("java.io.tmpdir"), 
"testCorrectMinOffsetAfterAllFilesDeleted");
+        FileUtils.deleteDirectory(tmpDir);
+        storeConfig.setStorePathRootDir(tmpDir.getAbsolutePath());
+        storeConfig.setEnableConsumeQueueExt(false);
+        DefaultMessageStore messageStore = 
Mockito.mock(DefaultMessageStore.class);
+        
Mockito.when(messageStore.getMessageStoreConfig()).thenReturn(storeConfig);
+
+        RunningFlags runningFlags = new RunningFlags();
+        Mockito.when(messageStore.getRunningFlags()).thenReturn(runningFlags);
+
+        StoreCheckpoint storeCheckpoint = Mockito.mock(StoreCheckpoint.class);
+        
Mockito.when(messageStore.getStoreCheckpoint()).thenReturn(storeCheckpoint);
+
+        ConsumeQueue consumeQueue = new ConsumeQueue(topic, queueId, 
storeConfig.getStorePathRootDir(),
+            storeConfig.getMappedFileSizeConsumeQueue(), messageStore);
+
+        int max = 10;
+        int messageSize = 100;
+        for (int i = 0; i < max; ++i) {
+            DispatchRequest dispatchRequest = new DispatchRequest(topic, 
queueId, messageSize * i, messageSize, 0, 0, i, null, null, 0, 0, null);
+            consumeQueue.putMessagePositionInfoWrapper(dispatchRequest);
+        }
+
+        File consumeQueueDir = new File(storeConfig.getStorePathRootDir(), 
topic + File.separator + queueId);
+        Assert.assertTrue(consumeQueueDir.exists());
+
+        consumeQueue.setMinLogicOffset(ConsumeQueue.CQ_STORE_UNIT_SIZE);
+        consumeQueue.setMaxPhysicOffset(max * messageSize);
+        FileUtils.deleteDirectory(consumeQueueDir);

Review Comment:
   This is the source of the Windows CI failure. The test deletes the 
consume-queue directory while the first `ConsumeQueue` instance still owns the 
mapped file and file channel, so Windows refuses to delete 
`.../T1/0/00000000000000000000` with "The process cannot access the file 
because it is being used by another process". Please release the first queue 
before deleting/reloading, preferably with `try/finally` cleanup, e.g. call 
`consumeQueue.destroy()` before `FileUtils.deleteDirectory(consumeQueueDir)` 
(and still destroy `reloadedConsumeQueue` in a finally block).



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