### Question:
MappedFileQueue { public MappedFile getLastMappedFile(final long startOffset, boolean needCreate) { long createOffset = -1; MappedFile mappedFileLast = getLastMappedFile(); if (mappedFileLast == null) { createOffset = startOffset - (startOffset % this.mappedFileSize); } if (mappedFileLast != null && mappedFileLast.isFull()) { createOffset = mappedFileLast.getFileFromOffset() + this.mappedFileSize; } if (createOffset != -1 && needCreate) { String nextFilePath = this.storePath + File.separator + UtilAll.offset2FileName(createOffset); String nextNextFilePath = this.storePath + File.separator + UtilAll.offset2FileName(createOffset + this.mappedFileSize); MappedFile mappedFile = null; if (this.allocateMappedFileService != null) { mappedFile = this.allocateMappedFileService.putRequestAndReturnMappedFile(nextFilePath, nextNextFilePath, this.mappedFileSize); } else { try { mappedFile = new MappedFile(nextFilePath, this.mappedFileSize); } catch (IOException e) { log.error("create mappedFile exception", e); } } if (mappedFile != null) { if (this.mappedFiles.isEmpty()) { mappedFile.setFirstCreateInQueue(true); } this.mappedFiles.add(mappedFile); } return mappedFile; } return mappedFileLast; } MappedFileQueue(final String storePath, int mappedFileSize,
                           AllocateMappedFileService allocateMappedFileService); void checkSelf(); MappedFile getMappedFileByTime(final long timestamp); void truncateDirtyFiles(long offset); boolean load(); long howMuchFallBehind(); MappedFile getLastMappedFile(final long startOffset, boolean needCreate); MappedFile getLastMappedFile(final long startOffset); MappedFile getLastMappedFile(); boolean resetOffset(long offset); long getMinOffset(); long getMaxOffset(); long getMaxWrotePosition(); long remainHowManyDataToCommit(); long remainHowManyDataToFlush(); void deleteLastMappedFile(); int deleteExpiredFileByTime(final long expiredTime,
                                       final int deleteFilesInterval,
                                       final long intervalForcibly,
                                       final boolean cleanImmediately,
                                       final long minTransOffset); int deleteExpiredFileByOffset(long offset, int unitSize); boolean flush(final int flushLeastPages); boolean commit(final int commitLeastPages); List<MappedFile> findGreaterThanMappedFileByOffset(final long offset); MappedFile findMappedFileByOffset(final long offset, final boolean returnFirstOnNotFound); MappedFile getFirstMappedFile(); MappedFile findMappedFileByOffset(final long offset); long getMappedMemorySize(); boolean retryDeleteFirstFile(final long intervalForcibly); void shutdown(final long intervalForcibly); void destroy(); long getFlushedWhere(); void setFlushedWhere(long flushedWhere); long getStoreTimestamp(); List<MappedFile> getMappedFiles(); int getMappedFileSize(); long getCommittedWhere(); void setCommittedWhere(final long committedWhere);  }### Answer:
@Test public void testGetLastMappedFile() { final String fixedMsg = "0123456789abcdef"; MappedFileQueue mappedFileQueue = new MappedFileQueue("target/unit_test_store/a/", 1024, null); for (int i = 0; i < 1024; i++) { MappedFile mappedFile = mappedFileQueue.getLastMappedFile(0); assertThat(mappedFile).isNotNull(); assertThat(mappedFile.appendMessage(fixedMsg.getBytes())).isTrue(); } mappedFileQueue.shutdown(1000); mappedFileQueue.destroy(); }