| Index: lucene/src/test/org/apache/lucene/index/TestDoc.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestDoc.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestDoc.java (working copy)
|
| @@ -36,6 +36,7 @@
|
| import org.apache.lucene.search.DocIdSetIterator; |
| import org.apache.lucene.store.Directory; |
| import org.apache.lucene.util.LuceneTestCase; |
| +import org.apache.lucene.util._TestUtil; |
| import org.apache.lucene.index.codecs.CodecProvider; |
| |
| |
| @@ -60,10 +61,10 @@
|
| if (VERBOSE) { |
| System.out.println("TEST: setUp"); |
| } |
| - workDir = new File(TEMP_DIR,"TestDoc"); |
| + workDir = _TestUtil.getTempDir("TestDoc"); |
| workDir.mkdirs(); |
| |
| - indexDir = new File(workDir, "testIndex"); |
| + indexDir = _TestUtil.getTempDir("testIndex"); |
| indexDir.mkdirs(); |
| |
| Directory directory = newFSDirectory(indexDir); |
| Index: lucene/src/test/org/apache/lucene/index/TestIndexReader.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestIndexReader.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestIndexReader.java (working copy)
|
| @@ -1139,7 +1139,7 @@
|
| } |
| |
| public void testOpenReaderAfterDelete() throws IOException { |
| - File dirFile = new File(TEMP_DIR, "deletetest"); |
| + File dirFile = _TestUtil.getTempDir("deletetest"); |
| Directory dir = newFSDirectory(dirFile); |
| try { |
| IndexReader.open(dir, false); |
| Index: lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (working copy)
|
| @@ -2755,7 +2755,7 @@
|
| // Tests that if FSDir is opened w/ a NoLockFactory (or SingleInstanceLF), |
| // then IndexWriter ctor succeeds. Previously (LUCENE-2386) it failed |
| // when listAll() was called in IndexFileDeleter. |
| - Directory dir = newFSDirectory(new File(TEMP_DIR, "emptyFSDirNoLock"), NoLockFactory.getNoLockFactory()); |
| + Directory dir = newFSDirectory(_TestUtil.getTempDir("emptyFSDirNoLock"), NoLockFactory.getNoLockFactory()); |
| new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random))).close(); |
| dir.close(); |
| } |
| Index: lucene/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java (working copy)
|
| @@ -21,6 +21,7 @@
|
| import java.io.FileNotFoundException; |
| import java.io.IOException; |
| import org.apache.lucene.util.LuceneTestCase; |
| +import org.apache.lucene.util._TestUtil; |
| import org.apache.lucene.analysis.MockAnalyzer; |
| import org.apache.lucene.index.IndexWriter; |
| import org.apache.lucene.index.IndexWriterConfig.OpenMode; |
| @@ -39,7 +40,7 @@
|
| public void setUp() throws Exception { |
| super.setUp(); |
| if (this.__test_dir == null) { |
| - this.__test_dir = new File(TEMP_DIR, "testIndexWriter"); |
| + this.__test_dir = _TestUtil.getTempDir("testIndexWriter"); |
| |
| if (this.__test_dir.exists()) { |
| throw new IOException("test directory \"" + this.__test_dir.getPath() + "\" already exists (please remove by hand)"); |
| Index: lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestCompoundFile.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestCompoundFile.java (working copy)
|
| @@ -57,8 +57,7 @@
|
| @Override |
| public void setUp() throws Exception { |
| super.setUp(); |
| - File file = new File(TEMP_DIR, "testIndex"); |
| - _TestUtil.rmDir(file); |
| + File file = _TestUtil.getTempDir("testIndex"); |
| // use a simple FSDir here, to be sure to have SimpleFSInputs |
| dir = new SimpleFSDirectory(file,null); |
| } |
| @@ -66,7 +65,6 @@
|
| @Override |
| public void tearDown() throws Exception { |
| dir.close(); |
| - _TestUtil.rmDir(new File(TEMP_DIR, "testIndex")); |
| super.tearDown(); |
| } |
| |
| Index: lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestFieldsReader.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestFieldsReader.java (working copy)
|
| @@ -286,8 +286,7 @@
|
| */ |
| public void testLazyPerformance() throws Exception { |
| String userName = System.getProperty("user.name"); |
| - File file = new File(TEMP_DIR, "lazyDir" + userName); |
| - _TestUtil.rmDir(file); |
| + File file = _TestUtil.getTempDir("lazyDir" + userName); |
| Directory tmpDir = newFSDirectory(file); |
| assertTrue(tmpDir != null); |
| |
| @@ -473,7 +472,7 @@
|
| |
| // LUCENE-1262 |
| public void testExceptions() throws Throwable { |
| - File indexDir = new File(TEMP_DIR, "testfieldswriterexceptions"); |
| + File indexDir = _TestUtil.getTempDir("testfieldswriterexceptions"); |
| |
| try { |
| Directory dir = new FaultyFSDirectory(indexDir); |
| Index: lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (working copy)
|
| @@ -1090,7 +1090,7 @@
|
| @Override |
| public void setUp() throws Exception { |
| super.setUp(); |
| - indexDir = new File(TEMP_DIR, "IndexReaderReopen"); |
| + indexDir = _TestUtil.getTempDir("IndexReaderReopen"); |
| } |
| |
| public void testCloseOrig() throws Throwable { |
| Index: lucene/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java (working copy)
|
| @@ -41,7 +41,7 @@
|
| @Override |
| public void setUp() throws Exception { |
| super.setUp(); |
| - tempDir = File.createTempFile("jrecrash", "tmp", TEMP_DIR); |
| + tempDir = _TestUtil.getTempDir("jrecrash"); |
| tempDir.delete(); |
| tempDir.mkdir(); |
| } |
| Index: lucene/src/test/org/apache/lucene/index/TestLongPostings.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/index/TestLongPostings.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/index/TestLongPostings.java (working copy)
|
| @@ -67,7 +67,7 @@
|
| |
| // Don't use _TestUtil.getTempDir so that we own the |
| // randomness (ie same seed will point to same dir): |
| - Directory dir = newFSDirectory(new File(LuceneTestCase.TEMP_DIR, "longpostings" + "." + random.nextLong())); |
| + Directory dir = newFSDirectory(_TestUtil.getTempDir("longpostings" + "." + random.nextLong())); |
| |
| final int NUM_DOCS = (int) ((TEST_NIGHTLY ? 4e6 : (RANDOM_MULTIPLIER*2e4)) * (1+random.nextDouble())); |
| |
| Index: lucene/src/test/org/apache/lucene/store/TestDirectory.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/store/TestDirectory.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/store/TestDirectory.java (working copy)
|
| @@ -42,7 +42,7 @@
|
| // Test that different instances of FSDirectory can coexist on the same |
| // path, can read, write, and lock files. |
| public void testDirectInstantiation() throws Exception { |
| - File path = new File(TEMP_DIR, "testDirectInstantiation"); |
| + File path = _TestUtil.getTempDir("testDirectInstantiation"); |
| |
| int sz = 3; |
| Directory[] dirs = new Directory[sz]; |
| @@ -134,7 +134,7 @@
|
| |
| // LUCENE-1468 |
| public void testFSDirectoryFilter() throws IOException { |
| - checkDirectoryFilter(newFSDirectory(new File(TEMP_DIR,"test"))); |
| + checkDirectoryFilter(newFSDirectory(_TestUtil.getTempDir("test"))); |
| } |
| |
| // LUCENE-1468 |
| @@ -151,7 +151,7 @@
|
| |
| // LUCENE-1468 |
| public void testCopySubdir() throws Throwable { |
| - File path = new File(TEMP_DIR, "testsubdir"); |
| + File path = _TestUtil.getTempDir("testsubdir"); |
| try { |
| path.mkdirs(); |
| new File(path, "subdir").mkdirs(); |
| @@ -164,7 +164,7 @@
|
| |
| // LUCENE-1468 |
| public void testNotDirectory() throws Throwable { |
| - File path = new File(TEMP_DIR, "testnotdir"); |
| + File path = _TestUtil.getTempDir("testnotdir"); |
| Directory fsDir = new SimpleFSDirectory(path, null); |
| try { |
| IndexOutput out = fsDir.createOutput("afile"); |
| Index: lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java (working copy)
|
| @@ -24,6 +24,7 @@
|
| import java.io.ByteArrayOutputStream; |
| |
| import org.apache.lucene.util.LuceneTestCase; |
| +import org.apache.lucene.util._TestUtil; |
| import org.apache.lucene.analysis.MockAnalyzer; |
| import org.apache.lucene.document.Document; |
| import org.apache.lucene.document.Field; |
| @@ -49,7 +50,7 @@
|
| @Override |
| public void setUp() throws Exception { |
| super.setUp(); |
| - indexDir = new File(TEMP_DIR, "RAMDirIndex"); |
| + indexDir = _TestUtil.getTempDir("RAMDirIndex"); |
| |
| Directory dir = newFSDirectory(indexDir); |
| IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig( |
| Index: lucene/src/test/org/apache/lucene/store/TestMultiMMap.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/store/TestMultiMMap.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/store/TestMultiMMap.java (working copy)
|
| @@ -41,7 +41,7 @@
|
| @Override |
| public void setUp() throws Exception { |
| super.setUp(); |
| - workDir = new File(TEMP_DIR, "TestMultiMMap"); |
| + workDir = _TestUtil.getTempDir("TestMultiMMap"); |
| workDir.mkdirs(); |
| } |
| |
| Index: lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java (working copy)
|
| @@ -20,6 +20,7 @@
|
| import java.io.File; |
| |
| import org.apache.lucene.util.LuceneTestCase; |
| +import org.apache.lucene.util._TestUtil; |
| |
| import org.apache.lucene.analysis.MockAnalyzer; |
| import org.apache.lucene.document.Document; |
| @@ -59,7 +60,7 @@
|
| } |
| |
| private final static String storePathname = |
| - new File(TEMP_DIR,"testLuceneMmap").getAbsolutePath(); |
| + _TestUtil.getTempDir("testLuceneMmap").getAbsolutePath(); |
| |
| public void testMmapIndex() throws Exception { |
| // sometimes the directory is not cleaned by rmDir, because on Windows it |
| Index: lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
|
| ===================================================================
|
| --- lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java (revision 1095935)
|
| +++ lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java (working copy)
|
| @@ -240,7 +240,7 @@
|
| } |
| |
| public void testSetBufferSize() throws IOException { |
| - File indexDir = new File(TEMP_DIR, "testSetBufferSize"); |
| + File indexDir = _TestUtil.getTempDir("testSetBufferSize"); |
| MockFSDirectory dir = new MockFSDirectory(indexDir, random); |
| try { |
| IndexWriter writer = new IndexWriter( |
| Index: lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
|
| ===================================================================
|
| --- lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (revision 1095935)
|
| +++ lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (working copy)
|
| @@ -128,6 +128,9 @@
|
| TEMP_DIR = new File(s); |
| TEMP_DIR.mkdirs(); |
| } |
| + |
| + /** set of directories we created, in afterclass we try to clean these up */ |
| + static final Set<String> tempDirs = Collections.synchronizedSet(new HashSet<String>()); |
| |
| // by default we randomly pick a different codec for |
| // each test case (non-J4 tests) and each test class (J4 |
| @@ -323,6 +326,7 @@
|
| public static void beforeClassLuceneTestCaseJ4() { |
| staticSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : TwoLongs.fromString(TEST_SEED).l1; |
| random.setSeed(staticSeed); |
| + tempDirs.clear(); |
| stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>()); |
| savedCodecProvider = CodecProvider.getDefault(); |
| if ("randomPerField".equals(TEST_CODEC)) { |
| @@ -411,6 +415,14 @@
|
| + "free=" + Runtime.getRuntime().freeMemory() + "," |
| + "total=" + Runtime.getRuntime().totalMemory()); |
| } |
| + // clear out any temp directories if we can |
| + for (String path : tempDirs) { |
| + try { |
| + _TestUtil.rmDir(new File(path)); |
| + } catch (IOException e) { |
| + e.printStackTrace(); |
| + } |
| + } |
| } |
| |
| private static boolean testsFailed; /* true if any tests failed */ |
| @@ -1063,6 +1075,7 @@
|
| final File tmpFile = File.createTempFile("test", "tmp", TEMP_DIR); |
| tmpFile.delete(); |
| tmpFile.mkdir(); |
| + tempDirs.add(tmpFile.getAbsolutePath()); |
| return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), tmpFile, null); |
| } |
| |
| Index: lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java
|
| ===================================================================
|
| --- lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java (revision 1095935)
|
| +++ lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java (working copy)
|
| @@ -54,7 +54,9 @@
|
| /** Returns temp dir, containing String arg in its name; |
| * does not create the directory. */ |
| public static File getTempDir(String desc) { |
| - return new File(LuceneTestCase.TEMP_DIR, desc + "." + new Random().nextLong()); |
| + File f = new File(LuceneTestCase.TEMP_DIR, desc + "." + new Random().nextLong()); |
| + LuceneTestCase.tempDirs.add(f.getAbsolutePath()); |
| + return f; |
| } |
| |
| /** |
| @@ -89,6 +91,7 @@
|
| rmDir(destDir); |
| |
| destDir.mkdir(); |
| + LuceneTestCase.tempDirs.add(destDir.getAbsolutePath()); |
| |
| while (entries.hasMoreElements()) { |
| ZipEntry entry = entries.nextElement(); |