Skip to content

Commit

Permalink
[ISSUE #7592] testCleanBuffer unit test modifies, changed non-direct … (
Browse files Browse the repository at this point in the history
#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 <[email protected]>

---------

Signed-off-by: Li Zhanhui <[email protected]>
Co-authored-by: Li Zhanhui <[email protected]>
  • Loading branch information
yp969803 and lizhanhui authored Nov 29, 2023
1 parent a194e1e commit 56e886b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions common/src/main/java/org/apache/rocketmq/common/UtilAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,19 @@ public static void deleteEmptyDirectory(File file) {
}
}

/**
* 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ public void setSubField1(boolean subField1) {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public void testStateAndRecover() throws Exception {
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() {
Expand Down

0 comments on commit 56e886b

Please sign in to comment.