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/04 14:04:50 UTC

svn commit: r1584633 - in /lucene/dev/branches/solr5914: lucene/ lucene/core/src/test/org/apache/lucene/index/ lucene/core/src/test/org/apache/lucene/store/ lucene/test-framework/src/java/org/apache/lucene/index/ lucene/test-framework/src/java/org/apac...

Author: dweiss
Date: Fri Apr  4 12:04:49 2014
New Revision: 1584633

URL: http://svn.apache.org/r1584633
Log:
Cleanups and refactorings after Mark's suggestions.

Added:
    lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java   (with props)
Removed:
    lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java
Modified:
    lucene/dev/branches/solr5914/lucene/common-build.xml
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java
    lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
    lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
    lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
    lucene/dev/branches/solr5914/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java
    lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java
    lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
    lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
    lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java
    lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java
    lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java
    lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java
    lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java
    lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
    lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java

Modified: lucene/dev/branches/solr5914/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/common-build.xml?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/common-build.xml (original)
+++ lucene/dev/branches/solr5914/lucene/common-build.xml Fri Apr  4 12:04:49 2014
@@ -990,6 +990,9 @@
                 <propertyref prefix="tests.jettyConnector" />
                 <propertyref prefix="tests.disableHdfs" />
                 <propertyref prefix="tests.filter" />
+                <propertyref prefix="tests.leavetmpdir" />
+                <propertyref prefix="tests.leaveTemporary" />
+                <propertyref prefix="solr.test.leavetmpdir" />
             </syspropertyset>
 
             <!-- Pass randomized settings to the forked JVM. -->

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java Fri Apr  4 12:04:49 2014
@@ -179,6 +179,6 @@ public class TestAtomicUpdate extends Lu
     directory = newFSDirectory(dirPath);
     runTest(directory);
     directory.close();
-    TestUtil.rmDir(dirPath);
+    TestUtil.rm(dirPath);
   }
 }

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java Fri Apr  4 12:04:49 2014
@@ -446,7 +446,7 @@ public void testFilesOpenClose() throws 
       dir.close();
 
       // Try to erase the data - this ensures that the writer closed all files
-      TestUtil.rmDir(dirFile);
+      TestUtil.rm(dirFile);
       dir = newFSDirectory(dirFile);
 
       // Now create the data set again, just as before
@@ -463,7 +463,7 @@ public void testFilesOpenClose() throws 
 
       // The following will fail if reader did not close
       // all files
-      TestUtil.rmDir(dirFile);
+      TestUtil.rm(dirFile);
   }
 
   public void testOpenReaderAfterDelete() throws IOException {
@@ -716,7 +716,7 @@ public void testFilesOpenClose() throws 
   // good exception
   public void testNoDir() throws Throwable {
     File tempDir = TestUtil.createTempDir("doesnotexist");
-    TestUtil.rmDir(tempDir);
+    TestUtil.rm(tempDir);
     Directory dir = newFSDirectory(tempDir);
     try {
       DirectoryReader.open(dir);

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java Fri Apr  4 12:04:49 2014
@@ -223,7 +223,7 @@ public class TestFieldsReader extends Lu
       reader.close();
       dir.close();
     } finally {
-      TestUtil.rmDir(indexDir);
+      TestUtil.rm(indexDir);
     }
 
   }

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java Fri Apr  4 12:04:49 2014
@@ -108,6 +108,6 @@ public class TestNeverDelete extends Luc
     w.close();
     d.close();
 
-    TestUtil.rmDir(tmpDir);
+    TestUtil.rm(tmpDir);
   }
 }

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java Fri Apr  4 12:04:49 2014
@@ -274,7 +274,7 @@ public class TestBufferedIndexInput exte
         writer.close();
         reader.close();
       } finally {
-        TestUtil.rmDir(indexDir);
+        TestUtil.rm(indexDir);
       }
     }
 

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java Fri Apr  4 12:04:49 2014
@@ -218,7 +218,7 @@ public class TestDirectory extends Lucen
       assertFalse(dir.isOpen);
     }
     
-    TestUtil.rmDir(path);
+    TestUtil.rm(path);
   }
 
   // LUCENE-1464
