@Test
public void testFindMappedFileByOffset() {

    // four-byte string.
    final String fixedMsg = "abcd";
    MappedFileQueue mappedFileQueue =
        new MappedFileQueue("target/unit_test_store/b/", 1024, null);
    for (int i = 0; i < 1024; i++) {
        MappedFile mappedFile = mappedFileQueue.getLastMappedFile(0);
        assertThat(mappedFile).isNotNull();
        assertThat(mappedFile.appendMessage(fixedMsg.getBytes())).isTrue();
    }
    assertThat(mappedFileQueue.getMappedMemorySize()).isEqualTo(fixedMsg.getBytes().length * 1024);
    MappedFile mappedFile = mappedFileQueue.findMappedFileByOffset(0);
    assertThat(mappedFile).isNotNull();
    assertThat(mappedFile.getFileFromOffset()).isEqualTo(0);
    mappedFile = mappedFileQueue.findMappedFileByOffset(100);
    assertThat(mappedFile).isNotNull();
    assertThat(mappedFile.getFileFromOffset()).isEqualTo(0);
    mappedFile = mappedFileQueue.findMappedFileByOffset(1024);
    assertThat(mappedFile).isNotNull();
    assertThat(mappedFile.getFileFromOffset()).isEqualTo(1024);
    mappedFile = mappedFileQueue.findMappedFileByOffset(1024 + 100);
    assertThat(mappedFile).isNotNull();
    assertThat(mappedFile.getFileFromOffset()).isEqualTo(1024);
    mappedFile = mappedFileQueue.findMappedFileByOffset(1024 * 2);
    assertThat(mappedFile).isNotNull();
    assertThat(mappedFile.getFileFromOffset()).isEqualTo(1024 * 2);
    mappedFile = mappedFileQueue.findMappedFileByOffset(1024 * 2 + 100);
    assertThat(mappedFile).isNotNull();
    assertThat(mappedFile.getFileFromOffset()).isEqualTo(1024 * 2);
    // over mapped memory size.
    mappedFile = mappedFileQueue.findMappedFileByOffset(1024 * 4);
    assertThat(mappedFile).isNull();
    mappedFile = mappedFileQueue.findMappedFileByOffset(1024 * 4 + 100);
    assertThat(mappedFile).isNull();
    mappedFileQueue.shutdown(1000);
    mappedFileQueue.destroy();
}