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 3f3d61dc10a..24515512cd5 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 @@ -62,7 +62,7 @@ public class TestFilesystemResourceLoader extends LuceneTestCase { } public void testBaseDir() throws Exception { - final File base = TestUtil.createTempDir("fsResourceLoaderBase").getAbsoluteFile(); + final File base = createTempDir("fsResourceLoaderBase").getAbsoluteFile(); try { base.mkdirs(); Writer os = new OutputStreamWriter(new FileOutputStream(new File(base, "template.txt")), StandardCharsets.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 d06668967d8..763e56a9c1a 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.createTempDir("testCompile"); + File dir = 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.createTempDir("testCompile"); + File dir = 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.createTempDir("testCompile"); + File dir = 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 37772b95712..ec5efb19171 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.createTempDir("benchmark"); + WORKDIR = 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 0579601f0b2..a0510b5c1fb 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 @@ -387,7 +387,7 @@ public class TestPerfTasksLogic extends BenchmarkTestCase { * Test WriteLineDoc and LineDocSource. */ public void testLineDocFile() throws Exception { - File lineFile = TestUtil.createTempFile("test.reuters.lines", ".txt"); + File lineFile = 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 515c8f7b503..3094e84eb32 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 @@ -125,13 +125,13 @@ public class TestPerfTasksParse extends LuceneTestCase { Config config = new Config(new InputStreamReader(new FileInputStream(algFile), StandardCharsets.UTF_8)); String contentSource = config.get("content.source", null); if (contentSource != null) { Class.forName(contentSource); } - config.set("work.dir", TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()).getAbsolutePath()); + config.set("work.dir", 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", TestUtil.createTempFile("linefile", ".txt").getAbsolutePath()); + config.set("line.file.out", createTempFile("linefile", ".txt").getAbsolutePath()); } if (config.get("query.maker", null) != null) { Class.forName(config.get("query.maker", null)); 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 f72e1a96fc1..9fc2f4f55b6 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.createTempDir("trecFeedAllTypes"); + File dataDir = 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 22e7991db20..993acf1fb04 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.createTempDir("addIndexesTask"); + testDir = 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 bdbc958a4e6..410cacff2f5 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.createTempDir("10kpulsed"); + File f = 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.createTempDir("10knotpulsed"); + File f = 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 b7ef0544daa..415771939c2 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.createTempDir("postings")); + Directory dir = newFSDirectory(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 04735d11433..4fe2f932bc8 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.createTempDir("testDFBlockSize")); + dir = newFSDirectory(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 155356cb42a..fd79189c0af 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.createTempDir("2BFixedBinary")); + BaseDirectoryWrapper dir = newFSDirectory(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.createTempDir("2BVariableBinary")); + BaseDirectoryWrapper dir = newFSDirectory(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 0530e18ceb3..fa7b87a329e 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.createTempDir("2Bdocs")); + dir = newFSDirectory(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.createTempDir("2BDocs2")); + Directory dir2 = newFSDirectory(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 a64220988ac..c02dad34810 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.createTempDir("2BNumerics")); + BaseDirectoryWrapper dir = newFSDirectory(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 715773d97dd..08dce8020ce 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.createTempDir("2BPositions")); + BaseDirectoryWrapper dir = newFSDirectory(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 1f847d64300..d9297f897de 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.createTempDir("2BPostings")); + BaseDirectoryWrapper dir = newFSDirectory(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 fe2bd80cd90..1fdedae0361 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.createTempDir("2BPostingsBytes1")); + BaseDirectoryWrapper dir = newFSDirectory(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.createTempDir("2BPostingsBytes2")); + BaseDirectoryWrapper dir2 = newFSDirectory(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.createTempDir("2BPostingsBytes3")); + BaseDirectoryWrapper dir3 = newFSDirectory(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 0c9134dc357..355b3643dc6 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.createTempDir("2BFixedSorted")); + BaseDirectoryWrapper dir = newFSDirectory(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.createTempDir("2BOrds")); + BaseDirectoryWrapper dir = newFSDirectory(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 e8482e3b21b..bc363316d21 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 savedTerms = null; - BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("2BTerms")); + BaseDirectoryWrapper dir = newFSDirectory(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 19cead51883..731a23aef90 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.createTempDir("4GBStoredFields"))); + MockDirectoryWrapper dir = new MockDirectoryWrapper(random(), new MMapDirectory(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 132fa56f519..3e0a2ee30cc 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.createTempDir("lucene.test.atomic"); + File dirPath = 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 4c82757e2c2..7a568af1911 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java @@ -228,7 +228,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { names.addAll(Arrays.asList(oldSingleSegmentNames)); oldIndexDirs = new HashMap<>(); for (String name : names) { - File dir = TestUtil.createTempDir(name); + File dir = createTempDir(name); File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI()); TestUtil.unzip(dataFile, dir); oldIndexDirs.put(name, newFSDirectory(dir)); @@ -249,7 +249,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { if (VERBOSE) { System.out.println("TEST: index " + unsupportedNames[i]); } - File oldIndxeDir = TestUtil.createTempDir(unsupportedNames[i]); + File oldIndxeDir = createTempDir(unsupportedNames[i]); TestUtil.unzip(getDataFile("unsupported." + unsupportedNames[i] + ".zip"), oldIndxeDir); BaseDirectoryWrapper dir = newFSDirectory(oldIndxeDir); // don't checkindex, these are intentionally not supported @@ -646,7 +646,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { public void testExactFileNames() throws IOException { String outputDirName = "lucene.backwardscompat0.index"; - File outputDir = TestUtil.createTempDir(outputDirName); + File outputDir = createTempDir(outputDirName); TestUtil.rm(outputDir); try { @@ -956,7 +956,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { public void testCommandLineArgs() throws Exception { for (String name : oldIndexDirs.keySet()) { - File dir = TestUtil.createTempDir(name); + File dir = createTempDir(name); File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI()); TestUtil.unzip(dataFile, dir); @@ -1049,7 +1049,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { public static final String moreTermsIndex = "moreterms.40.zip"; public void testMoreTerms() throws Exception { - File oldIndexDir = TestUtil.createTempDir("moreterms"); + File oldIndexDir = 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 70bdfa54794..726ee8701eb 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 postings = new ConcurrentLinkedQueue<>(postingsList); - Directory dir = newFSDirectory(TestUtil.createTempDir("bagofpositions")); + Directory dir = newFSDirectory(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 0af3d6c8ae0..0b8c176f1b3 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 postings = new ConcurrentLinkedQueue<>(postingsList); - Directory dir = newFSDirectory(TestUtil.createTempDir("bagofpostings")); + Directory dir = newFSDirectory(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 f151d5d06f7..a7465ef5f94 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.createTempDir("testIndex"); + File file = 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.createTempDir("CFSManySubFiles")); + final Directory d = newFSDirectory(createTempDir("CFSManySubFiles")); final int FILE_COUNT = atLeast(500); for(int fileIdx=0;fileIdx 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 7a08b2409e7..6ee79e91bcf 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.createTempDir("longpostings" + "." + random().nextLong())); + Directory dir = newFSDirectory(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.createTempDir("longpostings" + "." + random().nextLong())); + Directory dir = newFSDirectory(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 7c71924f1bf..bdd6f9885d4 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.createTempDir("TestNeverDelete"); + final File tmpDir = 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 87575564096..643af1b2d31 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestNorms.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestNorms.java @@ -109,7 +109,7 @@ public class TestNorms extends LuceneTestCase { } public void testMaxByteNorms() throws IOException { - Directory dir = newFSDirectory(TestUtil.createTempDir("TestNorms.testMaxByteNorms")); + Directory dir = newFSDirectory(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 3d560f93023..e8a07625b48 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.createTempDir("nrt")), 5, 128); + final Directory dir = new NRTCachingDirectory(newFSDirectory(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 f70848009da..5c4e085e553 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.createTempDir("livefieldupdates")); + Directory dir = newFSDirectory(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 8aee732bbb8..53883a112f4 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.createTempDir("testSetBufferSize"); + File indexDir = 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 0bf2b0fd0bc..e500a0dee1c 100644 --- a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java +++ b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java @@ -29,7 +29,7 @@ import org.apache.lucene.util.TestUtil; public class TestDirectory extends LuceneTestCase { public void testDetectClose() throws Throwable { - File tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File tempDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); Directory[] dirs = new Directory[] { new RAMDirectory(), new SimpleFSDirectory(tempDir), @@ -135,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.createTempDir("testDirectInstantiation"); + final File path = createTempDir("testDirectInstantiation"); final byte[] largeBuffer = new byte[random().nextInt(256*1024)], largeReadBuffer = new byte[largeBuffer.length]; for (int i = 0; i < largeBuffer.length; i++) { @@ -223,7 +223,7 @@ public class TestDirectory extends LuceneTestCase { // LUCENE-1464 public void testDontCreate() throws Throwable { - File path = new File(TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()), "doesnotexist"); + File path = new File(createTempDir(LuceneTestCase.getTestClass().getSimpleName()), "doesnotexist"); try { assertTrue(!path.exists()); Directory dir = new SimpleFSDirectory(path, null); @@ -241,7 +241,7 @@ public class TestDirectory extends LuceneTestCase { // LUCENE-1468 public void testFSDirectoryFilter() throws IOException { - checkDirectoryFilter(newFSDirectory(TestUtil.createTempDir("test"))); + checkDirectoryFilter(newFSDirectory(createTempDir("test"))); } // LUCENE-1468 @@ -258,7 +258,7 @@ public class TestDirectory extends LuceneTestCase { // LUCENE-1468 public void testCopySubdir() throws Throwable { - File path = TestUtil.createTempDir("testsubdir"); + File path = createTempDir("testsubdir"); try { path.mkdirs(); new File(path, "subdir").mkdirs(); @@ -271,7 +271,7 @@ public class TestDirectory extends LuceneTestCase { // LUCENE-1468 public void testNotDirectory() throws Throwable { - File path = TestUtil.createTempDir("testnotdir"); + File path = 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 e81eeb3b826..17a55492b61 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 primaryExtensions) throws IOException { - File primDir = TestUtil.createTempDir("foo"); - File secondDir = TestUtil.createTempDir("bar"); + File primDir = createTempDir("foo"); + File secondDir = 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.createTempDir("foo"); - File secondDir = TestUtil.createTempDir("bar"); + File primDir = createTempDir("foo"); + File secondDir = createTempDir("bar"); TestUtil.rm(primDir); TestUtil.rm(secondDir); Directory dir = newFSSwitchDirectory(primDir, secondDir, Collections.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 0061baf1024..e1b5befbed5 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.createTempDir("index.TestLockFactory6")); + _testStressLocks(null, 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.createTempDir("index.TestLockFactory7"); + File dir = createTempDir("index.TestLockFactory7"); _testStressLocks(new NativeFSLockFactory(dir), dir); } @@ -176,7 +176,7 @@ public class TestLockFactory extends LuceneTestCase { // Verify: NativeFSLockFactory works correctly public void testNativeFSLockFactory() throws IOException { - NativeFSLockFactory f = new NativeFSLockFactory(TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName())); + NativeFSLockFactory f = new NativeFSLockFactory(createTempDir(LuceneTestCase.getTestClass().getSimpleName())); f.setLockPrefix("test"); Lock l = f.makeLock("commit"); @@ -201,7 +201,7 @@ public class TestLockFactory extends LuceneTestCase { // Verify: NativeFSLockFactory works correctly if the lock file exists public void testNativeFSLockFactoryLockExists() throws IOException { - File tempDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File tempDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); File lockFile = new File(tempDir, "test.lock"); lockFile.createNewFile(); @@ -215,7 +215,7 @@ public class TestLockFactory extends LuceneTestCase { } public void testNativeFSLockReleaseByOtherLock() throws IOException { - NativeFSLockFactory f = new NativeFSLockFactory(TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName())); + NativeFSLockFactory f = new NativeFSLockFactory(createTempDir(LuceneTestCase.getTestClass().getSimpleName())); f.setLockPrefix("test"); Lock l = f.makeLock("commit"); @@ -236,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.createTempDir("TestLockFactory.8"); - File fdir2 = TestUtil.createTempDir("TestLockFactory.8.Lockdir"); + File fdir1 = createTempDir("TestLockFactory.8"); + File fdir2 = 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)); @@ -259,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.createTempDir("TestLockFactory.10"); + File dirName = 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 755f93c92df..17f60ad21e6 100644 --- a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java +++ b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java @@ -38,18 +38,15 @@ import org.apache.lucene.util.TestUtil; * Integer.MAX_VALUE in size using multiple byte buffers. */ public class TestMultiMMap extends LuceneTestCase { - File workDir; @Override public void setUp() throws Exception { super.setUp(); assumeTrue("test requires a jre that supports unmapping", MMapDirectory.UNMAP_SUPPORTED); - workDir = TestUtil.createTempDir("TestMultiMMap"); - workDir.mkdirs(); } public void testCloneSafety() throws Exception { - MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testCloneSafety")); + MMapDirectory mmapDir = new MMapDirectory(createTempDir("testCloneSafety")); IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random())); io.writeVInt(5); io.close(); @@ -83,7 +80,7 @@ public class TestMultiMMap extends LuceneTestCase { } public void testCloneClose() throws Exception { - MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testCloneClose")); + MMapDirectory mmapDir = new MMapDirectory(createTempDir("testCloneClose")); IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random())); io.writeVInt(5); io.close(); @@ -105,7 +102,7 @@ public class TestMultiMMap extends LuceneTestCase { } public void testCloneSliceSafety() throws Exception { - MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testCloneSliceSafety")); + MMapDirectory mmapDir = new MMapDirectory(createTempDir("testCloneSliceSafety")); IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random())); io.writeInt(1); io.writeInt(2); @@ -150,7 +147,7 @@ public class TestMultiMMap extends LuceneTestCase { } public void testCloneSliceClose() throws Exception { - MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testCloneSliceClose")); + MMapDirectory mmapDir = new MMapDirectory(createTempDir("testCloneSliceClose")); IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random())); io.writeInt(1); io.writeInt(2); @@ -177,7 +174,7 @@ public class TestMultiMMap extends LuceneTestCase { public void testSeekZero() throws Exception { for (int i = 0; i < 31; i++) { - MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeekZero"), null, 1<StringBuilder mismatch.", builder, array); - File tempDir = TestUtil.createTempDir("growingchararray"); + File tempDir = 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 c29c849e56d..cfd71a32f28 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.createTempDir("testLableToOrdinal"); + File tmpDir = 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 19054fd789c..d55de376f22 100644 --- a/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java +++ b/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java @@ -28,8 +28,8 @@ import org.apache.lucene.util.TestUtil; public class TestIndexSplitter extends LuceneTestCase { public void test() throws Exception { - File dir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); - File destDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File dir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File destDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); Directory fsDir = newFSDirectory(dir); // IndexSplitter.split makes its own commit directly with SIPC/SegmentInfos, // so the unreferenced files are expected. @@ -76,7 +76,7 @@ public class TestIndexSplitter extends LuceneTestCase { fsDirDest.close(); // now test cmdline - File destDir2 = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File destDir2 = 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 e956478d749..a7c9cfa6bb2 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.createTempDir("replicationClientTest"); + clientWorkDir = 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 9b93834d7ec..6cec41a201e 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.createTempDir("replicationClientTest")); + sourceDirFactory = new PerSessionDirectoryFactory(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 3a4a33e3e8e..3a21d8b568e 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.createTempDir("httpReplicatorTest"); + clientWorkDir = 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 1efebbefa0b..c57705abf8c 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 @@ -163,7 +163,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.createTempDir("LookupBenchmarkTest")), a); + lookup = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, FSDirectory.open(createTempDir("LookupBenchmarkTest")), a); } else { Constructor 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 128b088a589..b492cf4f29e 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 = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File storeDir = 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 19a4d2b825f..040258fffa3 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 @@ -91,7 +91,7 @@ public class AnalyzingInfixSuggesterTest extends LuceneTestCase { new Input("a penny saved is a penny earned", 10, new BytesRef("foobaz")), }; - File tempDir = TestUtil.createTempDir("AnalyzingInfixSuggesterTest"); + File tempDir = createTempDir("AnalyzingInfixSuggesterTest"); Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false); AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, newFSDirectory(tempDir), a, a, 3); @@ -210,7 +210,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.createTempDir("AnalyzingInfixSuggesterTest"); + File tempDir = createTempDir("AnalyzingInfixSuggesterTest"); Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false); int minPrefixLength = random().nextInt(10); @@ -471,7 +471,7 @@ public class AnalyzingInfixSuggesterTest extends LuceneTestCase { } public void testRandomNRT() throws Exception { - final File tempDir = TestUtil.createTempDir("AnalyzingInfixSuggesterTest"); + final File tempDir = createTempDir("AnalyzingInfixSuggesterTest"); Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false); int minPrefixChars = random().nextInt(7); if (VERBOSE) { @@ -806,7 +806,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.createTempDir("analyzingInfixContext"); + File tempDir = 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 586a7c2cd93..a8e1cf0d7c2 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.createTempDir("AnalyzingSuggesterTest"); + File tmpDir = 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.createTempDir("AnalyzingSuggesterTest"); + File tmpDir = 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.createTempDir("AnalyzingSuggesterTest"); + File tmpDir = 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 843ca6d1895..dca3193a8cb 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 @@ -17,6 +17,10 @@ package org.apache.lucene.search.suggest.analyzing; * limitations under the License. */ +import java.io.File; +import java.io.IOException; +import java.util.List; + import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.analysis.util.CharArraySet; @@ -25,11 +29,6 @@ import org.apache.lucene.search.suggest.InputArrayIterator; import org.apache.lucene.search.suggest.Lookup; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.util.TestUtil; - -import java.io.File; -import java.io.IOException; -import java.util.List; public class BlendedInfixSuggesterTest extends LuceneTestCase { @@ -45,7 +44,7 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase { new Input("star wars: episode v - the empire strikes back", 8, payload) }; - File tempDir = TestUtil.createTempDir("BlendedInfixSuggesterTest"); + File tempDir = 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 +83,7 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase { new Input("top of the lake", w, pl) }; - File tempDir = TestUtil.createTempDir("BlendedInfixSuggesterTest"); + File tempDir = createTempDir("BlendedInfixSuggesterTest"); Analyzer a = new StandardAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET); // BlenderType.LINEAR is used by default (remove position*10%) @@ -125,7 +124,7 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase { new Input("the returned", 10, ret), }; - File tempDir = TestUtil.createTempDir("BlendedInfixSuggesterTest"); + File tempDir = 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 +174,7 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase { new Input("the returned", 10, ret), }; - File tempDir = TestUtil.createTempDir("BlendedInfixSuggesterTest"); + File tempDir = 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 4b8cfa91a4f..e2ddc3c4b88 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.createTempDir("FreeTextSuggesterTest"); + File tmpDir = 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 48cd8298541..356b19273dc 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 @@ -503,7 +503,7 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase { !(postingsFormat.equals("Memory") || postingsFormat.equals("SimpleText")); if (rarely(random) && codecOk) { - dir = newFSDirectory(TestUtil.createTempDir("bttc")); + dir = newFSDirectory(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 a8829390830..bb8f3272137 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.createTempDir("hugeBinaryValues")); + Directory d = newFSDirectory(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.createTempDir("hugeBinaryValues")); + Directory d = newFSDirectory(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 10935a662f3..8862c0af497 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 @@ -1203,7 +1203,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.createTempDir("testPostingsFormat.testExact"); + File path = createTempDir("testPostingsFormat.testExact"); Directory dir = newFSDirectory(path); // TODO test thread safety of buildIndex too @@ -1256,7 +1256,7 @@ public abstract class BasePostingsFormatTestCase extends LuceneTestCase { int iters = 5; for(int iter=0;iter * - * - *