@@ -230,7 +230,7 @@ public class TestDirectory extends Lucen
       assertTrue(!path.exists());
       dir.close();
     } finally {
-      TestUtil.rmDir(path);
+      TestUtil.rm(path);
     }
   }
 
@@ -265,7 +265,7 @@ public class TestDirectory extends Lucen
       Directory fsDir = new SimpleFSDirectory(path, null);
       assertEquals(0, new RAMDirectory(fsDir, newIOContext(random())).listAll().length);
     } finally {
-      TestUtil.rmDir(path);
+      TestUtil.rm(path);
     }
   }
 
@@ -285,7 +285,7 @@ public class TestDirectory extends Lucen
       }
     } finally {
       fsDir.close();
-      TestUtil.rmDir(path);
+      TestUtil.rm(path);
     }
   }
 }

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java Fri Apr  4 12:04:49 2014
@@ -104,8 +104,8 @@ public class TestFileSwitchDirectory ext
   public void testNoDir() throws Throwable {
     File primDir = TestUtil.createTempDir("foo");
     File secondDir = TestUtil.createTempDir("bar");
-    TestUtil.rmDir(primDir);
-    TestUtil.rmDir(secondDir);
+    TestUtil.rm(primDir);
+    TestUtil.rm(secondDir);
     Directory dir = newFSSwitchDirectory(primDir, secondDir, Collections.<String>emptySet());
     try {
       DirectoryReader.open(dir);

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java Fri Apr  4 12:04:49 2014
@@ -171,7 +171,7 @@ public class TestLockFactory extends Luc
 
         dir.close();
         // Cleanup
-        TestUtil.rmDir(indexDir);
+        TestUtil.rm(indexDir);
     }
 
     // Verify: NativeFSLockFactory works correctly
@@ -250,8 +250,8 @@ public class TestLockFactory extends Luc
 
       dir1.close();
       dir2.close();
-      TestUtil.rmDir(fdir1);
-      TestUtil.rmDir(fdir2);
+      TestUtil.rm(fdir1);
+      TestUtil.rm(fdir2);
     }
 
     // Verify: default LockFactory has no prefix (ie
@@ -273,7 +273,7 @@ public class TestLockFactory extends Luc
       assertNull("Default lock prefix should be null", dir.getLockFactory().getLockPrefix());
       dir.close();
  
