commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1347789 - /commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java
Date Thu, 07 Jun 2012 20:54:51 GMT
Author: sebb
Date: Thu Jun  7 20:54:50 2012
New Revision: 1347789

URL: http://svn.apache.org/viewvc?rev=1347789&view=rev
Log:
Add extra tests from IO-278

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=1347789&r1=1347788&r2=1347789&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 Thu
Jun  7 20:54:50 2012
@@ -21,7 +21,9 @@ import java.io.FileNotFoundException;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.io.Writer;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -50,6 +52,57 @@ public class TailerTest extends FileBase
             Thread.sleep(1000);
         }
         FileUtils.deleteDirectory(getTestDirectory());
+        Thread.sleep(1000);
+    }
+
+    public void testLongFile() throws Exception {
+        long delay = 50;
+        
+        File file = new File(getTestDirectory(), "testLongFile.txt");
+        createFile(file, 0);
+        Writer writer = new FileWriter(file, true);
+        for (int i = 0; i < 100000; i++) {
+            writer.write("LineLineLineLineLineLineLineLineLineLine\n");
+        }
+        writer.write("SBTOURIST\n");
+        IOUtils.closeQuietly(writer);
+
+        TestTailerListener listener = new TestTailerListener();
+        tailer = new Tailer(file, listener, delay, false);
+
+        long start = System.currentTimeMillis();
+
+        Thread thread = new Thread(tailer);
+        thread.start();
+
+        List<String> lines = listener.getLines();
+        while (lines.isEmpty() || !lines.get(lines.size() - 1).equals("SBTOURIST")) {
+            lines = listener.getLines();
+        }
+        System.out.println("Elapsed: " + (System.currentTimeMillis() - start));
+
+        listener.clear();
+    }
+
+    public void testBufferBreak() throws Exception {
+        long delay = 50;
+
+        File file = new File(getTestDirectory(), "testBufferBreak.txt");
+        createFile(file, 0);
+        writeString(file, "SBTOURIST\n");
+
+        TestTailerListener listener = new TestTailerListener();
+        tailer = new Tailer(file, listener, delay, false, 1);
+
+        Thread thread = new Thread(tailer);
+        thread.start();
+
+        List<String> lines = listener.getLines();
+        while (lines.isEmpty() || !lines.get(lines.size() - 1).equals("SBTOURIST")) {
+            lines = listener.getLines();
+        }
+
+        listener.clear();
     }
 
     public void testTailerEof() throws Exception {
@@ -242,7 +295,8 @@ public class TailerTest extends FileBase
      */
     private static class TestTailerListener implements TailerListener {
 
-        private final List<String> lines = new ArrayList<String>();
+        // Must be synchronised because it is written by one thread and read by another
+        private final List<String> lines = Collections.synchronizedList(new ArrayList<String>());
 
         volatile Exception exception = null;
 



Mime
View raw message