commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1642533 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java src/changes/changes.xml
Date Sun, 30 Nov 2014 09:47:35 GMT
Author: ecki
Date: Sun Nov 30 09:47:34 2014
New Revision: 1642533

URL: http://svn.apache.org/r1642533
Log:
[VFS-487] DefaultFileMonitor detect re-creation events

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java?rev=1642533&r1=1642532&r2=1642533&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
Sun Nov 30 09:47:34 2014
@@ -356,11 +356,6 @@ public class DefaultFileMonitor implemen
         mainloop:
         while (!monitorThread.isInterrupted() && this.shouldRun)
         {
-            while (!this.deleteStack.empty())
-            {
-                this.removeFile(this.deleteStack.pop());
-            }
-
             // For each entry in the map
             Object[] fileNames;
             synchronized (this.monitorMap)
@@ -407,6 +402,11 @@ public class DefaultFileMonitor implemen
                 this.addFile(this.addStack.pop());
             }
 
+            while (!this.deleteStack.empty())
+            {
+                this.removeFile(this.deleteStack.pop());
+            }
+
             try
             {
                 Thread.sleep(getDelay());

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java?rev=1642533&r1=1642532&r2=1642533&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java
Sun Nov 30 09:47:34 2014
@@ -66,14 +66,19 @@ public class DefaultFileMonitorTests ext
     {
         final FileObject fileObj = fsManager.resolveFile(testFile.toURI().toURL().toString());
         final DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
+        // TestFileListener manipulates changeStatus
         monitor.setDelay(100);
         monitor.addFile(fileObj);
         monitor.start();
-        writeToFile(testFile);
-        Thread.sleep(300);
-        assertTrue("No event occurred", changeStatus != 0);
-        assertTrue("Incorrect event", changeStatus == 3);
-        monitor.stop();
+        try
+        {
+            writeToFile(testFile);
+            Thread.sleep(300);
+            assertTrue("No event occurred", changeStatus != 0);
+            assertTrue("Incorrect event", changeStatus == 3);
+        } finally {
+            monitor.stop();
+        }
     }
 
     public void testFileDeleted() throws Exception
@@ -81,14 +86,19 @@ public class DefaultFileMonitorTests ext
         writeToFile(testFile);
         final FileObject fileObj = fsManager.resolveFile(testFile.toURI().toString());
         final DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
+        // TestFileListener manipulates changeStatus
         monitor.setDelay(100);
         monitor.addFile(fileObj);
         monitor.start();
-        testFile.delete();
-        Thread.sleep(300);
-        assertTrue("No event occurred", changeStatus != 0);
-        assertTrue("Incorrect event", changeStatus == 2);
-        monitor.stop();
+        try
+        {
+            testFile.delete();
+            Thread.sleep(300);
+            assertTrue("No event occurred", changeStatus != 0);
+            assertTrue("Incorrect event", changeStatus == 2);
+        } finally {
+            monitor.stop();
+        }
     }
 
     public void testFileModified() throws Exception
@@ -96,19 +106,24 @@ public class DefaultFileMonitorTests ext
         writeToFile(testFile);
         final FileObject fileObj = fsManager.resolveFile(testFile.toURI().toURL().toString());
         final DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
+        // TestFileListener manipulates changeStatus
         monitor.setDelay(100);
         monitor.addFile(fileObj);
         monitor.start();
-        // Need a long delay to insure the new timestamp doesn't truncate to be the same
as
-        // the current timestammp. Java only guarantees the timestamp will be to 1 second.
-        Thread.sleep(1000);
-        final long value = System.currentTimeMillis();
-        final boolean rc = testFile.setLastModified(value);
-        assertTrue("setLastModified succeeded",rc);
-        Thread.sleep(300);
-        assertTrue("No event occurred", changeStatus != 0);
-        assertTrue("Incorrect event", changeStatus == 1);
-        monitor.stop();
+        try
+        {
+            // Need a long delay to insure the new timestamp doesn't truncate to be the same
as
+            // the current timestammp. Java only guarantees the timestamp will be to 1 second.
+            Thread.sleep(1000);
+            final long value = System.currentTimeMillis();
+            final boolean rc = testFile.setLastModified(value);
+            assertTrue("setLastModified succeeded",rc);
+            Thread.sleep(300);
+            assertTrue("No event occurred", changeStatus != 0);
+            assertTrue("Incorrect event", changeStatus == 1);
+        } finally {
+            monitor.stop();
+        }
     }
 
 
