DefaultCommandStore extends AbstractStore implements CommandStore { @Override public int appendCommands(ByteBuf byteBuf) throws IOException { makeSureOpen(); rotateFileIfNenessary(); CommandFileContext cmdFileCtx = cmdFileCtxRef.get(); if(delayTraceLogger.isDebugEnabled()) { delayTraceLogger.debug("[appendCommands][begin]{}"); } commandStoreDelay.beginWrite(); int wrote = ByteBufUtils.writeByteBufToFileChannel(byteBuf, cmdFileCtx.getChannel(), delayTraceLogger); if(delayTraceLogger.isDebugEnabled()){ logger.debug("[appendCommands]{}, {}, {}", cmdFileCtx, byteBuf.readableBytes(), cmdFileCtx.fileLength()); } long offset = cmdFileCtx.totalLength() - 1; if(delayTraceLogger.isDebugEnabled()){ delayTraceLogger.debug("[appendCommands][ end ]{}", offset + 1); } commandStoreDelay.endWrite(offset + 1); offsetNotifier.offsetIncreased(offset); return wrote; } DefaultCommandStore(File file, int maxFileSize, KeeperMonitor keeperMonitor);  DefaultCommandStore(File file, int maxFileSize, int minTimeMilliToGcAfterModified, IntSupplier fileNumToKeep, long commandReaderFlyingThreshold, KeeperMonitor keeperMonitor); @Override int appendCommands(ByteBuf byteBuf); @Override long totalLength(); @Override CommandReader beginRead(long startOffset); @Override boolean awaitCommandsOffset(long offset, int timeMilli); @Override long lowestReadingOffset(); @Override void addCommandsListener(long offset, final CommandsListener listener); @Override void close(); @Override void destroy(); @Override String toString(); String simpleDesc(); @Override long lowestAvailableOffset(); @Override void gc(); static final long DEFAULT_COMMAND_READER_FLYING_THRESHOLD; }
@Test public void testReadNotFromZero() throws IOException, InterruptedException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 20; i++) { int length = randomInt(100, 500); String random = randomString(length); sb.append(random); commandStore.appendCommands(Unpooled.wrappedBuffer(random.getBytes())); } int totalLength = sb.length(); for (int i = 0; i < 20; i++) { long offset = randomInt(0, totalLength); int expected = (int) (totalLength - offset); String result = readCommandStoreTilNoMessage(offset, commandStore, expected); Assert.assertEquals(sb.substring((int) offset), result); } }