diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java
index aa0f73f1f9..987833d73f 100644
--- a/spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java
+++ b/spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
* Default options are "-F -n 0" (follow file name, no existing records).
*
* @author Gary Russell
+ * @author Gavin Gray
* @since 3.0
*
*/
@@ -56,6 +57,10 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr
}
}
+ public String getCommand() {
+ return this.command;
+ }
+
@Override
public String getComponentType() {
return super.getComponentType() + " (native)";
@@ -65,13 +70,13 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr
protected void onInit() {
Assert.notNull(getFile(), "File cannot be null");
super.onInit();
- this.command = "tail " + this.options + " " + this.getFile().getAbsolutePath();
}
@Override
protected void doStart() {
super.doStart();
destroyProcess();
+ this.command = "tail " + this.options + " " + this.getFile().getAbsolutePath();
this.getTaskExecutor().execute(new Runnable() {
@Override
@@ -257,5 +262,4 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr
}
}
-
}
diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests-context.xml
index 7a26ed9948..a73df7ef22 100644
--- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests-context.xml
+++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests-context.xml
@@ -13,11 +13,13 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+
-
-
+
+
+
diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests.java
index 90fb8b250e..13c352cecb 100644
--- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests.java
+++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileTailInboundChannelAdapterParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@ package org.springframework.integration.file.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
import java.io.File;
@@ -26,6 +28,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.file.tail.ApacheCommonsFileTailingMessageProducer;
import org.springframework.integration.file.tail.OSDelegatingFileTailingMessageProducer;
@@ -36,6 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
+ * @author Gavin Gray
* @since 3.0
*
*/
@@ -71,8 +75,12 @@ public class FileTailInboundChannelAdapterParserTests {
assertEquals("/tmp/baz", normalizedName);
assertEquals("tail -F -n 0 " + fileName, TestUtils.getPropertyValue(defaultAdapter, "command"));
assertSame(exec, TestUtils.getPropertyValue(defaultAdapter, "taskExecutor"));
- assertFalse(TestUtils.getPropertyValue(defaultAdapter, "autoStartup", Boolean.class));
+ assertTrue(TestUtils.getPropertyValue(defaultAdapter, "autoStartup", Boolean.class));
assertEquals(123, TestUtils.getPropertyValue(defaultAdapter, "phase"));
+ this.defaultAdapter.stop();
+ this.defaultAdapter.setOptions("-F -n 6");
+ this.defaultAdapter.start();
+ assertEquals("tail -F -n 6 " + fileName, TestUtils.getPropertyValue(defaultAdapter, "command"));
}
@Test
@@ -83,7 +91,7 @@ public class FileTailInboundChannelAdapterParserTests {
assertEquals("tail -F -n 6 " + fileName, TestUtils.getPropertyValue(nativeAdapter, "command"));
assertSame(exec, TestUtils.getPropertyValue(nativeAdapter, "taskExecutor"));
assertSame(sched, TestUtils.getPropertyValue(nativeAdapter, "taskScheduler"));
- assertFalse(TestUtils.getPropertyValue(nativeAdapter, "autoStartup", Boolean.class));
+ assertTrue(TestUtils.getPropertyValue(nativeAdapter, "autoStartup", Boolean.class));
assertEquals(123, TestUtils.getPropertyValue(nativeAdapter, "phase"));
assertEquals(456L, TestUtils.getPropertyValue(nativeAdapter, "tailAttemptsDelay"));
}
@@ -127,4 +135,14 @@ public class FileTailInboundChannelAdapterParserTests {
}
return absolutePath;
}
+
+ public static class Config {
+
+ @Bean
+ public TaskExecutor exec() {
+ return mock(TaskExecutor.class);
+ }
+
+ }
+
}
diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java
index 53eaad9284..a9363f1815 100644
--- a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java
+++ b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import static org.mockito.Mockito.mock;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -42,6 +43,7 @@ import org.springframework.messaging.Message;
/**
* @author Gary Russell
+ * @author Gavin Gray
* @since 3.0
*
*/
@@ -90,6 +92,37 @@ public class FileTailingMessageProducerTests {
testGuts(adapter, "tailer");
}
+ @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();
+ }
+
private void testGuts(FileTailingMessageProducerSupport adapter, String field)
throws Exception {
this.adapter = adapter;