3737 */
3838public class TailerTest extends FileBasedTestCase {
3939
40+ private Tailer tailer ;
41+
4042 public TailerTest (String name ) {
4143 super (name );
4244 }
4345
4446 @ Override
4547 protected void tearDown () throws Exception {
48+ if (tailer != null ) {
49+ tailer .stop ();
50+ Thread .sleep (100 );
51+ }
4652 FileUtils .deleteDirectory (getTestDirectory ());
4753 }
4854
@@ -53,7 +59,7 @@ public void testTailer() throws Exception {
5359 final File file = new File (getTestDirectory (), "tailer1-test.txt" );
5460 createFile (file , 0 );
5561 final TestTailerListener listener = new TestTailerListener ();
56- final Tailer tailer = new Tailer (file , listener , delay , false );
62+ tailer = new Tailer (file , listener , delay , false );
5763 final Thread thread = new Thread (tailer );
5864 thread .start ();
5965
@@ -96,6 +102,7 @@ public void testTailer() throws Exception {
96102
97103 // Stop
98104 tailer .stop ();
105+ tailer =null ;
99106 thread .interrupt ();
100107 Thread .sleep (delay * 2 );
101108 write (file , "Line five" );
@@ -150,9 +157,10 @@ public void testStopWithNoFile() throws Exception {
150157 final TestTailerListener listener = new TestTailerListener ();
151158 int delay = 100 ;
152159 int idle = 50 ; // allow time for thread to work
153- final Tailer tailer = Tailer .create (file , listener , delay , false );
160+ tailer = Tailer .create (file , listener , delay , false );
154161 Thread .sleep (idle );
155162 tailer .stop ();
163+ tailer =null ;
156164 Thread .sleep (delay +idle );
157165 assertNull ("Should not generate Exception" , listener .exception );
158166 assertEquals ("Expected init to be called" , 1 , listener .initialised );
@@ -166,11 +174,12 @@ public void testStopWithNoFileUsingExecutor() throws Exception {
166174 TestTailerListener listener = new TestTailerListener ();
167175 int delay = 100 ;
168176 int idle = 50 ; // allow time for thread to work
169- Tailer tailer = new Tailer (file , listener , delay , false );
177+ tailer = new Tailer (file , listener , delay , false );
170178 Executor exec = new ScheduledThreadPoolExecutor (1 );
171179 exec .execute (tailer );
172180 Thread .sleep (idle );
173181 tailer .stop ();
182+ tailer =null ;
174183 Thread .sleep (delay +idle );
175184 assertNull ("Should not generate Exception" , listener .exception );
176185 assertEquals ("Expected init to be called" , 1 , listener .initialised );
0 commit comments