|
20 | 20 | import java.io.FileWriter; |
21 | 21 | import java.util.ArrayList; |
22 | 22 | import java.util.List; |
| 23 | +import java.util.concurrent.Executor; |
| 24 | +import java.util.concurrent.ScheduledThreadPoolExecutor; |
23 | 25 |
|
24 | 26 | import org.apache.commons.io.FileUtils; |
25 | 27 | import org.apache.commons.io.IOUtils; |
@@ -120,7 +122,25 @@ public void testStopWithNoFile() throws Exception { |
120 | 122 | TestTailerListener listener = new TestTailerListener(); |
121 | 123 | int delay = 100; |
122 | 124 | 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); |
124 | 144 | Thread.sleep(idle); |
125 | 145 | tailer.stop(); |
126 | 146 | Thread.sleep(delay+idle); |
|
0 commit comments