### 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) { int alignedSize = (entryLength + 64 - 1) & MASK_64_ALIGN; boolean fullDataSize = false; boolean fullIndexSize = false; boolean fullCount = false; this.writeLock.lock(); try { int dataOffset = this.cacheDataOffset.get(); int indexOffset = this.cacheIndexOffset.get(); if ((fullDataSize = (dataOffset + alignedSize > this.maxDataCacheSize)) || (fullIndexSize = (indexOffset + this.indexUnitLength > this.maxIndexCacheSize)) || (fullCount = (this.curMessageCount.get() + 1 > this.maxAllowedMsgCount))) { msgMemStatisInfo.addFullTypeCount(timeRecv, fullDataSize, fullIndexSize, fullCount); return false; } entry.putLong(DataStoreUtils.STORE_HEADER_POS_QUEUE_LOGICOFF, this.writeIndexStartPos + this.cacheIndexSize.get()); this.cacheDataSegment.position(dataOffset); this.cacheDataSegment.put(entry.array()); this.cachedIndexSegment.position(indexOffset); this.cachedIndexSegment.putInt(partitionId); this.cachedIndexSegment.putInt(keyCode); this.cachedIndexSegment.putInt(dataOffset); this.cachedIndexSegment.putInt(entryLength); this.cachedIndexSegment.putLong(timeRecv); this.cachedIndexSegment .putLong(this.writeDataStartPos + this.cacheDataSize.getAndAdd(entryLength)); Integer indexSizePos = this.cacheIndexSize.getAndAdd(DataStoreUtils.STORE_INDEX_HEAD_LEN); this.queuesMap.put(partitionId, indexSizePos); this.keysMap.put(keyCode, indexSizePos); this.cacheDataOffset.getAndAdd(alignedSize); this.cacheIndexOffset.getAndAdd(this.indexUnitLength); this.curMessageCount.getAndAdd(1); msgMemStatisInfo.addMsgSizeStatis(timeRecv, entryLength); } finally { this.writeLock.unlock(); } 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); GetCacheMsgResult getMessages(final long lastRdOffset, final long lastOffset,
                                         final int maxReadSize, final int maxReadCount,
                                         final int partitionId, final boolean isSecond,
                                         final boolean isFilterConsume,
                                         final Set<Integer> filterKeySet); boolean flush(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()); msgMemStore.appendMsg(msgMemStatisInfo, 0, 0, System.currentTimeMillis(), 3, bf); }