@Test public void testRenameFile() throws Exception { File testDir = this.tempDir.newFolder(); String filePrefix = "test"; SingerLogConfig config = createSingerLogConfig(filePrefix, testDir.getAbsolutePath()); config.setLogStreamRegex("test.tmp"); LogStream toMonitor = LogStreamManager.createNewLogStream(new SingerLog(config), filePrefix); FileSystemMonitor t = new FileSystemMonitor(Arrays.asList(toMonitor), "testRenameFile"); verifyFiles(testDir.list(), toMonitor); int NUM_FILES = 10; File[] created = createTestLogStreamFiles(testDir, "test.tmp", NUM_FILES); t.start(); Thread.sleep(FILE_EVENT_WAIT_TIME_MS); assertTrue(toMonitor.getLatestLogFileAndPath() != null); assertTrue(toMonitor.checkConsistency()); System.out.println(toMonitor.getLogFilePaths().size()); assertTrue(toMonitor.getLogFilePaths().size() == NUM_FILES); verifyFiles(testDir.list(), toMonitor); File toRename = created[1]; LogFile logFile = new LogFile(SingerUtils.getFileInode(toRename.toPath())); assertTrue(!logFile.equals(toMonitor.getLatestLogFileAndPath().getLogFile())); LogStream stream2 = LogStreamManager.getLogStreamsFor(testDir.toPath(), toRename.toPath()).get(0); assertTrue(stream2 != null); String firstFileName = toRename.getName(); assertTrue(toMonitor.containsFile(firstFileName)); long firstFileInode = SingerUtils.getFileInode(toRename.toPath()); String newName = "test.tmp.11"; toRename.renameTo(new File(testDir, newName)); Thread.sleep(FILE_EVENT_WAIT_TIME_MS); verifyFiles(testDir.list(), toMonitor); assertFalse(toMonitor.containsFile(firstFileName)); assertTrue(toMonitor.containsFile(newName)); assertEquals(toMonitor.getInodeByFileName(newName), firstFileInode); }
public void start() { if(thread == null) { thread = new Thread(this); thread.setName("FileSystemMonitor-" + name); thread.start(); } }
FileSystemMonitor implements Runnable { public void start() { if(thread == null) { thread = new Thread(this); thread.setName("FileSystemMonitor-" + name); thread.start(); } } }
FileSystemMonitor implements Runnable { public void start() { if(thread == null) { thread = new Thread(this); thread.setName("FileSystemMonitor-" + name); thread.start(); } } FileSystemMonitor(String name);  FileSystemMonitor(SingerConfig singerConfig, String name);  FileSystemMonitor(Collection<LogStream> streamsToWatch, String name); }
FileSystemMonitor implements Runnable { public void start() { if(thread == null) { thread = new Thread(this); thread.setName("FileSystemMonitor-" + name); thread.start(); } } FileSystemMonitor(String name);  FileSystemMonitor(SingerConfig singerConfig, String name);  FileSystemMonitor(Collection<LogStream> streamsToWatch, String name); void start(); void stop(); void join(); void registerPath(Path logDir); @VisibleForTesting void processFileSystemEvents(); void updateAllDirectories(); boolean isRunning(); @Override void run(); void destroy(); }
FileSystemMonitor implements Runnable { public void start() { if(thread == null) { thread = new Thread(this); thread.setName("FileSystemMonitor-" + name); thread.start(); } } FileSystemMonitor(String name);  FileSystemMonitor(SingerConfig singerConfig, String name);  FileSystemMonitor(Collection<LogStream> streamsToWatch, String name); void start(); void stop(); void join(); void registerPath(Path logDir); @VisibleForTesting void processFileSystemEvents(); void updateAllDirectories(); boolean isRunning(); @Override void run(); void destroy();  }