public void enterLoop() throws IOException, ServiceAlreadyStartedException { File userAppDir = UserConfig.getUserConfigDir(); userAppDir.mkdirs(); controlFile.delete(); controlFile.createNewFile(); controlFile.deleteOnExit(); logger.log(Level.INFO, "Monitoring control file for commands at " + controlFile + " ..."); logger.log(Level.INFO, " (Note: This is a blocking operation. The 'main' thread is now blocked until '" + ControlCommand.SHUTDOWN + "' is received.)"); controlFileTailer.run(); // This blocks! }
@Test public void testEnterLoop() throws IOException, ServiceAlreadyStartedException { // invoke method ctrlServer.enterLoop(); // verify interactions verify(ctrlFile).delete(); verify(ctrlFile).createNewFile(); verify(ctrlFile).deleteOnExit(); verify(ctrlFileTailer).run(); }
@Override public void run() { tailer.run(); } }).start();
public class LogTailTest { /** * TailerListener implementation. */ static public class ShowLinesListener extends TailerListenerAdapter { @Override public void handle(String line) { System.out.println(line); } } public static void main(String args[]) { TailerListener listener = new ShowLinesListener(); File file = new File("./test.log"); Tailer tailer = new Tailer(file, listener, 1000); tailer.run(); try { Thread.sleep(100000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } tailer.stop(); }