Author: sebb
Date: Wed May 25 17:10:05 2011
New Revision: 1127586

URL: http://svn.apache.org/viewvc?rev=1127586&view=rev
Log:
IO-274 - Tailer returning partial lines when reaching EOF before EOL
Added test case (disabled).
N.B. Had to add tailer.stop() call to allow test file to be cleared up properly

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=1127586&r1=1127585&r2=1127586&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
 Wed May 25 17:10:05 2011
@@ -47,10 +47,43 @@ public class TailerTest extends FileBase
     protected void tearDown() throws Exception {
         if (tailer != null) {
             tailer.stop();
-            Thread.sleep(100);
+            Thread.sleep(1000);
         }
         FileUtils.deleteDirectory(getTestDirectory());
     }
+    
+    public void FIXME_testTailerEof() throws Exception {
+        // Create & start the Tailer
+        long delay = 50;
+        final File file = new File(getTestDirectory(), "tailer2-test.txt");
+        createFile(file, 0);
+        final TestTailerListener listener = new TestTailerListener();
+        final Tailer tailer = new Tailer(file, listener, delay, false);
+        final Thread thread = new Thread(tailer);
+        thread.start();
+
+        // Write some lines to the file
+        FileWriter writer = null;
+        try {
+               writeString(file, "Line");
+            
+            Thread.sleep(delay * 2);
+            List<String> lines = listener.getLines();
+            assertEquals("1 line count", 0, lines.size());
+
+            writeString(file, " one\n");
+            Thread.sleep(delay * 2);
+            lines = listener.getLines();
+
+            assertEquals("1 line count", 1, lines.size());
+            assertEquals("1 line 1", "Line one", lines.get(0));
+
+            listener.clear();
+        } finally {
+            tailer.stop();
+            IOUtils.closeQuietly(writer);
+        }
+    }
 
     public void testTailer() throws Exception {
 
@@ -154,6 +187,17 @@ public class TailerTest extends FileBase
             IOUtils.closeQuietly(writer);
         }
     }
+    
+    /** Append a string to a file */
+    private void writeString(File file, String string) throws Exception {
+        FileWriter writer = null;
+        try {
+            writer = new FileWriter(file, true);
+            writer.write(string);
+        } finally {
+            IOUtils.closeQuietly(writer);
+        }
+    }
 
     public void testStopWithNoFile() throws Exception {
         final File file = new File(getTestDirectory(),"nosuchfile");


Reply via email to