@Override
    public AppendResult appendCommitLog(ByteBuffer message) {
        if (closed) {
            return AppendResult.FILE_CLOSED;
        }
        return commitLog.append(message, MessageFormatUtil.getStoreTimeStamp(message));
    }
@Test
    public void testAppendCommitLog() {
        String topic = "CommitLogTest";
        FlatMessageFile flatFile = new FlatMessageFile(flatFileFactory, topic, 0);
        Assert.assertTrue(flatFile.getTopicId() >= 0);
        Assert.assertEquals(topic, flatFile.getMessageQueue().getTopic());
        Assert.assertEquals(0, flatFile.getMessageQueue().getQueueId());
        Assert.assertFalse(flatFile.isFlatFileInit());

        flatFile.flushMetadata();
        Assert.assertNotNull(metadataStore.getQueue(flatFile.getMessageQueue()));

        long offset = 100;
        flatFile.initOffset(offset);
        for (int i = 0; i < 5; i++) {
            ByteBuffer buffer = MessageFormatUtilTest.buildMockedMessageBuffer();
            DispatchRequest request = new DispatchRequest(
                topic, 0, i, (long) buffer.remaining() * i, buffer.remaining(), 0L);
            flatFile.appendCommitLog(buffer);
            flatFile.appendConsumeQueue(request);
        }

        Assert.assertNotNull(flatFile.getFileLock());

        long time = MessageFormatUtil.getStoreTimeStamp(MessageFormatUtilTest.buildMockedMessageBuffer());
        Assert.assertEquals(time, flatFile.getMinStoreTimestamp());
        Assert.assertEquals(time, flatFile.getMaxStoreTimestamp());

        long size = MessageFormatUtilTest.buildMockedMessageBuffer().remaining();
        Assert.assertEquals(-1L, flatFile.getFirstMessageOffset());
        Assert.assertEquals(0L, flatFile.getCommitLogMinOffset());
        Assert.assertEquals(0L, flatFile.getCommitLogCommitOffset());
        Assert.assertEquals(5 * size, flatFile.getCommitLogMaxOffset());

        Assert.assertEquals(offset, flatFile.getConsumeQueueMinOffset());
        Assert.assertEquals(offset, flatFile.getConsumeQueueCommitOffset());
        Assert.assertEquals(offset + 5L, flatFile.getConsumeQueueMaxOffset());

        Assert.assertTrue(flatFile.commitAsync().join());
        Assert.assertEquals(6L, flatFile.getFirstMessageOffset());
        Assert.assertEquals(0L, flatFile.getCommitLogMinOffset());
        Assert.assertEquals(5 * size, flatFile.getCommitLogCommitOffset());
        Assert.assertEquals(5 * size, flatFile.getCommitLogMaxOffset());

        Assert.assertEquals(offset, flatFile.getConsumeQueueMinOffset());
        Assert.assertEquals(offset + 5L, flatFile.getConsumeQueueCommitOffset());
        Assert.assertEquals(offset + 5L, flatFile.getConsumeQueueMaxOffset());

        // test read
        ByteBuffer buffer = flatFile.getMessageAsync(offset).join();
        Assert.assertNotNull(buffer);
        Assert.assertEquals(size, buffer.remaining());
        Assert.assertEquals(6L, MessageFormatUtil.getQueueOffset(buffer));

        flatFile.destroyExpiredFile(0);
        flatFile.destroy();
    }