lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject svn commit: r1200402 - in /lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util: LuceneTestCase.java _TestUtil.java
Date Thu, 10 Nov 2011 16:16:36 GMT
Author: shaie
Date: Thu Nov 10 16:16:36 2011
New Revision: 1200402

URL: http://svn.apache.org/viewvc?rev=1200402&view=rev
Log:
rename LTC.registerTempFile to registerTempDir, clarified javadocs. Also fixed _TestUtil.rmDir()
to not throw NPE if a 'file' is given

Modified:
    lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java?rev=1200402&r1=1200401&r2=1200402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
Thu Nov 10 16:16:36 2011
@@ -1152,9 +1152,14 @@ public abstract class LuceneTestCase ext
     }
     return d;
   }
-  
-  /** Registers a temp file that will be deleted when tests are done. */
-  public static void registerTempFile(File tmpFile) {
+
+  /**
+   * Registers a temp directory that will be deleted when tests are done. This
+   * is used by {@link _TestUtil#getTempDir(String)} and
+   * {@link _TestUtil#unzip(File, File)}, so you should call these methods when
+   * possible.
+   */
+  static void registerTempDir(File tmpFile) {
     tempDirs.put(tmpFile.getAbsoluteFile(), Thread.currentThread().getStackTrace());
   }
   
@@ -1167,11 +1172,9 @@ public abstract class LuceneTestCase ext
       final Class<? extends Directory> clazz = Class.forName(clazzName).asSubclass(Directory.class);
       // If it is a FSDirectory type, try its ctor(File)
       if (FSDirectory.class.isAssignableFrom(clazz)) {
-        final File tmpFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
-        tmpFile.delete();
-        tmpFile.mkdir();
-        registerTempFile(tmpFile);
-        return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), tmpFile);
+        final File dir = _TestUtil.getTempDir("index");
+        dir.mkdirs(); // ensure it's created so we 'have' it.
+        return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir);
       }
 
       // try empty ctor

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java?rev=1200402&r1=1200401&r2=1200402&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java
Thu Nov 10 16:16:36 2011
@@ -58,7 +58,7 @@ public class _TestUtil {
     try {
       File f = createTempFile(desc, "tmp", LuceneTestCase.TEMP_DIR);
       f.delete();
-      LuceneTestCase.registerTempFile(f);
+      LuceneTestCase.registerTempDir(f);
       return f;
     } catch (IOException e) {
       throw new RuntimeException(e);
@@ -70,6 +70,9 @@ public class _TestUtil {
    */
   public static void rmDir(File dir) throws IOException {
     if (dir.exists()) {
+      if (dir.isFile() && !dir.delete()) {
+        throw new IOException("could not delete " + dir);
+      }
       for (File f : dir.listFiles()) {
         if (f.isDirectory()) {
           rmDir(f);
@@ -97,7 +100,7 @@ public class _TestUtil {
     rmDir(destDir);
     
     destDir.mkdir();
-    LuceneTestCase.registerTempFile(destDir);
+    LuceneTestCase.registerTempDir(destDir);
     
     while (entries.hasMoreElements()) {
       ZipEntry entry = entries.nextElement();



Mime
View raw message