Index: src/test/org/apache/lucene/index/TestIndexReader.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexReader.java (revision 783377) +++ src/test/org/apache/lucene/index/TestIndexReader.java (working copy) @@ -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"); Index: src/test/org/apache/lucene/index/TestIndexWriter.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexWriter.java (revision 783377) +++ src/test/org/apache/lucene/index/TestIndexWriter.java (working copy) @@ -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); } } Index: src/test/org/apache/lucene/index/TestStressIndexing.java =================================================================== --- src/test/org/apache/lucene/index/TestStressIndexing.java (revision 783377) +++ src/test/org/apache/lucene/index/TestStressIndexing.java (working copy) @@ -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(); Index: src/test/org/apache/lucene/index/TestPayloads.java =================================================================== --- src/test/org/apache/lucene/index/TestPayloads.java (revision 783377) +++ src/test/org/apache/lucene/index/TestPayloads.java (working copy) @@ -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); Index: src/test/org/apache/lucene/store/TestLockFactory.java =================================================================== --- src/test/org/apache/lucene/store/TestLockFactory.java (revision 783377) +++ src/test/org/apache/lucene/store/TestLockFactory.java (working copy) @@ -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 Index: src/test/org/apache/lucene/util/_TestUtil.java =================================================================== --- src/test/org/apache/lucene/util/_TestUtil.java (revision 783377) +++ src/test/org/apache/lucene/util/_TestUtil.java (working copy) @@ -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();