@Test public void testLogStream() throws Exception { final File testDir = this.tempDir.newFolder(); final String filePrefix = "test.tmp"; final int NUM_FILES = 10; SingerLogConfig singerLogConfig = createSingerLogConfig("test", testDir.getPath()); SingerLog singerLog = new SingerLog(singerLogConfig); File[] files = createTestLogStreamFiles(testDir, filePrefix, NUM_FILES); LogStream stream = new LogStream(singerLog, filePrefix); stream.initialize(); assertEquals("", stream.getLogFileAndPaths().size(), NUM_FILES); List<LogFileAndPath> logFileAndPaths = stream.getLogFileAndPaths(); logFileAndPaths.stream().forEachOrdered(lfp -> LOG.info("{}", lfp)); for (int i = 0; i < NUM_FILES; i++) { LogFileAndPath logFileAndPath = logFileAndPaths.get(i); assertEquals(logFileAndPath.getPath(), files[i].toString()); assertEquals(logFileAndPath.getLogFile().inode, SingerUtils.getFileInode(files[i].toPath())); if (i < NUM_FILES - 1) { assertEquals(stream.getNext(logFileAndPath.getLogFile()).getLogFile().inode, SingerUtils.getFileInode(files[i+1].toPath())); } if (i > 0) { assertEquals(stream.getPrev(logFileAndPath.getLogFile()).getLogFile().inode, SingerUtils.getFileInode(files[i-1].toPath())); } } assertTrue(stream.checkConsistency()); }
public LogStream(SingerLog singerLog, String fileNamePrefix) { Preconditions.checkArgument(!Strings.isNullOrEmpty(fileNamePrefix)); this.singerLog = Preconditions.checkNotNull(singerLog); this.logStreamName = fileNamePrefix; this.logStreamDescriptor = String.format("%s:%s", singerLog.getLogName(), fileNamePrefix); this.logFilePaths = Lists.newArrayList(); this.logFilePathsIndex = new HashMap<>(); this.lastStreamModificationTime = -1L; String dir = this.singerLog.getSingerLogConfig().getLogDir(); this.fileNameMatchMode = singerLog.getSingerLogConfig().getFilenameMatchMode(); this.fileNamePrefix = fileNamePrefix; this.fullPathPrefix = FilenameUtils.concat(dir, fileNamePrefix); this.creationTime = System.currentTimeMillis(); }
LogStream { public LogStream(SingerLog singerLog, String fileNamePrefix) { Preconditions.checkArgument(!Strings.isNullOrEmpty(fileNamePrefix)); this.singerLog = Preconditions.checkNotNull(singerLog); this.logStreamName = fileNamePrefix; this.logStreamDescriptor = String.format("%s:%s", singerLog.getLogName(), fileNamePrefix); this.logFilePaths = Lists.newArrayList(); this.logFilePathsIndex = new HashMap<>(); this.lastStreamModificationTime = -1L; String dir = this.singerLog.getSingerLogConfig().getLogDir(); this.fileNameMatchMode = singerLog.getSingerLogConfig().getFilenameMatchMode(); this.fileNamePrefix = fileNamePrefix; this.fullPathPrefix = FilenameUtils.concat(dir, fileNamePrefix); this.creationTime = System.currentTimeMillis(); } }
LogStream { public LogStream(SingerLog singerLog, String fileNamePrefix) { Preconditions.checkArgument(!Strings.isNullOrEmpty(fileNamePrefix)); this.singerLog = Preconditions.checkNotNull(singerLog); this.logStreamName = fileNamePrefix; this.logStreamDescriptor = String.format("%s:%s", singerLog.getLogName(), fileNamePrefix); this.logFilePaths = Lists.newArrayList(); this.logFilePathsIndex = new HashMap<>(); this.lastStreamModificationTime = -1L; String dir = this.singerLog.getSingerLogConfig().getLogDir(); this.fileNameMatchMode = singerLog.getSingerLogConfig().getFilenameMatchMode(); this.fileNamePrefix = fileNamePrefix; this.fullPathPrefix = FilenameUtils.concat(dir, fileNamePrefix); this.creationTime = System.currentTimeMillis(); } LogStream(SingerLog singerLog, String fileNamePrefix); }
LogStream { public LogStream(SingerLog singerLog, String fileNamePrefix) { Preconditions.checkArgument(!Strings.isNullOrEmpty(fileNamePrefix)); this.singerLog = Preconditions.checkNotNull(singerLog); this.logStreamName = fileNamePrefix; this.logStreamDescriptor = String.format("%s:%s", singerLog.getLogName(), fileNamePrefix); this.logFilePaths = Lists.newArrayList(); this.logFilePathsIndex = new HashMap<>(); this.lastStreamModificationTime = -1L; String dir = this.singerLog.getSingerLogConfig().getLogDir(); this.fileNameMatchMode = singerLog.getSingerLogConfig().getFilenameMatchMode(); this.fileNamePrefix = fileNamePrefix; this.fullPathPrefix = FilenameUtils.concat(dir, fileNamePrefix); this.creationTime = System.currentTimeMillis(); } LogStream(SingerLog singerLog, String fileNamePrefix); int size(); @SuppressWarnings({ "unchecked", "rawtypes" }) void initialize(); boolean containsFile(String fileName); List<LogFileAndPath> getLogFileAndPaths(); long getInodeByFileName(String fileName); long getCreationTime(); SingerLog getSingerLog(); String getLogStreamName(); String getFileNamePrefix(); String getFullPathPrefix(); String getLogStreamDescriptor(); long getLastStreamModificationTime(); long getLatestProcessedMessageTime(); void setLatestProcessedMessageTime(long timestamp); String getLogDir(); boolean acceptFile(String fileAbsolutePath); LogFileAndPath getFirstLogFile(); LogFileAndPath getLatestLogFileAndPath(); void put(LogFile logFile, String path); void append(LogFile logFile, String path); void removeLogFilePathInfo(String path); String getLogFilePath(LogFile logFile); LogFileAndPath getNext(LogFile logFile); LogFileAndPath getPrev(LogFile logFile); void removeOldFiles(LogFile logFile, int retentionInSeconds); boolean isEmpty(); boolean hasLogFile(LogFile logFile); List<String> getLogFilePaths(); @Override boolean equals(Object object); @Override String toString(); @Override int hashCode(); boolean checkConsistency(); void clearAllLogPaths(); void logStatus(); void setLastCompletedCycleTime(long lastCompleteCycleTime); long getLastCompleteCycleTime(); }
LogStream { public LogStream(SingerLog singerLog, String fileNamePrefix) { Preconditions.checkArgument(!Strings.isNullOrEmpty(fileNamePrefix)); this.singerLog = Preconditions.checkNotNull(singerLog); this.logStreamName = fileNamePrefix; this.logStreamDescriptor = String.format("%s:%s", singerLog.getLogName(), fileNamePrefix); this.logFilePaths = Lists.newArrayList(); this.logFilePathsIndex = new HashMap<>(); this.lastStreamModificationTime = -1L; String dir = this.singerLog.getSingerLogConfig().getLogDir(); this.fileNameMatchMode = singerLog.getSingerLogConfig().getFilenameMatchMode(); this.fileNamePrefix = fileNamePrefix; this.fullPathPrefix = FilenameUtils.concat(dir, fileNamePrefix); this.creationTime = System.currentTimeMillis(); } LogStream(SingerLog singerLog, String fileNamePrefix); int size(); @SuppressWarnings({ "unchecked", "rawtypes" }) void initialize(); boolean containsFile(String fileName); List<LogFileAndPath> getLogFileAndPaths(); long getInodeByFileName(String fileName); long getCreationTime(); SingerLog getSingerLog(); String getLogStreamName(); String getFileNamePrefix(); String getFullPathPrefix(); String getLogStreamDescriptor(); long getLastStreamModificationTime(); long getLatestProcessedMessageTime(); void setLatestProcessedMessageTime(long timestamp); String getLogDir(); boolean acceptFile(String fileAbsolutePath); LogFileAndPath getFirstLogFile(); LogFileAndPath getLatestLogFileAndPath(); void put(LogFile logFile, String path); void append(LogFile logFile, String path); void removeLogFilePathInfo(String path); String getLogFilePath(LogFile logFile); LogFileAndPath getNext(LogFile logFile); LogFileAndPath getPrev(LogFile logFile); void removeOldFiles(LogFile logFile, int retentionInSeconds); boolean isEmpty(); boolean hasLogFile(LogFile logFile); List<String> getLogFilePaths(); @Override boolean equals(Object object); @Override String toString(); @Override int hashCode(); boolean checkConsistency(); void clearAllLogPaths(); void logStatus(); void setLastCompletedCycleTime(long lastCompleteCycleTime); long getLastCompleteCycleTime();  }