mirror of https://github.com/apache/lucene.git
Moved createTemp* to LuceneTestCase, removing it from SolrTestCaseJ4. Created common infrastructure that creates temporary files and folders under the suite's master folder. Created a rule that cleans up afterwards (or provides an explicit message if something fails to clean up).:
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/solr5914@1584832 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c0bdf68730
commit
bfecbc9274
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ public class Test2BTerms extends LuceneTestCase {
|
|||
|
||||
List<BytesRef> 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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -68,7 +68,7 @@ public class TestBagOfPositions extends LuceneTestCase {
|
|||
|
||||
final ConcurrentLinkedQueue<String> postings = new ConcurrentLinkedQueue<>(postingsList);
|
||||
|
||||
Directory dir = newFSDirectory(TestUtil.createTempDir("bagofpositions"));
|
||||
Directory dir = newFSDirectory(createTempDir("bagofpositions"));
|
||||
|
||||
final RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public class TestBagOfPostings extends LuceneTestCase {
|
|||
|
||||
final ConcurrentLinkedQueue<String> 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);
|
||||
|
|
|
@ -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<FILE_COUNT;fileIdx++) {
|
||||
|
|
|
@ -42,7 +42,7 @@ public class TestCrashCausesCorruptIndex extends LuceneTestCase {
|
|||
* LUCENE-3627: This test fails.
|
||||
*/
|
||||
public void testCrashCorruptsIndexing() throws Exception {
|
||||
path = TestUtil.createTempDir("testCrashCorruptsIndexing");
|
||||
path = createTempDir("testCrashCorruptsIndexing");
|
||||
|
||||
indexAndCrashOnCreateOutputSegments2();
|
||||
|
||||
|
|
|
@ -438,7 +438,7 @@ void assertTermDocsCount(String msg,
|
|||
|
||||
public void testFilesOpenClose() throws IOException {
|
||||
// Create initial data set
|
||||
File dirFile = TestUtil.createTempDir("TestIndexReader.testFilesOpenClose");
|
||||
File dirFile = 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.createTempDir("deletetest");
|
||||
File dirFile = 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.createTempDir("doesnotexist");
|
||||
File tempDir = createTempDir("doesnotexist");
|
||||
TestUtil.rm(tempDir);
|
||||
Directory dir = newFSDirectory(tempDir);
|
||||
try {
|
||||
|
@ -1090,7 +1090,7 @@ public void testFilesOpenClose() throws IOException {
|
|||
}
|
||||
|
||||
public void testIndexExistsOnNonExistentDirectory() throws Exception {
|
||||
File tempDir = TestUtil.createTempDir("testIndexExistsOnNonExistentDirectory");
|
||||
File tempDir = createTempDir("testIndexExistsOnNonExistentDirectory");
|
||||
tempDir.delete();
|
||||
Directory dir = newFSDirectory(tempDir);
|
||||
assertFalse(DirectoryReader.indexExists(dir));
|
||||
|
|
|
@ -63,10 +63,10 @@ public class TestDoc extends LuceneTestCase {
|
|||
if (VERBOSE) {
|
||||
System.out.println("TEST: setUp");
|
||||
}
|
||||
workDir = TestUtil.createTempDir("TestDoc");
|
||||
workDir = createTempDir("TestDoc");
|
||||
workDir.mkdirs();
|
||||
|
||||
indexDir = TestUtil.createTempDir("testIndex");
|
||||
indexDir = createTempDir("testIndex");
|
||||
indexDir.mkdirs();
|
||||
|
||||
Directory directory = newFSDirectory(indexDir);
|
||||
|
|
|
@ -187,7 +187,7 @@ public class TestFieldsReader extends LuceneTestCase {
|
|||
|
||||
// LUCENE-1262
|
||||
public void testExceptions() throws Throwable {
|
||||
File indexDir = TestUtil.createTempDir("testfieldswriterexceptions");
|
||||
File indexDir = createTempDir("testfieldswriterexceptions");
|
||||
|
||||
try {
|
||||
Directory dir = new FaultyFSDirectory(indexDir);
|
||||
|
|
|
@ -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.createTempDir("emptyFSDirNoLock"), NoLockFactory.getNoLockFactory());
|
||||
Directory dir = newFSDirectory(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.createTempDir("TestIndexWriter.testWhetherDeleteAllDeletesWriteLock"));
|
||||
Directory d = newFSDirectory(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.createTempDir("TestIndexWriter.testChangingFields"));
|
||||
Directory dir = newFSDirectory(createTempDir("TestIndexWriter.testChangingFields"));
|
||||
IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
|
||||
iwc.setRAMBufferSizeMB(0.2);
|
||||
iwc.setMaxBufferedDocs(-1);
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.apache.lucene.util.TestUtil;
|
|||
public class TestIndexWriterLockRelease extends LuceneTestCase {
|
||||
|
||||
public void testIndexWriterLockRelease() throws IOException {
|
||||
Directory dir = newFSDirectory(TestUtil.createTempDir("testLockRelease"));
|
||||
Directory dir = newFSDirectory(createTempDir("testLockRelease"));
|
||||
try {
|
||||
new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
|
||||
} catch (FileNotFoundException | NoSuchFileException e) {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TestIndexWriterOnJRECrash extends TestNRTThreads {
|
|||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
tempDir = TestUtil.createTempDir("jrecrash");
|
||||
tempDir = createTempDir("jrecrash");
|
||||
tempDir.delete();
|
||||
tempDir.mkdir();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.apache.lucene.util.TestUtil;
|
|||
|
||||
public class TestIndexWriterOutOfFileDescriptors extends LuceneTestCase {
|
||||
public void test() throws Exception {
|
||||
MockDirectoryWrapper dir = newMockFSDirectory(TestUtil.createTempDir("TestIndexWriterOutOfFileDescriptors"));
|
||||
MockDirectoryWrapper dir = newMockFSDirectory(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.createTempDir("TestIndexWriterOutOfFileDescriptors.copy"));
|
||||
dirCopy = newMockFSDirectory(createTempDir("TestIndexWriterOutOfFileDescriptors.copy"));
|
||||
Set<String> files = new HashSet<>();
|
||||
for (String file : dir.listAll()) {
|
||||
dir.copy(dirCopy, file, file, IOContext.DEFAULT);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -88,8 +88,8 @@ public class TestFileSwitchDirectory extends LuceneTestCase {
|
|||
}
|
||||
|
||||
private Directory newFSSwitchDirectory(Set<String> 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.<String>emptySet());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<<i);
|
||||
MMapDirectory mmapDir = new MMapDirectory(createTempDir("testSeekZero"), null, 1<<i);
|
||||
IndexOutput io = mmapDir.createOutput("zeroBytes", newIOContext(random()));
|
||||
io.close();
|
||||
IndexInput ii = mmapDir.openInput("zeroBytes", newIOContext(random()));
|
||||
|
@ -189,7 +186,7 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
|
||||
public void testSeekSliceZero() throws Exception {
|
||||
for (int i = 0; i < 31; i++) {
|
||||
MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeekSliceZero"), null, 1<<i);
|
||||
MMapDirectory mmapDir = new MMapDirectory(createTempDir("testSeekSliceZero"), null, 1<<i);
|
||||
IndexOutput io = mmapDir.createOutput("zeroBytes", newIOContext(random()));
|
||||
io.close();
|
||||
IndexInputSlicer slicer = mmapDir.createSlicer("zeroBytes", newIOContext(random()));
|
||||
|
@ -203,7 +200,7 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
|
||||
public void testSeekEnd() throws Exception {
|
||||
for (int i = 0; i < 17; i++) {
|
||||
MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeekEnd"), null, 1<<i);
|
||||
MMapDirectory mmapDir = new MMapDirectory(createTempDir("testSeekEnd"), null, 1<<i);
|
||||
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
|
||||
byte bytes[] = new byte[1<<i];
|
||||
random().nextBytes(bytes);
|
||||
|
@ -221,7 +218,7 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
|
||||
public void testSeekSliceEnd() throws Exception {
|
||||
for (int i = 0; i < 17; i++) {
|
||||
MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeekSliceEnd"), null, 1<<i);
|
||||
MMapDirectory mmapDir = new MMapDirectory(createTempDir("testSeekSliceEnd"), null, 1<<i);
|
||||
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
|
||||
byte bytes[] = new byte[1<<i];
|
||||
random().nextBytes(bytes);
|
||||
|
@ -241,7 +238,7 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
|
||||
public void testSeeking() throws Exception {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
MMapDirectory mmapDir = new MMapDirectory(TestUtil.createTempDir("testSeeking"), null, 1<<i);
|
||||
MMapDirectory mmapDir = new MMapDirectory(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 +265,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.createTempDir("testSlicedSeeking"), null, 1<<i);
|
||||
MMapDirectory mmapDir = new MMapDirectory(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);
|
||||
|
@ -301,9 +298,7 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
}
|
||||
|
||||
private void assertChunking(Random random, int chunkSize) throws Exception {
|
||||
File path = TestUtil.createTempFile("mmap" + chunkSize, "tmp", workDir);
|
||||
path.delete();
|
||||
path.mkdirs();
|
||||
File path = createTempDir("mmap" + chunkSize);
|
||||
MMapDirectory mmapDir = new MMapDirectory(path, null, chunkSize);
|
||||
// we will map a lot, try to turn on the unmap hack
|
||||
if (MMapDirectory.UNMAP_SUPPORTED)
|
||||
|
|
|
@ -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.createTempDir("doesnotexist");
|
||||
File tempDir = createTempDir("doesnotexist");
|
||||
TestUtil.rm(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.createTempDir("foo")), 2.0, 25.0);
|
||||
Directory dir = new NRTCachingDirectory(newFSDirectory(createTempDir("foo")), 2.0, 25.0);
|
||||
String name = "file";
|
||||
try {
|
||||
dir.createOutput(name, newIOContext(random())).close();
|
||||
|
|
|
@ -50,7 +50,7 @@ public class TestRAMDirectory extends LuceneTestCase {
|
|||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
indexDir = TestUtil.createTempDir("RAMDirIndex");
|
||||
indexDir = createTempDir("RAMDirIndex");
|
||||
|
||||
Directory dir = newFSDirectory(indexDir);
|
||||
IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
|
||||
|
|
|
@ -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.createTempDir("testLuceneMmap");
|
||||
File dirPath = createTempDir("testLuceneMmap");
|
||||
rmDir(dirPath);
|
||||
MMapDirectory dir = new MMapDirectory(dirPath, null);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.junit.Ignore;
|
|||
public class Test2BPagedBytes extends LuceneTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
BaseDirectoryWrapper dir = newFSDirectory(TestUtil.createTempDir("test2BPagedBytes"));
|
||||
BaseDirectoryWrapper dir = newFSDirectory(createTempDir("test2BPagedBytes"));
|
||||
if (dir instanceof MockDirectoryWrapper) {
|
||||
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TestOfflineSorter extends LuceneTestCase {
|
|||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
tempDir = TestUtil.createTempDir("mergesort");
|
||||
tempDir = createTempDir("mergesort");
|
||||
TestUtil.rm(tempDir);
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
|
|
|
@ -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.createTempDir("testOverflow"));
|
||||
BaseDirectoryWrapper dir = newFSDirectory(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.createTempDir("testOverflow"));
|
||||
BaseDirectoryWrapper dir = newFSDirectory(createTempDir("testOverflow"));
|
||||
if (dir instanceof MockDirectoryWrapper) {
|
||||
((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
|
||||
}
|
||||
|
|
|
@ -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.createTempDir("2BFST"));
|
||||
Directory dir = new MMapDirectory(createTempDir("2BFST"));
|
||||
|
||||
for(int doPackIter=0;doPackIter<2;doPackIter++) {
|
||||
boolean doPack = doPackIter == 1;
|
||||
|
|
|
@ -310,7 +310,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.createTempDir("fstlines");
|
||||
final File tempDir = createTempDir("fstlines");
|
||||
final Directory dir = newFSDirectory(tempDir);
|
||||
final IndexWriter writer = new IndexWriter(dir, conf);
|
||||
final long stopTime = System.currentTimeMillis() + RUN_TIME_MSEC;
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TestLeaveFilesIfTestFails extends WithNestedTests {
|
|||
public static class Nested1 extends WithNestedTests.AbstractNestedTest {
|
||||
static File file;
|
||||
public void testDummy() {
|
||||
file = TestUtil.createTempDir("leftover");
|
||||
file = createTempDir("leftover");
|
||||
file.mkdirs();
|
||||
fail();
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TestDemo extends LuceneTestCase {
|
|||
|
||||
public void testIndexSearch() throws Exception {
|
||||
File dir = getDataFile("test-files/docs");
|
||||
File indexDir = TestUtil.createTempDir("ContribDemoTest");
|
||||
File indexDir = createTempDir("ContribDemoTest");
|
||||
IndexFiles.main(new String[] { "-create", "-docs", dir.getPath(), "-index", indexDir.getPath()});
|
||||
testOneSearch(indexDir, "apache", 3);
|
||||
testOneSearch(indexDir, "patent", 8);
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TestAddTaxonomy extends FacetTestCase {
|
|||
|
||||
private OrdinalMap randomOrdinalMap() throws IOException {
|
||||
if (random().nextBoolean()) {
|
||||
return new DiskOrdinalMap(TestUtil.createTempFile("taxoMap", ""));
|
||||
return new DiskOrdinalMap(createTempFile("taxoMap", ""));
|
||||
} else {
|
||||
return new MemoryOrdinalMap();
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class TestCharBlockArray extends FacetTestCase {
|
|||
|
||||
assertEqualsInternal("GrowingCharArray<->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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<? extends Lookup> ctor = cls.getConstructor(Analyzer.class);
|
||||
lookup = ctor.newInstance(a);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<iters;iter++) {
|
||||
File path = TestUtil.createTempDir("testPostingsFormat");
|
||||
File path = createTempDir("testPostingsFormat");
|
||||
Directory dir = newFSDirectory(path);
|
||||
|
||||
boolean indexPayloads = random().nextBoolean();
|
||||
|
|
|
@ -599,7 +599,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.createTempDir("testBigDocuments")));
|
||||
Directory dir = new MockDirectoryWrapper(random(), new MMapDirectory(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);
|
||||
|
|
|
@ -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.createTempDir(testName);
|
||||
final File tempDir = 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.
|
||||
|
|
|
@ -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.createTempDir("ShardSearchingTestBase"));
|
||||
dir = newFSDirectory(createTempDir("ShardSearchingTestBase"));
|
||||
// TODO: set warmer
|
||||
MockAnalyzer analyzer = new MockAnalyzer(random());
|
||||
analyzer.setMaxTokenLength(TestUtil.nextInt(random(), 1, IndexWriter.MAX_TERM_LENGTH));
|
||||
|
|
|
@ -17,55 +17,153 @@ package org.apache.lucene.util;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.lang.annotation.*;
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean;
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsInt;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Deque;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.document.Field.Store;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Field.Store;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.*;
|
||||
import org.apache.lucene.index.AlcoholicMergePolicy;
|
||||
import org.apache.lucene.index.AssertingAtomicReader;
|
||||
import org.apache.lucene.index.AssertingDirectoryReader;
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.AtomicReaderContext;
|
||||
import org.apache.lucene.index.BinaryDocValues;
|
||||
import org.apache.lucene.index.CompositeReader;
|
||||
import org.apache.lucene.index.ConcurrentMergeScheduler;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.DocsAndPositionsEnum;
|
||||
import org.apache.lucene.index.DocsEnum;
|
||||
import org.apache.lucene.index.FieldFilterAtomicReader;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.index.FieldInfos;
|
||||
import org.apache.lucene.index.Fields;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexReader.ReaderClosedListener;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.LogByteSizeMergePolicy;
|
||||
import org.apache.lucene.index.LogDocMergePolicy;
|
||||
import org.apache.lucene.index.LogMergePolicy;
|
||||
import org.apache.lucene.index.MergePolicy;
|
||||
import org.apache.lucene.index.MockRandomMergePolicy;
|
||||
import org.apache.lucene.index.MultiDocValues;
|
||||
import org.apache.lucene.index.MultiFields;
|
||||
import org.apache.lucene.index.NumericDocValues;
|
||||
import org.apache.lucene.index.ParallelAtomicReader;
|
||||
import org.apache.lucene.index.ParallelCompositeReader;
|
||||
import org.apache.lucene.index.SegmentReader;
|
||||
import org.apache.lucene.index.SerialMergeScheduler;
|
||||
import org.apache.lucene.index.SimpleMergedSegmentWarmer;
|
||||
import org.apache.lucene.index.SlowCompositeReaderWrapper;
|
||||
import org.apache.lucene.index.SortedDocValues;
|
||||
import org.apache.lucene.index.SortedSetDocValues;
|
||||
import org.apache.lucene.index.StorableField;
|
||||
import org.apache.lucene.index.StoredDocument;
|
||||
import org.apache.lucene.index.Terms;
|
||||
import org.apache.lucene.index.TermsEnum;
|
||||
import org.apache.lucene.index.TermsEnum.SeekStatus;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.index.TieredMergePolicy;
|
||||
import org.apache.lucene.search.AssertingIndexSearcher;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.FieldCache;
|
||||
import org.apache.lucene.search.FieldCache.CacheEntry;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.QueryUtils.FCInvisibleMultiReader;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.apache.lucene.store.BaseDirectoryWrapper;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.FlushInfo;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.IOContext.Context;
|
||||
import org.apache.lucene.store.LockFactory;
|
||||
import org.apache.lucene.store.MergeInfo;
|
||||
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||
import org.apache.lucene.store.MockDirectoryWrapper.Throttling;
|
||||
import org.apache.lucene.store.NRTCachingDirectory;
|
||||
import org.apache.lucene.store.RateLimitedDirectoryWrapper;
|
||||
import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
|
||||
import org.apache.lucene.util.automaton.AutomatonTestUtil;
|
||||
import org.apache.lucene.util.automaton.CompiledAutomaton;
|
||||
import org.apache.lucene.util.automaton.RegExp;
|
||||
import org.junit.*;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.RunWith;
|
||||
import com.carrotsearch.randomizedtesting.*;
|
||||
import com.carrotsearch.randomizedtesting.annotations.*;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.JUnit4MethodProvider;
|
||||
import com.carrotsearch.randomizedtesting.LifecycleScope;
|
||||
import com.carrotsearch.randomizedtesting.MixWithSuiteName;
|
||||
import com.carrotsearch.randomizedtesting.RandomizedContext;
|
||||
import com.carrotsearch.randomizedtesting.RandomizedRunner;
|
||||
import com.carrotsearch.randomizedtesting.RandomizedTest;
|
||||
import com.carrotsearch.randomizedtesting.annotations.Listeners;
|
||||
import com.carrotsearch.randomizedtesting.annotations.SeedDecorators;
|
||||
import com.carrotsearch.randomizedtesting.annotations.TestGroup;
|
||||
import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakGroup;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakGroup.Group;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;
|
||||
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
import com.carrotsearch.randomizedtesting.rules.NoClassHooksShadowingRule;
|
||||
import com.carrotsearch.randomizedtesting.rules.NoInstanceHooksOverridesRule;
|
||||
import com.carrotsearch.randomizedtesting.rules.StaticFieldsInvariantRule;
|
||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesInvariantRule;
|
||||
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean;
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsInt;
|
||||
import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;
|
||||
|
||||
/**
|
||||
* Base class for all Lucene unit tests, Junit3 or Junit4 variant.
|
||||
|
@ -112,13 +210,6 @@ import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAs
|
|||
* context ({@link RandomizedContext#current()}) and then calling
|
||||
* {@link RandomizedContext#getRunnerSeedAsString()}.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>There is a number of other facilities tests can use, like:
|
||||
* <ul>
|
||||
* <li>{@link #closeAfterTest(Closeable)} and {@link #closeAfterSuite(Closeable)} to
|
||||
* register resources to be closed after each scope (if close fails, the scope
|
||||
* will fail too).</li>
|
||||
* </ul>
|
||||
*/
|
||||
@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<? extends Directory> 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<File> cleanupQueue = new ArrayDeque<File>();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<File> unremoved = rm(location, new ArrayList<File>());
|
||||
public static void rm(File... locations) throws IOException {
|
||||
ArrayList<File> unremoved = rm(new ArrayList<File>(), 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<File> rm(File location, ArrayList<File> unremoved) {
|
||||
if (location.exists()) {
|
||||
if (location.isDirectory()) {
|
||||
for (File f : location.listFiles()) {
|
||||
rm(f, unremoved);
|
||||
private static ArrayList<File> rm(ArrayList<File> 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue