You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2014/04/10 17:32:56 UTC

svn commit: r1586338 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/CHANGES.txt lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java

Author: dweiss
Date: Thu Apr 10 15:32:56 2014
New Revision: 1586338

URL: http://svn.apache.org/r1586338
Log:
LUCENE-5592: Incorrectly reported uncloseable files.

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1586338&r1=1586337&r2=1586338&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Thu Apr 10 15:32:56 2014
@@ -194,6 +194,8 @@ Bug fixes
 
 Test Framework
 
+* LUCENE-5592: Incorrectly reported uncloseable files. (Dawid Weiss)
+
 * LUCENE-5577: Temporary folder and file management (and cleanup facilities)
   (Mark Miller, Uwe Schindler, Dawid Weiss)
 

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1586338&r1=1586337&r2=1586338&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java Thu Apr 10 15:32:56 2014
@@ -34,12 +34,10 @@ import java.lang.annotation.Target;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.nio.file.NoSuchFileException;
-import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Deque;
 import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -2347,7 +2345,7 @@ public abstract class LuceneTestCase ext
    * suite completes.
    * @see #registerToRemoveAfterSuite(File)
    */
-  private final static Deque<File> cleanupQueue = new ArrayDeque<File>();
+  private final static List<File> cleanupQueue = new ArrayList<File>();
 
   /**
    * Register temporary folder for removal after the suite completes.
@@ -2361,7 +2359,7 @@ public abstract class LuceneTestCase ext
     }
 
     synchronized (cleanupQueue) {
-      cleanupQueue.addLast(f);
+      cleanupQueue.add(f);
     }
   }
 
@@ -2374,38 +2372,39 @@ public abstract class LuceneTestCase ext
 
     @Override
     protected void afterAlways(List<Throwable> errors) throws Throwable {
-      try {
-        if (LuceneTestCase.suiteFailureMarker.wasSuccessful()) {
-          synchronized (cleanupQueue) {
-            File [] everything = new File [cleanupQueue.size()];
-            for (int i = 0; !cleanupQueue.isEmpty(); i++) {
-              everything[i] = cleanupQueue.removeLast();
-            }
-  
-            // Will throw an IOException on un-removable files.
-            try {
-              TestUtil.rm(everything);
-            } catch (IOException e) {
-              Class<?> suiteClass = RandomizedContext.current().getTargetClass();
-              if (suiteClass.isAnnotationPresent(SuppressTempFileChecks.class)) {
-                System.err.println("WARNING: Leftover undeleted temporary files (bugUrl: "
-                    + suiteClass.getAnnotation(SuppressTempFileChecks.class).bugUrl() + "): "
-                    + e.getMessage());
-                return;
-              }
-              throw e;
-            }
-          }
-        } else {
-          synchronized (cleanupQueue) {
-            if (tempDirBase != null) {
-              System.err.println("NOTE: leaving temporary files on disk at: " +
-                  tempDirBase.getAbsolutePath());
-            }
+      // Drain cleanup queue and clear it.
+      final File [] everything;
+      final String tempDirBasePath;
+      synchronized (cleanupQueue) {
+        tempDirBasePath = (tempDirBase != null ? tempDirBase.getAbsolutePath() : null);
+        tempDirBase = null;
+
+        Collections.reverse(cleanupQueue);
+        everything = new File [cleanupQueue.size()];
+        cleanupQueue.toArray(everything);
+        cleanupQueue.clear();
+      }
+
+      // Only check and throw an IOException on un-removable files if the test
+      // was successful. Otherwise just report the path of temporary files
+      // and leave them there.
+      if (LuceneTestCase.suiteFailureMarker.wasSuccessful()) {
+        try {
+          TestUtil.rm(everything);
+        } catch (IOException e) {
+          Class<?> suiteClass = RandomizedContext.current().getTargetClass();
+          if (suiteClass.isAnnotationPresent(SuppressTempFileChecks.class)) {
+            System.err.println("WARNING: Leftover undeleted temporary files (bugUrl: "
+                + suiteClass.getAnnotation(SuppressTempFileChecks.class).bugUrl() + "): "
+                + e.getMessage());
+            return;
           }
+          throw e;
+        }
+      } else {
+        if (tempDirBasePath != null) {
+          System.err.println("NOTE: leaving temporary files on disk at: " + tempDirBasePath);
         }
-      } finally {
-        tempDirBase = null;
       }
     }
   }