@Test public void testLogFileRotation() throws Exception { final File testDir = this.tempDir.newFolder(); final String filePrefix = "test"; SingerLogConfig config = createSingerLogConfig(filePrefix, testDir.getAbsolutePath()); config.setLogStreamRegex("test.tmp"); LogStream toMonitor = new LogStream(new SingerLog(config), filePrefix); FileSystemMonitor t = new FileSystemMonitor(Arrays.asList(toMonitor), "testLogFileRotation"); t.start(); Thread.sleep(FILE_EVENT_WAIT_TIME_MS); int NUM_FILES = 10; File[] created = createTestLogStreamFiles(testDir, "test.tmp", NUM_FILES); Thread.sleep(FILE_EVENT_WAIT_TIME_MS); File[] renamed = new File[ created.length + 1]; created[0].delete(); for (int i = 1; i < NUM_FILES; i++) { renamed[i] = new File(testDir, "test.tmp." + (NUM_FILES - i)); created[i].renameTo(renamed[i]); Thread.sleep(FILE_EVENT_WAIT_TIME_MS); toMonitor.logStatus(); assertTrue(toMonitor.checkConsistency()); } renamed[NUM_FILES] = new File(testDir, filePrefix); renamed[NUM_FILES].createNewFile(); Thread.sleep(FILE_EVENT_WAIT_TIME_MS); toMonitor.logStatus(); assertTrue(toMonitor.checkConsistency()); }
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();  }