-      TestUtil.rmDir(dirName);
+      TestUtil.rm(dirName);
     }
 
     private class WriterThread extends Thread { 

Modified: lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java (original)
+++ lucene/dev/branches/solr5914/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java Fri Apr  4 12:04:49 2014
@@ -124,7 +124,7 @@ public class TestNRTCachingDirectory ext
   // LUCENE-3382 -- make sure we get exception if the directory really does not exist.
   public void testNoDir() throws Throwable {
     File tempDir = TestUtil.createTempDir("doesnotexist");
-    TestUtil.rmDir(tempDir);
+    TestUtil.rm(tempDir);
     Directory dir = new NRTCachingDirectory(newFSDirectory(tempDir), 2.0, 25.0);
     try {
       DirectoryReader.open(dir);

Modified: lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java (original)
+++ lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java Fri Apr  4 12:04:49 2014
@@ -645,7 +645,7 @@ public abstract class ThreadedIndexingAn
 
     TestUtil.checkIndex(dir);
     dir.close();
-    TestUtil.rmDir(tempDir);
+    TestUtil.rm(tempDir);
 
     if (VERBOSE) {
       System.out.println("TEST: done [" + (System.currentTimeMillis()-t0) + " ms]");

Modified: lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java Fri Apr  4 12:04:49 2014
@@ -228,6 +228,23 @@ public abstract class LuceneTestCase ext
     String[] value();
   }
   
+  /**
+   * Marks any suites which are known not to close all the temporary
+   * files. This may prevent temp. files and folders from being cleaned
+   * up after the suite is completed.
+   * 
+   * @see TestUtil#createTempDir()
+   * @see TestUtil#createTempFile(String, String)
+   */
+  @Documented
+  @Inherited
+  @Retention(RetentionPolicy.RUNTIME)
+  @Target(ElementType.TYPE)
+  public @interface SuppressTempFileChecks {
+    /** Point to JIRA entry. */
+    public String bugUrl() default "None";
+  }
+
   // -----------------------------------------------------------------
   // Truly immutable fields and constants, initialized once and valid 
   // for all suites ever since.
@@ -291,6 +308,20 @@ public abstract class LuceneTestCase ext
   /** Throttling, see {@link MockDirectoryWrapper#setThrottling(Throttling)}. */
   public static final Throttling TEST_THROTTLING = TEST_NIGHTLY ? Throttling.SOMETIMES : Throttling.NEVER;
 
+  /** Leave temporary files on disk, even on successful runs. */
+  public static final boolean LEAVE_TEMPORARY;
+  static {
+    boolean defaultValue = false;
+    for (String property : Arrays.asList(
+        "tests.leaveTemporary" /* ANT tasks's (junit4) flag. */,
+        "tests.leavetemporary" /* lowercase */,
+        "tests.leavetmpdir" /* default */,
+        "solr.test.leavetmpdir" /* Solr's legacy */)) {
+      defaultValue |= systemPropertyAsBoolean(property, false);
+    }
+    LEAVE_TEMPORARY = defaultValue;
+  }
+
   /**
    * These property keys will be ignored in verification of altered properties.
    * @see SystemPropertiesInvariantRule
@@ -1147,7 +1178,7 @@ public abstract class LuceneTestCase ext
       final Class<? extends Directory> clazz = CommandLineUtil.loadDirectoryClass(clazzName);
       // If it is a FSDirectory type, try its ctor(File)
       if (FSDirectory.class.isAssignableFrom(clazz)) {
-        final File dir = TestUtil.createTempDir("index");
+        final File dir = new File(TestUtil.createTempDir(), "index");
         dir.mkdirs(); // ensure it's created so we 'have' it.
         return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir);
       }

Added: lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java?rev=1584633&view=auto
==============================================================================
--- lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java (added)
+++ lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java Fri Apr  4 12:04:49 2014
@@ -0,0 +1,58 @@
+package org.apache.lucene.util;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * A {@link Closeable} that attempts to remove a given file/folder.
+ */
+final class RemoveUponClose implements Closeable {
+  private final File file;
+  private final TestRuleMarkFailure failureMarker;
+  private final String creationStack;
+
+  public RemoveUponClose(File file, TestRuleMarkFailure failureMarker) {
+    this.file = file;
+    this.failureMarker = failureMarker;
+
+    StringBuilder b = new StringBuilder();
+    for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
+      b.append('\t').append(e.toString()).append('\n');
+    }
+    creationStack = b.toString();
+  }
+
+  @Override
+  public void close() throws IOException {
+    // only if there were no other test failures.
+    if (failureMarker.wasSuccessful()) {
+      if (file.exists()) {
+        try {
+          TestUtil.rm(file);
+        } catch (IOException e) {
+          throw new IOException(
+              "Could not remove temporary location '" 
+                  + file.getAbsolutePath() + "', created at stack trace:\n" + creationStack, e);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

Modified: lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java (original)
+++ lucene/dev/branches/solr5914/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java Fri Apr  4 12:04:49 2014
@@ -28,6 +28,7 @@ import java.io.PrintStream;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.nio.CharBuffer;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -36,6 +37,7 @@ import java.util.Map;
 import java.util.Random;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 import java.util.zip.ZipEntry;
@@ -85,6 +87,7 @@ import org.apache.lucene.search.Filtered
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
 import org.junit.Assert;
 
 import com.carrotsearch.randomizedtesting.RandomizedContext;
@@ -101,26 +104,36 @@ public final class TestUtil {
 
   // the max number of retries we're going to do in getTempDir
   private static final int GET_TEMP_DIR_RETRY_THRESHOLD = 1000;
-  
+
   /**
    * Deletes a file or a directory (and everything underneath it).
    */
   public static void rm(File location) throws IOException {
-    if (!location.exists()) {
-      return;
+    ArrayList<File> unremoved = rm(location, new ArrayList<File>());
+    if (!unremoved.isEmpty()) {
+      StringBuilder b = new StringBuilder("Could not remove the following files (in the order of attempts):\n");
+      for (File f : unremoved) {
+        b.append("   ")
+         .append(f.getAbsolutePath())
+         .append("\n");
+      }
+      throw new IOException(b.toString());
     }
+  }
 
-    if (location.isDirectory()) {
-      for (File f : location.listFiles()) {
-        rm(f);
+  private static ArrayList<File> rm(File location, ArrayList<File> unremoved) {
+    if (location.exists()) {
+      if (location.isDirectory()) {
+        for (File f : location.listFiles()) {
+          rm(f, unremoved);
+        }
       }
-    } else {
+      
       if (!location.delete()) {
-        throw new IOException("Could not delete: " + location.getAbsolutePath());
+        unremoved.add(location);
       }
     }
-
-    assert !location.exists();
+    return unremoved;
   }
 
   /** 
@@ -130,7 +143,7 @@ public final class TestUtil {
   public static void unzip(File zipName, File destDir) throws IOException {
     rm(destDir);
     destDir.mkdir();
-    LuceneTestCase.closeAfterSuite(new CloseableFile(destDir, LuceneTestCase.suiteFailureMarker));
+    maybeRemoveAfterSuite(destDir);
 
     ZipFile zipFile = new ZipFile(zipName);
     Enumeration<? extends ZipEntry> entries = zipFile.entries();
@@ -779,104 +792,128 @@ public final class TestUtil {
   }
   
   /**
-   * Returns a new, empty temporary folder, based on the given name. The folder will be
-   * deleted at the end of the suite. Failure to delete the temporary folder will cause
-   * an exception (typically on Windows).
+   * Returns a new, empty temporary folder, based on the current test class's name.
+   * 
+   * @see #createTempDir(String, File)
    */
-  public static File createTempDir(String name) {
-    return createTempDir(name, new File(System.getProperty("tempDir", System.getProperty("java.io.tmpdir"))));
+  public static File createTempDir() {
+    Class<?> clazz = RandomizedContext.current().getTargetClass();
+    String prefix = clazz.getName();
+    prefix = prefix.replaceFirst("^org.apache.lucene.", "lucene-");
+    prefix = prefix.replaceFirst("^org.apache.solr.", "solr-");
+    return createTempDir(prefix);
   }
-  
+
   /**
-   * Returns a new, empty temporary folder, based on the given name. The folder will be
-   * deleted at the end of the suite. Failure to delete the temporary folder will cause
-   * an exception (typically on Windows).
+   * @see #createTempDir(String, File)
    */
-  public static File createTempDir(String name, File tmpDir) {
-    return createTempDir(name, tmpDir, true);
+  public static File createTempDir(String prefix) {
+    return createTempDir(prefix, null);
   }
-  
+
   /**
-   * Returns a new, empty temporary folder, based on the given name. The folder will be
-   * deleted at the end of the suite. Failure to delete the temporary folder will cause
-   * an exception (typically on Windows).
+   * Returns a new and empty temporary folder, based on the given name. The folder will be
+   * deleted at the end of the test suite. Failure to delete the temporary folder will cause
+   * an exception (typically happens on Windows on unclosed file handles).
    */
-  public static File createTempDir(String name, File tmpDir, boolean ensureCleanedUp) {
-    if (name.length() < 3) {
-      throw new IllegalArgumentException("description must be at least 3 characters");
+  public static File createTempDir(String prefix, File parent) {
+    if (prefix.length() < 3) {
+      throw new IllegalArgumentException("The prefix must be at least 3 characters: " + prefix);
     }
-  
-    // always pull a long from master random. that way, the randomness of the test
+    
+    if (parent == null) {
+      parent = tempDirectory();
+    }
+
+    if (!parent.exists()) {
+      throw new RuntimeException("Parent location does not exist: " + parent.getAbsolutePath());
+    }
+
+    if (!parent.isDirectory()) {
+      throw new RuntimeException("Parent location is not a folder: " + parent.getAbsolutePath());
+    }
+
+    if (!parent.canWrite()) {
+      throw new RuntimeException("Parent folder not writeable: " + parent.getAbsolutePath());
+    }
+
+    // Always pull a long from master random. that way, the randomness of the test
     // is not affected by whether it initialized the counter (in genTempFile) or not.
     // note that the Random used by genTempFile is *not* the master Random, and therefore
     // does not affect the randomness of the test.
-    final Random random = new Random(RandomizedContext.current().getRandom().nextLong());
     int attempt = 0;
     File f;
     do {
-      f = genTempFile(random, name + "_", "", tmpDir);
+      f = genTempFile(prefix + "_", "", parent);
     } while (!f.mkdir() && (attempt++) < GET_TEMP_DIR_RETRY_THRESHOLD);
     
     if (attempt > GET_TEMP_DIR_RETRY_THRESHOLD) {
       throw new RuntimeException(
-          "failed to get a temporary dir too many times. check your temp directory and consider manually cleaning it.");
+          "Failed to get a temporary dir too many times, check your temp directory and consider manually cleaning it: "
+            + parent.getAbsolutePath());
     }
-    if (ensureCleanedUp) {
-      LuceneTestCase.closeAfterSuite(new CloseableFile(f, LuceneTestCase.suiteFailureMarker));
+
+    return maybeRemoveAfterSuite(f);
+  }
+
+  private static File maybeRemoveAfterSuite(File f) {
+    if (LuceneTestCase.LEAVE_TEMPORARY) {
+      System.err.println("INFO: Will leave temporary file: " + f.getAbsolutePath());
+      return f;
+    }
+
+    Class<?> suiteClass = RandomizedContext.current().getTargetClass();
+    if (suiteClass.isAnnotationPresent(SuppressTempFileChecks.class)) {
+      System.err.println("WARNING: Will leave temporary files (bugUrl: "
+          + suiteClass.getAnnotation(SuppressTempFileChecks.class).bugUrl() + "): "
+          + f.getAbsolutePath());
+      return f;
     }
+
+    LuceneTestCase.closeAfterSuite(new RemoveUponClose(f, LuceneTestCase.suiteFailureMarker));
     return f;
   }
 
   public static File createTempFile(String prefix, String suffix) throws IOException {
-    String tmpDir = System.getProperty("tempDir", System.getProperty("java.io.tmpdir"));
-    return createTempFile(prefix, suffix, new File(tmpDir));
+    return createTempFile(prefix, suffix, tempDirectory());
+  }
+
+  /**
+   * Do NOT expose this method public. Use {@link #createTempDir()} instead.
+   */
+  private static File tempDirectory() {
+    File directory = new File(System.getProperty("tempDir", System.getProperty("java.io.tmpdir")));
+    assert directory.exists() && 
+           directory.isDirectory() && 
+           directory.canWrite();
+    return directory;
   }
 
   /** 
    * Insecure, fast version of {@link File#createTempFile(String, String)}, uses 
    * Random instead of SecureRandom.
    */
-  public static File createTempFile(String prefix, String suffix, File directory)
-      throws IOException {
+  public static File createTempFile(String prefix, String suffix, File directory) throws IOException {
     if (prefix.length() < 3) {
       throw new IllegalArgumentException("prefix must be at least 3 characters");
     }
     String newSuffix = suffix == null ? ".tmp" : suffix;
-    // always pull a long from master random. that way, the randomness of the test
-    // is not affected by whether it initialized the counter (in genTempFile) or not.
-    // note that the Random used by genTempFile is *not* the master Random, and therefore
-    // does not affect the randomness of the test.
-    final Random random = new Random(RandomizedContext.current().getRandom().nextLong());
     File result;
     do {
-      result = genTempFile(random, prefix, newSuffix, directory);
+      result = genTempFile(prefix, newSuffix, directory);
     } while (!result.createNewFile());
-    LuceneTestCase.closeAfterSuite(new CloseableFile(result, LuceneTestCase.suiteFailureMarker));
-    return result;
+    return maybeRemoveAfterSuite(result);
   }
 
-  /* identify for differnt VM processes */
-  private static String counterBase;
-  
   /* Temp file counter */
-  private static int counter;
-  private static final Object counterLock = new Object();
+  private static final AtomicInteger counter = new AtomicInteger();
 
-  private static File genTempFile(Random random, String prefix, String suffix, File directory) {
-    final int identify;
-    synchronized (counterLock) {
-      if (counterBase == null) { // init once
-        counter = random.nextInt() & 0xFFFF; // up to five digits number
-        counterBase = Integer.toString(counter);
-      }
-      identify = counter++;
-    }
-    StringBuilder newName = new StringBuilder();
-    newName.append(prefix);
-    newName.append(counterBase);
-    newName.append(identify);
-    newName.append(suffix);
-    return new File(directory, newName.toString());
+  private static File genTempFile(String prefix, String suffix, File directory) {
+    return new File(directory, 
+        prefix 
+          + RandomizedContext.current().getRunnerSeedAsString() 
+          + "-" + counter.incrementAndGet() 
+          + suffix);
   }
 
   public static void assertEquals(TopDocs expected, TopDocs actual) {

Modified: lucene/dev/branches/solr5914/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java (original)
+++ lucene/dev/branches/solr5914/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java Fri Apr  4 12:04:49 2014
@@ -20,8 +20,6 @@ import java.io.File;
 import java.util.List;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.TestUtil;
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
 import org.apache.solr.client.solrj.impl.HttpSolrServer;
 import org.apache.solr.client.solrj.request.DirectXmlRequest;
@@ -151,10 +149,7 @@ public class TestContentStreamDataSource
 
 
     public void setUp() throws Exception {
-      File home = new File(dataDir,
-              getClass().getName() + "-" + System.currentTimeMillis());
-
-      homeDir = new File(home, "inst");
+      homeDir = createTempDir("inst");
       dataDir = new File(homeDir + "/collection1", "data");
       confDir = new File(homeDir + "/collection1", "conf");
 

Modified: lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java (original)
+++ lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java Fri Apr  4 12:04:49 2014
@@ -76,7 +76,7 @@ public class ResourceLoaderTest extends 
       }
       loader.close();
     } finally {
-      TestUtil.rmDir(temp);
+      TestUtil.rm(temp);
     }
   }
 

Modified: lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java (original)
+++ lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java Fri Apr  4 12:04:49 2014
@@ -23,8 +23,8 @@ import java.util.List;
 
 import junit.framework.Assert;
 
-import org.apache.solr.SolrTestCaseJ4.SuppressTempDirCleanUp;
 import org.apache.lucene.util.LuceneTestCase.Slow;
+import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
 import org.apache.solr.BaseDistributedSearchTestCase;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.response.QueryResponse;
@@ -41,7 +41,7 @@ import org.junit.BeforeClass;
  * @see org.apache.solr.handler.component.SpellCheckComponent
  */
 @Slow
-@SuppressTempDirCleanUp(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
+@SuppressTempFileChecks(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
 public class DistributedSpellCheckComponentTest extends BaseDistributedSearchTestCase {
   
   public DistributedSpellCheckComponentTest()

Modified: lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java (original)
+++ lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java Fri Apr  4 12:04:49 2014
@@ -21,8 +21,8 @@ import java.io.File;
 import java.util.*;
 
 import org.apache.lucene.util.LuceneTestCase.Slow;
+import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.SolrTestCaseJ4.SuppressTempDirCleanUp;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.params.SpellingParams;
@@ -42,7 +42,7 @@ import org.junit.Test;
  * @since solr 1.3
  */
 @Slow
-@SuppressTempDirCleanUp(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
+@SuppressTempFileChecks(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
 public class SpellCheckComponentTest extends SolrTestCaseJ4 {
   static String rh = "spellCheckCompRH";
 

Modified: lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java (original)
+++ lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java Fri Apr  4 12:04:49 2014
@@ -21,8 +21,8 @@ import java.util.Collection;
 import java.util.Map;
 
 import org.apache.lucene.analysis.Token;
+import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.SolrTestCaseJ4.SuppressTempDirCleanUp;
 import org.apache.solr.common.params.SpellingParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.SolrCore;
@@ -35,7 +35,7 @@ import org.junit.Test;
 /**
  * Simple tests for {@link DirectSolrSpellChecker}
  */
-@SuppressTempDirCleanUp(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
+@SuppressTempFileChecks(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
 public class DirectSolrSpellCheckerTest extends SolrTestCaseJ4 {
 
   private static SpellingQueryConverter queryConverter;

Modified: lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java (original)
+++ lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java Fri Apr  4 12:04:49 2014
@@ -24,8 +24,8 @@ import java.util.Map;
 import org.apache.lucene.analysis.Token;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
+import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.SolrTestCaseJ4.SuppressTempDirCleanUp;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.search.SolrIndexSearcher;
@@ -38,7 +38,7 @@ import org.junit.Test;
  *
  * @since solr 1.3
  **/
-@SuppressTempDirCleanUp(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
+@SuppressTempFileChecks(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
 public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {
 
   private static SpellingQueryConverter queryConverter;

Modified: lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java (original)
+++ lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java Fri Apr  4 12:04:49 2014
@@ -37,8 +37,8 @@ import org.apache.lucene.search.spell.Su
 import org.apache.lucene.search.spell.SuggestWord;
 import org.apache.lucene.search.spell.SuggestWordFrequencyComparator;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.SolrTestCaseJ4.SuppressTempDirCleanUp;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.handler.component.SpellCheckComponent;
@@ -51,7 +51,7 @@ import org.junit.Test;
 /**
  * @since solr 1.3
  */
-@SuppressTempDirCleanUp(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
+@SuppressTempFileChecks(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
 public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 {
   protected static SpellingQueryConverter queryConverter;
 

Modified: lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java (original)
+++ lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java Fri Apr  4 12:04:49 2014
@@ -21,9 +21,9 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.lucene.util.LuceneTestCase.Slow;
+import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
 import org.apache.lucene.util.TestUtil;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.SolrTestCaseJ4.SuppressTempDirCleanUp;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.GroupParams;
@@ -42,7 +42,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 @Slow
-@SuppressTempDirCleanUp(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
+@SuppressTempFileChecks(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
 public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
   @BeforeClass
   public static void beforeClass() throws Exception {

Modified: lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java (original)
+++ lucene/dev/branches/solr5914/solr/core/src/test/org/apache/solr/spelling/WordBreakSolrSpellCheckerTest.java Fri Apr  4 12:04:49 2014
@@ -23,8 +23,8 @@ import java.util.Map;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.Token;
+import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.SolrTestCaseJ4.SuppressTempDirCleanUp;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.handler.component.SpellCheckComponent;
@@ -33,7 +33,7 @@ import org.apache.solr.util.RefCounted;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-@SuppressTempDirCleanUp(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
+@SuppressTempFileChecks(bugUrl = "https://issues.apache.org/jira/browse/SOLR-1877 Spellcheck IndexReader leak bug?")
 public class WordBreakSolrSpellCheckerTest extends SolrTestCaseJ4 {
   
   @BeforeClass

Modified: lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Fri Apr  4 12:04:49 2014
@@ -134,25 +134,9 @@ public abstract class SolrTestCaseJ4 ext
     public String bugUrl() default "None";
   }
   
-
-  /**
-   * Annotation for test classes to prevent TEMP_DIR cleanup.
-   */
-  @Documented
-  @Inherited
-  @Retention(RetentionPolicy.RUNTIME)
-  @Target(ElementType.TYPE)
-  public @interface SuppressTempDirCleanUp {
-    /** Point to JIRA entry. */
-    public String bugUrl() default "None";
-  }
-  
   // these are meant to be accessed sequentially, but are volatile just to ensure any test
   // thread will read the latest value
   protected static volatile SSLTestConfig sslConfig;
-  
-  private static boolean LEAVE_TEST_TMP_DIR = Boolean.getBoolean("solr.test.leavetmpdir");
-  private static boolean LEAVE_TEST_TMP_DIR_ANNOTATION;
 
   @ClassRule
   public static TestRule solrClassRules = 
@@ -166,14 +150,10 @@ public abstract class SolrTestCaseJ4 ext
   @BeforeClass 
   @SuppressWarnings("unused")
   private static void beforeClass() {
-    String cname = getSimpleClassName();
-    
-    LEAVE_TEST_TMP_DIR_ANNOTATION = RandomizedContext.current().getTargetClass()
-        .isAnnotationPresent(SuppressTempDirCleanUp.class);
-    
-    boolean ensureClosed = !(LEAVE_TEST_TMP_DIR || LEAVE_TEST_TMP_DIR_ANNOTATION);
-    rootTmpDir = TestUtil.createTempDir("solrtest-" + cname, null, ensureClosed);
-    initCoreDataDir = TestUtil.createTempDir("solrtest-" + cname, rootTmpDir, ensureClosed);
+    // Create the root parent folder for all other temporary solr files. 
+    rootTmpDir = TestUtil.createTempDir();
+
+    initCoreDataDir = TestUtil.createTempDir("init-core-data", rootTmpDir);
 
     System.err.println("Creating dataDir: " + initCoreDataDir.getAbsolutePath());
     
@@ -207,42 +187,19 @@ public abstract class SolrTestCaseJ4 ext
       resetFactory();
       coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;
     } finally {
-      try {
-
-        if (LEAVE_TEST_TMP_DIR) {
-          System.err
-              .println("NOTE: per solr.test.leavetmpdir, the test tmp directory will not be removed: "
-                  + rootTmpDir.getAbsolutePath());
-        } else {
-          // TODO: tmp files should already get cleaned up by the test framework, but
-          // we still do it here as well, so that we clean up as much as we can, even
-          // when a test is the SuppressTempDirCleanUp annotation
-          if (rootTmpDir != null && rootTmpDir.exists() && !recurseDelete(rootTmpDir)) {
-            String msg = "!!!! WARNING: best effort to remove "
-                + rootTmpDir.getAbsolutePath() + " FAILED !!!!!";
-            if (LEAVE_TEST_TMP_DIR_ANNOTATION) {
-              System.err.println(msg);
-            } else {
-              // TODO: do we want to fail here with this message? Is the test framework
-              // fail that should happen better?
-              fail(msg);
-            }
-          }
-        }
-      } finally {
-        initCoreDataDir = null;
-        System.clearProperty("jetty.testMode");
-        System.clearProperty("tests.shardhandler.randomSeed");
-        System.clearProperty("enable.update.log");
-        System.clearProperty("useCompoundFile");
-        System.clearProperty("urlScheme");
-        
-        if (isSSLMode()) {
-          HttpClientUtil.setConfigurer(new HttpClientConfigurer());
-        }
-        // clean up static
-        sslConfig = null;
+      initCoreDataDir = null;
+      System.clearProperty("jetty.testMode");
+      System.clearProperty("tests.shardhandler.randomSeed");
+      System.clearProperty("enable.update.log");
+      System.clearProperty("useCompoundFile");
+      System.clearProperty("urlScheme");
+      
+      if (isSSLMode()) {
+        HttpClientUtil.setConfigurer(new HttpClientConfigurer());
       }
+
+      // clean up static
+      sslConfig = null;
     }
     
     IpTables.unblockAllPorts();
@@ -511,9 +468,9 @@ public abstract class SolrTestCaseJ4 ext
   public static File createTempDir() {
     return createTempDir(null);
   }
-  
-  public static File createTempDir(String tag) {
-    return TestUtil.createTempDir(getClassName() + (tag == null ? "" : "-" + tag), rootTmpDir, !(LEAVE_TEST_TMP_DIR || LEAVE_TEST_TMP_DIR_ANNOTATION));
+
+  public static File createTempDir(String prefix) {
+    return TestUtil.createTempDir(prefix == null ? "temp" : prefix, rootTmpDir);
   }
   
   public static void resetExceptionIgnores() {

Modified: lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java?rev=1584633&r1=1584632&r2=1584633&view=diff
==============================================================================
--- lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java (original)
+++ lucene/dev/branches/solr5914/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java Fri Apr  4 12:04:49 2014
@@ -154,13 +154,11 @@ public abstract class AbstractZkTestCase
     System.clearProperty("jetty.port");
     System.clearProperty(ZOOKEEPER_FORCE_SYNC);
 
-    zkServer.shutdown();
-
-    zkServer = null;
+    if (zkServer != null) {
+      zkServer.shutdown();
+      zkServer = null;
+    }
     zkDir = null;
-    
-    // wait just a bit for any zk client threads to outlast timeout
-    Thread.sleep(2000);
   }
 
   protected void printLayout(String zkHost) throws Exception {