### Question:
MsgMemStore implements Closeable { public boolean appendMsg(final MsgMemStatisInfo msgMemStatisInfo, final int partitionId, final int keyCode, final long timeRecv, final int entryLength, final ByteBuffer entry, final AppendResult appendResult) { boolean fullDataSize = false; boolean fullIndexSize = false; boolean fullCount = false; long indexOffset = TBaseConstants.META_VALUE_UNDEFINED; long dataOffset = TBaseConstants.META_VALUE_UNDEFINED; this.writeLock.lock(); try { if ((fullDataSize = (this.cacheDataOffset.get() + entryLength > this.maxDataCacheSize)) || (fullIndexSize = (this.cacheIndexOffset.get() + DataStoreUtils.STORE_INDEX_HEAD_LEN > this.maxIndexCacheSize)) || (fullCount = (this.curMessageCount.get() + 1 > maxAllowedMsgCount))) { msgMemStatisInfo.addFullTypeCount(timeRecv, fullDataSize, fullIndexSize, fullCount); return false; } indexOffset = this.writeIndexStartPos + this.cacheIndexOffset.get(); dataOffset = this.writeDataStartPos + this.cacheDataOffset.get(); entry.putLong(DataStoreUtils.STORE_HEADER_POS_QUEUE_LOGICOFF, indexOffset); this.cacheDataSegment.position(this.cacheDataOffset.get()); this.cacheDataSegment.put(entry.array()); this.cachedIndexSegment.position(this.cacheIndexOffset.get()); this.cachedIndexSegment.putInt(partitionId); this.cachedIndexSegment.putLong(dataOffset); this.cachedIndexSegment.putInt(entryLength); this.cachedIndexSegment.putInt(keyCode); this.cachedIndexSegment.putLong(timeRecv); this.cacheDataOffset.getAndAdd(entryLength); Integer indexSizePos = this.cacheIndexOffset.getAndAdd(DataStoreUtils.STORE_INDEX_HEAD_LEN); this.queuesMap.put(partitionId, indexSizePos); this.keysMap.put(keyCode, indexSizePos); this.curMessageCount.getAndAdd(1); msgMemStatisInfo.addMsgSizeStatis(timeRecv, entryLength); } finally { this.writeLock.unlock(); } appendResult.putAppendResult(indexOffset, dataOffset); return true; } MsgMemStore(int maxCacheSize, int maxMsgCount, final BrokerConfig tubeConfig); void resetStartPos(long writeDataStartPos, long writeIndexStartPos); boolean appendMsg(final MsgMemStatisInfo msgMemStatisInfo,
                             final int partitionId, final int keyCode,
                             final long timeRecv, final int entryLength,
                             final ByteBuffer entry, final AppendResult appendResult); GetCacheMsgResult getMessages(final long lstRdDataOffset, final long lstRdIndexOffset,
                                         final int maxReadSize, final int maxReadCount,
                                         final int partitionId, final boolean isSecond,
                                         final boolean isFilterConsume,
                                         final Set<Integer> filterKeySet); boolean batchFlush(MsgFileStore msgFileStore,
                              final StringBuilder strBuffer); int getCurMsgCount(); int getCurDataCacheSize(); int getIndexCacheSize(); int getMaxDataCacheSize(); int getMaxAllowedMsgCount(); int isOffsetInHold(long requestOffset); long getDataLastWritePos(); long getIndexLastWritePos(); void clear(); @Override void close();  }### Answer:
@Test public void appendMsg() { int maxCacheSize = 2 * 1024 * 1024; int maxMsgCount = 10000; MsgMemStore msgMemStore = new MsgMemStore(maxCacheSize, maxMsgCount, null); MsgMemStatisInfo msgMemStatisInfo = new MsgMemStatisInfo(); ByteBuffer bf = ByteBuffer.allocate(1024); bf.put("abc".getBytes()); AppendResult appendResult = new AppendResult(); msgMemStore.appendMsg(msgMemStatisInfo, 0, 0, System.currentTimeMillis(), 3, bf, appendResult); }