This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 56e886bf70 [ISSUE #7592] testCleanBuffer unit test modifies, changed 
non-direct … (#7593)
56e886bf70 is described below

commit 56e886bf70669befd7b9e7380e68751fe67f05b2
Author: YASH PATEL <121890726+yp969...@users.noreply.github.com>
AuthorDate: Wed Nov 29 10:02:38 2023 +0530

    [ISSUE #7592] testCleanBuffer unit test modifies, changed non-direct … 
(#7593)
    
    * [ISSUE #7592] testCleanBuffer unit test modifies, changed non-direct to 
direct buffer allocation
    
    * fix: consolidate UtilAll#cleanBuffer by checking if the given buffer is 
direct or not
    
    Signed-off-by: Li Zhanhui <lizhan...@gmail.com>
    
    ---------
    
    Signed-off-by: Li Zhanhui <lizhan...@gmail.com>
    Co-authored-by: Li Zhanhui <lizhan...@gmail.com>
---
 common/src/main/java/org/apache/rocketmq/common/UtilAll.java     | 9 +++++++++
 common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java | 3 ++-
 .../org/apache/rocketmq/store/timer/TimerMessageStoreTest.java   | 2 +-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java 
b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
index 2808f106ae..19efa9aa90 100644
--- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
+++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
@@ -699,10 +699,19 @@ public class UtilAll {
         }
     }
 
+    /**
+     * Free direct-buffer's memory actively.
+     * @param buffer Direct buffer to free.
+     */
     public static void cleanBuffer(final ByteBuffer buffer) {
         if (null == buffer) {
             return;
         }
+
+        if (!buffer.isDirect()) {
+            return;
+        }
+
         PlatformDependent.freeDirectBuffer(buffer);
     }
 
diff --git a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java 
b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
index cb288578cc..2d22d5254a 100644
--- a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
+++ b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
@@ -215,8 +215,9 @@ public class UtilAllTest {
     @Test
     public void testCleanBuffer() {
         UtilAll.cleanBuffer(null);
+        UtilAll.cleanBuffer(ByteBuffer.allocateDirect(10));
+        UtilAll.cleanBuffer(ByteBuffer.allocateDirect(0));
         UtilAll.cleanBuffer(ByteBuffer.allocate(10));
-        UtilAll.cleanBuffer(ByteBuffer.allocate(0));
     }
 
     @Test
diff --git 
a/store/src/test/java/org/apache/rocketmq/store/timer/TimerMessageStoreTest.java
 
b/store/src/test/java/org/apache/rocketmq/store/timer/TimerMessageStoreTest.java
index 63ec97cdb0..02ff35681d 100644
--- 
a/store/src/test/java/org/apache/rocketmq/store/timer/TimerMessageStoreTest.java
+++ 
b/store/src/test/java/org/apache/rocketmq/store/timer/TimerMessageStoreTest.java
@@ -387,7 +387,7 @@ public class TimerMessageStoreTest {
             assertEquals(PutMessageStatus.PUT_OK, 
putMessageResult.getPutMessageStatus());
         }
 
-        // Wait until messages have wrote to TimerLog and currReadTimeMs 
catches up current time.
+        // Wait until messages have written to TimerLog and currReadTimeMs 
catches up current time.
         await().atMost(5000, TimeUnit.MILLISECONDS).until(new 
Callable<Boolean>() {
             @Override
             public Boolean call() {

Reply via email to