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


##########
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:
   Thanks for pointing this out. I’ve updated the test to release the 
ConsumeQueue before deleting the directory, and also use a unique temporary 
directory with cleanup in finally. This should avoid the IOExceptionList caused 
by deleting files while resources are still held.
   
   I’ve verified the test locally with Bazel and it passes now.



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