lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r783487 - in /lucene/java/trunk/src/test/org/apache/lucene: index/TestIndexReader.java index/TestIndexWriter.java index/TestPayloads.java index/TestStressIndexing.java store/TestLockFactory.java util/_TestUtil.java
Date Wed, 10 Jun 2009 20:15:19 GMT
Author: mikemccand
Date: Wed Jun 10 20:15:19 2009
New Revision: 783487

URL: http://svn.apache.org/viewvc?rev=783487&view=rev
Log:
LUCENE-1682: fix some unit tests to use private filesystem dir when testing

Modified:
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java
    lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
    lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?rev=783487&r1=783486&r2=783487&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Wed Jun 10 20:15:19
2009
@@ -1539,10 +1539,7 @@
 
     public void testFalseDirectoryAlreadyClosed() throws Throwable {
 
-      String tempDir = System.getProperty("java.io.tmpdir");
-      if (tempDir == null)
-        throw new RuntimeException("java.io.tmpdir undefined");
-      File indexDir = new File(tempDir, "lucenetestdiralreadyclosed");
+      File indexDir = _TestUtil.getTempDir("lucenetestdiralreadyclosed");
 
       try {
         FSDirectory dir = FSDirectory.getDirectory(indexDir);
@@ -1625,8 +1622,7 @@
   // IndexReader on a non-existent directory, you get a
   // good exception
   public void testNoDir() throws Throwable {
-    String tempDir = System.getProperty("java.io.tmpdir");
-    Directory dir = FSDirectory.open(new File(tempDir, "doesnotexist"));
+    Directory dir = FSDirectory.open(_TestUtil.getTempDir("doesnotexist"));
     try {
       IndexReader.open(dir);
       fail("did not hit expected exception");

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=783487&r1=783486&r2=783487&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Wed Jun 10 20:15:19
2009
@@ -741,10 +741,7 @@
     // reader holds it open (this fails pre lock-less
     // commits on windows):
     public void testCreateWithReader() throws IOException {
-        String tempDir = System.getProperty("java.io.tmpdir");
-        if (tempDir == null)
-            throw new IOException("java.io.tmpdir undefined, cannot run test");
-        File indexDir = new File(tempDir, "lucenetestindexwriter");
+        File indexDir = _TestUtil.getTempDir("lucenetestindexwriter");
 
         try {
           Directory dir = FSDirectory.open(indexDir);
@@ -778,10 +775,7 @@
     // Same test as above, but use IndexWriter constructor
     // that takes File:
     public void testCreateWithReader2() throws IOException {
-        String tempDir = System.getProperty("java.io.tmpdir");
-        if (tempDir == null)
-            throw new IOException("java.io.tmpdir undefined, cannot run test");
-        File indexDir = new File(tempDir, "lucenetestindexwriter");
+        File indexDir = _TestUtil.getTempDir("lucenetestindexwriter");
         try {
           // add one document & close writer
           IndexWriter writer = new IndexWriter(indexDir, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
@@ -811,11 +805,7 @@
     // Same test as above, but use IndexWriter constructor
     // that takes String:
     public void testCreateWithReader3() throws IOException {
-        String tempDir = System.getProperty("tempDir");
-        if (tempDir == null)
-            throw new IOException("java.io.tmpdir undefined, cannot run test");
-
-        String dirName = tempDir + "/lucenetestindexwriter";
+        File dirName = _TestUtil.getTempDir("lucenetestindexwriter");
         try {
 
           // add one document & close writer
@@ -839,7 +829,7 @@
           reader.close();
           reader2.close();
         } finally {
-          rmDir(new File(dirName));
+          rmDir(dirName);
         }
     }
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java?rev=783487&r1=783486&r2=783487&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java Wed Jun 10 20:15:19
2009
@@ -41,6 +41,7 @@
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.UnicodeUtil;
+import org.apache.lucene.util._TestUtil;
 
 
 public class TestPayloads extends LuceneTestCase {
@@ -157,10 +158,10 @@
         performTest(dir);
         
         // now use a FSDirectory and repeat same test
-        String dirName = "test_payloads"; 
-        dir = FSDirectory.open(new File(dirName));
+        File dirName = _TestUtil.getTempDir("test_payloads");
+        dir = FSDirectory.open(dirName);
         performTest(dir);
-        rmDir(dirName);
+       _TestUtil.rmDir(dirName);
     }
     
     // builds an index with payloads in the given Directory and performs
@@ -364,21 +365,6 @@
     }
 
 
-    private void rmDir(String dir) {
-        File fileDir = new File(dir);
-        if (fileDir.exists()) {
-          File[] files = fileDir.listFiles();
-          if (files != null) {
-            for (int i = 0; i < files.length; i++) {
-              files[i].delete();
-            }
-          }
-          fileDir.delete();
-        }
-      }
-
- 
-
     void assertByteArrayEquals(byte[] b1, byte[] b2) {
         if (b1.length != b2.length) {
           fail("Byte arrays have different lengths: " + b1.length + ", " + b2.length);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java?rev=783487&r1=783486&r2=783487&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java Wed Jun 10
20:15:19 2009
@@ -172,8 +172,7 @@
     directory.close();
 
     // FSDir
-    String tempDir = System.getProperty("java.io.tmpdir");
-    File dirPath = new File(tempDir, "lucene.test.stress");
+    File dirPath = _TestUtil.getTempDir("lucene.test.stress");
     directory = FSDirectory.open(dirPath);
     runStressTest(directory, true, null);
     directory.close();

Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java?rev=783487&r1=783486&r2=783487&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java Wed Jun 10 20:15:19
2009
@@ -34,6 +34,7 @@
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util._TestUtil;
 
 public class TestLockFactory extends LuceneTestCase {
 
@@ -339,7 +340,8 @@
     }
 
     public void _testStressLocks(LockFactory lockFactory, String indexDirName) throws Exception
{
-        FSDirectory fs1 = FSDirectory.open(new File(indexDirName), lockFactory);
+        File indexDir = _TestUtil.getTempDir(indexDirName);
+        FSDirectory fs1 = FSDirectory.open(indexDir, lockFactory);
 
         // First create a 1 doc index:
         IndexWriter w = new IndexWriter(fs1, new WhitespaceAnalyzer(), true,
@@ -360,7 +362,7 @@
         assertTrue("IndexSearcher hit unexpected exceptions", !searcher.hitException);
 
         // Cleanup
-        rmDir(indexDirName);
+        _TestUtil.rmDir(indexDir);
     }
 
     // Verify: NativeFSLockFactory works correctly

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java?rev=783487&r1=783486&r2=783487&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java Wed Jun 10 20:15:19 2009
@@ -30,6 +30,15 @@
 
 public class _TestUtil {
 
+  /** Returns temp dir, containing String arg in its name;
+   *  does not create the directory. */
+  public static File getTempDir(String desc) {
+    String tempDir = System.getProperty("java.io.tmpdir");
+    if (tempDir == null)
+      throw new RuntimeException("java.io.tmpdir undefined, cannot run test");
+    return new File(tempDir, desc + "." + new Random().nextLong());
+  }
+
   public static void rmDir(File dir) throws IOException {
     if (dir.exists()) {
       File[] files = dir.listFiles();



Mime
View raw message