@Test public void testTwoLogStreamsInSameDir() throws Exception { File testDir = this.tempDir.newFolder(); String filePrefix = "test"; String filePrefix2 = "second.test"; SingerLogConfig config = createSingerLogConfig(filePrefix, testDir.getAbsolutePath()); SingerLogConfig config2 = createSingerLogConfig(filePrefix2, testDir.getAbsolutePath()); LogStream toMonitor = new LogStream(new SingerLog(config), filePrefix); LogStream toMonitor2 = new LogStream(new SingerLog(config2), filePrefix2); FileSystemMonitor t = new FileSystemMonitor(Arrays.asList(toMonitor, toMonitor2), "testTwoLogStreamsInSameDir"); t.start(); final int NUM_FILES = 10; File[] created = new File[NUM_FILES]; for (int i = 0; i < NUM_FILES; i++) { created[i] = File.createTempFile(filePrefix, ".tmp", testDir); Thread.sleep(FILE_EVENT_WAIT_TIME_MS); } final int NUM_FILES_2 = 10; File[] created2 = new File[NUM_FILES_2]; for (int i = 0; i < NUM_FILES_2; i++) { created2[i] = File.createTempFile(filePrefix2, ".tmp", testDir); Thread.sleep(FILE_EVENT_WAIT_TIME_MS); } Thread.sleep(15000); String[] files = testDir.list(); assertEquals("Number of files should be the sum of the number of files in the two log streams", files.length, toMonitor.size() + toMonitor2.size()); for (String fileName : testDir.list()) { if (toMonitor.containsFile(fileName)) { assertFalse("File should be in only one log stream", toMonitor2.containsFile(fileName)); } else if (toMonitor2.containsFile(fileName)) { assertFalse("File should be in only one log stream", toMonitor.containsFile(fileName)); } else { fail("File should be in exactly one log stream"); } } }
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();  }