Skip to content

Commit 09899f0

Browse files
committed
Test static method and Executor method
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1003158 13f79535-47bb-0310-9956-ffa450edef68
1 parent 70f4ddc commit 09899f0

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/test/org/apache/commons/io/input/TailerTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.FileWriter;
2121
import java.util.ArrayList;
2222
import java.util.List;
23+
import java.util.concurrent.Executor;
24+
import java.util.concurrent.ScheduledThreadPoolExecutor;
2325

2426
import org.apache.commons.io.FileUtils;
2527
import org.apache.commons.io.IOUtils;
@@ -120,7 +122,25 @@ public void testStopWithNoFile() throws Exception {
120122
TestTailerListener listener = new TestTailerListener();
121123
int delay = 100;
122124
int idle = 50; // allow time for thread to work
123-
Tailer tailer = start(file, listener, delay, false);
125+
Tailer tailer = Tailer.create(file, listener, delay, false);
126+
Thread.sleep(idle);
127+
tailer.stop();
128+
Thread.sleep(delay+idle);
129+
assertNull("Should not generate Exception", listener.exception);
130+
assertEquals("Expected init to be called", 1 , listener.initialised);
131+
assertEquals("fileNotFound should be called", 1 , listener.notFound);
132+
assertEquals("fileRotated should be not be called", 0 , listener.rotated);
133+
}
134+
135+
public void testStopWithNoFileUsingExecutor() throws Exception {
136+
File file = new File(getTestDirectory(),"nosuchfile");
137+
assertFalse("nosuchfile should not exist", file.exists());
138+
TestTailerListener listener = new TestTailerListener();
139+
int delay = 100;
140+
int idle = 50; // allow time for thread to work
141+
Tailer tailer = new Tailer(file, listener, delay, false);
142+
Executor exec = new ScheduledThreadPoolExecutor(1);
143+
exec.execute(tailer);
124144
Thread.sleep(idle);
125145
tailer.stop();
126146
Thread.sleep(delay+idle);

0 commit comments

Comments
 (0)