There is a number of other facilities tests can use, like: - *

    - *
  • {@link #closeAfterTest(Closeable)} and {@link #closeAfterSuite(Closeable)} to - * register resources to be closed after each scope (if close fails, the scope - * will fail too).
  • - *
*/ @RunWith(RandomizedRunner.class) @TestMethodProviders({ @@ -233,8 +324,8 @@ public abstract class LuceneTestCase extends Assert { * files. This may prevent temp. files and folders from being cleaned * up after the suite is completed. * - * @see TestUtil#createTempDir() - * @see TestUtil#createTempFile(String, String) + * @see LuceneTestCase#createTempDir() + * @see LuceneTestCase#createTempFile(String, String) */ @Documented @Inherited @@ -444,6 +535,7 @@ public abstract class LuceneTestCase extends Assert { .around(ignoreAfterMaxFailures) .around(suiteFailureMarker = new TestRuleMarkFailure()) .around(new TestRuleAssertionsRequired()) + .around(new TemporaryFilesCleanupRule()) .around(new StaticFieldsInvariantRule(STATIC_LEAK_THRESHOLD, true) { @Override protected boolean accept(java.lang.reflect.Field field) { @@ -1178,7 +1270,7 @@ public abstract class LuceneTestCase extends Assert { final Class clazz = CommandLineUtil.loadDirectoryClass(clazzName); // If it is a FSDirectory type, try its ctor(File) if (FSDirectory.class.isAssignableFrom(clazz)) { - final File dir = new File(TestUtil.createTempDir(), "index"); + final File dir = createTempDir("index-" + clazzName); dir.mkdirs(); // ensure it's created so we 'have' it. return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir); } @@ -2091,4 +2183,148 @@ public abstract class LuceneTestCase extends Assert { return false; } } + + /** + * A base location for temporary files of a given test. Helps in figuring out + * which tests left which files and where. + */ + private static File tempDirBase; + + /** + * Retry to create temporary file name this many times. + */ + private static final int TEMP_NAME_RETRY_THRESHOLD = 9999; + + /** + */ + private static File getTempDirBase() { + synchronized (LuceneTestCase.class) { + if (tempDirBase == null) { + File directory = new File(System.getProperty("tempDir", System.getProperty("java.io.tmpdir"))); + assert directory.exists() && + directory.isDirectory() && + directory.canWrite(); + + RandomizedContext ctx = RandomizedContext.current(); + Class clazz = ctx.getTargetClass(); + String prefix = clazz.getName(); + prefix = prefix.replaceFirst("^org.apache.lucene.", "oa.lucene."); + prefix = prefix.replaceFirst("^org.apache.solr.", "oa.solr."); + + int attempt = 0; + File f; + do { + if (attempt++ >= TEMP_NAME_RETRY_THRESHOLD) { + throw new RuntimeException( + "Failed to get a temporary name too many times, check your temp directory and consider manually cleaning it: " + + directory.getAbsolutePath()); + } + f = new File(directory, prefix + "-" + ctx.getRunnerSeedAsString() + + "-" + String.format(Locale.ENGLISH, "%3d", attempt)); + } while (!f.mkdirs()); + + tempDirBase = f; + registerToRemoveAfterSuite(tempDirBase); + } + } + return tempDirBase; + } + + /** + */ + protected static File createTempDir(String prefix) { + File base = getTempDirBase(); + + int attempt = 0; + File f; + do { + if (attempt++ >= TEMP_NAME_RETRY_THRESHOLD) { + throw new RuntimeException( + "Failed to get a temporary name too many times, check your temp directory and consider manually cleaning it: " + + base.getAbsolutePath()); + } + f = new File(base, prefix + "-" + String.format(Locale.ENGLISH, "%3d", attempt)); + } while (!f.mkdirs()); + + registerToRemoveAfterSuite(f); + return f; + } + + /** + */ + protected static File createTempFile(String prefix, String suffix) throws IOException { + File base = getTempDirBase(); + + int attempt = 0; + File f; + do { + if (attempt++ >= TEMP_NAME_RETRY_THRESHOLD) { + throw new RuntimeException( + "Failed to get a temporary name too many times, check your temp directory and consider manually cleaning it: " + + base.getAbsolutePath()); + } + f = new File(base, prefix + "-" + String.format(Locale.ENGLISH, "%3d", attempt) + suffix); + } while (!f.createNewFile()); + + registerToRemoveAfterSuite(f); + return f; + } + + /** + */ + protected static File createTempDir() { + return createTempDir("tempDir"); + } + + /** + */ + protected static File createTempFile() throws IOException { + return createTempFile("tempFile", ".tmp"); + } + + /** + * A queue of temporary resources to be removed after the + * suite completes. + * @see #registerToRemoveAfterSuite(File) + */ + private final static Deque cleanupQueue = new ArrayDeque(); + + /** + * Register temporary folder for removal after the suite completes. + */ + private static void registerToRemoveAfterSuite(File f) { + assert f != null; + + if (LuceneTestCase.LEAVE_TEMPORARY) { + System.err.println("INFO: Will leave temporary file: " + f.getAbsolutePath()); + return; + } + + Class suiteClass = RandomizedContext.current().getTargetClass(); + if (suiteClass.isAnnotationPresent(SuppressTempFileChecks.class)) { + System.err.println("WARNING: Will leave temporary files (bugUrl: " + + suiteClass.getAnnotation(SuppressTempFileChecks.class).bugUrl() + "): " + + f.getAbsolutePath()); + return; + } + + synchronized (cleanupQueue) { + cleanupQueue.addLast(f); + } + } + + private static class TemporaryFilesCleanupRule extends TestRuleAdapter { + @Override + protected void afterIfSuccessful() throws Throwable { + synchronized (cleanupQueue) { + File [] everything = new File [cleanupQueue.size()]; + for (int i = 0; !cleanupQueue.isEmpty(); i++) { + everything[i] = cleanupQueue.removeFirst(); + } + + // Will throw an IOException on un-removable files. + TestUtil.rm(everything); + } + } + } } 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 0d03ee82f9d..bba87713ec7 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 @@ -37,7 +37,6 @@ import java.util.Map; import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import java.util.zip.ZipEntry; @@ -87,10 +86,8 @@ import org.apache.lucene.search.FilteredQuery.FilterStrategy; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; -import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks; import org.junit.Assert; -import com.carrotsearch.randomizedtesting.RandomizedContext; import com.carrotsearch.randomizedtesting.generators.RandomInts; import com.carrotsearch.randomizedtesting.generators.RandomPicks; @@ -102,14 +99,14 @@ 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; - /** - * Deletes a file or a directory (and everything underneath it). + * Deletes one or more files or directories (and everything underneath it). + * + * @throws IOException if any of the given files (or their subhierarchy files in case + * of directories) cannot be removed. */ - public static void rm(File location) throws IOException { - ArrayList unremoved = rm(location, new ArrayList()); + public static void rm(File... locations) throws IOException { + ArrayList unremoved = rm(new ArrayList(), locations); if (!unremoved.isEmpty()) { StringBuilder b = new StringBuilder("Could not remove the following files (in the order of attempts):\n"); for (File f : unremoved) { @@ -121,16 +118,16 @@ public final class TestUtil { } } - private static ArrayList rm(File location, ArrayList unremoved) { - if (location.exists()) { - if (location.isDirectory()) { - for (File f : location.listFiles()) { - rm(f, unremoved); + private static ArrayList rm(ArrayList unremoved, File... locations) { + for (File location : locations) { + if (location.exists()) { + if (location.isDirectory()) { + rm(unremoved, location.listFiles()); + } + + if (!location.delete()) { + unremoved.add(location); } - } - - if (!location.delete()) { - unremoved.add(location); } } return unremoved; @@ -789,131 +786,6 @@ public final class TestUtil { }); Assert.assertEquals("Reflection does not produce same map", reflectedValues, map); } - - /** - * Returns a new, empty temporary folder, based on the current test class's name. - * - * @see #createTempDir(String, File) - */ - public static File createTempDir() { - Class clazz = RandomizedContext.current().getTargetClass(); - String prefix = clazz.getName(); - prefix = prefix.replaceFirst("^org.apache.lucene.", "lucene-"); - prefix = prefix.replaceFirst("^org.apache.solr.", "solr-"); - return createTempDir(prefix); - } - - /** - * @see #createTempDir(String, File) - */ - public static File createTempDir(String prefix) { - return createTempDir(prefix, null); - } - - /** - * Returns a new and empty temporary folder, based on the given name. The folder will be - * deleted at the end of the test suite. Failure to delete the temporary folder will cause - * an exception (typically happens on Windows on unclosed file handles). - */ - public static File createTempDir(String prefix, File parent) { - if (prefix.length() < 3) { - throw new IllegalArgumentException("The prefix must be at least 3 characters: " + prefix); - } - - if (parent == null) { - parent = tempDirectory(); - } - - if (!parent.exists()) { - throw new RuntimeException("Parent location does not exist: " + parent.getAbsolutePath()); - } - - if (!parent.isDirectory()) { - throw new RuntimeException("Parent location is not a folder: " + parent.getAbsolutePath()); - } - - if (!parent.canWrite()) { - throw new RuntimeException("Parent folder not writeable: " + parent.getAbsolutePath()); - } - - // 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. - int attempt = 0; - File f; - do { - f = genTempFile(prefix + "_", "", parent); - } 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: " - + parent.getAbsolutePath()); - } - - return maybeRemoveAfterSuite(f); - } - - private static File maybeRemoveAfterSuite(File f) { - if (LuceneTestCase.LEAVE_TEMPORARY) { - System.err.println("INFO: Will leave temporary file: " + f.getAbsolutePath()); - return f; - } - - Class suiteClass = RandomizedContext.current().getTargetClass(); - if (suiteClass.isAnnotationPresent(SuppressTempFileChecks.class)) { - System.err.println("WARNING: Will leave temporary files (bugUrl: " - + suiteClass.getAnnotation(SuppressTempFileChecks.class).bugUrl() + "): " - + f.getAbsolutePath()); - return f; - } - - LuceneTestCase.closeAfterSuite(new RemoveUponClose(f, LuceneTestCase.suiteFailureMarker)); - return f; - } - - public static File createTempFile(String prefix, String suffix) throws IOException { - return createTempFile(prefix, suffix, tempDirectory()); - } - - /** - * Do NOT expose this method public. Use {@link #createTempDir()} instead. - */ - private static File tempDirectory() { - File directory = new File(System.getProperty("tempDir", System.getProperty("java.io.tmpdir"))); - assert directory.exists() && - directory.isDirectory() && - directory.canWrite(); - return directory; - } - - /** - * 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 { - if (prefix.length() < 3) { - throw new IllegalArgumentException("prefix must be at least 3 characters"); - } - String newSuffix = suffix == null ? ".tmp" : suffix; - File result; - do { - result = genTempFile(prefix, newSuffix, directory); - } while (!result.createNewFile()); - return maybeRemoveAfterSuite(result); - } - - /* Temp file counter */ - private static final AtomicInteger counter = new AtomicInteger(); - - private static File genTempFile(String prefix, String suffix, File directory) { - return new File(directory, - prefix - + RandomizedContext.current().getRunnerSeedAsString() - + "-" + counter.incrementAndGet() - + suffix); - } public static void assertEquals(TopDocs expected, TopDocs actual) { Assert.assertEquals("wrong total hits", expected.totalHits, actual.totalHits); 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 5f0c58d0aa8..00109d16181 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 @@ -32,7 +32,7 @@ public class TestFileListWithLineEntityProcessor extends AbstractDataImportHandl } public void test() throws Exception { - File tmpdir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File tmpdir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); createFile(tmpdir, "a.txt", "a line one\na line two\na line three".getBytes(StandardCharsets.UTF_8), false); createFile(tmpdir, "b.txt", "b line one\nb line two".getBytes(StandardCharsets.UTF_8), false); createFile(tmpdir, "c.txt", "c line one\nc line two\nc line three\nc line four".getBytes(StandardCharsets.UTF_8), false); 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 3036bbe9339..7dda63ef76a 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.createTempDir("testEscapeInstanceDir"); + File temp = 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.createTempDir("testClassLoaderLibs"); + File tmpRoot = createTempDir("testClassLoaderLibs"); File lib = new File(tmpRoot, "lib"); lib.mkdirs(); 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 3f83e61cf5b..f63643c5f66 100644 --- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java +++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java @@ -233,7 +233,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 { @Test public void testSharedLib() throws Exception { - File tmpRoot = TestUtil.createTempDir("testSharedLib"); + File tmpRoot = createTempDir("testSharedLib"); File lib = new File(tmpRoot, "lib"); lib.mkdirs(); 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 056f9745b46..2ae8128e1c0 100644 --- a/solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java +++ b/solr/core/src/test/org/apache/solr/core/TestSolrXMLSerializer.java @@ -81,12 +81,10 @@ public class TestSolrXMLSerializer extends SolrTestCaseJ4 { } assertResults(w.toString().getBytes(StandardCharsets.UTF_8)); - - // again with default file - File tmpFile = TestUtil.createTempFile("solr.xml", null, createTempDir()); - - serializer.persistFile(tmpFile, solrXMLDef); + // again with default file + File tmpFile = new File(createTempDir(), "solr.xml"); + serializer.persistFile(tmpFile, solrXMLDef); assertResults(FileUtils.readFileToByteArray(tmpFile)); tmpFile.delete(); } 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 f9a5dad4fc2..c7332011139 100644 --- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java +++ b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java @@ -66,7 +66,7 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 { @Before public void setupTest() { - solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + solrHomeDirectory = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); } private CoreContainer init(String solrXmlString, String... subDirs) throws Exception { 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 3f9c715147b..56824283401 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.createTempDir("TestCSVLoader"); + File tempDir = createTempDir("TestCSVLoader"); file = new File(tempDir, "solr_tmp.csv"); filename = file.getPath(); cleanup(); 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 fce5d7871de..1fdfb23580b 100644 --- a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java +++ b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java @@ -56,7 +56,7 @@ public class TestRemoteStreaming extends SolrJettyTestBase { @BeforeClass public static void beforeTest() throws Exception { //this one has handleSelect=true which a test here needs - solrHomeDirectory = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + solrHomeDirectory = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); setupJettyTestHome(solrHomeDirectory, "collection1"); createJetty(solrHomeDirectory.getAbsolutePath(), null, null); } 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 e501e5f23b3..d4168c8e285 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.createTempDir("collation1"); + File tmpFile = 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 8fc326eecc1..2bc5cfc32b8 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.createTempDir("collation1"); + File tmpFile = createTempDir("collation1"); tmpFile.delete(); tmpFile.mkdir(); 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 8a44a338bcb..aacc945981a 100644 --- a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java +++ b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java @@ -30,7 +30,6 @@ import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.impl.cookie.DateUtils; -import org.apache.lucene.util.TestUtil; import org.apache.solr.common.params.CommonParams; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -255,7 +254,7 @@ public class CacheHeaderTest extends CacheHeaderTestBase { protected File makeFile(String contents, String charset) { try { - File f = TestUtil.createTempFile("cachetest_csv", null, initCoreDataDir); + File f = new File(initCoreDataDir, "cachetest_csv"); 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 b76001c4b1d..f2f0e48b44d 100644 --- a/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java +++ b/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java @@ -71,7 +71,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 = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File indexDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath()); SolrCore core = h.getCore(); String dictName = checker.init(spellchecker, core); 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 d06e96b9ffe..fe29cbb5b24 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 @@ -76,7 +76,7 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase { public void testConfigSet() throws Exception { SolrServer server = getSolrAdmin(); - File testDir = TestUtil.createTempDir(LuceneTestCase.getTestClass().getSimpleName()); + File testDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()); File newCoreInstanceDir = new File(testDir, "newcore"); 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 2945a189cb6..618e6c9abac 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 @@ -49,7 +49,7 @@ public class ContentStreamTest extends SolrTestCaseJ4 { InputStream is = new SolrResourceLoader(null, null).openResource( "solrj/README" ); assertNotNull( is ); - File file = TestUtil.createTempFile("README", "", createTempDir()); + File file = new File(createTempDir(), "README"); FileOutputStream os = new FileOutputStream(file); IOUtils.copy(is, os); os.close(); 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 4e6cf8024d4..651a2667eb8 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -150,10 +150,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { @BeforeClass @SuppressWarnings("unused") private static void beforeClass() { - // Create the root parent folder for all other temporary solr files. - rootTmpDir = TestUtil.createTempDir(); - - initCoreDataDir = TestUtil.createTempDir("init-core-data", rootTmpDir); + initCoreDataDir = createTempDir("init-core-data"); System.err.println("Creating dataDir: " + initCoreDataDir.getAbsolutePath()); @@ -465,14 +462,6 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { SolrException.ignorePatterns.remove(pattern); } - public static File createTempDir() { - return createTempDir(null); - } - - public static File createTempDir(String prefix) { - return TestUtil.createTempDir(prefix == null ? "temp" : prefix, rootTmpDir); - } - public static void resetExceptionIgnores() { SolrException.ignorePatterns = null; ignoreException("ignore_exception"); // always ignore "ignore_exception" @@ -533,8 +522,6 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { */ protected static volatile File initCoreDataDir; - protected static volatile File rootTmpDir; - // hack due to File dataDir protected static String hdfsDataDir;