Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #7592] testCleanBuffer unit test modifies, changed non-direct … #7593

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading