You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/04/10 01:54:15 UTC
svn commit: r1090714 -
/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java
Author: sebb
Date: Sat Apr 9 23:54:15 2011
New Revision: 1090714
URL: http://svn.apache.org/viewvc?rev=1090714&view=rev
Log:
Ensure that tailer is stopped even if test aborts
Modified:
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java?rev=1090714&r1=1090713&r2=1090714&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java Sat Apr 9 23:54:15 2011
@@ -37,12 +37,18 @@ import org.apache.commons.io.testtools.F
*/
public class TailerTest extends FileBasedTestCase {
+ private Tailer tailer;
+
public TailerTest(String name) {
super(name);
}
@Override
protected void tearDown() throws Exception {
+ if (tailer != null) {
+ tailer.stop();
+ Thread.sleep(100);
+ }
FileUtils.deleteDirectory(getTestDirectory());
}
@@ -53,7 +59,7 @@ public class TailerTest extends FileBase
final File file = new File(getTestDirectory(), "tailer1-test.txt");
createFile(file, 0);
final TestTailerListener listener = new TestTailerListener();
- final Tailer tailer = new Tailer(file, listener, delay, false);
+ tailer = new Tailer(file, listener, delay, false);
final Thread thread = new Thread(tailer);
thread.start();
@@ -96,6 +102,7 @@ public class TailerTest extends FileBase
// Stop
tailer.stop();
+ tailer=null;
thread.interrupt();
Thread.sleep(delay * 2);
write(file, "Line five");
@@ -150,9 +157,10 @@ public class TailerTest extends FileBase
final TestTailerListener listener = new TestTailerListener();
int delay = 100;
int idle = 50; // allow time for thread to work
- final Tailer tailer = Tailer.create(file, listener, delay, false);
+ tailer = Tailer.create(file, listener, delay, false);
Thread.sleep(idle);
tailer.stop();
+ tailer=null;
Thread.sleep(delay+idle);
assertNull("Should not generate Exception", listener.exception);
assertEquals("Expected init to be called", 1 , listener.initialised);
@@ -166,11 +174,12 @@ public class TailerTest extends FileBase
TestTailerListener listener = new TestTailerListener();
int delay = 100;
int idle = 50; // allow time for thread to work
- Tailer tailer = new Tailer(file, listener, delay, false);
+ tailer = new Tailer(file, listener, delay, false);
Executor exec = new ScheduledThreadPoolExecutor(1);
exec.execute(tailer);
Thread.sleep(idle);
tailer.stop();
+ tailer=null;
Thread.sleep(delay+idle);
assertNull("Should not generate Exception", listener.exception);
assertEquals("Expected init to be called", 1 , listener.initialised);