Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Branch for solr5914

Dawid Weiss688addbd503b
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java
index 977781b6f22..d37acf104c8 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java
@@ -61,7 +61,7 @@ public class TestFilesystemResourceLoader extends LuceneTestCase {
}
public void testBaseDir() throws Exception {
- final File base = TestUtil.getTempDir("fsResourceLoaderBase").getAbsoluteFile();
+ final File base = TestUtil.createTempDir("fsResourceLoaderBase").getAbsoluteFile();
try {
base.mkdirs();
Writer os = new OutputStreamWriter(new FileOutputStream(new File(base, "template.txt")), IOUtils.CHARSET_UTF_8);
diff --git a/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java b/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java
index 76bd275cee1..75d91688918 100644
--- a/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java
+++ b/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java
@@ -75,7 +75,7 @@ import org.apache.lucene.util.TestUtil;
public class TestCompile extends LuceneTestCase {
public void testCompile() throws Exception {
- File dir = TestUtil.getTempDir("testCompile");
+ File dir = TestUtil.createTempDir("testCompile");
dir.mkdirs();
InputStream input = getClass().getResourceAsStream("testRules.txt");
File output = new File(dir, "testRules.txt");
@@ -91,7 +91,7 @@ public class TestCompile extends LuceneTestCase {
}
public void testCompileBackwards() throws Exception {
- File dir = TestUtil.getTempDir("testCompile");
+ File dir = TestUtil.createTempDir("testCompile");
dir.mkdirs();
InputStream input = getClass().getResourceAsStream("testRules.txt");
File output = new File(dir, "testRules.txt");
@@ -107,7 +107,7 @@ public class TestCompile extends LuceneTestCase {
}
public void testCompileMulti() throws Exception {
- File dir = TestUtil.getTempDir("testCompile");
+ File dir = TestUtil.createTempDir("testCompile");
dir.mkdirs();
InputStream input = getClass().getResourceAsStream("testRules.txt");
File output = new File(dir, "testRules.txt");
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java
index a00d72797f7..37772b95712 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/BenchmarkTestCase.java
@@ -36,7 +36,7 @@ public abstract class BenchmarkTestCase extends LuceneTestCase {
@BeforeClass
public static void beforeClassBenchmarkTestCase() {
- WORKDIR = TestUtil.getTempDir("benchmark");
+ WORKDIR = TestUtil.createTempDir("benchmark");
WORKDIR.delete();
WORKDIR.mkdirs();
}
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
index 2100e798b0c..ed62ba3a0e7 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
@@ -386,7 +386,7 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
* Test WriteLineDoc and LineDocSource.
*/
public void testLineDocFile() throws Exception {
- File lineFile = new File(TEMP_DIR, "test.reuters.lines.txt");
+ File lineFile = TestUtil.createTempFile("test.reuters.lines", ".txt");
// We will call WriteLineDocs this many times
final int NUM_TRY_DOCS = 50;
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
index 2f8a555cf2b..77674bd4549 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
@@ -20,11 +20,9 @@ package org.apache.lucene.benchmark.byTask;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
-import java.nio.charset.Charset;
import java.util.ArrayList;
import org.apache.lucene.benchmark.byTask.feeds.AbstractQueryMaker;
@@ -38,6 +36,9 @@ import org.apache.lucene.benchmark.byTask.utils.Config;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
+
+import com.carrotsearch.randomizedtesting.RandomizedTest;
import conf.ConfLoader;
@@ -123,13 +124,13 @@ public class TestPerfTasksParse extends LuceneTestCase {
Config config = new Config(new InputStreamReader(new FileInputStream(algFile), "UTF-8"));
String contentSource = config.get("content.source", null);
if (contentSource != null) { Class.forName(contentSource); }
- config.set("work.dir", new File(TEMP_DIR,"work").getAbsolutePath());
+ config.set("work.dir", TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath());
config.set("content.source", MockContentSource.class.getName());
String dir = config.get("content.source", null);
if (dir != null) { Class.forName(dir); }
config.set("directory", RAMDirectory.class.getName());
if (config.get("line.file.out", null) != null) {
- config.set("line.file.out", new File(TEMP_DIR,"o.txt").getAbsolutePath());
+ config.set("line.file.out", TestUtil.createTempFile("linefile", ".txt").getAbsolutePath());
}
if (config.get("query.maker", null) != null) {
Class.forName(config.get("query.maker", null));
@@ -138,9 +139,7 @@ public class TestPerfTasksParse extends LuceneTestCase {
PerfRunData data = new PerfRunData(config);
new Algorithm(data);
} catch (Throwable t) {
- t.printStackTrace();
- fail("Could not parse sample file: " + algFile + " reason:"
- + t.getClass() + ":" + t.getMessage());
+ throw new AssertionError("Could not parse sample file: " + algFile, t);
}
foundFiles = true;
}
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java
index 006fbba0d05..f72e1a96fc1 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/TrecContentSourceTest.java
@@ -344,7 +344,7 @@ public class TrecContentSourceTest extends LuceneTestCase {
* supported formats - bzip, gzip, txt.
*/
public void testTrecFeedDirAllTypes() throws Exception {
- File dataDir = TestUtil.getTempDir("trecFeedAllTypes");
+ File dataDir = TestUtil.createTempDir("trecFeedAllTypes");
TestUtil.unzip(getDataFile("trecdocs.zip"), dataDir);
TrecContentSource tcs = new TrecContentSource();
Properties props = new Properties();
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTaskTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTaskTest.java
index b8a4da5490d..22e7991db20 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTaskTest.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/AddIndexesTaskTest.java
@@ -41,7 +41,7 @@ public class AddIndexesTaskTest extends BenchmarkTestCase {
@BeforeClass
public static void beforeClassAddIndexesTaskTest() throws Exception {
- testDir = TestUtil.getTempDir("addIndexesTask");
+ testDir = TestUtil.createTempDir("addIndexesTask");
// create a dummy index under inputDir
inputDir = new File(testDir, "input");
diff --git a/lucene/codecs/src/test/org/apache/lucene/codecs/pulsing/Test10KPulsings.java b/lucene/codecs/src/test/org/apache/lucene/codecs/pulsing/Test10KPulsings.java
index eaf96396b98..bdbc958a4e6 100644
--- a/lucene/codecs/src/test/org/apache/lucene/codecs/pulsing/Test10KPulsings.java
+++ b/lucene/codecs/src/test/org/apache/lucene/codecs/pulsing/Test10KPulsings.java
@@ -52,7 +52,7 @@ public class Test10KPulsings extends LuceneTestCase {
// we always run this test with pulsing codec.
Codec cp = TestUtil.alwaysPostingsFormat(new Pulsing41PostingsFormat(1));
- File f = TestUtil.getTempDir("10kpulsed");
+ File f = TestUtil.createTempDir("10kpulsed");
BaseDirectoryWrapper dir = newFSDirectory(f);
dir.setCheckIndexOnClose(false); // we do this ourselves explicitly
RandomIndexWriter iw = new RandomIndexWriter(random(), dir,
@@ -103,7 +103,7 @@ public class Test10KPulsings extends LuceneTestCase {
int freqCutoff = TestUtil.nextInt(random(), 1, 10);
Codec cp = TestUtil.alwaysPostingsFormat(new Pulsing41PostingsFormat(freqCutoff));
- File f = TestUtil.getTempDir("10knotpulsed");
+ File f = TestUtil.createTempDir("10knotpulsed");
BaseDirectoryWrapper dir = newFSDirectory(f);
dir.setCheckIndexOnClose(false); // we do this ourselves explicitly
RandomIndexWriter iw = new RandomIndexWriter(random(), dir,
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestLucene40PostingsReader.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestLucene40PostingsReader.java
index a149e3bd5c7..b7ef0544daa 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestLucene40PostingsReader.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene40/TestLucene40PostingsReader.java
@@ -53,7 +53,7 @@ public class TestLucene40PostingsReader extends LuceneTestCase {
* depends heavily on term vectors cross-check at checkIndex
*/
public void testPostings() throws Exception {
- Directory dir = newFSDirectory(TestUtil.getTempDir("postings"));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("postings"));
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
iwc.setCodec(Codec.forName("Lucene40"));
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat2.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat2.java
index f336bd6a26f..04735d11433 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat2.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene41/TestBlockPostingsFormat2.java
@@ -43,7 +43,7 @@ public class TestBlockPostingsFormat2 extends LuceneTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
- dir = newFSDirectory(TestUtil.getTempDir("testDFBlockSize"));
+ dir = newFSDirectory(TestUtil.createTempDir("testDFBlockSize"));
iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
iwc.setCodec(TestUtil.alwaysPostingsFormat(new Lucene41PostingsFormat()));
iw = new RandomIndexWriter(random(), dir, iwc.clone());
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BBinaryDocValues.java b/lucene/core/src/test/org/apache/lucene/index/Test2BBinaryDocValues.java
index 074144624ab..155356cb42a 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test2BBinaryDocValues.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BBinaryDocValues.java
@@ -38,7 +38,7 @@ public class Test2BBinaryDocValues extends LuceneTestCase {
// indexes Integer.MAX_VALUE docs with a fixed binary field
public void testFixedBinary() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BFixedBinary"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BFixedBinary"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
@@ -98,7 +98,7 @@ public class Test2BBinaryDocValues extends LuceneTestCase {
// indexes Integer.MAX_VALUE docs with a variable binary field
public void testVariableBinary() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BVariableBinary"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BVariableBinary"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java b/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java
index f2985210fab..0530e18ceb3 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BDocs.java
@@ -31,7 +31,7 @@ public class Test2BDocs extends LuceneTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
- dir = newFSDirectory(TestUtil.getTempDir("2Bdocs"));
+ dir = newFSDirectory(TestUtil.createTempDir("2Bdocs"));
IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
Document doc = new Document();
for (int i = 0; i < 262144; i++) {
@@ -61,7 +61,7 @@ public class Test2BDocs extends LuceneTestCase {
}
public void testExactlyAtLimit() throws Exception {
- Directory dir2 = newFSDirectory(TestUtil.getTempDir("2BDocs2"));
+ Directory dir2 = newFSDirectory(TestUtil.createTempDir("2BDocs2"));
IndexWriter iw = new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
Document doc = new Document();
for (int i = 0; i < 262143; i++) {
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BNumericDocValues.java b/lucene/core/src/test/org/apache/lucene/index/Test2BNumericDocValues.java
index f83ef7a78f0..a64220988ac 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test2BNumericDocValues.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BNumericDocValues.java
@@ -35,7 +35,7 @@ public class Test2BNumericDocValues extends LuceneTestCase {
// indexes Integer.MAX_VALUE docs with an increasing dv field
public void testNumerics() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BNumerics"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BNumerics"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BPositions.java b/lucene/core/src/test/org/apache/lucene/index/Test2BPositions.java
index 7b9951338e5..715773d97dd 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test2BPositions.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BPositions.java
@@ -47,7 +47,7 @@ public class Test2BPositions extends LuceneTestCase {
// uses lots of space and takes a few minutes
@Ignore("Very slow. Enable manually by removing @Ignore.")
public void test() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BPositions"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BPositions"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BPostings.java b/lucene/core/src/test/org/apache/lucene/index/Test2BPostings.java
index 8fad986e2ac..1f847d64300 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test2BPostings.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BPostings.java
@@ -45,7 +45,7 @@ public class Test2BPostings extends LuceneTestCase {
@Nightly
public void test() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BPostings"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BPostings"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BPostingsBytes.java b/lucene/core/src/test/org/apache/lucene/index/Test2BPostingsBytes.java
index 71ffeae71c1..fe2bd80cd90 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test2BPostingsBytes.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BPostingsBytes.java
@@ -50,7 +50,7 @@ public class Test2BPostingsBytes extends LuceneTestCase {
// with some codecs needs more heap space as well.
@Ignore("Very slow. Enable manually by removing @Ignore.")
public void test() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BPostingsBytes1"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BPostingsBytes1"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
@@ -93,7 +93,7 @@ public class Test2BPostingsBytes extends LuceneTestCase {
IndexReader subReaders[] = new IndexReader[1000];
Arrays.fill(subReaders, oneThousand);
MultiReader mr = new MultiReader(subReaders);
- BaseDirectoryWrapper dir2 = newFSDirectory(TestUtil.getTempDir("2BPostingsBytes2"));
+ BaseDirectoryWrapper dir2 = newFSDirectory(TestUtil.createTempDir("2BPostingsBytes2"));
if (dir2 instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir2).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
@@ -108,7 +108,7 @@ public class Test2BPostingsBytes extends LuceneTestCase {
subReaders = new IndexReader[2000];
Arrays.fill(subReaders, oneMillion);
mr = new MultiReader(subReaders);
- BaseDirectoryWrapper dir3 = newFSDirectory(TestUtil.getTempDir("2BPostingsBytes3"));
+ BaseDirectoryWrapper dir3 = newFSDirectory(TestUtil.createTempDir("2BPostingsBytes3"));
if (dir3 instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir3).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BSortedDocValues.java b/lucene/core/src/test/org/apache/lucene/index/Test2BSortedDocValues.java
index b7c7a0f0dfb..0c9134dc357 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test2BSortedDocValues.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BSortedDocValues.java
@@ -38,7 +38,7 @@ public class Test2BSortedDocValues extends LuceneTestCase {
// indexes Integer.MAX_VALUE docs with a fixed binary field
public void testFixedSorted() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BFixedSorted"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BFixedSorted"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
@@ -95,7 +95,7 @@ public class Test2BSortedDocValues extends LuceneTestCase {
// indexes Integer.MAX_VALUE docs with a fixed binary field
// TODO: must use random.nextBytes (like Test2BTerms) to avoid BytesRefHash probing issues
public void test2BOrds() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BOrds"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BOrds"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java b/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java
index 8616615a2dd..e8482e3b21b 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test2BTerms.java
@@ -148,7 +148,7 @@ public class Test2BTerms extends LuceneTestCase {
List<BytesRef> savedTerms = null;
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("2BTerms"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BTerms"));
//MockDirectoryWrapper dir = newFSDirectory(new File("/p/lucene/indices/2bindex"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test4GBStoredFields.java b/lucene/core/src/test/org/apache/lucene/index/Test4GBStoredFields.java
index 14b5ba56178..19cead51883 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test4GBStoredFields.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test4GBStoredFields.java
@@ -42,7 +42,7 @@ public class Test4GBStoredFields extends LuceneTestCase {
@Nightly
public void test() throws Exception {
- MockDirectoryWrapper dir = new MockDirectoryWrapper(random(), new MMapDirectory(TestUtil.getTempDir("4GBStoredFields")));
+ MockDirectoryWrapper dir = new MockDirectoryWrapper(random(), new MMapDirectory(TestUtil.createTempDir("4GBStoredFields")));
dir.setThrottling(MockDirectoryWrapper.Throttling.NEVER);
IndexWriter w = new IndexWriter(dir,
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java b/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java
index e94667cd40d..b84695c3b7b 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestAtomicUpdate.java
@@ -175,7 +175,7 @@ public class TestAtomicUpdate extends LuceneTestCase {
directory.close();
// Second in an FSDirectory:
- File dirPath = TestUtil.getTempDir("lucene.test.atomic");
+ File dirPath = TestUtil.createTempDir("lucene.test.atomic");
directory = newFSDirectory(dirPath);
runTest(directory);
directory.close();
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
index efd759f5229..3ba113c417e 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
@@ -227,7 +227,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
names.addAll(Arrays.asList(oldSingleSegmentNames));
oldIndexDirs = new HashMap<>();
for (String name : names) {
- File dir = TestUtil.getTempDir(name);
+ File dir = TestUtil.createTempDir(name);
File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI());
TestUtil.unzip(dataFile, dir);
oldIndexDirs.put(name, newFSDirectory(dir));
@@ -248,7 +248,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
if (VERBOSE) {
System.out.println("TEST: index " + unsupportedNames[i]);
}
- File oldIndxeDir = TestUtil.getTempDir(unsupportedNames[i]);
+ File oldIndxeDir = TestUtil.createTempDir(unsupportedNames[i]);
TestUtil.unzip(getDataFile("unsupported." + unsupportedNames[i] + ".zip"), oldIndxeDir);
BaseDirectoryWrapper dir = newFSDirectory(oldIndxeDir);
// don't checkindex, these are intentionally not supported
@@ -645,7 +645,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
public void testExactFileNames() throws IOException {
String outputDirName = "lucene.backwardscompat0.index";
- File outputDir = TestUtil.getTempDir(outputDirName);
+ File outputDir = TestUtil.createTempDir(outputDirName);
TestUtil.rmDir(outputDir);
try {
@@ -955,7 +955,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
public void testCommandLineArgs() throws Exception {
for (String name : oldIndexDirs.keySet()) {
- File dir = TestUtil.getTempDir(name);
+ File dir = TestUtil.createTempDir(name);
File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI());
TestUtil.unzip(dataFile, dir);
@@ -1048,7 +1048,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
public static final String moreTermsIndex = "moreterms.40.zip";
public void testMoreTerms() throws Exception {
- File oldIndexDir = TestUtil.getTempDir("moreterms");
+ File oldIndexDir = TestUtil.createTempDir("moreterms");
TestUtil.unzip(getDataFile(moreTermsIndex), oldIndexDir);
Directory dir = newFSDirectory(oldIndexDir);
// TODO: more tests
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBagOfPositions.java b/lucene/core/src/test/org/apache/lucene/index/TestBagOfPositions.java
index 61b41136cf0..4df23640c64 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestBagOfPositions.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestBagOfPositions.java
@@ -68,7 +68,7 @@ public class TestBagOfPositions extends LuceneTestCase {
final ConcurrentLinkedQueue<String> postings = new ConcurrentLinkedQueue<>(postingsList);
- Directory dir = newFSDirectory(TestUtil.getTempDir("bagofpositions"));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("bagofpositions"));
final RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBagOfPostings.java b/lucene/core/src/test/org/apache/lucene/index/TestBagOfPostings.java
index a3067e01cde..0af3d6c8ae0 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestBagOfPostings.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestBagOfPostings.java
@@ -70,7 +70,7 @@ public class TestBagOfPostings extends LuceneTestCase {
final ConcurrentLinkedQueue<String> postings = new ConcurrentLinkedQueue<>(postingsList);
- Directory dir = newFSDirectory(TestUtil.getTempDir("bagofpostings"));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("bagofpostings"));
final RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
int threadCount = TestUtil.nextInt(random(), 1, 5);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java b/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java
index 489d8927e0e..f151d5d06f7 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestCompoundFile.java
@@ -42,7 +42,7 @@ public class TestCompoundFile extends LuceneTestCase
@Override
public void setUp() throws Exception {
super.setUp();
- File file = TestUtil.getTempDir("testIndex");
+ File file = TestUtil.createTempDir("testIndex");
// use a simple FSDir here, to be sure to have SimpleFSInputs
dir = new SimpleFSDirectory(file,null);
}
@@ -769,7 +769,7 @@ public class TestCompoundFile extends LuceneTestCase
// when reading a CFS with many subs:
public void testManySubFiles() throws IOException {
- final Directory d = newFSDirectory(TestUtil.getTempDir("CFSManySubFiles"));
+ final Directory d = newFSDirectory(TestUtil.createTempDir("CFSManySubFiles"));
final int FILE_COUNT = atLeast(500);
for(int fileIdx=0;fileIdx<FILE_COUNT;fileIdx++) {
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
index 5cd1f7a4781..f1dad5d8c85 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestCrashCausesCorruptIndex.java
@@ -42,7 +42,7 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase {
* LUCENE-3627: This test fails.
*/
public void testCrashCorruptsIndexing() throws Exception {
- path = TestUtil.getTempDir("testCrashCorruptsIndexing");
+ path = TestUtil.createTempDir("testCrashCorruptsIndexing");
indexAndCrashOnCreateOutputSegments2();
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
index 89fd37733b5..a302506a990 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java
@@ -438,7 +438,7 @@ void assertTermDocsCount(String msg,
public void testFilesOpenClose() throws IOException {
// Create initial data set
- File dirFile = TestUtil.getTempDir("TestIndexReader.testFilesOpenClose");
+ File dirFile = TestUtil.createTempDir("TestIndexReader.testFilesOpenClose");
Directory dir = newFSDirectory(dirFile);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
addDoc(writer, "test");
@@ -467,7 +467,7 @@ public void testFilesOpenClose() throws IOException {
}
public void testOpenReaderAfterDelete() throws IOException {
- File dirFile = TestUtil.getTempDir("deletetest");
+ File dirFile = TestUtil.createTempDir("deletetest");
Directory dir = newFSDirectory(dirFile);
try {
DirectoryReader.open(dir);
@@ -715,7 +715,7 @@ public void testFilesOpenClose() throws IOException {
// DirectoryReader on a non-existent directory, you get a
// good exception
public void testNoDir() throws Throwable {
- File tempDir = TestUtil.getTempDir("doesnotexist");
+ File tempDir = TestUtil.createTempDir("doesnotexist");
TestUtil.rmDir(tempDir);
Directory dir = newFSDirectory(tempDir);
try {
@@ -1090,7 +1090,7 @@ public void testFilesOpenClose() throws IOException {
}
public void testIndexExistsOnNonExistentDirectory() throws Exception {
- File tempDir = TestUtil.getTempDir("testIndexExistsOnNonExistentDirectory");
+ File tempDir = TestUtil.createTempDir("testIndexExistsOnNonExistentDirectory");
tempDir.delete();
Directory dir = newFSDirectory(tempDir);
assertFalse(DirectoryReader.indexExists(dir));
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java b/lucene/core/src/test/org/apache/lucene/index/TestDoc.java
index 1ef079e6da2..2a786f42cc8 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDoc.java
@@ -62,10 +62,10 @@ public class TestDoc extends LuceneTestCase {
if (VERBOSE) {
System.out.println("TEST: setUp");
}
- workDir = TestUtil.getTempDir("TestDoc");
+ workDir = TestUtil.createTempDir("TestDoc");
workDir.mkdirs();
- indexDir = TestUtil.getTempDir("testIndex");
+ indexDir = TestUtil.createTempDir("testIndex");
indexDir.mkdirs();
Directory directory = newFSDirectory(indexDir);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java b/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java
index 3c188bc11c7..8ab81adb679 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java
@@ -187,7 +187,7 @@ public class TestFieldsReader extends LuceneTestCase {
// LUCENE-1262
public void testExceptions() throws Throwable {
- File indexDir = TestUtil.getTempDir("testfieldswriterexceptions");
+ File indexDir = TestUtil.createTempDir("testfieldswriterexceptions");
try {
Directory dir = new FaultyFSDirectory(indexDir);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
index b866b51d626..41340044ca7 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -1476,7 +1476,7 @@ public class TestIndexWriter extends LuceneTestCase {
// 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(TestUtil.getTempDir("emptyFSDirNoLock"), NoLockFactory.getNoLockFactory());
+ Directory dir = newFSDirectory(TestUtil.createTempDir("emptyFSDirNoLock"), NoLockFactory.getNoLockFactory());
new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random()))).close();
dir.close();
}
@@ -1783,7 +1783,7 @@ public class TestIndexWriter extends LuceneTestCase {
}
public void testWhetherDeleteAllDeletesWriteLock() throws Exception {
- Directory d = newFSDirectory(TestUtil.getTempDir("TestIndexWriter.testWhetherDeleteAllDeletesWriteLock"));
+ Directory d = newFSDirectory(TestUtil.createTempDir("TestIndexWriter.testWhetherDeleteAllDeletesWriteLock"));
// Must use SimpleFSLockFactory... NativeFSLockFactory
// somehow "knows" a lock is held against write.lock
// even if you remove that file:
@@ -2032,7 +2032,7 @@ public class TestIndexWriter extends LuceneTestCase {
// LUCENE-4398
public void testRotatingFieldNames() throws Exception {
- Directory dir = newFSDirectory(TestUtil.getTempDir("TestIndexWriter.testChangingFields"));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("TestIndexWriter.testChangingFields"));
IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
iwc.setRAMBufferSizeMB(0.2);
iwc.setMaxBufferedDocs(-1);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
index 0833c6e017a..4f71cf3263a 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
@@ -36,7 +36,7 @@ import org.apache.lucene.util.TestUtil;
public class TestIndexWriterLockRelease extends LuceneTestCase {
public void testIndexWriterLockRelease() throws IOException {
- Directory dir = newFSDirectory(TestUtil.getTempDir("testLockRelease"));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("testLockRelease"));
try {
new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
} catch (FileNotFoundException | NoSuchFileException e) {
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java
index 9620ed795e0..d84555d7229 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java
@@ -43,7 +43,7 @@ public class TestIndexWriterOnJRECrash extends TestNRTThreads {
@Override
public void setUp() throws Exception {
super.setUp();
- tempDir = TestUtil.getTempDir("jrecrash");
+ tempDir = TestUtil.createTempDir("jrecrash");
tempDir.delete();
tempDir.mkdir();
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java
index ac3ff6eb45a..9930a8c76e4 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java
@@ -32,7 +32,7 @@ import org.apache.lucene.util.TestUtil;
public class TestIndexWriterOutOfFileDescriptors extends LuceneTestCase {
public void test() throws Exception {
- MockDirectoryWrapper dir = newMockFSDirectory(TestUtil.getTempDir("TestIndexWriterOutOfFileDescriptors"));
+ MockDirectoryWrapper dir = newMockFSDirectory(TestUtil.createTempDir("TestIndexWriterOutOfFileDescriptors"));
dir.setPreventDoubleWrite(false);
double rate = random().nextDouble()*0.01;
//System.out.println("rate=" + rate);
@@ -132,7 +132,7 @@ public class TestIndexWriterOutOfFileDescriptors extends LuceneTestCase {
// it to addIndexes later:
dir.setRandomIOExceptionRateOnOpen(0.0);
r = DirectoryReader.open(dir);
- dirCopy = newMockFSDirectory(TestUtil.getTempDir("TestIndexWriterOutOfFileDescriptors.copy"));
+ dirCopy = newMockFSDirectory(TestUtil.createTempDir("TestIndexWriterOutOfFileDescriptors.copy"));
Set<String> files = new HashSet<>();
for (String file : dir.listAll()) {
dir.copy(dirCopy, file, file, IOContext.DEFAULT);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java b/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java
index 5c767c0b8a9..7a08b2409e7 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java
@@ -78,7 +78,7 @@ public class TestLongPostings extends LuceneTestCase {
public void testLongPostings() throws Exception {
// Don't use _TestUtil.getTempDir so that we own the
// randomness (ie same seed will point to same dir):
- Directory dir = newFSDirectory(TestUtil.getTempDir("longpostings" + "." + random().nextLong()));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("longpostings" + "." + random().nextLong()));
final int NUM_DOCS = atLeast(2000);
@@ -275,7 +275,7 @@ public class TestLongPostings extends LuceneTestCase {
public void doTestLongPostingsNoPositions(IndexOptions options) throws Exception {
// Don't use _TestUtil.getTempDir so that we own the
// randomness (ie same seed will point to same dir):
- Directory dir = newFSDirectory(TestUtil.getTempDir("longpostings" + "." + random().nextLong()));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("longpostings" + "." + random().nextLong()));
final int NUM_DOCS = atLeast(2000);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java b/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java
index 21facbbe7c1..f04ca6c7b27 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestNeverDelete.java
@@ -35,7 +35,7 @@ import org.apache.lucene.util.TestUtil;
public class TestNeverDelete extends LuceneTestCase {
public void testIndexing() throws Exception {
- final File tmpDir = TestUtil.getTempDir("TestNeverDelete");
+ final File tmpDir = TestUtil.createTempDir("TestNeverDelete");
final BaseDirectoryWrapper d = newFSDirectory(tmpDir);
// We want to "see" files removed if Lucene removed
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestNorms.java b/lucene/core/src/test/org/apache/lucene/index/TestNorms.java
index 29fba3b5871..ab09ba02ba4 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestNorms.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestNorms.java
@@ -110,7 +110,7 @@ public class TestNorms extends LuceneTestCase {
}
public void testMaxByteNorms() throws IOException {
- Directory dir = newFSDirectory(TestUtil.getTempDir("TestNorms.testMaxByteNorms"));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("TestNorms.testMaxByteNorms"));
buildIndex(dir);
AtomicReader open = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir));
NumericDocValues normValues = open.getNormValues(byteTestField);
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java
index 16763ffa445..3d560f93023 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java
@@ -473,7 +473,7 @@ public class TestControlledRealTimeReopenThread extends ThreadedIndexingAndSearc
String content = builder.toString();
final SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
- final Directory dir = new NRTCachingDirectory(newFSDirectory(TestUtil.getTempDir("nrt")), 5, 128);
+ final Directory dir = new NRTCachingDirectory(newFSDirectory(TestUtil.createTempDir("nrt")), 5, 128);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_46,
new MockAnalyzer(random()));
config.setIndexDeletionPolicy(sdp);
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java b/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java
index 6a4f29509c6..f70848009da 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestLiveFieldValues.java
@@ -44,7 +44,7 @@ import org.apache.lucene.util.TestUtil;
public class TestLiveFieldValues extends LuceneTestCase {
public void test() throws Exception {
- Directory dir = newFSDirectory(TestUtil.getTempDir("livefieldupdates"));
+ Directory dir = newFSDirectory(TestUtil.createTempDir("livefieldupdates"));
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
final IndexWriter w = new IndexWriter(dir, iwc);
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java b/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
index 4b90c7831b2..47731be22e6 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
@@ -222,7 +222,7 @@ public class TestBufferedIndexInput extends LuceneTestCase {
}
public void testSetBufferSize() throws IOException {
- File indexDir = TestUtil.getTempDir("testSetBufferSize");
+ File indexDir = TestUtil.createTempDir("testSetBufferSize");
MockFSDirectory dir = new MockFSDirectory(indexDir, random());
try {
IndexWriter writer = new IndexWriter(
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
index 6f107b493b3..9f13e3a2928 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
@@ -29,10 +29,11 @@ import org.apache.lucene.util.TestUtil;
public class TestDirectory extends LuceneTestCase {
public void testDetectClose() throws Throwable {
+ File tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
Directory[] dirs = new Directory[] {
new RAMDirectory(),
- new SimpleFSDirectory(TEMP_DIR),
- new NIOFSDirectory(TEMP_DIR)
+ new SimpleFSDirectory(tempDir),
+ new NIOFSDirectory(tempDir)
};
for (Directory dir : dirs) {
@@ -134,7 +135,7 @@ public class TestDirectory extends LuceneTestCase {
// Test that different instances of FSDirectory can coexist on the same
// path, can read, write, and lock files.
public void testDirectInstantiation() throws Exception {
- final File path = TestUtil.getTempDir("testDirectInstantiation");
+ final File path = TestUtil.createTempDir("testDirectInstantiation");
final byte[] largeBuffer = new byte[random().nextInt(256*1024)], largeReadBuffer = new byte[largeBuffer.length];
for (int i = 0; i < largeBuffer.length; i++) {
@@ -222,7 +223,7 @@ public class TestDirectory extends LuceneTestCase {
// LUCENE-1464
public void testDontCreate() throws Throwable {
- File path = new File(TEMP_DIR, "doesnotexist");
+ File path = new File(TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()), "doesnotexist");
try {
assertTrue(!path.exists());
Directory dir = new SimpleFSDirectory(path, null);
@@ -240,7 +241,7 @@ public class TestDirectory extends LuceneTestCase {
// LUCENE-1468
public void testFSDirectoryFilter() throws IOException {
- checkDirectoryFilter(newFSDirectory(TestUtil.getTempDir("test")));
+ checkDirectoryFilter(newFSDirectory(TestUtil.createTempDir("test")));
}
// LUCENE-1468
@@ -257,7 +258,7 @@ public class TestDirectory extends LuceneTestCase {
// LUCENE-1468
public void testCopySubdir() throws Throwable {
- File path = TestUtil.getTempDir("testsubdir");
+ File path = TestUtil.createTempDir("testsubdir");
try {
path.mkdirs();
new File(path, "subdir").mkdirs();
@@ -270,7 +271,7 @@ public class TestDirectory extends LuceneTestCase {
// LUCENE-1468
public void testNotDirectory() throws Throwable {
- File path = TestUtil.getTempDir("testnotdir");
+ File path = TestUtil.createTempDir("testnotdir");
Directory fsDir = new SimpleFSDirectory(path, null);
try {
IndexOutput out = fsDir.createOutput("afile", newIOContext(random()));
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
index f7e6ecb8419..67914d26ea5 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
@@ -88,8 +88,8 @@ public class TestFileSwitchDirectory extends LuceneTestCase {
}
private Directory newFSSwitchDirectory(Set<String> primaryExtensions) throws IOException {
- File primDir = TestUtil.getTempDir("foo");
- File secondDir = TestUtil.getTempDir("bar");
+ File primDir = TestUtil.createTempDir("foo");
+ File secondDir = TestUtil.createTempDir("bar");
return newFSSwitchDirectory(primDir, secondDir, primaryExtensions);
}
@@ -102,8 +102,8 @@ public class TestFileSwitchDirectory extends LuceneTestCase {
// LUCENE-3380 -- make sure we get exception if the directory really does not exist.
public void testNoDir() throws Throwable {
- File primDir = TestUtil.getTempDir("foo");
- File secondDir = TestUtil.getTempDir("bar");
+ File primDir = TestUtil.createTempDir("foo");
+ File secondDir = TestUtil.createTempDir("bar");
TestUtil.rmDir(primDir);
TestUtil.rmDir(secondDir);
Directory dir = newFSSwitchDirectory(primDir, secondDir, Collections.<String>emptySet());
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java b/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java
index 137ed923463..d633a425142 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestLockFactory.java
@@ -136,7 +136,7 @@ public class TestLockFactory extends LuceneTestCase {
// no unexpected exceptions are raised:
@Nightly
public void testStressLocks() throws Exception {
- _testStressLocks(null, TestUtil.getTempDir("index.TestLockFactory6"));
+ _testStressLocks(null, TestUtil.createTempDir("index.TestLockFactory6"));
}
// Verify: do stress test, by opening IndexReaders and
@@ -145,7 +145,7 @@ public class TestLockFactory extends LuceneTestCase {
// NativeFSLockFactory:
@Nightly
public void testStressLocksNativeFSLockFactory() throws Exception {
- File dir = TestUtil.getTempDir("index.TestLockFactory7");
+ File dir = TestUtil.createTempDir("index.TestLockFactory7");
_testStressLocks(new NativeFSLockFactory(dir), dir);
}
@@ -176,8 +176,7 @@ public class TestLockFactory extends LuceneTestCase {
// Verify: NativeFSLockFactory works correctly
public void testNativeFSLockFactory() throws IOException {
-
- NativeFSLockFactory f = new NativeFSLockFactory(TEMP_DIR);
+ NativeFSLockFactory f = new NativeFSLockFactory(TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()));
f.setLockPrefix("test");
Lock l = f.makeLock("commit");
@@ -202,11 +201,11 @@ public class TestLockFactory extends LuceneTestCase {
// Verify: NativeFSLockFactory works correctly if the lock file exists
public void testNativeFSLockFactoryLockExists() throws IOException {
-
- File lockFile = new File(TEMP_DIR, "test.lock");
+ File tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ File lockFile = new File(tempDir, "test.lock");
lockFile.createNewFile();
- Lock l = new NativeFSLockFactory(TEMP_DIR).makeLock("test.lock");
+ Lock l = new NativeFSLockFactory(tempDir).makeLock("test.lock");
assertTrue("failed to obtain lock", l.obtain());
l.close();
assertFalse("failed to release lock", l.isLocked());
@@ -216,8 +215,7 @@ public class TestLockFactory extends LuceneTestCase {
}
public void testNativeFSLockReleaseByOtherLock() throws IOException {
-
- NativeFSLockFactory f = new NativeFSLockFactory(TEMP_DIR);
+ NativeFSLockFactory f = new NativeFSLockFactory(TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()));
f.setLockPrefix("test");
Lock l = f.makeLock("commit");
@@ -238,8 +236,8 @@ public class TestLockFactory extends LuceneTestCase {
// Verify: NativeFSLockFactory assigns null as lockPrefix if the lockDir is inside directory
public void testNativeFSLockFactoryPrefix() throws IOException {
- File fdir1 = TestUtil.getTempDir("TestLockFactory.8");
- File fdir2 = TestUtil.getTempDir("TestLockFactory.8.Lockdir");
+ File fdir1 = TestUtil.createTempDir("TestLockFactory.8");
+ File fdir2 = TestUtil.createTempDir("TestLockFactory.8.Lockdir");
Directory dir1 = newFSDirectory(fdir1, new NativeFSLockFactory(fdir1));
// same directory, but locks are stored somewhere else. The prefix of the lock factory should != null
Directory dir2 = newFSDirectory(fdir1, new NativeFSLockFactory(fdir2));
@@ -261,7 +259,7 @@ public class TestLockFactory extends LuceneTestCase {
public void testDefaultFSLockFactoryPrefix() throws IOException {
// Make sure we get null prefix, which wont happen if setLockFactory is ever called.
- File dirName = TestUtil.getTempDir("TestLockFactory.10");
+ File dirName = TestUtil.createTempDir("TestLockFactory.10");
Directory dir = new SimpleFSDirectory(dirName);
assertNull("Default lock prefix should be null", dir.getLockFactory().getLockPrefix());
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
index 9ddd7155b5a..755f93c92df 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
@@ -44,12 +44,12 @@ public class TestMultiMMap extends LuceneTestCase {
public void setUp() throws Exception {
super.setUp();
assumeTrue("test requires a jre that supports unmapping", MMapDirectory.UNMAP_SUPPORTED);
- workDir = TestUtil.getTempDir("TestMultiMMap");
+ workDir = TestUtil.createTempDir("TestMultiMMap");
workDir.mkdirs();
}
public void testCloneSafety() throws Exception {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testCloneSafety"));
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testCloneSafety"));
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
io.writeVInt(5);
io.close();
@@ -83,7 +83,7 @@ public class TestMultiMMap extends LuceneTestCase {
}
public void testCloneClose() throws Exception {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testCloneClose"));
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testCloneClose"));
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
io.writeVInt(5);
io.close();
@@ -105,7 +105,7 @@ public class TestMultiMMap extends LuceneTestCase {
}
public void testCloneSliceSafety() throws Exception {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testCloneSliceSafety"));
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testCloneSliceSafety"));
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
io.writeInt(1);
io.writeInt(2);
@@ -150,7 +150,7 @@ public class TestMultiMMap extends LuceneTestCase {
}
public void testCloneSliceClose() throws Exception {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testCloneSliceClose"));
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testCloneSliceClose"));
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
io.writeInt(1);
io.writeInt(2);
@@ -177,7 +177,7 @@ public class TestMultiMMap extends LuceneTestCase {
public void testSeekZero() throws Exception {
for (int i = 0; i < 31; i++) {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testSeekZero"), null, 1<<i);
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeekZero"), null, 1<<i);
IndexOutput io = mmapDir.createOutput("zeroBytes", newIOContext(random()));
io.close();
IndexInput ii = mmapDir.openInput("zeroBytes", newIOContext(random()));
@@ -189,7 +189,7 @@ public class TestMultiMMap extends LuceneTestCase {
public void testSeekSliceZero() throws Exception {
for (int i = 0; i < 31; i++) {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testSeekSliceZero"), null, 1<<i);
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeekSliceZero"), null, 1<<i);
IndexOutput io = mmapDir.createOutput("zeroBytes", newIOContext(random()));
io.close();
IndexInputSlicer slicer = mmapDir.createSlicer("zeroBytes", newIOContext(random()));
@@ -203,7 +203,7 @@ public class TestMultiMMap extends LuceneTestCase {
public void testSeekEnd() throws Exception {
for (int i = 0; i < 17; i++) {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testSeekEnd"), null, 1<<i);
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeekEnd"), null, 1<<i);
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
byte bytes[] = new byte[1<<i];
random().nextBytes(bytes);
@@ -221,7 +221,7 @@ public class TestMultiMMap extends LuceneTestCase {
public void testSeekSliceEnd() throws Exception {
for (int i = 0; i < 17; i++) {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testSeekSliceEnd"), null, 1<<i);
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeekSliceEnd"), null, 1<<i);
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
byte bytes[] = new byte[1<<i];
random().nextBytes(bytes);
@@ -241,7 +241,7 @@ public class TestMultiMMap extends LuceneTestCase {
public void testSeeking() throws Exception {
for (int i = 0; i < 10; i++) {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testSeeking"), null, 1<<i);
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeeking"), null, 1<<i);
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
byte bytes[] = new byte[1<<(i+1)]; // make sure we switch buffers
random().nextBytes(bytes);
@@ -268,7 +268,7 @@ public class TestMultiMMap extends LuceneTestCase {
// the various offset+length and just does readBytes.
public void testSlicedSeeking() throws Exception {
for (int i = 0; i < 10; i++) {
- MMapDirectory mmapDir = new MMapDirectory(TestUtil.getTempDir("testSlicedSeeking"), null, 1<<i);
+ MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSlicedSeeking"), null, 1<<i);
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
byte bytes[] = new byte[1<<(i+1)]; // make sure we switch buffers
random().nextBytes(bytes);
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
index df4b6a47ab0..de796348f2f 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestNRTCachingDirectory.java
@@ -123,7 +123,7 @@ public class TestNRTCachingDirectory extends LuceneTestCase {
// LUCENE-3382 -- make sure we get exception if the directory really does not exist.
public void testNoDir() throws Throwable {
- File tempDir = TestUtil.getTempDir("doesnotexist");
+ File tempDir = TestUtil.createTempDir("doesnotexist");
TestUtil.rmDir(tempDir);
Directory dir = new NRTCachingDirectory(newFSDirectory(tempDir), 2.0, 25.0);
try {
@@ -137,7 +137,7 @@ public class TestNRTCachingDirectory extends LuceneTestCase {
// LUCENE-3382 test that we can add a file, and then when we call list() we get it back
public void testDirectoryFilter() throws IOException {
- Directory dir = new NRTCachingDirectory(newFSDirectory(TestUtil.getTempDir("foo")), 2.0, 25.0);
+ Directory dir = new NRTCachingDirectory(newFSDirectory(TestUtil.createTempDir("foo")), 2.0, 25.0);
String name = "file";
try {
dir.createOutput(name, newIOContext(random())).close();
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java
index 610267f37c9..260b6654aee 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java
@@ -50,7 +50,7 @@ public class TestRAMDirectory extends LuceneTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
- indexDir = TestUtil.getTempDir("RAMDirIndex");
+ indexDir = TestUtil.createTempDir("RAMDirIndex");
Directory dir = newFSDirectory(indexDir);
IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestWindowsMMap.java b/lucene/core/src/test/org/apache/lucene/store/TestWindowsMMap.java
index 25f970fd554..e28fb836c40 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestWindowsMMap.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestWindowsMMap.java
@@ -65,7 +65,7 @@ public class TestWindowsMMap extends LuceneTestCase {
// sometimes the directory is not cleaned by rmDir, because on Windows it
// may take some time until the files are finally dereferenced. So clean the
// directory up front, or otherwise new IndexWriter will fail.
- File dirPath = TestUtil.getTempDir("testLuceneMmap");
+ File dirPath = TestUtil.createTempDir("testLuceneMmap");
rmDir(dirPath);
MMapDirectory dir = new MMapDirectory(dirPath, null);
diff --git a/lucene/core/src/test/org/apache/lucene/util/Test2BPagedBytes.java b/lucene/core/src/test/org/apache/lucene/util/Test2BPagedBytes.java
index 47446b1f2ef..06e5fc7e753 100644
--- a/lucene/core/src/test/org/apache/lucene/util/Test2BPagedBytes.java
+++ b/lucene/core/src/test/org/apache/lucene/util/Test2BPagedBytes.java
@@ -30,7 +30,7 @@ import org.junit.Ignore;
public class Test2BPagedBytes extends LuceneTestCase {
public void test() throws Exception {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("test2BPagedBytes"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("test2BPagedBytes"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java b/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
index 273f59f446b..425059a267b 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java
@@ -42,7 +42,7 @@ public class TestOfflineSorter extends LuceneTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
- tempDir = TestUtil.getTempDir("mergesort");
+ tempDir = TestUtil.createTempDir("mergesort");
TestUtil.rmDir(tempDir);
tempDir.mkdirs();
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java b/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java
index 99d27619be4..290bf91e28f 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java
@@ -37,7 +37,7 @@ public class TestPagedBytes extends LuceneTestCase {
public void testDataInputOutput() throws Exception {
Random random = random();
for(int iter=0;iter<5*RANDOM_MULTIPLIER;iter++) {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("testOverflow"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("testOverflow"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
@@ -150,7 +150,7 @@ public class TestPagedBytes extends LuceneTestCase {
@Ignore // memory hole
public void testOverflow() throws IOException {
- BaseDirectoryWrapper dir = newFSDirectory(TestUtil.getTempDir("testOverflow"));
+ BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("testOverflow"));
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/fst/Test2BFST.java b/lucene/core/src/test/org/apache/lucene/util/fst/Test2BFST.java
index 96288751631..4275cb32ed2 100644
--- a/lucene/core/src/test/org/apache/lucene/util/fst/Test2BFST.java
+++ b/lucene/core/src/test/org/apache/lucene/util/fst/Test2BFST.java
@@ -45,7 +45,7 @@ public class Test2BFST extends LuceneTestCase {
IntsRef input = new IntsRef(ints, 0, ints.length);
long seed = random().nextLong();
- Directory dir = new MMapDirectory(TestUtil.getTempDir("2BFST"));
+ Directory dir = new MMapDirectory(TestUtil.createTempDir("2BFST"));
for(int doPackIter=0;doPackIter<2;doPackIter++) {
boolean doPack = doPackIter == 1;
diff --git a/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java b/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
index 0b6d6188a10..b8966e1427a 100644
--- a/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
+++ b/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java
@@ -309,7 +309,7 @@ public class TestFSTs extends LuceneTestCase {
analyzer.setMaxTokenLength(TestUtil.nextInt(random(), 1, IndexWriter.MAX_TERM_LENGTH));
final IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(-1).setRAMBufferSizeMB(64);
- final File tempDir = TestUtil.getTempDir("fstlines");
+ final File tempDir = TestUtil.createTempDir("fstlines");
final Directory dir = newFSDirectory(tempDir);
final IndexWriter writer = new IndexWriter(dir, conf);
final long stopTime = System.currentTimeMillis() + RUN_TIME_MSEC;
diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java
index 9e9c7393443..30bf3abcd53 100644
--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java
+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestLeaveFilesIfTestFails.java
@@ -33,7 +33,7 @@ public class TestLeaveFilesIfTestFails extends WithNestedTests {
public static class Nested1 extends WithNestedTests.AbstractNestedTest {
static File file;
public void testDummy() {
- file = TestUtil.getTempDir("leftover");
+ file = TestUtil.createTempDir("leftover");
file.mkdirs();
fail();
}
diff --git a/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java b/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java
index d3b91c3af50..e30887eb866 100644
--- a/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java
+++ b/lucene/demo/src/test/org/apache/lucene/demo/TestDemo.java
@@ -44,7 +44,7 @@ public class TestDemo extends LuceneTestCase {
public void testIndexSearch() throws Exception {
File dir = getDataFile("test-files/docs");
- File indexDir = TestUtil.getTempDir("ContribDemoTest");
+ File indexDir = TestUtil.createTempDir("ContribDemoTest");
IndexFiles.main(new String[] { "-create", "-docs", dir.getPath(), "-index", indexDir.getPath()});
testOneSearch(indexDir, "apache", 3);
testOneSearch(indexDir, "patent", 8);
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
index 55d8384b64c..5fd58d54dc3 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
@@ -941,10 +941,12 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
map[origordinal] = newordinal;
}
in.close();
+
// Delete the temporary file, which is no longer needed.
if (!tmpfile.delete()) {
tmpfile.deleteOnExit();
}
+
return map;
}
}
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestAddTaxonomy.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestAddTaxonomy.java
index fdf492b01a4..032634fe66f 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestAddTaxonomy.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestAddTaxonomy.java
@@ -74,7 +74,7 @@ public class TestAddTaxonomy extends FacetTestCase {
private OrdinalMap randomOrdinalMap() throws IOException {
if (random().nextBoolean()) {
- return new DiskOrdinalMap(TestUtil.createTempFile("taxoMap", "", TEMP_DIR));
+ return new DiskOrdinalMap(TestUtil.createTempFile("taxoMap", ""));
} else {
return new MemoryOrdinalMap();
}
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java
index 799df78cf23..63aaeb42c1b 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java
@@ -85,7 +85,7 @@ public class TestCharBlockArray extends FacetTestCase {
assertEqualsInternal("GrowingCharArray<->StringBuilder mismatch.", builder, array);
- File tempDir = TestUtil.getTempDir("growingchararray");
+ File tempDir = TestUtil.createTempDir("growingchararray");
File f = new File(tempDir, "GrowingCharArrayTest.tmp");
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
array.flush(out);
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java
index eddcb1b492b..b5805e7e4ee 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java
@@ -68,7 +68,7 @@ public class TestCompactLabelToOrdinal extends FacetTestCase {
}
}
- File tmpDir = TestUtil.getTempDir("testLableToOrdinal");
+ File tmpDir = TestUtil.createTempDir("testLableToOrdinal");
File f = new File(tmpDir, "CompactLabelToOrdinalTest.tmp");
int flushInterval = 10;
diff --git a/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java b/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java
index 9ffd4a75722..19054fd789c 100644
--- a/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java
+++ b/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java
@@ -28,12 +28,8 @@ import org.apache.lucene.util.TestUtil;
public class TestIndexSplitter extends LuceneTestCase {
public void test() throws Exception {
- File dir = new File(TEMP_DIR, "testfilesplitter");
- TestUtil.rmDir(dir);
- dir.mkdirs();
- File destDir = new File(TEMP_DIR, "testfilesplitterdest");
- TestUtil.rmDir(destDir);
- destDir.mkdirs();
+ File dir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ File destDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
Directory fsDir = newFSDirectory(dir);
// IndexSplitter.split makes its own commit directly with SIPC/SegmentInfos,
// so the unreferenced files are expected.
@@ -80,9 +76,7 @@ public class TestIndexSplitter extends LuceneTestCase {
fsDirDest.close();
// now test cmdline
- File destDir2 = new File(TEMP_DIR, "testfilesplitterdest2");
- TestUtil.rmDir(destDir2);
- destDir2.mkdirs();
+ File destDir2 = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
IndexSplitter.main(new String[] {dir.getAbsolutePath(), destDir2.getAbsolutePath(), splitSegName});
assertEquals(5, destDir2.listFiles().length);
Directory fsDirDest2 = newFSDirectory(destDir2);
diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java
index 0462ce01f93..e956478d749 100644
--- a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java
+++ b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java
@@ -191,7 +191,7 @@ public class IndexAndTaxonomyReplicationClientTest extends ReplicatorTestCase {
publishTaxoDir = newDirectory();
handlerIndexDir = newMockDirectory();
handlerTaxoDir = newMockDirectory();
- clientWorkDir = TestUtil.getTempDir("replicationClientTest");
+ clientWorkDir = TestUtil.createTempDir("replicationClientTest");
sourceDirFactory = new PerSessionDirectoryFactory(clientWorkDir);
replicator = new LocalReplicator();
callback = new IndexAndTaxonomyReadyCallback(handlerIndexDir, handlerTaxoDir);
diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexReplicationClientTest.java b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexReplicationClientTest.java
index 76e92e8e0d8..9b93834d7ec 100644
--- a/lucene/replicator/src/test/org/apache/lucene/replicator/IndexReplicationClientTest.java
+++ b/lucene/replicator/src/test/org/apache/lucene/replicator/IndexReplicationClientTest.java
@@ -136,7 +136,7 @@ public class IndexReplicationClientTest extends ReplicatorTestCase {
super.setUp();
publishDir = newMockDirectory();
handlerDir = newMockDirectory();
- sourceDirFactory = new PerSessionDirectoryFactory(TestUtil.getTempDir("replicationClientTest"));
+ sourceDirFactory = new PerSessionDirectoryFactory(TestUtil.createTempDir("replicationClientTest"));
replicator = new LocalReplicator();
callback = new IndexReadyCallback(handlerDir);
handler = new IndexReplicationHandler(handlerDir, callback);
diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/http/HttpReplicatorTest.java b/lucene/replicator/src/test/org/apache/lucene/replicator/http/HttpReplicatorTest.java
index b549f7f6e2b..3a4a33e3e8e 100644
--- a/lucene/replicator/src/test/org/apache/lucene/replicator/http/HttpReplicatorTest.java
+++ b/lucene/replicator/src/test/org/apache/lucene/replicator/http/HttpReplicatorTest.java
@@ -68,7 +68,7 @@ public class HttpReplicatorTest extends ReplicatorTestCase {
public void setUp() throws Exception {
super.setUp();
System.setProperty("org.eclipse.jetty.LEVEL", "DEBUG"); // sets stderr logging to DEBUG level
- clientWorkDir = TestUtil.getTempDir("httpReplicatorTest");
+ clientWorkDir = TestUtil.createTempDir("httpReplicatorTest");
handlerIndexDir = newDirectory();
serverIndexDir = newDirectory();
serverReplicator = new LocalReplicator();
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/LookupBenchmarkTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/LookupBenchmarkTest.java
index 7d99824d8b9..3bcedab6d50 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/LookupBenchmarkTest.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/LookupBenchmarkTest.java
@@ -162,7 +162,7 @@ public class LookupBenchmarkTest extends LuceneTestCase {
} catch (InstantiationException e) {
Analyzer a = new MockAnalyzer(random, MockTokenizer.KEYWORD, false);
if (cls == AnalyzingInfixSuggester.class) {
- lookup = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, FSDirectory.open(TestUtil.getTempDir("LookupBenchmarkTest")), a);
+ lookup = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, FSDirectory.open(TestUtil.createTempDir("LookupBenchmarkTest")), a);
} else {
Constructor<? extends Lookup> ctor = cls.getConstructor(Analyzer.class);
lookup = ctor.newInstance(a);
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/PersistenceTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/PersistenceTest.java
index 3a29effb556..128b088a589 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/PersistenceTest.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/PersistenceTest.java
@@ -70,7 +70,7 @@ public class PersistenceTest extends LuceneTestCase {
lookup.build(new InputArrayIterator(keys));
// Store the suggester.
- File storeDir = TEMP_DIR;
+ File storeDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
lookup.store(new FileOutputStream(new File(storeDir, "lookup.dat")));
// Re-read it from disk.
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java
index 00ca3786e98..1de609a4d2d 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java
@@ -94,7 +94,7 @@ public class AnalyzingInfixSuggesterTest extends LuceneTestCase {
new Input("a penny saved is a penny earned", 10, new BytesRef("foobaz")),
};
- File tempDir = TestUtil.getTempDir("AnalyzingInfixSuggesterTest");
+ File tempDir = TestUtil.createTempDir("AnalyzingInfixSuggesterTest");
Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false);
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, newFSDirectory(tempDir), a, a, 3);
@@ -213,7 +213,7 @@ public class AnalyzingInfixSuggesterTest extends LuceneTestCase {
new Input("lend me your ear", 8, new BytesRef("foobar")),
new Input("a penny saved is a penny earned", 10, new BytesRef("foobaz")),
};
- File tempDir = TestUtil.getTempDir("AnalyzingInfixSuggesterTest");
+ File tempDir = TestUtil.createTempDir("AnalyzingInfixSuggesterTest");
Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false);
int minPrefixLength = random().nextInt(10);
@@ -474,7 +474,7 @@ public class AnalyzingInfixSuggesterTest extends LuceneTestCase {
}
public void testRandomNRT() throws Exception {
- final File tempDir = TestUtil.getTempDir("AnalyzingInfixSuggesterTest");
+ final File tempDir = TestUtil.createTempDir("AnalyzingInfixSuggesterTest");
Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false);
int minPrefixChars = random().nextInt(7);
if (VERBOSE) {
@@ -809,7 +809,7 @@ public class AnalyzingInfixSuggesterTest extends LuceneTestCase {
new Input("a penny saved is a penny earned", 10, new BytesRef("foobaz"), asSet("foo", "baz"))
};
- File tempDir = TestUtil.getTempDir("analyzingInfixContext");
+ File tempDir = TestUtil.createTempDir("analyzingInfixContext");
for(int iter=0;iter<2;iter++) {
AnalyzingInfixSuggester suggester;
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java
index ccbecc62eae..586a7c2cd93 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java
@@ -921,7 +921,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase {
assertEquals(3, results.get(2).value);
// Try again after save/load:
- File tmpDir = TestUtil.getTempDir("AnalyzingSuggesterTest");
+ File tmpDir = TestUtil.createTempDir("AnalyzingSuggesterTest");
tmpDir.mkdir();
File path = new File(tmpDir, "suggester");
@@ -983,7 +983,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase {
assertEquals(5, results.get(1).value);
// Try again after save/load:
- File tmpDir = TestUtil.getTempDir("AnalyzingSuggesterTest");
+ File tmpDir = TestUtil.createTempDir("AnalyzingSuggesterTest");
tmpDir.mkdir();
File path = new File(tmpDir, "suggester");
@@ -1053,7 +1053,7 @@ public class AnalyzingSuggesterTest extends LuceneTestCase {
assertEquals(5, results.get(1).value);
// Try again after save/load:
- File tmpDir = TestUtil.getTempDir("AnalyzingSuggesterTest");
+ File tmpDir = TestUtil.createTempDir("AnalyzingSuggesterTest");
tmpDir.mkdir();
File path = new File(tmpDir, "suggester");
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
index cbd21ec1fa8..843ca6d1895 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
@@ -45,7 +45,7 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
new Input("star wars: episode v - the empire strikes back", 8, payload)
};
- File tempDir = TestUtil.getTempDir("BlendedInfixSuggesterTest");
+ File tempDir = TestUtil.createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET);
BlendedInfixSuggester suggester = new BlendedInfixSuggester(TEST_VERSION_CURRENT, newFSDirectory(tempDir), a, a,
@@ -84,7 +84,7 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
new Input("top of the lake", w, pl)
};
- File tempDir = TestUtil.getTempDir("BlendedInfixSuggesterTest");
+ File tempDir = TestUtil.createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET);
// BlenderType.LINEAR is used by default (remove position*10%)
@@ -125,7 +125,7 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
new Input("the returned", 10, ret),
};
- File tempDir = TestUtil.getTempDir("BlendedInfixSuggesterTest");
+ File tempDir = TestUtil.createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET);
// if factor is small, we don't get the expected element
@@ -175,7 +175,7 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
new Input("the returned", 10, ret),
};
- File tempDir = TestUtil.getTempDir("BlendedInfixSuggesterTest");
+ File tempDir = TestUtil.createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET);
// if factor is small, we don't get the expected element
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java
index b24945b6dcc..4b8cfa91a4f 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java
@@ -82,7 +82,7 @@ public class TestFreeTextSuggester extends LuceneTestCase {
toString(sug.lookup("b", 10)));
// Try again after save/load:
- File tmpDir = TestUtil.getTempDir("FreeTextSuggesterTest");
+ File tmpDir = TestUtil.createTempDir("FreeTextSuggesterTest");
tmpDir.mkdir();
File path = new File(tmpDir, "suggester");
diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
index 668b7e7eb27..da0ec735601 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
@@ -502,7 +502,7 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
!(postingsFormat.equals("Memory") ||
postingsFormat.equals("SimpleText"));
if (rarely(random) && codecOk) {
- dir = newFSDirectory(TestUtil.getTempDir("bttc"));
+ dir = newFSDirectory(TestUtil.createTempDir("bttc"));
iw = new RandomIndexWriter(new Random(seed), dir, a);
}
boolean success = false;
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
index 422eb1d433f..a8829390830 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java
@@ -2615,7 +2615,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {
Analyzer analyzer = new MockAnalyzer(random());
// FSDirectory because SimpleText will consume gobbs of
// space when storing big binary values:
- Directory d = newFSDirectory(TestUtil.getTempDir("hugeBinaryValues"));
+ Directory d = newFSDirectory(TestUtil.createTempDir("hugeBinaryValues"));
boolean doFixed = random().nextBoolean();
int numDocs;
int fixedLength = 0;
@@ -2713,7 +2713,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {
Analyzer analyzer = new MockAnalyzer(random());
// FSDirectory because SimpleText will consume gobbs of
// space when storing big binary values:
- Directory d = newFSDirectory(TestUtil.getTempDir("hugeBinaryValues"));
+ Directory d = newFSDirectory(TestUtil.createTempDir("hugeBinaryValues"));
boolean doFixed = random().nextBoolean();
int numDocs;
int fixedLength = 0;
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
index a0550c7cb7e..5ef63464ffb 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
@@ -1211,7 +1211,7 @@ public abstract class BasePostingsFormatTestCase extends LuceneTestCase {
/** Indexes all fields/terms at the specified
* IndexOptions, and fully tests at that IndexOptions. */
private void testFull(IndexOptions options, boolean withPayloads) throws Exception {
- File path = TestUtil.getTempDir("testPostingsFormat.testExact");
+ File path = TestUtil.createTempDir("testPostingsFormat.testExact");
Directory dir = newFSDirectory(path);
// TODO test thread safety of buildIndex too
@@ -1264,7 +1264,7 @@ public abstract class BasePostingsFormatTestCase extends LuceneTestCase {
int iters = 5;
for(int iter=0;iter<iters;iter++) {
- File path = TestUtil.getTempDir("testPostingsFormat");
+ File path = TestUtil.createTempDir("testPostingsFormat");
Directory dir = newFSDirectory(path);
boolean indexPayloads = random().nextBoolean();
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
index a2d9234e0ff..a84a253c7dc 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
@@ -598,7 +598,7 @@ public abstract class BaseStoredFieldsFormatTestCase extends LuceneTestCase {
// for this test we force a FS dir
// we can't just use newFSDirectory, because this test doesn't really index anything.
// so if we get NRTCachingDir+SimpleText, we make massive stored fields and OOM (LUCENE-4484)
- Directory dir = new MockDirectoryWrapper(random(), new MMapDirectory(TestUtil.getTempDir("testBigDocuments")));
+ Directory dir = new MockDirectoryWrapper(random(), new MMapDirectory(TestUtil.createTempDir("testBigDocuments")));
IndexWriterConfig iwConf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
iwConf.setMaxBufferedDocs(RandomInts.randomIntBetween(random(), 2, 30));
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConf);
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
index 8beff389228..13221d4c6b4 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
@@ -435,7 +435,7 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCas
Random random = new Random(random().nextLong());
final LineFileDocs docs = new LineFileDocs(random, true);
- final File tempDir = TestUtil.getTempDir(testName);
+ final File tempDir = TestUtil.createTempDir(testName);
dir = getDirectory(newMockFSDirectory(tempDir)); // some subclasses rely on this being MDW
if (dir instanceof BaseDirectoryWrapper) {
((BaseDirectoryWrapper) dir).setCheckIndexOnClose(false); // don't double-checkIndex, we do it ourselves.
diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java b/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java
index 43b33e9a631..7f551d45f5f 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java
@@ -447,7 +447,7 @@ public abstract class ShardSearchingTestBase extends LuceneTestCase {
public NodeState(Random random, int nodeID, int numNodes) throws IOException {
myNodeID = nodeID;
- dir = newFSDirectory(TestUtil.getTempDir("ShardSearchingTestBase"));
+ dir = newFSDirectory(TestUtil.createTempDir("ShardSearchingTestBase"));
// TODO: set warmer
MockAnalyzer analyzer = new MockAnalyzer(random());
analyzer.setMaxTokenLength(TestUtil.nextInt(random(), 1, IndexWriter.MAX_TERM_LENGTH));
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java b/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java
index 33737b10189..5bcc38ded0f 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/CloseableFile.java
@@ -1,6 +1,8 @@
package org.apache.lucene.util;
-import java.io.*;
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,10 +27,17 @@ import java.io.*;
final class CloseableFile implements Closeable {
private final File file;
private final TestRuleMarkFailure failureMarker;
+ private final String creationStack;
public CloseableFile(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
@@ -36,6 +45,10 @@ final class CloseableFile implements Closeable {
// only if there were no other test failures.
if (failureMarker.wasSuccessful()) {
if (file.exists()) {
+ if (file.listFiles().length > 0) {
+ // throw new IOException("Temporary folder not clean: " + file.getAbsolutePath() + ". Created at stack trace:\n" + creationStack);
+ }
+
try {
TestUtil.rmDir(file);
} catch (IOException e) {
@@ -45,9 +58,9 @@ final class CloseableFile implements Closeable {
// Re-check.
if (file.exists()) {
throw new IOException(
- "Could not remove: " + file.getAbsolutePath());
+ "Could not remove temporary folder: " + file.getAbsolutePath() + ". Created at stack trace:\n" + creationStack);
}
- }
+ }
}
}
}
\ No newline at end of file
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
index 6891382ce93..439238e70ee 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
@@ -290,16 +290,6 @@ public abstract class LuceneTestCase extends Assert {
/** Throttling, see {@link MockDirectoryWrapper#setThrottling(Throttling)}. */
public static final Throttling TEST_THROTTLING = TEST_NIGHTLY ? Throttling.SOMETIMES : Throttling.NEVER;
- /** Create indexes in this directory, optimally use a subdir, named after the test */
- public static final File TEMP_DIR;
- static {
- String s = System.getProperty("tempDir", System.getProperty("java.io.tmpdir"));
- if (s == null)
- throw new RuntimeException("To run tests, you need to define system property 'tempDir' or 'java.io.tmpdir'.");
- TEMP_DIR = new File(s);
- TEMP_DIR.mkdirs();
- }
-
/**
* These property keys will be ignored in verification of altered properties.
* @see SystemPropertiesInvariantRule
@@ -1164,7 +1154,7 @@ public abstract class LuceneTestCase extends Assert {
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.getTempDir("index");
+ final File dir = TestUtil.createTempDir("index");
dir.mkdirs(); // ensure it's created so we 'have' it.
return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir);
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
index e7718da3eda..144a3b40c58 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java
@@ -102,34 +102,6 @@ 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;
- /**
- * Returns a temp directory, based on the given description. Creates the
- * directory.
- */
- public static File getTempDir(String desc) {
- if (desc.length() < 3) {
- throw new IllegalArgumentException("description must be at least 3 characters");
- }
- // 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, desc, "tmp", LuceneTestCase.TEMP_DIR);
- } 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.");
- }
-
- LuceneTestCase.closeAfterSuite(new CloseableFile(f, LuceneTestCase.suiteFailureMarker));
- return f;
- }
-
/**
* Deletes a directory and everything underneath it.
*/
@@ -809,9 +781,45 @@ public final class TestUtil {
Assert.assertEquals("Reflection does not produce same map", reflectedValues, map);
}
+ /**
+ * 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).
+ */
+ public static File createTempDir(String name) {
+ if (name.length() < 3) {
+ throw new IllegalArgumentException("description must be at least 3 characters");
+ }
+
+ // 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;
+ String tmpDir = System.getProperty("tempDir", System.getProperty("java.io.tmpdir"));
+ File f;
+ do {
+ f = genTempFile(random, name + "_", "", new File(tmpDir));
+ } 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.");
+ }
+
+ LuceneTestCase.closeAfterSuite(new CloseableFile(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));
+ }
+
/**
- * insecure, fast version of File.createTempFile
- * uses Random instead of SecureRandom.
+ * 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 {
@@ -828,6 +836,7 @@ public final class TestUtil {
do {
result = genTempFile(random, prefix, newSuffix, directory);
} while (!result.createNewFile());
+ LuceneTestCase.closeAfterSuite(new CloseableFile(result, LuceneTestCase.suiteFailureMarker));
return result;
}
diff --git a/solr/contrib/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationField.java b/solr/contrib/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationField.java
index 76124eb26e5..057ea007c38 100644
--- a/solr/contrib/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationField.java
+++ b/solr/contrib/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationField.java
@@ -22,6 +22,8 @@ import java.io.FileOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.BeforeClass;
@@ -62,7 +64,7 @@ public class TestICUCollationField extends SolrTestCaseJ4 {
*/
public static String setupSolrHome() throws Exception {
// make a solr home underneath the test's TEMP_DIR
- File tmpFile = File.createTempFile("test", "tmp", TEMP_DIR);
+ File tmpFile = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
tmpFile.delete();
tmpFile.mkdir();
diff --git a/solr/contrib/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldDocValues.java b/solr/contrib/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldDocValues.java
index b7ddfaf7c4f..e8c06577510 100644
--- a/solr/contrib/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldDocValues.java
+++ b/solr/contrib/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldDocValues.java
@@ -22,6 +22,8 @@ import java.io.FileOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.BeforeClass;
@@ -64,7 +66,7 @@ public class TestICUCollationFieldDocValues extends SolrTestCaseJ4 {
*/
public static String setupSolrHome() throws Exception {
// make a solr home underneath the test's TEMP_DIR
- File tmpFile = File.createTempFile("test", "tmp", TEMP_DIR);
+ File tmpFile = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
tmpFile.delete();
tmpFile.mkdir();
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractSqlEntityProcessorTestCase.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractSqlEntityProcessorTestCase.java
index 0077005d2ff..c55ebc5a74a 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractSqlEntityProcessorTestCase.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractSqlEntityProcessorTestCase.java
@@ -16,6 +16,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.junit.After;
import org.junit.Before;
@@ -54,9 +56,7 @@ public abstract class AbstractSqlEntityProcessorTestCase extends
@Before
public void beforeSqlEntitiyProcessorTestCase() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
fileLocation = tmpdir.getPath();
fileName = "the.properties";
}
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java
index 396ce64cbef..62dad182e66 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java
@@ -16,7 +16,12 @@
*/
package org.apache.solr.handler.dataimport;
+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;
@@ -25,14 +30,10 @@ import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.UpdateParams;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import java.io.File;
-import java.util.List;
-
/**
* Test for ContentStreamDataSource
*
@@ -150,10 +151,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
public void setUp() throws Exception {
-
- File home = new File(TEMP_DIR,
- getClass().getName() + "-" + System.currentTimeMillis());
-
+ File home = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
homeDir = new File(home, "inst");
dataDir = new File(homeDir + "/collection1", "data");
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDocBuilder2.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDocBuilder2.java
index dbd38be1899..54417e0bd61 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDocBuilder2.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDocBuilder2.java
@@ -20,6 +20,8 @@ import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.request.LocalSolrQueryRequest;
import java.util.ArrayList;
@@ -240,10 +242,7 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
@Test
@Ignore("Fix Me. See SOLR-4103.")
public void testFileListEntityProcessor_lastIndexTime() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
Map<String, String> params = createMap("baseDir", tmpdir.getAbsolutePath());
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListEntityProcessor.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListEntityProcessor.java
index 654065582e0..fc6575e4097 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListEntityProcessor.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListEntityProcessor.java
@@ -16,6 +16,8 @@ package org.apache.solr.handler.dataimport;
* limitations under the License.
*/
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.junit.Ignore;
import org.junit.Test;
@@ -37,10 +39,7 @@ public class TestFileListEntityProcessor extends AbstractDataImportHandlerTestCa
@Test
@SuppressWarnings("unchecked")
public void testSimple() throws IOException {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
createFile(tmpdir, "a.xml", "a.xml".getBytes("UTF-8"), false);
createFile(tmpdir, "b.xml", "b.xml".getBytes("UTF-8"), false);
createFile(tmpdir, "c.props", "c.props".getBytes("UTF-8"), false);
@@ -63,10 +62,7 @@ public class TestFileListEntityProcessor extends AbstractDataImportHandlerTestCa
@Test
public void testBiggerSmallerFiles() throws IOException {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
long minLength = Long.MAX_VALUE;
String smallestFile = "";
byte[] content = "abcdefgij".getBytes("UTF-8");
@@ -133,10 +129,7 @@ public class TestFileListEntityProcessor extends AbstractDataImportHandlerTestCa
@Test
public void testNTOT() throws IOException {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
createFile(tmpdir, "a.xml", "a.xml".getBytes("UTF-8"), true);
createFile(tmpdir, "b.xml", "b.xml".getBytes("UTF-8"), true);
createFile(tmpdir, "c.props", "c.props".getBytes("UTF-8"), true);
@@ -169,13 +162,8 @@ public class TestFileListEntityProcessor extends AbstractDataImportHandlerTestCa
@Test
public void testRECURSION() throws IOException {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
File childdir = new File(tmpdir + "/child" );
- childdir.mkdirs();
- childdir.deleteOnExit();
createFile(childdir, "a.xml", "a.xml".getBytes("UTF-8"), true);
createFile(childdir, "b.xml", "b.xml".getBytes("UTF-8"), true);
createFile(childdir, "c.props", "c.props".getBytes("UTF-8"), true);
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListWithLineEntityProcessor.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListWithLineEntityProcessor.java
index 31e9216367a..c07a6cf29a3 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListWithLineEntityProcessor.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestFileListWithLineEntityProcessor.java
@@ -2,6 +2,8 @@ package org.apache.solr.handler.dataimport;
import java.io.File;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.junit.BeforeClass;
@@ -29,10 +31,7 @@ public class TestFileListWithLineEntityProcessor extends AbstractDataImportHandl
}
public void test() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
createFile(tmpdir, "a.txt", "a line one\na line two\na line three".getBytes("UTF-8"), false);
createFile(tmpdir, "b.txt", "b line one\nb line two".getBytes("UTF-8"), false);
createFile(tmpdir, "c.txt", "c line one\nc line two\nc line three\nc line four".getBytes("UTF-8"), false);
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java
index 7aec93abb99..d9f9c24736a 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java
@@ -17,6 +17,8 @@
package org.apache.solr.handler.dataimport;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -53,7 +55,7 @@ public class TestNonWritablePersistFile extends AbstractDataImportHandlerTestCas
@BeforeClass
public static void createTempSolrHomeAndCore() throws Exception {
createTempDir();
- tmpSolrHome = TEMP_DIR + File.separator + TestNonWritablePersistFile.class.getSimpleName() + System.currentTimeMillis();
+ tmpSolrHome = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
FileUtils.copyDirectory(getFile("dih/solr"), new File(tmpSolrHome).getAbsoluteFile());
initCore("dataimport-solrconfig.xml", "dataimport-schema.xml",
new File(tmpSolrHome).getAbsolutePath());
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSimplePropertiesWriter.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSimplePropertiesWriter.java
index 3cf21a70a86..0e22cf8e7b9 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSimplePropertiesWriter.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSimplePropertiesWriter.java
@@ -14,6 +14,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -46,9 +48,7 @@ public class TestSimplePropertiesWriter extends AbstractDIHJdbcTestCase {
@Before
public void spwBefore() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
fileLocation = tmpdir.getPath();
fileName = "the.properties";
}
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
index d9d010e8922..97a8d13b6d4 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
@@ -26,6 +26,8 @@ import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
@@ -316,9 +318,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
}
public void setUp() throws Exception {
-
- File home = new File(TEMP_DIR, getClass().getName() + "-"
- + System.currentTimeMillis());
+ File home = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
homeDir = new File(home + "inst");
dataDir = new File(homeDir + "/collection1", "data");
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathEntityProcessor.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathEntityProcessor.java
index dfbdcbfa979..c5f153bd0db 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathEntityProcessor.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestXPathEntityProcessor.java
@@ -16,6 +16,8 @@
*/
package org.apache.solr.handler.dataimport;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.junit.Test;
import java.io.File;
@@ -42,10 +44,7 @@ public class TestXPathEntityProcessor extends AbstractDataImportHandlerTestCase
@Test
public void withFieldsAndXpath() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
createFile(tmpdir, "x.xsl", xsl.getBytes("UTF-8"), false);
Map entityAttrs = createMap("name", "e", "url", "cd.xml",
XPathEntityProcessor.FOR_EACH, "/catalog/cd");
@@ -333,12 +332,8 @@ public class TestXPathEntityProcessor extends AbstractDataImportHandlerTestCase
@Test
public void withDefaultSolrAndXsl() throws Exception {
- File tmpdir = File.createTempFile("test", "tmp", TEMP_DIR);
- tmpdir.delete();
- tmpdir.mkdir();
- tmpdir.deleteOnExit();
- AbstractDataImportHandlerTestCase.createFile(tmpdir, "x.xsl", xsl.getBytes("UTF-8"),
- false);
+ File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ AbstractDataImportHandlerTestCase.createFile(tmpdir, "x.xsl", xsl.getBytes("UTF-8"), false);
Map entityAttrs = createMap("name", "e",
XPathEntityProcessor.USE_SOLR_ADD_SCHEMA, "true", "xsl", ""
+ new File(tmpdir, "x.xsl").toURI(), "url", "cd.xml");
diff --git a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MRUnitBase.java b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MRUnitBase.java
index 75715398912..0b792037834 100644
--- a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MRUnitBase.java
+++ b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MRUnitBase.java
@@ -21,6 +21,8 @@ import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.hadoop.morphline.MorphlineMapRunner;
import org.apache.solr.morphlines.solr.AbstractSolrMorphlineTestBase;
@@ -45,11 +47,9 @@ public abstract class MRUnitBase extends SolrTestCaseJ4 {
}
protected void setupHadoopConfig(Configuration config) throws IOException {
-
- String tempDir = TEMP_DIR + "/test-morphlines-" + System.currentTimeMillis();
- new File(tempDir).mkdirs();
+ String tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
FileUtils.copyFile(new File(RESOURCES_DIR + "/custom-mimetypes.xml"), new File(tempDir + "/custom-mimetypes.xml"));
-
+
AbstractSolrMorphlineTestBase.setupMorphline(tempDir, "test-morphlines/solrCellDocumentTypes", true);
config.set(MorphlineMapRunner.MORPHLINE_FILE_PARAM, tempDir + "/test-morphlines/solrCellDocumentTypes.conf");
diff --git a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MapReduceIndexerToolArgumentParserTest.java b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MapReduceIndexerToolArgumentParserTest.java
index 6767389f752..a8f4c689a87 100644
--- a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MapReduceIndexerToolArgumentParserTest.java
+++ b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MapReduceIndexerToolArgumentParserTest.java
@@ -27,6 +27,8 @@ import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.cloud.AbstractZkTestCase;
import org.apache.solr.hadoop.dedup.NoChangeUpdateConflictResolver;
@@ -55,11 +57,12 @@ public class MapReduceIndexerToolArgumentParserTest extends SolrTestCaseJ4 {
private static final Logger LOG = LoggerFactory.getLogger(MapReduceIndexerToolArgumentParserTest.class);
- private static final File solrHomeDirectory = new File(TEMP_DIR, MorphlineGoLiveMiniMRTest.class.getName());
+ private static File solrHomeDirectory;
@BeforeClass
public static void beforeClass() {
assumeFalse("Does not work on Windows, because it uses UNIX shell commands or POSIX paths", Constants.WINDOWS);
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
}
@Before
diff --git a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineBasicMiniMRTest.java b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineBasicMiniMRTest.java
index b433bcf48c5..13ccdb6a2df 100644
--- a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineBasicMiniMRTest.java
+++ b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineBasicMiniMRTest.java
@@ -38,6 +38,8 @@ import org.apache.hadoop.util.JarFinder;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.cloud.AbstractZkTestCase;
@@ -79,7 +81,7 @@ public class MorphlineBasicMiniMRTest extends SolrTestCaseJ4 {
private static String tempDir;
- private static final File solrHomeDirectory = new File(TEMP_DIR, MorphlineBasicMiniMRTest.class.getName());
+ private static File solrHomeDirectory;
protected MapReduceIndexerTool createTool() {
return new MapReduceIndexerTool();
@@ -108,6 +110,8 @@ public class MorphlineBasicMiniMRTest extends SolrTestCaseJ4 {
@BeforeClass
public static void setupClass() throws Exception {
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+
assumeTrue(
"Currently this test can only be run without the lucene test security policy in place",
System.getProperty("java.security.manager", "").equals(""));
@@ -121,8 +125,8 @@ public class MorphlineBasicMiniMRTest extends SolrTestCaseJ4 {
AbstractZkTestCase.SOLRHOME = solrHomeDirectory;
FileUtils.copyDirectory(MINIMR_CONF_DIR, solrHomeDirectory);
-
- tempDir = TEMP_DIR + "/test-morphlines-" + System.currentTimeMillis();
+
+ tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
new File(tempDir).mkdirs();
FileUtils.copyFile(new File(RESOURCES_DIR + "/custom-mimetypes.xml"), new File(tempDir + "/custom-mimetypes.xml"));
diff --git a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java
index ae6bd25b704..e5efb653072 100644
--- a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java
+++ b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java
@@ -43,6 +43,8 @@ import org.apache.hadoop.util.JarFinder;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
@@ -108,8 +110,8 @@ public class MorphlineGoLiveMiniMRTest extends AbstractFullDistribZkTestBase {
private final String inputAvroFile2;
private final String inputAvroFile3;
- private static final File solrHomeDirectory = new File(TEMP_DIR, MorphlineGoLiveMiniMRTest.class.getName());
-
+ private static File solrHomeDirectory;
+
@Override
public String getSolrHome() {
return solrHomeDirectory.getPath();
@@ -138,11 +140,11 @@ public class MorphlineGoLiveMiniMRTest extends AbstractFullDistribZkTestBase {
assumeFalse("FIXME: This test fails under Java 8 due to the Saxon dependency - see SOLR-1301", Constants.JRE_IS_MINIMUM_JAVA8);
assumeFalse("FIXME: This test fails under J9 due to the Saxon dependency - see SOLR-1301", System.getProperty("java.vm.info", "<?>").contains("IBM J9"));
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
AbstractZkTestCase.SOLRHOME = solrHomeDirectory;
- FileUtils.copyDirectory(MINIMR_INSTANCE_DIR, solrHomeDirectory);
+ FileUtils.copyDirectory(MINIMR_INSTANCE_DIR, AbstractZkTestCase.SOLRHOME);
- tempDir = TEMP_DIR + "/test-morphlines-" + System.currentTimeMillis();
- new File(tempDir).mkdirs();
+ tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
FileUtils.copyFile(new File(RESOURCES_DIR + "/custom-mimetypes.xml"), new File(tempDir + "/custom-mimetypes.xml"));
AbstractSolrMorphlineTestBase.setupMorphline(tempDir, "test-morphlines/solrCellDocumentTypes", true);
diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java
index f9dd687602c..f5ddff8e435 100644
--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java
+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java
@@ -32,6 +32,8 @@ import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
@@ -118,8 +120,7 @@ public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {
testServer = new SolrServerDocumentLoader(solrServer, batchSize);
deleteAllDocuments();
- tempDir = new File(TEMP_DIR + "/test-morphlines-" + System.currentTimeMillis()).getAbsolutePath();
- new File(tempDir).mkdirs();
+ tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
}
@After
diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java
index 8593dfa93ca..07e652df0b5 100644
--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java
+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.Iterator;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
@@ -47,8 +48,8 @@ import com.google.common.collect.ListMultimap;
import com.typesafe.config.Config;
public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistribZkTestBase {
- private static final File solrHomeDirectory = new File(TEMP_DIR, AbstractSolrMorphlineZkTestBase.class.getName());
-
+ private static File solrHomeDirectory;
+
protected static final String RESOURCES_DIR = getFile("morphlines-core.marker").getParent();
private static final File SOLR_INSTANCE_DIR = new File(RESOURCES_DIR + "/solr");
private static final File SOLR_CONF_DIR = new File(RESOURCES_DIR + "/solr/collection1");
@@ -69,6 +70,7 @@ public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistri
@BeforeClass
public static void setupClass() throws Exception {
+ solrHomeDirectory = TestUtil.createTempDir(AbstractSolrMorphlineZkTestBase.class.getName());
AbstractZkTestCase.SOLRHOME = solrHomeDirectory;
FileUtils.copyDirectory(SOLR_INSTANCE_DIR, solrHomeDirectory);
createTempDir();
diff --git a/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java b/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java
index a7284272fc4..5b94f1b0067 100644
--- a/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java
+++ b/solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java
@@ -18,6 +18,7 @@ package org.apache.solr;
*/
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
@@ -43,7 +44,7 @@ public class AnalysisAfterCoreReloadTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
createTempDir();
- tmpSolrHome = TEMP_DIR + File.separator + AnalysisAfterCoreReloadTest.class.getSimpleName() + System.currentTimeMillis();
+ tmpSolrHome = TestUtil.createTempDir(AnalysisAfterCoreReloadTest.class.getSimpleName()).getAbsolutePath();
FileUtils.copyDirectory(new File(TEST_HOME()), new File(tmpSolrHome).getAbsoluteFile());
initCore("solrconfig.xml", "schema.xml", new File(tmpSolrHome).getAbsolutePath());
}
diff --git a/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java b/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java
index d713547490f..0f753dc3d4d 100644
--- a/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java
+++ b/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java
@@ -18,6 +18,8 @@ package org.apache.solr;
*/
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -31,11 +33,10 @@ public class SolrTestCaseJ4Test extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
-
// Create a temporary directory that holds a core NOT named "collection1". Use the smallest configuration sets
// we can so we don't copy that much junk around.
createTempDir();
- tmpSolrHome = TEMP_DIR + File.separator + SolrTestCaseJ4Test.class.getSimpleName() + System.currentTimeMillis();
+ tmpSolrHome = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
File subHome = new File(new File(tmpSolrHome, "core0"), "conf");
assertTrue("Failed to make subdirectory ", subHome.mkdirs());
diff --git a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
index 181dae10b29..ca4ce5a47b7 100644
--- a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
+++ b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
@@ -17,6 +17,7 @@
package org.apache.solr;
import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.TestUtil;
//import org.apache.lucene.util.LuceneTestCase;
//import org.apache.solr.util.AbstractSolrTestCase;
//import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -45,8 +46,7 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- File homeDir = new File(TEMP_DIR,
- "solrtest-TestSolrCoreProperties-" + System.currentTimeMillis());
+ File homeDir = TestUtil.createTempDir(TestSolrCoreProperties.class.getSimpleName());
File collDir = new File(homeDir, "collection1");
File dataDir = new File(collDir, "data");
File confDir = new File(collDir, "conf");
diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
index b8f0bf7a77e..6dfe0bf92b0 100644
--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
@@ -26,6 +26,8 @@ import java.util.regex.Pattern;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
@@ -415,15 +417,15 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/replication");
params.set("command", "backup");
- File location = new File(TEMP_DIR, BasicDistributedZk2Test.class.getName() + "-backupdir-" + System.currentTimeMillis());
+ File location = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + "-backupdir");
params.set("location", location.getAbsolutePath());
QueryRequest request = new QueryRequest(params);
NamedList<Object> results = client.request(request );
checkForBackupSuccess(client, location);
-
}
+
private void checkForBackupSuccess(final HttpSolrServer client, File location)
throws InterruptedException, IOException {
class CheckStatus extends Thread {
diff --git a/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java b/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java
index 35d49d76b2a..e520f5a9a0f 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java
@@ -18,6 +18,7 @@ package org.apache.solr.cloud;
*/
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.ClusterState;
@@ -67,11 +68,11 @@ public class ClusterStateUpdateTest extends SolrTestCaseJ4 {
private File dataDir4;
-
- private static final File solrHomeDirectory = new File(TEMP_DIR, "ZkControllerTest");
+ private static File solrHomeDirectory;
@BeforeClass
public static void beforeClass() throws IOException {
+ solrHomeDirectory = TestUtil.createTempDir(ClusterStateUpdateTest.class.getSimpleName());
System.setProperty("solrcloud.skip.autorecovery", "true");
System.setProperty("genericCoreNodeNames", "false");
if (solrHomeDirectory.exists()) {
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestMultiCoreConfBootstrap.java b/solr/core/src/test/org/apache/solr/cloud/TestMultiCoreConfBootstrap.java
index 09fe71724f5..736a2ed46a5 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestMultiCoreConfBootstrap.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestMultiCoreConfBootstrap.java
@@ -17,10 +17,13 @@
package org.apache.solr.cloud;
+import java.io.File;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.core.CoreContainer;
-import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.util.ExternalPaths;
import org.junit.After;
import org.junit.Before;
@@ -28,8 +31,6 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-
public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
protected static Logger log = LoggerFactory.getLogger(TestMultiCoreConfBootstrap.class);
protected CoreContainer cores = null;
@@ -45,9 +46,7 @@ public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {
super.setUp();
createTempDir();
- dataDir2 = new File(TEMP_DIR, getSimpleClassName() + "-core1-"
- + System.currentTimeMillis());
- dataDir2.mkdirs();
+ dataDir2 = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
home = ExternalPaths.EXAMPLE_MULTICORE_HOME;
System.setProperty("solr.solr.home", home);
diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
index b4b605321e6..f10735418a3 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
@@ -28,6 +28,8 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.SolrZkClient;
@@ -231,11 +233,9 @@ public class ZkCLITest extends SolrTestCaseJ4 {
assertEquals(confsetname, collectionProps.getStr("configName"));
// test down config
- File confDir = new File(TEMP_DIR,
- "solrtest-confdropspot-" + this.getClass().getName() + "-" + System.currentTimeMillis());
-
+ File confDir = new File(TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()), "solrtest-confdropspot");
assertFalse(confDir.exists());
-
+
args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
"downconfig", "-confdir", confDir.getAbsolutePath(), "-confname", confsetname};
ZkCLI.main(args);
@@ -281,8 +281,7 @@ public class ZkCLITest extends SolrTestCaseJ4 {
byte [] data = new String("getFileNode-data").getBytes("UTF-8");
this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true);
- File file = new File(TEMP_DIR,
- "solrtest-getfile-" + this.getClass().getName() + "-" + System.currentTimeMillis());
+ File file = TestUtil.createTempFile("solrtest-getfile", "");
String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
"getfile", getNode, file.getAbsolutePath()};
ZkCLI.main(args);
@@ -295,8 +294,7 @@ public class ZkCLITest extends SolrTestCaseJ4 {
public void testGetFileNotExists() throws Exception {
String getNode = "/getFileNotExistsNode";
- File file = new File(TEMP_DIR,
- "solrtest-getfilenotexists-" + this.getClass().getName() + "-" + System.currentTimeMillis());
+ File file = TestUtil.createTempFile("solrtest-getfilenotexists", "");
String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
"getfile", getNode, file.getAbsolutePath()};
try {
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsBasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsBasicDistributedZk2Test.java
index 2e343eb4cdf..7ecff9bfdd7 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsBasicDistributedZk2Test.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsBasicDistributedZk2Test.java
@@ -17,11 +17,11 @@ package org.apache.solr.cloud.hdfs;
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.util.LuceneTestCase.Slow;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.cloud.BasicDistributedZk2Test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -38,9 +38,7 @@ public class HdfsBasicDistributedZk2Test extends BasicDistributedZk2Test {
@BeforeClass
public static void setupClass() throws Exception {
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsBasicDistributedZk2Test.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
}
@AfterClass
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsBasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsBasicDistributedZkTest.java
index 8f7486d5ad0..3ea2f338de0 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsBasicDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsBasicDistributedZkTest.java
@@ -21,6 +21,7 @@ import java.io.File;
import java.io.IOException;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.cloud.BasicDistributedZkTest;
import org.junit.AfterClass;
@@ -38,9 +39,7 @@ public class HdfsBasicDistributedZkTest extends BasicDistributedZkTest {
@BeforeClass
public static void setupClass() throws Exception {
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsBasicDistributedZk2Test.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
}
@AfterClass
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsChaosMonkeySafeLeaderTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsChaosMonkeySafeLeaderTest.java
index 7e49963a226..1c70919310e 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsChaosMonkeySafeLeaderTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsChaosMonkeySafeLeaderTest.java
@@ -17,11 +17,11 @@ package org.apache.solr.cloud.hdfs;
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.util.LuceneTestCase.Slow;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.cloud.ChaosMonkeySafeLeaderTest;
import org.junit.AfterClass;
import org.junit.Before;
@@ -39,9 +39,7 @@ public class HdfsChaosMonkeySafeLeaderTest extends ChaosMonkeySafeLeaderTest {
@BeforeClass
public static void setupClass() throws Exception {
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsBasicDistributedZk2Test.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
}
@AfterClass
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsCollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsCollectionsAPIDistributedZkTest.java
index 226df65c8a7..7c16f33cf2a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsCollectionsAPIDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsCollectionsAPIDistributedZkTest.java
@@ -21,6 +21,7 @@ import java.io.File;
import java.io.IOException;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.cloud.CollectionsAPIDistributedZkTest;
import org.junit.AfterClass;
@@ -38,9 +39,7 @@ public class HdfsCollectionsAPIDistributedZkTest extends CollectionsAPIDistribut
@BeforeClass
public static void setupClass() throws Exception {
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsCollectionsAPIDistributedZkTest.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
System.setProperty("solr.hdfs.home", dfsCluster.getURI().toString() + "/solr");
System.setProperty("solr.hdfs.blockcache.enabled", "false");
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsRecoveryZkTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsRecoveryZkTest.java
index c9ee82f5100..9ccf613daa3 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsRecoveryZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsRecoveryZkTest.java
@@ -38,9 +38,7 @@ public class HdfsRecoveryZkTest extends RecoveryZkTest {
@BeforeClass
public static void setupClass() throws Exception {
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsBasicDistributedZk2Test.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
System.setProperty("solr.hdfs.blockcache.blocksperbank", "2048");
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsSyncSliceTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsSyncSliceTest.java
index f0a73bd1955..36aab7dfbcd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsSyncSliceTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsSyncSliceTest.java
@@ -40,9 +40,7 @@ public class HdfsSyncSliceTest extends SyncSliceTest {
@BeforeClass
public static void setupClass() throws Exception {
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsBasicDistributedZk2Test.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
}
@AfterClass
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsTestUtil.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsTestUtil.java
index 1384cb270d0..6c440a4b1be 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsTestUtil.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsTestUtil.java
@@ -13,6 +13,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
/*
@@ -38,11 +39,11 @@ public class HdfsTestUtil {
private static Map<MiniDFSCluster,Timer> timers = new ConcurrentHashMap<>();
- public static MiniDFSCluster setupClass(String dataDir) throws Exception {
+ public static MiniDFSCluster setupClass() throws Exception {
LuceneTestCase.assumeFalse("HDFS tests were disabled by -Dtests.disableHdfs",
Boolean.parseBoolean(System.getProperty("tests.disableHdfs", "false")));
- File dir = new File(dataDir);
- new File(dataDir).mkdirs();
+
+ File dir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
savedLocale = Locale.getDefault();
// TODO: we HACK around HADOOP-9643
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsUnloadDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsUnloadDistributedZkTest.java
index 7f89b79e94a..9600730a032 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsUnloadDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsUnloadDistributedZkTest.java
@@ -21,6 +21,8 @@ import java.io.File;
import java.io.IOException;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.cloud.UnloadDistributedZkTest;
import org.junit.AfterClass;
@@ -38,9 +40,7 @@ public class HdfsUnloadDistributedZkTest extends UnloadDistributedZkTest {
@BeforeClass
public static void setupClass() throws Exception {
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsUnloadDistributedZkTest.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
}
@AfterClass
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java
index a43ef3c27ef..3b6761b37c2 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java
@@ -26,6 +26,8 @@ import java.util.List;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.NRTCachingDirectory;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Nightly;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrQuery;
@@ -60,9 +62,7 @@ public class HdfsWriteToMultipleCollectionsTest extends BasicDistributedZkTest {
@BeforeClass
public static void setupClass() throws Exception {
schemaString = "schema15.xml"; // we need a string id
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsBasicDistributedZk2Test.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
System.setProperty(SOLR_HDFS_HOME, dfsCluster.getURI().toString() + "/solr");
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java
index 7e4f72ae0b6..e2dadaa2bb4 100644
--- a/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java
@@ -32,6 +32,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
@@ -62,10 +63,7 @@ public class StressHdfsTest extends BasicDistributedZkTest {
@BeforeClass
public static void setupClass() throws Exception {
-
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsBasicDistributedZk2Test.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
System.setProperty("solr.hdfs.home", dfsCluster.getURI().toString() + "/solr");
}
@@ -182,8 +180,7 @@ public class StressHdfsTest extends BasicDistributedZkTest {
NamedList<Object> response = c.query(
new SolrQuery().setRequestHandler("/admin/system")).getResponse();
NamedList<Object> coreInfo = (NamedList<Object>) response.get("core");
- String dataDir = (String) ((NamedList<Object>) coreInfo
- .get("directory")).get("data");
+ String dataDir = (String) ((NamedList<Object>) coreInfo.get("directory")).get("data");
dataDirs.add(dataDir);
} finally {
c.shutdown();
diff --git a/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java b/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
index 78fc6cf2919..802c8f5931e 100644
--- a/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
+++ b/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java
@@ -17,18 +17,20 @@
package org.apache.solr.core;
+import java.io.File;
+import java.util.Collection;
+import java.util.Map;
+import java.util.regex.Pattern;
+
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.junit.After;
import org.xml.sax.SAXParseException;
-import java.io.File;
-import java.util.Collection;
-import java.util.Map;
-import java.util.regex.Pattern;
-
public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
File solrHome = null;
@@ -37,8 +39,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
private void init(final String dirSuffix) {
// would be nice to do this in an @Before method,
// but junit doesn't let @Before methods have test names
- solrHome = new File(TEMP_DIR, this.getClass().getName() + "_" + dirSuffix);
- assertTrue("Failed to mkdirs solrhome [" + solrHome + "]", solrHome.mkdirs());
+ solrHome = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + dirSuffix);
}
@After
diff --git a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java
index 97c8bf6c975..497471c47a5 100644
--- a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java
+++ b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java
@@ -30,7 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.io.FileUtils;
-import org.apache.lucene.util.LuceneTestCase.BadApple;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -86,9 +87,7 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
coreNames = new ArrayList<>();
cumulativeDocs = 0;
- solrHomeDirectory = new File(TEMP_DIR, "OpenCloseCoreStressTest_");
- FileUtils.deleteDirectory(solrHomeDirectory); // Ensure that a failed test didn't leave something lying around.
-
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
jetty = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), "/solr", 0, null, null, true, null, sslConfig);
}
diff --git a/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java b/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java
index c9ea6d8bad1..38a03344f98 100644
--- a/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java
+++ b/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java
@@ -60,7 +60,7 @@ public class ResourceLoaderTest extends SolrTestCaseJ4
}
public void testEscapeInstanceDir() throws Exception {
- File temp = TestUtil.getTempDir("testEscapeInstanceDir");
+ File temp = TestUtil.createTempDir("testEscapeInstanceDir");
try {
temp.mkdirs();
new File(temp, "dummy.txt").createNewFile();
@@ -170,7 +170,7 @@ public class ResourceLoaderTest extends SolrTestCaseJ4
}
public void testClassLoaderLibs() throws Exception {
- File tmpRoot = TestUtil.getTempDir("testClassLoaderLibs");
+ File tmpRoot = TestUtil.createTempDir("testClassLoaderLibs");
File lib = new File(tmpRoot, "lib");
lib.mkdirs();
diff --git a/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java b/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
index 567b1bec9ce..6d9f06ca1af 100644
--- a/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
+++ b/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
@@ -33,7 +33,8 @@ import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.Version;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.handler.SnapPuller;
@@ -73,11 +74,7 @@ public class TestArbitraryIndexDir extends AbstractSolrTestCase{
public void setUp() throws Exception {
super.setUp();
- dataDir = new File(TEMP_DIR,
- getClass().getName() + "-" + System.currentTimeMillis() + System.getProperty("file.separator") + "solr"
- + System.getProperty("file.separator") + "data");
- dataDir.mkdirs();
-
+ dataDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
solrConfig = TestHarness.createConfig(getSolrHome(), "solrconfig.xml");
h = new TestHarness( dataDir.getAbsolutePath(),
solrConfig,
diff --git a/solr/core/src/test/org/apache/solr/core/TestConfigSets.java b/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
index 1b8de6a55a1..0540976e8bd 100644
--- a/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
+++ b/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
@@ -17,21 +17,24 @@ package org.apache.solr.core;
* limitations under the License.
*/
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.core.Is.is;
+import static org.junit.internal.matchers.StringContains.containsString;
+
+import java.io.File;
+import java.io.IOException;
+
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
-import java.io.File;
-import java.io.IOException;
-
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.Is.is;
-import static org.junit.internal.matchers.StringContains.containsString;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
public class TestConfigSets extends SolrTestCaseJ4 {
@@ -41,10 +44,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
public static String solrxml = "<solr><str name=\"configSetBaseDir\">${configsets:configsets}</str></solr>";
public CoreContainer setupContainer(String testName, String configSetsBaseDir) {
-
- File testDirectory = new File(TEMP_DIR, testName);
- testDirectory.mkdirs();
-
+ File testDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + "-" + testName);
System.setProperty("configsets", configSetsBaseDir);
SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());
@@ -95,8 +95,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
@Test
public void testConfigSetOnCoreReload() throws IOException {
- File testDirectory = new File(TEMP_DIR, "core-reload");
- testDirectory.mkdirs();
+ File testDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + "-core-reload");
File configSetsDir = new File(testDirectory, "configsets");
FileUtils.copyDirectory(getFile("solr/configsets"), configSetsDir);
diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
index 8aaf209f19e..d08dc8ec228 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@ -17,19 +17,9 @@
package org.apache.solr.core;
-import org.apache.commons.io.FileUtils;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.TestUtil;
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.handler.admin.CollectionsHandler;
-import org.apache.solr.handler.admin.CoreAdminHandler;
-import org.apache.solr.handler.admin.InfoHandler;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.xml.sax.SAXException;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import javax.xml.parsers.ParserConfigurationException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
@@ -40,8 +30,20 @@ import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.handler.admin.CollectionsHandler;
+import org.apache.solr.handler.admin.CoreAdminHandler;
+import org.apache.solr.handler.admin.InfoHandler;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.xml.sax.SAXException;
public class TestCoreContainer extends SolrTestCaseJ4 {
@@ -67,12 +69,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
private CoreContainer init(String dirName) throws Exception {
- solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName() + dirName);
-
- if (solrHomeDirectory.exists()) {
- FileUtils.deleteDirectory(solrHomeDirectory);
- }
- assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + dirName);
FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory);
System.out.println("Using solrconfig from " + new File(SolrTestCaseJ4.TEST_HOME()).getAbsolutePath());
@@ -151,8 +148,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
@Test
public void testNoCores() throws IOException, ParserConfigurationException, SAXException {
//create solrHome
- File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName()
- + "_noCores");
+ File solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + "_noCores");
boolean oldSolrXml = random().nextBoolean();
@@ -238,7 +234,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
@Test
public void testSharedLib() throws Exception {
- File tmpRoot = TestUtil.getTempDir("testSharedLib");
+ File tmpRoot = TestUtil.createTempDir("testSharedLib");
File lib = new File(tmpRoot, "lib");
lib.mkdirs();
diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java b/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
index 4bda2adb723..93ad1bd17fc 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
@@ -17,20 +17,22 @@ package org.apache.solr.core;
* limitations under the License.
*/
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.Properties;
+
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.Properties;
-
public class TestCoreDiscovery extends SolrTestCaseJ4 {
@BeforeClass
@@ -38,14 +40,10 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
initCore();
}
- private final File solrHomeDirectory = new File(TEMP_DIR, "org.apache.solr.core.TestCoreDiscovery" + File.separator + "solrHome");
+ private File solrHomeDirectory;
private void setMeUp(String alternateCoreDir) throws Exception {
- if (solrHomeDirectory.exists()) {
- FileUtils.deleteDirectory(solrHomeDirectory);
- }
- assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
-
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
System.setProperty("solr.solr.home", solrHomeDirectory.getAbsolutePath());
String xmlStr = SOLR_XML;
if (alternateCoreDir != null) {
@@ -198,9 +196,7 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
@Test
public void testAlternateCoreDir() throws Exception {
- File alt = new File(TEMP_DIR, "alternateCoreDir");
- if (alt.exists()) FileUtils.deleteDirectory(alt);
- alt.mkdirs();
+ File alt = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
setMeUp(alt.getAbsolutePath());
addCoreWithProps(makeCorePropFile("core1", false, true, "dataDir=core1"),
new File(alt, "core1" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
@@ -218,9 +214,7 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
}
@Test
public void testNoCoreDir() throws Exception {
- File noCoreDir = new File(TEMP_DIR, "noCoreDir");
- if (noCoreDir.exists()) FileUtils.deleteDirectory(noCoreDir);
- noCoreDir.mkdirs();
+ File noCoreDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
setMeUp(noCoreDir.getAbsolutePath());
addCoreWithProps(makeCorePropFile("core1", false, true),
new File(noCoreDir, "core1" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
diff --git a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
index 187d62c91b4..762deca5647 100644
--- a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
+++ b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
@@ -17,8 +17,20 @@ package org.apache.solr.core;
* limitations under the License.
*/
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
@@ -35,16 +47,6 @@ import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-
public class TestLazyCores extends SolrTestCaseJ4 {
@BeforeClass
@@ -52,14 +54,10 @@ public class TestLazyCores extends SolrTestCaseJ4 {
initCore("solrconfig-minimal.xml", "schema-tiny.xml");
}
- private final File solrHomeDirectory = new File(TEMP_DIR, TestLazyCores.getSimpleClassName());
+ private File solrHomeDirectory;
private CoreContainer init() throws Exception {
-
- if (solrHomeDirectory.exists()) {
- FileUtils.deleteDirectory(solrHomeDirectory);
- }
- assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
for (int idx = 1; idx < 10; ++idx) {
copyMinConf(new File(solrHomeDirectory, "collection" + idx));
}
diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java b/solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java
index 775fcb052b1..c8e84fbe4ad 100644
--- a/solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java
@@ -81,7 +81,7 @@ public class TestSolrXMLSerializer extends LuceneTestCase {
assertResults(((StringWriter) w).getBuffer().toString().getBytes("UTF-8"));
// again with default file
- File tmpFile = TestUtil.createTempFile("solr.xml", null, TEMP_DIR);
+ File tmpFile = TestUtil.createTempFile("solr.xml", null);
serializer.persistFile(tmpFile, solrXMLDef);
diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXml.java b/solr/core/src/test/org/apache/solr/core/TestSolrXml.java
index 60bd801339b..65be5a07155 100644
--- a/solr/core/src/test/org/apache/solr/core/TestSolrXml.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXml.java
@@ -17,23 +17,32 @@ package org.apache.solr.core;
* limitations under the License.
*/
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import java.io.File;
+import java.io.IOException;
+
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
-import java.io.File;
-import java.io.IOException;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
public class TestSolrXml extends SolrTestCaseJ4 {
@Rule
public TestRule solrTestRules = RuleChain.outerRule(new SystemPropertiesRestoreRule());
- private final File solrHome = new File(TEMP_DIR, TestSolrXml.getClassName() + File.separator + "solrHome");
+ private File solrHome;
+
+ @Before
+ public void setupTest() {
+ solrHome = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ }
@Test
public void testAllInfoPresent() throws IOException {
diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java
index ea0fb3c1909..478acff1230 100644
--- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java
@@ -17,16 +17,31 @@
package org.apache.solr.core;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
-import com.google.common.base.Charsets;
+import static org.hamcrest.core.Is.is;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.TestHarness;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
@@ -37,30 +52,23 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.hamcrest.core.Is.is;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import com.google.common.base.Charsets;
public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
- private File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName());
+ private File solrHomeDirectory;
@Rule
public TestRule solrTestRules =
RuleChain.outerRule(new SystemPropertiesRestoreRule());
+ @Before
+ public void setupTest() {
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ }
private CoreContainer init(String solrXmlString, String... subDirs) throws Exception {
-
createTempDir();
solrHomeDirectory = dataDir;
diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java
index 647dab603e1..4052e754c97 100644
--- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistor.java
@@ -22,6 +22,8 @@ import java.io.IOException;
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.SolrTestCaseJ4;
import org.junit.Test;
@@ -62,7 +64,7 @@ public class TestSolrXmlPersistor extends SolrTestCaseJ4 {
final String solrxml = "<solr><cores></cores></solr>";
- final File solrHomeDirectory = new File(TEMP_DIR, "ZkControllerTest");
+ final File solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
try {
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
diff --git a/solr/core/src/test/org/apache/solr/handler/PingRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/PingRequestHandlerTest.java
index 8cf4c02b292..6d17d1d4467 100644
--- a/solr/core/src/test/org/apache/solr/handler/PingRequestHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/PingRequestHandlerTest.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
@@ -54,7 +55,7 @@ public class PingRequestHandlerTest extends SolrTestCaseJ4 {
// sometimes randomly use an absolute File path instead
if (random().nextBoolean()) {
- healthcheckFile = new File(TEMP_DIR, fileName);
+ healthcheckFile = TestUtil.createTempFile(fileName, "");
fileNameParam = healthcheckFile.getAbsolutePath();
}
diff --git a/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java b/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java
index 4000d478d5a..2eb1b066a29 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java
@@ -50,7 +50,7 @@ public class TestCSVLoader extends SolrTestCaseJ4 {
// if you override setUp or tearDown, you better call
// the super classes version
super.setUp();
- File tempDir = TestUtil.getTempDir("TestCSVLoader");
+ File tempDir = TestUtil.createTempDir("TestCSVLoader");
file = new File(tempDir, "solr_tmp.csv");
filename = file.getPath();
cleanup();
diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
index 6c87ee3e44a..f5f91cbb15b 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
@@ -44,6 +44,7 @@ import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.SimpleFSDirectory;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.BaseDistributedSearchTestCase;
import org.apache.solr.SolrTestCaseJ4;
@@ -1594,10 +1595,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
- File home = new File(TEMP_DIR,
- getClass().getName() + "-" +
- System.currentTimeMillis());
-
+ File home = TestUtil.createTempDir(getClass().getName());
homeDir = new File(home, name);
dataDir = new File(homeDir + "/collection1", "data");
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java
index ad9f3ccd25d..2ad8de15210 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java
@@ -19,6 +19,7 @@ package org.apache.solr.handler.admin;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
@@ -49,7 +50,7 @@ public class CoreAdminCreateDiscoverTest extends SolrTestCaseJ4 {
public static void beforeClass() throws Exception {
useFactory(null); // I require FS-based indexes for this test.
- solrHomeDirectory = new File(TEMP_DIR, "solrHome/" + CoreAdminCreateDiscoverTest.getClassName());
+ solrHomeDirectory = TestUtil.createTempDir(CoreAdminCreateDiscoverTest.getClassName());
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
index bb9001e9773..dfe39323cc6 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
@@ -17,9 +17,13 @@
package org.apache.solr.handler.admin;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import java.io.File;
+import java.util.Map;
+
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
@@ -39,8 +43,7 @@ import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
-import java.io.File;
-import java.util.Map;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
@@ -58,12 +61,8 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
public void testCreateWithSysVars() throws Exception {
useFactory(null); // I require FS-based indexes for this test.
- final File workDir = new File(TEMP_DIR, getCoreName());
+ final File workDir = TestUtil.createTempDir(getCoreName());
- if (workDir.exists()) {
- FileUtils.deleteDirectory(workDir);
- }
- assertTrue("Failed to mkdirs workDir", workDir.mkdirs());
String coreName = "with_sys_vars";
File instDir = new File(workDir, coreName);
File subHome = new File(instDir, "conf");
@@ -133,7 +132,7 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
@Test
public void testCoreAdminHandler() throws Exception {
- final File workDir = new File(TEMP_DIR, this.getClass().getName());
+ final File workDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
if (workDir.exists()) {
FileUtils.deleteDirectory(workDir);
@@ -224,9 +223,7 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
@Test
public void testDeleteInstanceDir() throws Exception {
- File solrHomeDirectory = new File(TEMP_DIR, getClass().getName() + "-corex-"
- + System.currentTimeMillis());
- solrHomeDirectory.mkdirs();
+ File solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
copySolrHomeToTemp(solrHomeDirectory, "corex", true);
File corex = new File(solrHomeDirectory, "corex");
FileUtils.write(new File(corex, "core.properties"), "", Charsets.UTF_8.toString());
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminRequestStatusTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminRequestStatusTest.java
index 091398b4ba6..7161b91bc05 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminRequestStatusTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminRequestStatusTest.java
@@ -17,7 +17,11 @@ package org.apache.solr.handler.admin;
* limitations under the License.
*/
+import java.io.File;
+
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.core.CoreContainer;
@@ -26,8 +30,6 @@ import org.apache.solr.response.SolrQueryResponse;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-
public class CoreAdminRequestStatusTest extends SolrTestCaseJ4{
@BeforeClass
@@ -37,13 +39,7 @@ public class CoreAdminRequestStatusTest extends SolrTestCaseJ4{
@Test
public void testCoreAdminRequestStatus() throws Exception {
- final File workDir = new File(TEMP_DIR, this.getClass().getName());
-
- if (workDir.exists()) {
- FileUtils.deleteDirectory(workDir);
- }
- assertTrue("Failed to mkdirs workDir", workDir.mkdirs());
-
+ final File workDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
final CoreContainer cores = h.getCoreContainer();
final CoreAdminHandler admin = new CoreAdminHandler(cores);
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java
index c9ceeb582a5..778c48c4490 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreMergeIndexesAdminHandlerTest.java
@@ -17,9 +17,13 @@ package org.apache.solr.handler.admin;
* limitations under the License.
*/
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import java.io.File;
+import java.io.IOException;
+
import org.apache.commons.io.FileUtils;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.core.CoreContainer;
@@ -32,8 +36,7 @@ import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
-import java.io.File;
-import java.io.IOException;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
public class CoreMergeIndexesAdminHandlerTest extends SolrTestCaseJ4 {
@@ -68,7 +71,7 @@ public class CoreMergeIndexesAdminHandlerTest extends SolrTestCaseJ4 {
@Test
public void testMergeIndexesCoreAdminHandler() throws Exception {
- final File workDir = new File(TEMP_DIR, this.getClass().getName());
+ final File workDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
if (workDir.exists()) {
FileUtils.deleteDirectory(workDir);
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
index 51b2bb69848..7a09dd60f4d 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
@@ -3,6 +3,7 @@ package org.apache.solr.handler.component;
import java.io.File;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
@@ -48,7 +49,7 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
}
private static File createSolrHome() throws Exception {
- File workDir = new File(TEMP_DIR, DistributedDebugComponentTest.class.getName());
+ File workDir = TestUtil.createTempDir(DistributedDebugComponentTest.class.getName());
setupJettyTestHome(workDir, "collection1");
FileUtils.copyDirectory(new File(workDir, "collection1"), new File(workDir, "collection2"));
return workDir;
diff --git a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
index 03cb1d8deef..24cb6efccd2 100644
--- a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
+++ b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
@@ -18,6 +18,8 @@ package org.apache.solr.request;
*/
import org.apache.commons.io.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrQuery;
@@ -48,12 +50,12 @@ import java.net.URLEncoder;
*/
@SuppressSSL // does not yet work with ssl yet - uses raw java.net.URL API rather than HttpClient
public class TestRemoteStreaming extends SolrJettyTestBase {
-
- private static final File solrHomeDirectory = new File(TEMP_DIR, "TestRemoteStreaming");
+ private static File solrHomeDirectory;
@BeforeClass
public static void beforeTest() throws Exception {
//this one has handleSelect=true which a test here needs
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
setupJettyTestHome(solrHomeDirectory, "collection1");
createJetty(solrHomeDirectory.getAbsolutePath(), null, null);
}
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java b/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java
index c7a053f006b..fa4b4534da3 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java
@@ -16,7 +16,14 @@ package org.apache.solr.rest.schema;
* limitations under the License.
*/
+import java.io.File;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.regex.Pattern;
+
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.util.RestTestBase;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
@@ -24,11 +31,6 @@ import org.junit.Before;
import org.junit.Test;
import org.restlet.ext.servlet.ServerServlet;
-import java.io.File;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.regex.Pattern;
-
public class TestManagedSchemaFieldResource extends RestTestBase {
private static File tmpSolrHome;
@@ -41,11 +43,10 @@ public class TestManagedSchemaFieldResource extends RestTestBase {
@Before
public void before() throws Exception {
createTempDir();
- tmpSolrHome = new File( TEMP_DIR + File.separator + TestManagedSchemaFieldResource.class.getSimpleName()
- + System.currentTimeMillis());
+ tmpSolrHome = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
tmpConfDir = new File(tmpSolrHome, confDir);
FileUtils.copyDirectory(new File(TEST_HOME()), tmpSolrHome.getAbsoluteFile());
-
+
final SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();
final ServletHolder solrRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);
solrRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
index 08662a1b940..84bc56754a0 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
@@ -22,6 +22,8 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.util.RestTestBase;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
@@ -45,8 +47,7 @@ public class TestManagedStopFilterFactory extends RestTestBase {
@Before
public void before() throws Exception {
createTempDir();
- tmpSolrHome = new File(TEMP_DIR + File.separator + TestManagedStopFilterFactory.class.getSimpleName()
- + System.currentTimeMillis());
+ tmpSolrHome = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
tmpConfDir = new File(tmpSolrHome, confDir);
FileUtils.copyDirectory(new File(TEST_HOME()), tmpSolrHome.getAbsoluteFile());
diff --git a/solr/core/src/test/org/apache/solr/schema/ChangedSchemaMergeTest.java b/solr/core/src/test/org/apache/solr/schema/ChangedSchemaMergeTest.java
index d172cb3be76..eaa1708d8cf 100644
--- a/solr/core/src/test/org/apache/solr/schema/ChangedSchemaMergeTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/ChangedSchemaMergeTest.java
@@ -17,8 +17,13 @@
package org.apache.solr.schema;
+import java.io.File;
+import java.io.IOException;
+
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.CoreContainer;
@@ -31,16 +36,13 @@ import org.apache.solr.update.UpdateHandler;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.io.IOException;
-
public class ChangedSchemaMergeTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
initCore();
}
- private final File solrHomeDirectory = new File(TEMP_DIR, getSimpleClassName());
+ private File solrHomeDirectory;
private File schemaFile = null;
private void addDoc(SolrCore core, String... fieldValues) throws IOException {
@@ -51,11 +53,7 @@ public class ChangedSchemaMergeTest extends SolrTestCaseJ4 {
}
private CoreContainer init() throws Exception {
-
- if (solrHomeDirectory.exists()) {
- FileUtils.deleteDirectory(solrHomeDirectory);
- }
- assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
File changed = new File(solrHomeDirectory, "changed");
copyMinConf(changed, "name=changed");
// Overlay with my local schema
diff --git a/solr/core/src/test/org/apache/solr/schema/ModifyConfFileTest.java b/solr/core/src/test/org/apache/solr/schema/ModifyConfFileTest.java
index 0fe67441000..be6c2c9b5cf 100644
--- a/solr/core/src/test/org/apache/solr/schema/ModifyConfFileTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/ModifyConfFileTest.java
@@ -17,9 +17,15 @@
package org.apache.solr.schema;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import static org.junit.internal.matchers.StringContains.containsString;
+
+import java.io.File;
+import java.util.ArrayList;
+
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ContentStream;
@@ -36,13 +42,10 @@ import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
-import java.io.File;
-import java.util.ArrayList;
-
-import static org.junit.internal.matchers.StringContains.containsString;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
public class ModifyConfFileTest extends SolrTestCaseJ4 {
- private File solrHomeDirectory = new File(TEMP_DIR, this.getClass().getName());
+ private File solrHomeDirectory;
@Rule
public TestRule solrTestRules = RuleChain.outerRule(new SystemPropertiesRestoreRule());
@@ -51,10 +54,7 @@ public class ModifyConfFileTest extends SolrTestCaseJ4 {
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
- if (solrHomeDirectory.exists()) {
- FileUtils.deleteDirectory(solrHomeDirectory);
- }
- assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
+ solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
copySolrHomeToTemp(solrHomeDirectory, "core1", true);
FileUtils.write(new File(new File(solrHomeDirectory, "core1"), "core.properties"), "", Charsets.UTF_8.toString());
diff --git a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
index 2c0a8203de5..da47ba481b7 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
@@ -22,6 +22,7 @@ import java.util.List;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrQuery;
@@ -35,8 +36,7 @@ public class TestBinaryField extends SolrJettyTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- File homeDir = new File(TEMP_DIR,
- "solrtest-TestBinaryField-" + System.currentTimeMillis());
+ File homeDir = TestUtil.createTempDir("solrtest-TestBinaryField");
File collDir = new File(homeDir, "collection1");
File dataDir = new File(collDir, "data");
File confDir = new File(collDir, "conf");
diff --git a/solr/core/src/test/org/apache/solr/schema/TestCollationField.java b/solr/core/src/test/org/apache/solr/schema/TestCollationField.java
index 71a5733bb60..e501e5f23b3 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestCollationField.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestCollationField.java
@@ -63,7 +63,7 @@ public class TestCollationField extends SolrTestCaseJ4 {
*/
public static String setupSolrHome() throws Exception {
// make a solr home underneath the test's TEMP_DIR
- File tmpFile = TestUtil.getTempDir("collation1");
+ File tmpFile = TestUtil.createTempDir("collation1");
tmpFile.delete();
tmpFile.mkdir();
diff --git a/solr/core/src/test/org/apache/solr/schema/TestCollationFieldDocValues.java b/solr/core/src/test/org/apache/solr/schema/TestCollationFieldDocValues.java
index a3f489ed28e..8fc326eecc1 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestCollationFieldDocValues.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestCollationFieldDocValues.java
@@ -65,7 +65,7 @@ public class TestCollationFieldDocValues extends SolrTestCaseJ4 {
*/
public static String setupSolrHome() throws Exception {
// make a solr home underneath the test's TEMP_DIR
- File tmpFile = TestUtil.getTempDir("collation1");
+ File tmpFile = TestUtil.createTempDir("collation1");
tmpFile.delete();
tmpFile.mkdir();
diff --git a/solr/core/src/test/org/apache/solr/schema/TestManagedSchema.java b/solr/core/src/test/org/apache/solr/schema/TestManagedSchema.java
index 2c95ef6c86d..4cf082f41c9 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestManagedSchema.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestManagedSchema.java
@@ -16,8 +16,17 @@ package org.apache.solr.schema;
* limitations under the License.
*/
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.util.NamedList;
@@ -29,13 +38,6 @@ import org.apache.solr.response.SolrQueryResponse;
import org.junit.After;
import org.junit.Before;
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
public class TestManagedSchema extends AbstractBadConfigTestBase {
private static File tmpSolrHome;
@@ -47,8 +49,7 @@ public class TestManagedSchema extends AbstractBadConfigTestBase {
@Before
private void initManagedSchemaCore() throws Exception {
createTempDir();
- final String tmpSolrHomePath
- = TEMP_DIR + File.separator + TestManagedSchema.class.getSimpleName() + System.currentTimeMillis();
+ final String tmpSolrHomePath = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
tmpSolrHome = new File(tmpSolrHomePath).getAbsoluteFile();
tmpConfDir = new File(tmpSolrHome, confDir);
File testHomeConfDir = new File(TEST_HOME(), confDir);
diff --git a/solr/core/src/test/org/apache/solr/search/TestAddFieldRealTimeGet.java b/solr/core/src/test/org/apache/solr/search/TestAddFieldRealTimeGet.java
index 392f038e4dd..b59d3fae822 100644
--- a/solr/core/src/test/org/apache/solr/search/TestAddFieldRealTimeGet.java
+++ b/solr/core/src/test/org/apache/solr/search/TestAddFieldRealTimeGet.java
@@ -17,15 +17,16 @@ package org.apache.solr.search;
* limitations under the License.
*/
+import java.io.File;
+import java.util.Collections;
+
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
-import org.apache.solr.schema.TestManagedSchema;
import org.junit.Before;
-import java.io.File;
-import java.util.Collections;
-
public class TestAddFieldRealTimeGet extends TestRTGBase {
private static File tmpSolrHome;
@@ -37,8 +38,7 @@ public class TestAddFieldRealTimeGet extends TestRTGBase {
@Before
private void initManagedSchemaCore() throws Exception {
createTempDir();
- final String tmpSolrHomePath
- = TEMP_DIR + File.separator + TestManagedSchema.class.getSimpleName() + System.currentTimeMillis();
+ final String tmpSolrHomePath = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
tmpSolrHome = new File(tmpSolrHomePath).getAbsoluteFile();
tmpConfDir = new File(tmpSolrHome, confDir);
File testHomeConfDir = new File(TEST_HOME(), confDir);
@@ -46,7 +46,7 @@ public class TestAddFieldRealTimeGet extends TestRTGBase {
final String schemaFileName = "schema-id-and-version-fields-only.xml";
FileUtils.copyFileToDirectory(new File(testHomeConfDir, configFileName), tmpConfDir);
FileUtils.copyFileToDirectory(new File(testHomeConfDir, schemaFileName), tmpConfDir);
- FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"), tmpConfDir);
+ FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"), tmpConfDir);
// initCore will trigger an upgrade to managed schema, since the solrconfig has
// <schemaFactory class="ManagedIndexSchemaFactory" ... />
diff --git a/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java b/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java
index 9de9d3bf73f..57d4b80b133 100644
--- a/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java
+++ b/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java
@@ -40,6 +40,8 @@ import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.cloud.hdfs.HdfsBasicDistributedZk2Test;
import org.apache.solr.cloud.hdfs.HdfsTestUtil;
@@ -76,9 +78,7 @@ public class TestRecoveryHdfs extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
- dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
- HdfsBasicDistributedZk2Test.class.getName() + "_"
- + System.currentTimeMillis()).getAbsolutePath());
+ dfsCluster = HdfsTestUtil.setupClass();
hdfsUri = dfsCluster.getFileSystem().getUri().toString();
try {
diff --git a/solr/core/src/test/org/apache/solr/search/TestSearcherReuse.java b/solr/core/src/test/org/apache/solr/search/TestSearcherReuse.java
index 27c7986d9a1..416bb36e2d6 100644
--- a/solr/core/src/test/org/apache/solr/search/TestSearcherReuse.java
+++ b/solr/core/src/test/org/apache/solr/search/TestSearcherReuse.java
@@ -23,6 +23,7 @@ import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.ManagedIndexSchema;
+import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.commons.io.FileUtils;
@@ -55,7 +56,7 @@ public class TestSearcherReuse extends SolrTestCaseJ4 {
@BeforeClass
private static void setupTempDirAndCoreWithManagedSchema() throws Exception {
createTempDir();
- solrHome = new File(TEMP_DIR, TestSearcherReuse.class.getSimpleName());
+ solrHome = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
solrHome = solrHome.getAbsoluteFile();
File confDir = new File(solrHome, confPath);
diff --git a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
index d4f9e1bb7ac..aedb2cd031d 100644
--- a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
@@ -39,10 +39,11 @@ import com.google.common.base.Charsets;
* A test case for the several HTTP cache headers emitted by Solr
*/
public class CacheHeaderTest extends CacheHeaderTestBase {
- private static final File solrHomeDirectory = new File(TEMP_DIR, "CacheHeaderTest");
+ private static File solrHomeDirectory;
@BeforeClass
public static void beforeTest() throws Exception {
+ solrHomeDirectory = TestUtil.createTempDir("CacheHeaderTest");
setupJettyTestHome(solrHomeDirectory, "collection1");
createJetty(solrHomeDirectory.getAbsolutePath(), null, null);
}
@@ -253,7 +254,7 @@ public class CacheHeaderTest extends CacheHeaderTestBase {
protected File makeFile(String contents, String charset) {
try {
- File f = TestUtil.createTempFile("cachetest_csv", null, TEMP_DIR);
+ File f = TestUtil.createTempFile("cachetest_csv", null);
Writer out = new OutputStreamWriter(new FileOutputStream(f), charset);
out.write(contents);
out.close();
diff --git a/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java b/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java
index dc8ba81e3a3..51452101104 100644
--- a/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java
+++ b/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java
@@ -17,21 +17,22 @@
package org.apache.solr.spelling;
+import java.io.File;
+import java.util.Collection;
+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.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.util.RefCounted;
-import org.apache.lucene.analysis.Token;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.util.Date;
-import java.util.Map;
-import java.util.Collection;
-
/**
*
* @since solr 1.3
@@ -68,8 +69,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {
spellchecker.add(AbstractLuceneSpellChecker.LOCATION, "spellings.txt");
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "teststop");
spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8");
- File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
- indexDir.mkdirs();
+ File indexDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
SolrCore core = h.getCore();
String dictName = checker.init(spellchecker, core);
@@ -104,8 +104,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {
spellchecker.add(AbstractLuceneSpellChecker.LOCATION, "spellings.txt");
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "teststop");
spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8");
- File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
- indexDir.mkdirs();
+ File indexDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(SolrSpellChecker.FIELD_TYPE, "teststop");
spellchecker.add(AbstractLuceneSpellChecker.SPELLCHECKER_ARG_NAME, spellchecker);
diff --git a/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java b/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java
index a16dd6810bc..f06fcbbd085 100644
--- a/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java
+++ b/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java
@@ -16,6 +16,12 @@
*/
package org.apache.solr.spelling;
+import java.io.File;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Map;
+
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
@@ -31,22 +37,18 @@ import org.apache.lucene.search.spell.SuggestMode;
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;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.SpellCheckComponent;
-import org.apache.solr.util.RefCounted;
import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.util.RefCounted;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.Map;
-
/**
* @since solr 1.3
*/
@@ -108,8 +110,7 @@ public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 {
NamedList spellchecker = new NamedList();
spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
- File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
- indexDir.mkdirs();
+ File indexDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "title");
spellchecker.add(AbstractLuceneSpellChecker.SPELLCHECKER_ARG_NAME, spellchecker);
@@ -184,8 +185,7 @@ public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 {
NamedList spellchecker = new NamedList();
spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
- File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
- indexDir.mkdirs();
+ File indexDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "title");
spellchecker.add(AbstractLuceneSpellChecker.SPELLCHECKER_ARG_NAME, spellchecker);
@@ -241,8 +241,7 @@ public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 {
NamedList spellchecker = new NamedList();
spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
- File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
- indexDir.mkdirs();
+ File indexDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(AbstractLuceneSpellChecker.FIELD, "title");
spellchecker.add(AbstractLuceneSpellChecker.SPELLCHECKER_ARG_NAME, spellchecker);
@@ -281,9 +280,10 @@ public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 {
NamedList spellchecker = new NamedList();
spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
- File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
+ File base = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ File indexDir = new File(base, "spellingIdx");
//create a standalone index
- File altIndexDir = new File(TEMP_DIR, "alternateIdx" + new Date().getTime());
+ File altIndexDir = new File(base, "alternateIdx");
Directory dir = newFSDirectory(altIndexDir);
IndexWriter iw = new IndexWriter(
dir,
diff --git a/solr/core/src/test/org/apache/solr/store/blockcache/BlockDirectoryTest.java b/solr/core/src/test/org/apache/solr/store/blockcache/BlockDirectoryTest.java
index 9dedebd1e4f..5b1730c5635 100644
--- a/solr/core/src/test/org/apache/solr/store/blockcache/BlockDirectoryTest.java
+++ b/solr/core/src/test/org/apache/solr/store/blockcache/BlockDirectoryTest.java
@@ -30,7 +30,7 @@ import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.MergeInfo;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.solr.store.hdfs.HdfsDirectory;
+import org.apache.lucene.util.TestUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -103,9 +103,7 @@ public class BlockDirectoryTest extends LuceneTestCase {
@Before
public void setUp() throws Exception {
super.setUp();
- file = new File(TEMP_DIR, HdfsDirectory.class.getName() + "-" + System.currentTimeMillis());
- rm(file);
- file.mkdirs();
+ file = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
FSDirectory dir = FSDirectory.open(new File(file, "base"));
mapperCache = new MapperCache();
directory = new BlockDirectory("test", dir, mapperCache, null, true, true);
diff --git a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java
index ee571d9a3ba..cc864191852 100644
--- a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java
+++ b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsDirectoryTest.java
@@ -31,6 +31,8 @@ import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.cloud.hdfs.HdfsTestUtil;
import org.junit.After;
@@ -59,9 +61,7 @@ public class HdfsDirectoryTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
createTempDir();
- dfsCluster = HdfsTestUtil.setupClass(TEMP_DIR.getAbsolutePath()
- + File.separator + HdfsDirectoryTest.class.getName() + "_hdfsdir-"
- + System.currentTimeMillis());
+ dfsCluster = HdfsTestUtil.setupClass();
}
@AfterClass
diff --git a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsLockFactoryTest.java b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsLockFactoryTest.java
index 65ce20290d3..5fe7ee34b8e 100644
--- a/solr/core/src/test/org/apache/solr/store/hdfs/HdfsLockFactoryTest.java
+++ b/solr/core/src/test/org/apache/solr/store/hdfs/HdfsLockFactoryTest.java
@@ -17,7 +17,6 @@ package org.apache.solr.store.hdfs;
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
import java.net.URI;
@@ -25,6 +24,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.store.Lock;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.cloud.hdfs.HdfsTestUtil;
import org.junit.After;
@@ -44,11 +44,9 @@ public class HdfsLockFactoryTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
createTempDir();
- dfsCluster = HdfsTestUtil.setupClass(TEMP_DIR.getAbsolutePath()
- + File.separator + HdfsLockFactoryTest.class.getName() + "_hdfsdir-"
- + System.currentTimeMillis());
+ dfsCluster = HdfsTestUtil.setupClass();
}
-
+
@AfterClass
public static void afterClass() throws Exception {
HdfsTestUtil.teardownClass(dfsCluster);
diff --git a/solr/core/src/test/org/apache/solr/update/SolrIndexSplitterTest.java b/solr/core/src/test/org/apache/solr/update/SolrIndexSplitterTest.java
index d12e87e6cd6..b418a34488d 100644
--- a/solr/core/src/test/org/apache/solr/update/SolrIndexSplitterTest.java
+++ b/solr/core/src/test/org/apache/solr/update/SolrIndexSplitterTest.java
@@ -17,11 +17,16 @@ package org.apache.solr.update;
* limitations under the License.
*/
-import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
import org.apache.commons.io.FileUtils;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
@@ -37,9 +42,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.util.List;
+import com.google.common.collect.Lists;
public class SolrIndexSplitterTest extends SolrTestCaseJ4 {
File indexDir1 = null, indexDir2 = null, indexDir3 = null;
@@ -56,12 +59,10 @@ public class SolrIndexSplitterTest extends SolrTestCaseJ4 {
super.setUp();
clearIndex();
assertU(commit());
- indexDir1 = new File(TEMP_DIR, this.getClass().getName()
- + "_testSplit1");
- indexDir2 = new File(TEMP_DIR, this.getClass().getName()
- + "_testSplit2");
- indexDir3 = new File(TEMP_DIR, this.getClass().getName()
- + "_testSplit3");
+ File tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ indexDir1 = new File(tempDir, this.getClass().getName() + "_testSplit1");
+ indexDir2 = new File(tempDir, this.getClass().getName() + "_testSplit2");
+ indexDir3 = new File(tempDir, this.getClass().getName() + "_testSplit3");
if (indexDir1.exists()) {
FileUtils.deleteDirectory(indexDir1);
@@ -269,11 +270,7 @@ public class SolrIndexSplitterTest extends SolrTestCaseJ4 {
@Test
public void testSplitByRouteKey() throws Exception {
- File indexDir = new File(TEMP_DIR, this.getClass().getName() + "testSplitByRouteKey");
- if (indexDir.exists()) {
- FileUtils.deleteDirectory(indexDir);
- }
- indexDir.mkdirs();
+ File indexDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
CompositeIdRouter r1 = new CompositeIdRouter();
String splitKey = "sea-line!";
diff --git a/solr/core/src/test/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactoryTest.java b/solr/core/src/test/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactoryTest.java
index 007d89e02b7..1065995658c 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactoryTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactoryTest.java
@@ -18,6 +18,8 @@
package org.apache.solr.update.processor;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.TestManagedSchema;
@@ -48,8 +50,7 @@ public class AddSchemaFieldsUpdateProcessorFactoryTest extends UpdateProcessorTe
@Before
private void initManagedSchemaCore() throws Exception {
createTempDir();
- final String tmpSolrHomePath
- = TEMP_DIR + File.separator + TestManagedSchema.class.getSimpleName() + System.currentTimeMillis();
+ final String tmpSolrHomePath = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath();
tmpSolrHome = new File(tmpSolrHomePath).getAbsoluteFile();
tmpConfDir = new File(tmpSolrHome, confDir);
File testHomeConfDir = new File(TEST_HOME(), confDir);
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java
index 42f83a1d932..018be8eefef 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java
@@ -17,6 +17,12 @@
package org.apache.solr.client.solrj;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
@@ -30,10 +36,6 @@ import org.apache.solr.core.SolrCore;
import org.apache.solr.util.ExternalPaths;
import org.junit.BeforeClass;
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-
/**
* Abstract base class for testing merge indexes command
*
@@ -73,8 +75,7 @@ public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
// setup datadirs
System.setProperty( "solr.core0.data.dir", SolrTestCaseJ4.dataDir.getCanonicalPath() );
- dataDir2 = new File(TEMP_DIR, getClass().getName() + "-"
- + System.currentTimeMillis());
+ dataDir2 = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
dataDir2.mkdirs();
System.setProperty( "solr.core1.data.dir", this.dataDir2.getCanonicalPath() );
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
index 723bdb2f093..edea32dee89 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
@@ -21,6 +21,8 @@ import java.io.File;
import java.util.HashSet;
import java.util.Set;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload;
@@ -56,17 +58,11 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
@Override public void setUp() throws Exception {
super.setUp();
- dataDir1 = new File(TEMP_DIR, getClass().getName() + "-core0-"
- + System.currentTimeMillis());
- dataDir1.mkdirs();
-
- dataDir2 = new File(TEMP_DIR, getClass().getName() + "-core1-"
- + System.currentTimeMillis());
- dataDir2.mkdirs();
-
+ dataDir1 = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + "-core0");
+ dataDir2 = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + "-core1");
+
System.setProperty( "solr.core0.data.dir", this.dataDir1.getCanonicalPath() );
System.setProperty( "solr.core1.data.dir", this.dataDir2.getCanonicalPath() );
-
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
index afe712d641c..b9445ff865c 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
@@ -31,6 +31,7 @@ import org.apache.http.client.HttpClient;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.QuickPatchThreadsFilter;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrIgnoredThreadsFilter;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -284,10 +285,7 @@ public class TestLBHttpSolrServer extends SolrTestCaseJ4 {
public void setUp() throws Exception {
- File home = new File(LuceneTestCase.TEMP_DIR,
- getClass().getName() + "-" + System.currentTimeMillis());
-
-
+ File home = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
homeDir = new File(home, name);
dataDir = new File(homeDir + "/collection1", "data");
confDir = new File(homeDir + "/collection1", "conf");
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
index 0525f373259..56987ed8e3e 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
@@ -18,6 +18,7 @@ package org.apache.solr.client.solrj.embedded;
*/
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.core.CoreContainer;
@@ -38,13 +39,6 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends LuceneTestCase
protected CoreContainer cores = null;
protected File tempDir;
- protected void createTempDir() {
- if (tempDir == null) {
- tempDir = new File(TEMP_DIR, "solrtest-" + getTestClass().getSimpleName() + "-" + System.currentTimeMillis());
- tempDir.mkdirs();
- }
- }
-
@Override
@Before
public void setUp() throws Exception {
@@ -55,7 +49,7 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends LuceneTestCase
System.out.println("Solr home: " + SOLR_HOME.getAbsolutePath());
//The index is always stored within a temporary directory
- createTempDir();
+ tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
File dataDir = new File(tempDir,"data1");
File dataDir2 = new File(tempDir,"data2");
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
index c7d75048e7b..99928468864 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
@@ -23,6 +23,7 @@ import java.util.Random;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.util.ExternalPaths;
import org.eclipse.jetty.server.Connector;
@@ -58,9 +59,7 @@ public class JettyWebappTest extends SolrTestCaseJ4
System.setProperty("solr.solr.home", ExternalPaths.EXAMPLE_HOME);
System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
- File dataDir = new File(LuceneTestCase.TEMP_DIR,
- getClass().getName() + "-" + System.currentTimeMillis());
- dataDir.mkdirs();
+ File dataDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
String path = ExternalPaths.WEBAPP_HOME;
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
index 27c48bfffda..0c67f7a88be 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
@@ -17,9 +17,14 @@
package org.apache.solr.client.solrj.request;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.core.Is.is;
+
+import java.io.File;
+
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrIgnoredThreadsFilter;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.embedded.AbstractEmbeddedSolrServerTestCase;
@@ -38,10 +43,8 @@ import org.junit.rules.TestRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.core.Is.is;
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
@ThreadLeakFilters(defaultFilters = true, filters = {SolrIgnoredThreadsFilter.class})
public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
@@ -73,7 +76,7 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
public void testConfigSet() throws Exception {
SolrServer server = getSolrAdmin();
- File testDir = createTestDirectory();
+ File testDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
File newCoreInstanceDir = new File(testDir, "newcore");
@@ -91,18 +94,12 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
}
- private File createTestDirectory() {
- File tmp = new File(TEMP_DIR, "solrtest-" + getTestClass().getSimpleName() + "-" + System.currentTimeMillis());
- assertTrue("Couldn't create temporary directory " + tmp.getAbsolutePath(), tmp.mkdirs());
- return tmp;
- }
-
@Test
public void testCustomUlogDir() throws Exception {
SolrServer server = getSolrAdmin();
- File tmp = createTestDirectory();
+ File tmp = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
log.info("Creating cores underneath {}", tmp);
diff --git a/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java b/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
index 65dae081a3f..c04f4b0d666 100644
--- a/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
@@ -27,6 +27,7 @@ import java.net.URL;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.apache.solr.core.SolrResourceLoader;
/**
@@ -46,7 +47,7 @@ public class ContentStreamTest extends LuceneTestCase
{
InputStream is = new SolrResourceLoader(null, null).openResource( "solrj/README" );
assertNotNull( is );
- File file = new File(TEMP_DIR, "README");
+ File file = TestUtil.createTempFile("README", "");
FileOutputStream os = new FileOutputStream(file);
IOUtils.copy(is, os);
os.close();
@@ -62,7 +63,7 @@ public class ContentStreamTest extends LuceneTestCase
{
InputStream is = new SolrResourceLoader(null, null).openResource( "solrj/README" );
assertNotNull( is );
- File file = new File(TEMP_DIR, "README");
+ File file = TestUtil.createTempFile("README", "");
FileOutputStream os = new FileOutputStream(file);
IOUtils.copy(is, os);
os.close();
diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
index 9aa669af64e..b329faf9f5d 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -37,6 +37,7 @@ import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServer;
@@ -53,7 +54,6 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.schema.TrieDateField;
-import org.apache.solr.util.AbstractSolrTestCase;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -278,8 +278,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
super.setUp();
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
- testDir = new File(TEMP_DIR,
- getClass().getName() + "-" + System.currentTimeMillis());
+ testDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName());
testDir.mkdirs();
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index 10318dbaf52..2ca2ba3d258 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -540,7 +540,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
}
/**
- * The directory used to story the index managed by the TestHarness h
+ * The directory used to story the index managed by the TestHarness
*/
protected static volatile File dataDir;
@@ -563,10 +563,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
private static String factoryProp;
public static void createTempDir() {
- String cname = getSimpleClassName();
- dataDir = new File(TEMP_DIR,
- "solrtest-" + cname + "-" + System.currentTimeMillis());
- dataDir.mkdirs();
+ dataDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName() + "-datadir");
System.err.println("Creating dataDir: " + dataDir.getAbsolutePath());
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
index 3a1ef0d0909..f3bdd8ea81f 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
@@ -40,6 +40,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.params.CoreConnectionPNames;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
@@ -284,8 +285,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
// System.clearProperty(ZkStateReader.NUM_SHARDS_PROP);
System.setProperty(ZkStateReader.NUM_SHARDS_PROP, "1");
- File controlJettyDir = new File(TEMP_DIR,
- getClass().getName() + "-controljetty-" + System.currentTimeMillis());
+ File controlJettyDir = TestUtil.createTempDir(getClass().getSimpleName() + "-controljetty");
setupJettySolrHome(controlJettyDir);
controlJetty = createJetty(controlJettyDir, testDir + "/control/data"); // don't pass shard name... let it default to "shard1"
@@ -360,8 +360,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
for (int i = 1; i <= numJettys; i++) {
if (sb.length() > 0) sb.append(',');
int cnt = this.jettyIntCntr.incrementAndGet();
- File jettyDir = new File(TEMP_DIR,
- getClass().getName() + "-jetty" + cnt + "-" + System.currentTimeMillis());
+ File jettyDir = TestUtil.createTempDir(getClass().getSimpleName() + "-jetty" + cnt);
jettyDir.mkdirs();
setupJettySolrHome(jettyDir);
log.info("create jetty " + i);
@@ -417,7 +416,6 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
protected SolrServer startCloudJetty(String collection, String shard) throws Exception {
-
// TODO: use the collection string!!!!
collection = DEFAULT_COLLECTION;
@@ -425,8 +423,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
int cnt = this.jettyIntCntr.incrementAndGet();
- File jettyDir = new File(TEMP_DIR,
- getClass().getName() + "-jetty" + cnt + "-" + System.currentTimeMillis());
+ File jettyDir = TestUtil.createTempDir(getClass().getSimpleName() + "-jetty" + cnt);
jettyDir.mkdirs();
org.apache.commons.io.FileUtils.copyDirectory(new File(getSolrHome()), jettyDir);
JettySolrRunner j = createJetty(jettyDir, testDir + "/jetty" + cnt, shard, "solrconfig.xml", null);