@@ -116,33 +131,64 @@ public class DefaultFileMonitorTests ext
     {
         final FileObject fileObj = fsManager.resolveFile(testFile.toURI().toURL().toString());
         final DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
+        // TestFileListener manipulates changeStatus
         monitor.setDelay(100);
         monitor.addFile(fileObj);
         monitor.start();
+        try
+        {
+            writeToFile(testFile);
+            Thread.sleep(300);
+            assertTrue("No event occurred", changeStatus != 0);
+            assertTrue("Incorrect event " + changeStatus, changeStatus == 3);
+            changeStatus = 0;
+            testFile.delete();
+            Thread.sleep(300);
+            assertTrue("No event occurred", changeStatus != 0);
+            assertTrue("Incorrect event " + changeStatus, changeStatus == 2);
+            changeStatus = 0;
+            Thread.sleep(500);
+            monitor.addFile(fileObj);
+            writeToFile(testFile);
+            Thread.sleep(300);
+            assertTrue("No event occurred", changeStatus != 0);
+            assertTrue("Incorrect event " + changeStatus, changeStatus == 3);
+        } finally {
+            monitor.stop();
+        }
+    }
+
+    public void testChildFileRecreated() throws Exception
+    {
         writeToFile(testFile);
-        Thread.sleep(300);
-        assertTrue("No event occurred", changeStatus != 0);
-        assertTrue("Incorrect event " + changeStatus, changeStatus == 3);
-        changeStatus = 0;
-        testFile.delete();
-        Thread.sleep(300);
-        assertTrue("No event occurred", changeStatus != 0);
-        assertTrue("Incorrect event " + changeStatus, changeStatus == 2);
-        changeStatus = 0;
-        Thread.sleep(500);
+        final FileObject fileObj = fsManager.resolveFile(testDir.toURI().toURL().toString());
+        final DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
+        monitor.setDelay(2000);
         monitor.addFile(fileObj);
-        writeToFile(testFile);
-        Thread.sleep(300);
-        assertTrue("No event occurred", changeStatus != 0);
-        assertTrue("Incorrect event " + changeStatus, changeStatus == 3);
-        monitor.stop();
+        monitor.start();
+        try
+        {
+            changeStatus = 0;
+            Thread.sleep(300);
+            testFile.delete();
+            Thread.sleep(3000);
+            assertTrue("No event occurred", changeStatus != 0);
+            assertTrue("Incorrect event " + changeStatus, changeStatus == 2);
+            changeStatus = 0;
+            Thread.sleep(300);
+            writeToFile(testFile);
+            Thread.sleep(3000);
+            assertTrue("No event occurred", changeStatus != 0);
+            assertTrue("Incorrect event " + changeStatus, changeStatus == 3);
+        } finally {
+            monitor.stop();
+        }
     }
 
     private void writeToFile(final File file) throws Exception
     {
         final FileWriter out = new FileWriter(file);
         out.write("string=value1");
-        out.flush();
         out.close();
     }
 

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1642533&r1=1642532&r2=1642533&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Sun Nov 30 09:47:34 2014
@@ -26,6 +26,9 @@
 <!--       <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen">
-->
 <!--        [Local] Need an easy way to convert from a FileObject to a File. -->
 <!--       </action> -->
+      <action issue="VFS-487" dev="ecki" type="fix" due-to="Dave Marion">
+       DefaultFileMonitor detects recreated files.
+      </action>
       <action issue="VFS-523" dev="ecki" type="fix" due-to="Roger Whitcomb">
        [HDFS] Make HdfsFileObject.equal use system hashcode/equals instead of 
        wrongly comparing file path only.



Mime
View raw message