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

DLedgerCommitlogTest#testTruncateCQ unit test error #2993

Closed
fangzhiheng opened this issue Jun 10, 2021 · 3 comments · Fixed by #3865
Closed

DLedgerCommitlogTest#testTruncateCQ unit test error #2993

fangzhiheng opened this issue Jun 10, 2021 · 3 comments · Fixed by #3865

Comments

@fangzhiheng
Copy link

public void testTruncateCQ() throws Exception {
    {
        Test Case
    }
    {
        Test Case
    }
    ...
}

由于他们复用了一个数据目录,而在第一个测试用例执行的时候,程序依然占用着数据目录中的文件句柄,导致第二个测试用例在删除文件时失败,最终断言失败:

DefaultMessageStore messageStore = createDledgerMessageStore(base, group, "n0", peers, null, false, 0);  // 此时创建了24个文件
DefaultMessageStore messageStore = createDledgerMessageStore(base, group, "n0", peers, null, false, 4);  // 删除4个

执行结果如下:

java.lang.AssertionError: 
Expected :20
Actual   :24
...

操作系统:Windows 10 (Linux 无此问题)

@duhenglucky duhenglucky changed the title DLedgerCommitlogTest#testTruncateCQ 单元测试执行错误 DLedgerCommitlogTest#testTruncateCQ unit test error Jun 15, 2021
@duhenglucky
Copy link
Contributor

@fangzhiheng would you like to submit a PR. to fix it?

@fangzhiheng
Copy link
Author

fangzhiheng commented Jun 19, 2021

不知道算是DLedger库的问题,还是测试用例的问题,所以我把问题的原因及解决方案贴出来吧
原因:
DLedgerMmapFileStore在关闭的时候,其内部的MmapFileList#dataFileList没有关闭它所持有的MmapFile#fileChannel 及MmapFile#mappedByteBuffer,因此导致句柄无法回收。
解决办法:
可以在测试用例MessageStore#shutdown后,分别关闭FileChannel以及MappedByteBuffer即可。

但是我认为可能是DLedger库的一个问题 :)

@fangzhiheng
Copy link
Author

@fangzhiheng would you like to submit a PR. to fix it?

I submit a PR for dledger repo, i think it should be fixed by them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants