@Test @TailAvailable public void testOS() throws Exception { OSDelegatingFileTailingMessageProducer adapter = new OSDelegatingFileTailingMessageProducer(); adapter.setOptions(TAIL_OPTIONS_FOLLOW_NAME_ALL_LINES); testGuts(adapter, "stdOutReader"); }
@Test @TailAvailable public void canRecalculateCommandWhenFileOrOptionsChanged() throws IOException { File firstFile = File.createTempFile("first", ".txt"); String firstOptions = "-f options"; File secondFile = File.createTempFile("second", ".txt"); String secondOptions = "-f newoptions"; OSDelegatingFileTailingMessageProducer adapter = new OSDelegatingFileTailingMessageProducer(); adapter.setFile(firstFile); adapter.setOptions(firstOptions); adapter.setOutputChannel(new QueueChannel()); adapter.setTailAttemptsDelay(500); adapter.setBeanFactory(mock(BeanFactory.class)); adapter.afterPropertiesSet(); adapter.start(); assertEquals("tail " + firstOptions + " " + firstFile.getAbsolutePath(), adapter.getCommand()); adapter.stop(); adapter.setFile(secondFile); adapter.start(); assertEquals("tail " + firstOptions + " " + secondFile.getAbsolutePath(), adapter.getCommand()); adapter.stop(); adapter.setOptions(secondOptions); adapter.start(); assertEquals("tail " + secondOptions + " " + secondFile.getAbsolutePath(), adapter.getCommand()); adapter.stop(); }
((OSDelegatingFileTailingMessageProducer) adapter).setEnableStatusReader(this.enableStatusReader); if (this.nativeOptions != null) { ((OSDelegatingFileTailingMessageProducer) adapter).setOptions(this.nativeOptions);
@Test public void testDefault() { String fileName = TestUtils.getPropertyValue(defaultAdapter, "file", File.class).getAbsolutePath(); String normalizedName = getNormalizedPath(fileName); assertEquals("/tmp/baz", normalizedName); assertEquals("tail -F -n 0 " + fileName, TestUtils.getPropertyValue(defaultAdapter, "command")); assertSame(exec, TestUtils.getPropertyValue(defaultAdapter, "taskExecutor")); assertTrue(TestUtils.getPropertyValue(defaultAdapter, "autoStartup", Boolean.class)); assertTrue(TestUtils.getPropertyValue(defaultAdapter, "enableStatusReader", Boolean.class)); assertEquals(123, TestUtils.getPropertyValue(defaultAdapter, "phase")); assertSame(this.tailErrorChannel, TestUtils.getPropertyValue(defaultAdapter, "errorChannel")); this.defaultAdapter.stop(); this.defaultAdapter.setOptions("-F -n 6"); this.defaultAdapter.start(); assertEquals("tail -F -n 6 " + fileName, TestUtils.getPropertyValue(defaultAdapter, "command")); }
public class MyApplicationListener implements ApplicationListener<ContextRefreshedEvent> { @Autowired @Qualifier("outputChannel") private SubscribableChannel outputChannel; @Override public void onApplicationEvent(ContextRefreshedEvent event) { OSDelegatingFileTailingMessageProducer tailer = new OSDelegatingFileTailingMessageProducer(); tailer.setOutputChannel(outputChannel); tailer.setFile(new File("/file/to/tail.txt")); tailer.setOptions("-f -n 0"); tailer.afterPropertiesSet(); tailer.start(); } }