You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2010/12/09 15:33:26 UTC
svn commit: r1043979 - in /lucene/dev/branches/branch_3x: lucene/
lucene/contrib/ant/src/test/org/apache/lucene/ant/
lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/quality/
lucene/contrib/instantiated/src/test/org/apache/lucene/store/ins...
Author: shaie
Date: Thu Dec 9 14:33:25 2010
New Revision: 1043979
URL: http://svn.apache.org/viewvc?rev=1043979&view=rev
Log:
LUCENE-2804: use newFSDirectory instead of FSDirectory.open in tests
Modified:
lucene/dev/branches/branch_3x/lucene/CHANGES.txt
lucene/dev/branches/branch_3x/lucene/contrib/ant/src/test/org/apache/lucene/ant/IndexTaskTest.java
lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java
lucene/dev/branches/branch_3x/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java
lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java
lucene/dev/branches/branch_3x/lucene/contrib/wordnet/src/test/org/apache/lucene/wordnet/TestWordnet.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/FSDirectory.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMDirectory.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestDirectory.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestLockFactory.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java
lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java
Modified: lucene/dev/branches/branch_3x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/CHANGES.txt?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/CHANGES.txt Thu Dec 9 14:33:25 2010
@@ -74,6 +74,9 @@ Changes in backwards compatibility polic
If you index empty fields and uses positions/offsets information on that
fields, reindex is recommended. (David Smiley, Koji Sekiguchi)
+* LUCENE-2804: Directory.setLockFactory new declares throwing an IOException.
+ (Shai Erera, Robert Muir)
+
Changes in runtime behavior
* LUCENE-1923: Made IndexReader.toString() produce something
@@ -544,6 +547,9 @@ Test Cases
as Eclipse and IntelliJ.
(Paolo Castagna, Steven Rowe via Robert Muir)
+* LUCENE-2804: add newFSDirectory to LuceneTestCase to create a FSDirectory at
+ random. (Shai Erera, Robert Muir)
+
Documentation
* LUCENE-2579: Fix oal.search's package.html description of abstract
Modified: lucene/dev/branches/branch_3x/lucene/contrib/ant/src/test/org/apache/lucene/ant/IndexTaskTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/ant/src/test/org/apache/lucene/ant/IndexTaskTest.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/ant/src/test/org/apache/lucene/ant/IndexTaskTest.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/ant/src/test/org/apache/lucene/ant/IndexTaskTest.java Thu Dec 9 14:33:25 2010
@@ -26,7 +26,7 @@ import org.apache.lucene.queryParser.Que
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
-import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.Directory;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.apache.lucene.util.LuceneTestCase;
@@ -41,7 +41,7 @@ public class IndexTaskTest extends Lucen
private Searcher searcher;
private Analyzer analyzer;
- private FSDirectory dir;
+ private Directory dir;
/**
@@ -68,7 +68,7 @@ public class IndexTaskTest extends Lucen
task.setProject(project);
task.execute();
- dir = FSDirectory.open(indexDir);
+ dir = newFSDirectory(indexDir);
searcher = new IndexSearcher(dir, true);
analyzer = new StopAnalyzer(TEST_VERSION_CURRENT);
}
Modified: lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java Thu Dec 9 14:33:25 2010
@@ -23,7 +23,7 @@ import org.apache.lucene.benchmark.quali
import org.apache.lucene.benchmark.quality.utils.SimpleQQParser;
import org.apache.lucene.benchmark.quality.utils.SubmissionReport;
import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.Directory;
import java.io.BufferedReader;
import java.io.File;
@@ -67,7 +67,8 @@ public class TestQualityRun extends Benc
// validate topics & judgments match each other
judge.validateData(qqs, logger);
- IndexSearcher searcher = new IndexSearcher(FSDirectory.open(new File(getWorkDir(),"index")), true);
+ Directory dir = newFSDirectory(new File(getWorkDir(),"index"));
+ IndexSearcher searcher = new IndexSearcher(dir, true);
QualityQueryParser qqParser = new SimpleQQParser("title","body");
QualityBenchmark qrun = new QualityBenchmark(qqs, qqParser, searcher, docNameField);
@@ -131,8 +132,9 @@ public class TestQualityRun extends Benc
for (int j = 1; j <= QualityStats.MAX_POINTS; j++) {
assertTrue("avg p_at_"+j+" should be hurt: "+avg.getPrecisionAt(j), 1.0 > avg.getPrecisionAt(j));
}
-
+ searcher.close();
+ dir.close();
}
public void testTrecTopicsReader() throws Exception {
Modified: lucene/dev/branches/branch_3x/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java Thu Dec 9 14:33:25 2010
@@ -30,7 +30,6 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Payload;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java Thu Dec 9 14:33:25 2010
@@ -21,7 +21,7 @@ import java.io.File;
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
@@ -33,7 +33,7 @@ public class TestIndexSplitter extends L
File destDir = new File(TEMP_DIR, "testfilesplitterdest");
_TestUtil.rmDir(destDir);
destDir.mkdirs();
- FSDirectory fsDir = FSDirectory.open(dir);
+ Directory fsDir = newFSDirectory(dir);
IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT,
new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
.setOpenMode(OpenMode.CREATE);
@@ -56,14 +56,20 @@ public class TestIndexSplitter extends L
iw.addDocument(doc);
}
iw.commit();
- assertEquals(3, iw.getReader().getSequentialSubReaders().length);
+ IndexReader iwReader = iw.getReader();
+ assertEquals(3, iwReader.getSequentialSubReaders().length);
+ iwReader.close();
iw.close();
+
// we should have 2 segments now
IndexSplitter is = new IndexSplitter(dir);
String splitSegName = is.infos.info(1).name;
is.split(destDir, new String[] {splitSegName});
- IndexReader r = IndexReader.open(FSDirectory.open(destDir), true);
+ Directory fsDirDest = newFSDirectory(destDir);
+ IndexReader r = IndexReader.open(fsDirDest, true);
assertEquals(50, r.maxDoc());
+ r.close();
+ fsDirDest.close();
// now test cmdline
File destDir2 = new File(TEMP_DIR, "testfilesplitterdest2");
@@ -71,12 +77,17 @@ public class TestIndexSplitter extends L
destDir2.mkdirs();
IndexSplitter.main(new String[] {dir.getAbsolutePath(), destDir2.getAbsolutePath(), splitSegName});
assertEquals(3, destDir2.listFiles().length);
- r = IndexReader.open(FSDirectory.open(destDir2), true);
+ Directory fsDirDest2 = newFSDirectory(destDir2);
+ r = IndexReader.open(fsDirDest2, true);
assertEquals(50, r.maxDoc());
+ r.close();
+ fsDirDest2.close();
// now remove the copied segment from src
IndexSplitter.main(new String[] {dir.getAbsolutePath(), "-d", splitSegName});
- r = IndexReader.open(FSDirectory.open(dir), true);
+ r = IndexReader.open(fsDir, true);
assertEquals(2, r.getSequentialSubReaders().length);
+ r.close();
+ fsDir.close();
}
}
Modified: lucene/dev/branches/branch_3x/lucene/contrib/wordnet/src/test/org/apache/lucene/wordnet/TestWordnet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/wordnet/src/test/org/apache/lucene/wordnet/TestWordnet.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/wordnet/src/test/org/apache/lucene/wordnet/TestWordnet.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/wordnet/src/test/org/apache/lucene/wordnet/TestWordnet.java Thu Dec 9 14:33:25 2010
@@ -28,14 +28,14 @@ import org.apache.lucene.search.IndexSea
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
public class TestWordnet extends LuceneTestCase {
private Searcher searcher;
-
- String storePathName =
- new File(TEMP_DIR,"testLuceneWordnet").getAbsolutePath();
+ private Directory dir;
+
+ String storePathName = new File(TEMP_DIR,"testLuceneWordnet").getAbsolutePath();
@Override
public void setUp() throws Exception {
@@ -48,7 +48,8 @@ public class TestWordnet extends LuceneT
Syns2Index.main(commandLineArgs);
} catch (Throwable t) { throw new RuntimeException(t); }
- searcher = new IndexSearcher(FSDirectory.open(new File(storePathName)), true);
+ dir = newFSDirectory(new File(storePathName));
+ searcher = new IndexSearcher(dir, true);
}
public void testExpansion() throws IOException {
@@ -72,6 +73,7 @@ public class TestWordnet extends LuceneT
@Override
public void tearDown() throws Exception {
searcher.close();
+ dir.close();
rmDir(storePathName); // delete our temporary synonym index
super.tearDown();
}
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/Directory.java Thu Dec 9 14:33:25 2010
@@ -170,7 +170,7 @@ public abstract class Directory implemen
*
* @param lockFactory instance of {@link LockFactory}.
*/
- public void setLockFactory(LockFactory lockFactory) {
+ public void setLockFactory(LockFactory lockFactory) throws IOException {
assert lockFactory != null;
this.lockFactory = lockFactory;
lockFactory.setLockPrefix(this.getLockID());
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/FSDirectory.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/FSDirectory.java Thu Dec 9 14:33:25 2010
@@ -156,20 +156,6 @@ public abstract class FSDirectory extend
throw new NoSuchDirectoryException("file '" + directory + "' exists but is not a directory");
setLockFactory(lockFactory);
-
- // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed
- // in index dir. If no index dir is given, set ourselves
- if (lockFactory instanceof FSLockFactory) {
- final FSLockFactory lf = (FSLockFactory) lockFactory;
- final File dir = lf.getLockDir();
- // if the lock factory has no lockDir set, use the this directory as lockDir
- if (dir == null) {
- lf.setLockDir(directory);
- lf.setLockPrefix(null);
- } else if (dir.getCanonicalPath().equals(directory.getCanonicalPath())) {
- lf.setLockPrefix(null);
- }
- }
}
/** Creates an FSDirectory instance, trying to pick the
@@ -209,6 +195,26 @@ public abstract class FSDirectory extend
}
}
+ @Override
+ public void setLockFactory(LockFactory lockFactory) throws IOException {
+ super.setLockFactory(lockFactory);
+
+ // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed
+ // in index dir. If no index dir is given, set ourselves
+ if (lockFactory instanceof FSLockFactory) {
+ final FSLockFactory lf = (FSLockFactory) lockFactory;
+ final File dir = lf.getLockDir();
+ // if the lock factory has no lockDir set, use the this directory as lockDir
+ if (dir == null) {
+ lf.setLockDir(directory);
+ lf.setLockPrefix(null);
+ } else if (dir.getCanonicalPath().equals(directory.getCanonicalPath())) {
+ lf.setLockPrefix(null);
+ }
+ }
+
+ }
+
/** Lists all files (not subdirectories) in the
* directory. This method never returns null (throws
* {@link IOException} instead).
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMDirectory.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMDirectory.java Thu Dec 9 14:33:25 2010
@@ -48,7 +48,11 @@ public class RAMDirectory extends Direct
/** Constructs an empty {@link Directory}. */
public RAMDirectory() {
- setLockFactory(new SingleInstanceLockFactory());
+ try {
+ setLockFactory(new SingleInstanceLockFactory());
+ } catch (IOException e) {
+ // Cannot happen
+ }
}
/**
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java Thu Dec 9 14:33:25 2010
@@ -43,7 +43,6 @@ public class Test2BTerms extends LuceneT
private final static int TOKEN_LEN = 5;
private final char[] chars;
private final byte[] bytes;
- private int charUpto;
public MyTokenStream(int tokensPerDoc) {
super();
@@ -54,6 +53,7 @@ public class Test2BTerms extends LuceneT
bytes = new byte[2*TOKEN_LEN];
}
+ @Override
public boolean incrementToken() {
if (tokenCount >= tokensPerDoc) {
return false;
@@ -68,6 +68,7 @@ public class Test2BTerms extends LuceneT
return true;
}
+ @Override
public void reset() {
tokenCount = 0;
}
@@ -80,7 +81,7 @@ public class Test2BTerms extends LuceneT
int TERMS_PER_DOC = 1000000;
- Directory dir = FSDirectory.open(_TestUtil.getTempDir("2BTerms"));
+ Directory dir = newFSDirectory(_TestUtil.getTempDir("2BTerms"));
IndexWriter w = new IndexWriter(dir,
newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
.setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH)
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java Thu Dec 9 14:33:25 2010
@@ -195,7 +195,7 @@ public class TestAtomicUpdate extends Lu
// Second in an FSDirectory:
File dirPath = _TestUtil.getTempDir("lucene.test.atomic");
- directory = FSDirectory.open(dirPath);
+ directory = newFSDirectory(dirPath);
runTest(directory);
directory.close();
_TestUtil.rmDir(dirPath);
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Thu Dec 9 14:33:25 2010
@@ -47,7 +47,6 @@ import org.apache.lucene.search.ScoreDoc
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.ReaderUtil;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
@@ -213,7 +212,7 @@ public class TestBackwardsCompatibility
for(int i=0;i<oldNames.length;i++) {
unzip(getDataFile("index." + oldNames[i] + ".zip"), oldNames[i]);
String fullPath = fullDir(oldNames[i]);
- Directory dir = FSDirectory.open(new File(fullPath));
+ Directory dir = newFSDirectory(new File(fullPath));
if (oldNames[i].startsWith("29.")) {
assertCompressedFields29(dir, true);
@@ -243,7 +242,7 @@ public class TestBackwardsCompatibility
for (String name : oldNames) {
unzip(getDataFile("index." + name + ".zip"), name);
String fullPath = fullDir(name);
- Directory dir = FSDirectory.open(new File(fullPath));
+ Directory dir = newFSDirectory(new File(fullPath));
Directory targetDir = newDirectory();
IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(
@@ -263,7 +262,7 @@ public class TestBackwardsCompatibility
for (String name : oldNames) {
unzip(getDataFile("index." + name + ".zip"), name);
String fullPath = fullDir(name);
- Directory dir = FSDirectory.open(new File(fullPath));
+ Directory dir = newFSDirectory(new File(fullPath));
IndexReader reader = IndexReader.open(dir);
Directory targetDir = newDirectory();
@@ -320,7 +319,7 @@ public class TestBackwardsCompatibility
dirName = fullDir(dirName);
- Directory dir = FSDirectory.open(new File(dirName));
+ Directory dir = newFSDirectory(new File(dirName));
IndexSearcher searcher = new IndexSearcher(dir, true);
IndexReader reader = searcher.getIndexReader();
@@ -397,7 +396,7 @@ public class TestBackwardsCompatibility
String origDirName = dirName;
dirName = fullDir(dirName);
- Directory dir = FSDirectory.open(new File(dirName));
+ Directory dir = newFSDirectory(new File(dirName));
// open writer
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
// add 10 docs
@@ -465,7 +464,7 @@ public class TestBackwardsCompatibility
dirName = fullDir(dirName);
- Directory dir = FSDirectory.open(new File(dirName));
+ Directory dir = newFSDirectory(new File(dirName));
// make sure searching sees right # hits
IndexSearcher searcher = new IndexSearcher(dir, true);
@@ -515,7 +514,7 @@ public class TestBackwardsCompatibility
dirName = fullDir(dirName);
- Directory dir = FSDirectory.open(new File(dirName));
+ Directory dir = newFSDirectory(new File(dirName));
IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(10);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(doCFS);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundDocStore(doCFS);
@@ -547,6 +546,7 @@ public class TestBackwardsCompatibility
// Set one norm so we get a .s0 file:
reader.setNorm(21, "content", (float) 1.5);
reader.close();
+ dir.close();
}
/* Verifies that the expected file names were produced */
@@ -557,7 +557,7 @@ public class TestBackwardsCompatibility
rmDir(outputDir);
try {
- Directory dir = FSDirectory.open(new File(fullDir(outputDir)));
+ Directory dir = newFSDirectory(new File(fullDir(outputDir)));
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(-1).setRAMBufferSizeMB(16.0);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(true);
@@ -706,7 +706,7 @@ public class TestBackwardsCompatibility
unzip(getDataFile("index." + oldNames[i] + ".zip"), oldNames[i]);
String fullPath = fullDir(oldNames[i]);
- Directory dir = FSDirectory.open(new File(fullPath));
+ Directory dir = newFSDirectory(new File(fullPath));
IndexSearcher searcher = new IndexSearcher(dir, true);
for (int id=10; id<15; id++) {
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java Thu Dec 9 14:33:25 2010
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.analysis.WhitespaceAnalyzer;
@@ -66,7 +67,7 @@ public class TestCrash extends LuceneTes
// happened, so we must create an initial commit just to allow that, but
// before any documents were added.
IndexWriter writer = initIndex(random, true);
- MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
+ Directory dir = writer.getDirectory();
crash(writer);
IndexReader reader = IndexReader.open(dir, false);
assertTrue(reader.numDocs() < 157);
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java Thu Dec 9 14:33:25 2010
@@ -34,10 +34,8 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.LuceneTestCase;
-
/** JUnit adaptation of an older test case DocTest. */
public class TestDoc extends LuceneTestCase {
@@ -46,12 +44,10 @@ public class TestDoc extends LuceneTestC
TestRunner.run (new TestSuite(TestDoc.class));
}
-
private File workDir;
private File indexDir;
private LinkedList<File> files;
-
/** Set the test case. This test case needs
* a few text files created in the current working directory.
*/
@@ -64,7 +60,7 @@ public class TestDoc extends LuceneTestC
indexDir = new File(workDir, "testIndex");
indexDir.mkdirs();
- Directory directory = FSDirectory.open(indexDir);
+ Directory directory = newFSDirectory(indexDir);
directory.close();
files = new LinkedList<File>();
@@ -109,7 +105,7 @@ public class TestDoc extends LuceneTestC
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw, true);
- Directory directory = FSDirectory.open(indexDir);
+ Directory directory = newFSDirectory(indexDir);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT))
.setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(-1));
@@ -140,7 +136,7 @@ public class TestDoc extends LuceneTestC
sw = new StringWriter();
out = new PrintWriter(sw, true);
- directory = FSDirectory.open(indexDir);
+ directory = newFSDirectory(indexDir);
writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT))
.setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(-1));
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java Thu Dec 9 14:33:25 2010
@@ -36,7 +36,6 @@ import org.apache.lucene.index.IndexWrit
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.util.LuceneTestCase;
@@ -162,7 +161,6 @@ public class TestFieldsReader extends Lu
assertTrue(dir != null);
assertTrue(fieldInfos != null);
FieldsReader reader = new FieldsReader(dir, TEST_SEGMENT_NAME, fieldInfos);
- assertTrue(reader != null);
assertTrue(reader.size() == 1);
Set<String> loadFieldNames = new HashSet<String>();
loadFieldNames.add(DocHelper.TEXT_FIELD_1_KEY);
@@ -176,6 +174,7 @@ public class TestFieldsReader extends Lu
// Use LATENT instead of LAZY
SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames) {
+ @Override
public FieldSelectorResult accept(String fieldName) {
final FieldSelectorResult result = super.accept(fieldName);
if (result == FieldSelectorResult.LAZY_LOAD) {
@@ -292,7 +291,7 @@ public class TestFieldsReader extends Lu
String userName = System.getProperty("user.name");
File file = new File(TEMP_DIR, "lazyDir" + userName);
_TestUtil.rmDir(file);
- FSDirectory tmpDir = FSDirectory.open(file);
+ Directory tmpDir = newFSDirectory(file);
assertTrue(tmpDir != null);
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE);
@@ -345,8 +344,9 @@ public class TestFieldsReader extends Lu
assertTrue("value is null and it shouldn't be", value != null);
lazyTime += (finish - start);
reader.close();
-
}
+ tmpDir.close();
+
if (VERBOSE) {
System.out.println("Average Non-lazy time (should be very close to zero): " + regularTime / length + " ms for " + length + " reads");
System.out.println("Average Lazy Time (should be greater than zero): " + lazyTime / length + " ms for " + length + " reads");
@@ -390,9 +390,9 @@ public class TestFieldsReader extends Lu
public static class FaultyFSDirectory extends Directory {
- FSDirectory fsDir;
+ Directory fsDir;
public FaultyFSDirectory(File dir) throws IOException {
- fsDir = FSDirectory.open(dir);
+ fsDir = newFSDirectory(dir);
lockFactory = fsDir.getLockFactory();
}
@Override
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java Thu Dec 9 14:33:25 2010
@@ -46,7 +46,6 @@ import org.apache.lucene.search.ScoreDoc
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.NoSuchDirectoryException;
@@ -55,8 +54,7 @@ import org.apache.lucene.store.LockRelea
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
-public class TestIndexReader extends LuceneTestCase
-{
+public class TestIndexReader extends LuceneTestCase {
public void testCommitUserData() throws Exception {
Directory d = newDirectory();
@@ -519,8 +517,7 @@ public class TestIndexReader extends Luc
// Make sure you can set norms & commit even if a reader
// is open against the index:
public void testWritingNorms() throws IOException {
- File indexDir = new File(TEMP_DIR, "lucenetestnormwriter");
- Directory dir = FSDirectory.open(indexDir);
+ Directory dir = newDirectory();
IndexWriter writer;
IndexReader reader;
Term searchTerm = new Term("content", "aaa");
@@ -556,8 +553,6 @@ public class TestIndexReader extends Luc
reader2.close();
dir.close();
-
- rmDir(indexDir);
}
@@ -700,7 +695,7 @@ public class TestIndexReader extends Luc
public void testFilesOpenClose() throws IOException {
// Create initial data set
File dirFile = _TestUtil.getTempDir("TestIndexReader.testFilesOpenClose");
- Directory dir = FSDirectory.open(dirFile);
+ Directory dir = newFSDirectory(dirFile);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
addDoc(writer, "test");
writer.close();
@@ -708,7 +703,7 @@ public class TestIndexReader extends Luc
// Try to erase the data - this ensures that the writer closed all files
_TestUtil.rmDir(dirFile);
- dir = FSDirectory.open(dirFile);
+ dir = newFSDirectory(dirFile);
// Now create the data set again, just as before
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
@@ -717,7 +712,7 @@ public class TestIndexReader extends Luc
dir.close();
// Now open existing directory and test that reader closes all files
- dir = FSDirectory.open(dirFile);
+ dir = newFSDirectory(dirFile);
IndexReader reader1 = IndexReader.open(dir, false);
reader1.close();
dir.close();
@@ -1151,7 +1146,7 @@ public class TestIndexReader extends Luc
public void testOpenReaderAfterDelete() throws IOException {
File dirFile = new File(TEMP_DIR, "deletetest");
- Directory dir = FSDirectory.open(dirFile);
+ Directory dir = newFSDirectory(dirFile);
try {
IndexReader.open(dir, false);
fail("expected FileNotFoundException");
@@ -1306,19 +1301,11 @@ public class TestIndexReader extends Luc
writer.addDocument(doc);
}
- private void addDoc(IndexWriter writer, String value) throws IOException
- {
+ private void addDoc(IndexWriter writer, String value) throws IOException {
Document doc = new Document();
doc.add(newField("content", value, Field.Store.NO, Field.Index.ANALYZED));
writer.addDocument(doc);
}
- private void rmDir(File dir) {
- File[] files = dir.listFiles();
- for (int i = 0; i < files.length; i++) {
- files[i].delete();
- }
- dir.delete();
- }
public static void assertIndexEquals(IndexReader index1, IndexReader index2) throws IOException {
assertEquals("IndexReaders have different values for numDocs.", index1.numDocs(), index2.numDocs());
@@ -1567,7 +1554,7 @@ public class TestIndexReader extends Luc
// IndexReader on a non-existent directory, you get a
// good exception
public void testNoDir() throws Throwable {
- Directory dir = FSDirectory.open(_TestUtil.getTempDir("doesnotexist"));
+ Directory dir = newFSDirectory(_TestUtil.getTempDir("doesnotexist"));
try {
IndexReader.open(dir, true);
fail("did not hit expected exception");
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java Thu Dec 9 14:33:25 2010
@@ -17,7 +17,6 @@ package org.apache.lucene.index;
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
@@ -34,7 +33,6 @@ import org.apache.lucene.index.SegmentRe
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.LuceneTestCase;
/**
@@ -79,8 +77,7 @@ public class TestIndexReaderCloneNorms e
*/
public void testNorms() throws IOException {
// test with a single index: index1
- File indexDir1 = new File(TEMP_DIR, "lucenetestindex1");
- Directory dir1 = FSDirectory.open(indexDir1);
+ Directory dir1 = newDirectory();
IndexWriter.unlock(dir1);
norms = new ArrayList<Float>();
@@ -98,15 +95,13 @@ public class TestIndexReaderCloneNorms e
modifiedNorms = new ArrayList<Float>();
numDocNorms = 0;
- File indexDir2 = new File(TEMP_DIR, "lucenetestindex2");
- Directory dir2 = FSDirectory.open(indexDir2);
+ Directory dir2 = newDirectory();
createIndex(random, dir2);
doTestNorms(random, dir2);
// add index1 and index2 to a third index: index3
- File indexDir3 = new File(TEMP_DIR, "lucenetestindex3");
- Directory dir3 = FSDirectory.open(indexDir3);
+ Directory dir3 = newDirectory();
createIndex(random, dir3);
IndexWriter iw = new IndexWriter(dir3, newIndexWriterConfig(
@@ -157,6 +152,9 @@ public class TestIndexReaderCloneNorms e
verifyIndex(irc3);
irc3.flush();
irc3.close();
+
+ irc.close();
+ ir.close();
}
public void testNormsClose() throws IOException {
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java Thu Dec 9 14:33:25 2010
@@ -42,11 +42,9 @@ import org.apache.lucene.search.IndexSea
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.BitVector;
-import org.apache.lucene.util.LuceneTestCase;
public class TestIndexReaderReopen extends LuceneTestCase {
@@ -151,12 +149,12 @@ public class TestIndexReaderReopen exten
// in each iteration verify the work of previous iteration.
// try this once with reopen once recreate, on both RAMDir and FSDir.
public void testCommitReopenFS () throws IOException {
- Directory dir = FSDirectory.open(indexDir);
+ Directory dir = newFSDirectory(indexDir);
doTestReopenWithCommit(random, dir, true);
dir.close();
}
public void testCommitRecreateFS () throws IOException {
- Directory dir = FSDirectory.open(indexDir);
+ Directory dir = newFSDirectory(indexDir);
doTestReopenWithCommit(random, dir, false);
dir.close();
}
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Thu Dec 9 14:33:25 2010
@@ -58,7 +58,6 @@ import org.apache.lucene.search.TermQuer
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.LockFactory;
@@ -377,34 +376,30 @@ public class TestIndexWriter extends Luc
// reader holds it open (this fails pre lock-less
// commits on windows):
public void testCreateWithReader() throws IOException {
- File indexDir = _TestUtil.getTempDir("lucenetestindexwriter");
-
- try {
- Directory dir = FSDirectory.open(indexDir);
-
- // add one document & close writer
- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
- addDoc(writer);
- writer.close();
-
- // now open reader:
- IndexReader reader = IndexReader.open(dir, true);
- assertEquals("should be one document", reader.numDocs(), 1);
-
- // now open index for create:
- writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
- assertEquals("should be zero documents", writer.maxDoc(), 0);
- addDoc(writer);
- writer.close();
-
- assertEquals("should be one document", reader.numDocs(), 1);
- IndexReader reader2 = IndexReader.open(dir, true);
- assertEquals("should be one document", reader2.numDocs(), 1);
- reader.close();
- reader2.close();
- } finally {
- rmDir(indexDir);
- }
+ Directory dir = newDirectory();
+
+ // add one document & close writer
+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+ addDoc(writer);
+ writer.close();
+
+ // now open reader:
+ IndexReader reader = IndexReader.open(dir, true);
+ assertEquals("should be one document", reader.numDocs(), 1);
+
+ // now open index for create:
+ writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+ assertEquals("should be zero documents", writer.maxDoc(), 0);
+ addDoc(writer);
+ writer.close();
+
+ assertEquals("should be one document", reader.numDocs(), 1);
+ IndexReader reader2 = IndexReader.open(dir, true);
+ assertEquals("should be one document", reader2.numDocs(), 1);
+ reader.close();
+ reader2.close();
+
+ dir.close();
}
public void testChangesAfterClose() throws IOException {
@@ -1097,16 +1092,6 @@ public class TestIndexWriter extends Luc
dir.close();
}
- private void rmDir(File dir) {
- File[] files = dir.listFiles();
- if (files != null) {
- for (int i = 0; i < files.length; i++) {
- files[i].delete();
- }
- }
- dir.delete();
- }
-
/**
* Test that no NullPointerException will be raised,
* when adding one document with a single, empty field
@@ -2107,11 +2092,9 @@ public class TestIndexWriter extends Luc
// create=true does not remove non-index files
public void testOtherFiles() throws Throwable {
- File indexDir = new File(TEMP_DIR, "otherfiles");
- Directory dir = FSDirectory.open(indexDir);
+ Directory dir = newDirectory();
try {
// Create my own random file:
-
IndexOutput out = dir.createOutput("myrandomfile");
out.writeByte((byte) 42);
out.close();
@@ -2126,7 +2109,6 @@ public class TestIndexWriter extends Luc
dir2.close();
} finally {
dir.close();
- _TestUtil.rmDir(indexDir);
}
}
@@ -2632,8 +2614,9 @@ public class TestIndexWriter extends Luc
// 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.
- FSDirectory dir = FSDirectory.open(new File(TEMP_DIR, "emptyFSDirNoLock"), NoLockFactory.getNoLockFactory());
+ Directory dir = newFSDirectory(new File(TEMP_DIR, "emptyFSDirNoLock"), NoLockFactory.getNoLockFactory());
new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))).close();
+ dir.close();
}
public void testEmptyDirRollback() throws Exception {
@@ -2681,27 +2664,22 @@ public class TestIndexWriter extends Luc
}
public void testNoSegmentFile() throws IOException {
- File tempDir = _TestUtil.getTempDir("noSegmentFile");
- try {
- Directory dir = FSDirectory.open(tempDir);
- dir.setLockFactory(NoLockFactory.getNoLockFactory());
- IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(
- TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(2));
-
- Document doc = new Document();
- doc.add(newField("c", "val", Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
- w.addDocument(doc);
- w.addDocument(doc);
- IndexWriter w2 = new IndexWriter(dir, newIndexWriterConfig(
- TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
- .setMaxBufferedDocs(2).setOpenMode(OpenMode.CREATE));
-
- w2.close();
- w.rollback();
- dir.close();
- } finally {
- _TestUtil.rmDir(tempDir);
- }
+ Directory dir = newDirectory();
+ dir.setLockFactory(NoLockFactory.getNoLockFactory());
+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(
+ TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(2));
+
+ Document doc = new Document();
+ doc.add(newField("c", "val", Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
+ w.addDocument(doc);
+ w.addDocument(doc);
+ IndexWriter w2 = new IndexWriter(dir, newIndexWriterConfig(
+ TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
+ .setMaxBufferedDocs(2).setOpenMode(OpenMode.CREATE));
+
+ w2.close();
+ w.rollback();
+ dir.close();
}
public void testFutureCommit() throws Exception {
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java Thu Dec 9 14:33:25 2010
@@ -24,7 +24,7 @@ import org.apache.lucene.util.LuceneTest
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.Directory;
/**
* This tests the patch for issue #LUCENE-715 (IndexWriter does not
@@ -73,7 +73,7 @@ public class TestIndexWriterLockRelease
}
public void testIndexWriterLockRelease() throws IOException {
- FSDirectory dir = FSDirectory.open(this.__test_dir);
+ Directory dir = newFSDirectory(this.__test_dir);
try {
new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
new StandardAnalyzer(TEST_VERSION_CURRENT))
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestPayloads.java Thu Dec 9 14:33:25 2010
@@ -37,7 +37,6 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.UnicodeUtil;
import org.apache.lucene.util._TestUtil;
@@ -157,7 +156,7 @@ public class TestPayloads extends Lucene
dir.close();
// now use a FSDirectory and repeat same test
File dirName = _TestUtil.getTempDir("test_payloads");
- dir = FSDirectory.open(dirName);
+ dir = newFSDirectory(dirName);
performTest(dir);
_TestUtil.rmDir(dirName);
dir.close();
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java Thu Dec 9 14:33:25 2010
@@ -84,18 +84,9 @@ public class TestSnapshotDeletionPolicy
@Test
public void testSnapshotDeletionPolicy() throws Exception {
- File dir = _TestUtil.getTempDir(INDEX_PATH);
- try {
- Directory fsDir = FSDirectory.open(dir);
- runTest(random, fsDir);
- fsDir.close();
- } finally {
- _TestUtil.rmDir(dir);
- }
-
- Directory dir2 = newDirectory();
- runTest(random, dir2);
- dir2.close();
+ Directory fsDir = newDirectory();
+ runTest(random, fsDir);
+ fsDir.close();
}
private void runTest(Random random, Directory dir) throws Exception {
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java Thu Dec 9 14:33:25 2010
@@ -163,17 +163,8 @@ public class TestStressIndexing extends
FSDirectory.
*/
public void testStressIndexAndSearching() throws Exception {
- // With ConcurrentMergeScheduler, in RAMDir
Directory directory = newDirectory();
runStressTest(directory, new ConcurrentMergeScheduler());
directory.close();
-
- // With ConcurrentMergeScheduler, in FSDir
- File dirPath = _TestUtil.getTempDir("lucene.test.stress");
- directory = FSDirectory.open(dirPath);
- runStressTest(directory, new ConcurrentMergeScheduler());
- directory.close();
-
- _TestUtil.rmDir(dirPath);
}
}
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java Thu Dec 9 14:33:25 2010
@@ -76,7 +76,6 @@ public class TestStressIndexing2 extends
public void testRandom() throws Throwable {
Directory dir1 = newDirectory();
- // dir1 = FSDirectory.open("foofoofoo");
Directory dir2 = newDirectory();
// mergeFactor=2; maxBufferedDocs=2; Map docs = indexRandom(1, 3, 2, dir1);
int maxThreadStates = 1+random.nextInt(10);
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.java Thu Dec 9 14:33:25 2010
@@ -136,12 +136,5 @@ public class TestThreadedOptimize extend
runTest(random, directory, new SerialMergeScheduler());
runTest(random, directory, new ConcurrentMergeScheduler());
directory.close();
-
- File dirName = new File(TEMP_DIR, "luceneTestThreadedOptimize");
- directory = FSDirectory.open(dirName);
- runTest(random, directory, new SerialMergeScheduler());
- runTest(random, directory, new ConcurrentMergeScheduler());
- directory.close();
- _TestUtil.rmDir(dirName);
}
}
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java Thu Dec 9 14:33:25 2010
@@ -513,7 +513,7 @@ public class MockDirectoryWrapper extend
}
@Override
- public synchronized void setLockFactory(LockFactory lockFactory) {
+ public synchronized void setLockFactory(LockFactory lockFactory) throws IOException {
maybeYield();
delegate.setLockFactory(lockFactory);
}
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestDirectory.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestDirectory.java Thu Dec 9 14:33:25 2010
@@ -27,20 +27,14 @@ import java.util.Arrays;
public class TestDirectory extends LuceneTestCase {
public void testDetectClose() throws Throwable {
- Directory dir = new RAMDirectory();
- dir.close();
- try {
- dir.createOutput("test");
- fail("did not hit expected exception");
- } catch (AlreadyClosedException ace) {
- }
-
- dir = FSDirectory.open(TEMP_DIR);
- dir.close();
- try {
- dir.createOutput("test");
- fail("did not hit expected exception");
- } catch (AlreadyClosedException ace) {
+ Directory[] dirs = new Directory[] { new RAMDirectory(), new SimpleFSDirectory(TEMP_DIR), new NIOFSDirectory(TEMP_DIR) };
+ for (Directory dir : dirs) {
+ dir.close();
+ try {
+ dir.createOutput("test");
+ fail("did not hit expected exception");
+ } catch (AlreadyClosedException ace) {
+ }
}
}
@@ -140,7 +134,7 @@ public class TestDirectory extends Lucen
// LUCENE-1468
public void testFSDirectoryFilter() throws IOException {
- checkDirectoryFilter(FSDirectory.open(new File(TEMP_DIR,"test")));
+ checkDirectoryFilter(newFSDirectory(new File(TEMP_DIR,"test")));
}
// LUCENE-1468
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestLockFactory.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestLockFactory.java Thu Dec 9 14:33:25 2010
@@ -145,27 +145,28 @@ public class TestLockFactory extends Luc
}
public void _testStressLocks(LockFactory lockFactory, File indexDir) throws Exception {
- FSDirectory fs1 = FSDirectory.open(indexDir, lockFactory);
+ Directory dir = newFSDirectory(indexDir, lockFactory);
- // First create a 1 doc index:
- IndexWriter w = new IndexWriter(fs1, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
- addDoc(w);
- w.close();
-
- WriterThread writer = new WriterThread(100, fs1);
- SearcherThread searcher = new SearcherThread(100, fs1);
- writer.start();
- searcher.start();
+ // First create a 1 doc index:
+ IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+ addDoc(w);
+ w.close();
+
+ WriterThread writer = new WriterThread(100, dir);
+ SearcherThread searcher = new SearcherThread(100, dir);
+ writer.start();
+ searcher.start();
- while(writer.isAlive() || searcher.isAlive()) {
- Thread.sleep(1000);
- }
+ while(writer.isAlive() || searcher.isAlive()) {
+ Thread.sleep(1000);
+ }
- assertTrue("IndexWriter hit unexpected exceptions", !writer.hitException);
- assertTrue("IndexSearcher hit unexpected exceptions", !searcher.hitException);
+ assertTrue("IndexWriter hit unexpected exceptions", !writer.hitException);
+ assertTrue("IndexSearcher hit unexpected exceptions", !searcher.hitException);
- // Cleanup
- _TestUtil.rmDir(indexDir);
+ dir.close();
+ // Cleanup
+ _TestUtil.rmDir(indexDir);
}
// Verify: NativeFSLockFactory works correctly
@@ -231,19 +232,21 @@ public class TestLockFactory extends Luc
// Verify: NativeFSLockFactory assigns null as lockPrefix if the lockDir is inside directory
public void testNativeFSLockFactoryPrefix() throws IOException {
-
File fdir1 = _TestUtil.getTempDir("TestLockFactory.8");
File fdir2 = _TestUtil.getTempDir("TestLockFactory.8.Lockdir");
- Directory dir1 = FSDirectory.open(fdir1, new NativeFSLockFactory(fdir1));
+ 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 = FSDirectory.open(fdir1, new NativeFSLockFactory(fdir2));
-
+ Directory dir2 = newFSDirectory(fdir1, new NativeFSLockFactory(fdir2));
+
String prefix1 = dir1.getLockFactory().getLockPrefix();
assertNull("Lock prefix for lockDir same as directory should be null", prefix1);
String prefix2 = dir2.getLockFactory().getLockPrefix();
assertNotNull("Lock prefix for lockDir outside of directory should be not null", prefix2);
-
+
+ dir1.close();
+ dir2.close();
+
_TestUtil.rmDir(fdir1);
_TestUtil.rmDir(fdir2);
}
@@ -251,15 +254,15 @@ public class TestLockFactory extends Luc
// Verify: default LockFactory has no prefix (ie
// write.lock is stored in index):
public void testDefaultFSLockFactoryPrefix() throws IOException {
-
// Make sure we get null prefix:
File dirName = _TestUtil.getTempDir("TestLockFactory.10");
- Directory dir = FSDirectory.open(dirName);
-
+ Directory dir = newFSDirectory(dirName);
+
String prefix = dir.getLockFactory().getLockPrefix();
-
+
assertTrue("Default lock prefix should be null", null == prefix);
+ dir.close();
_TestUtil.rmDir(dirName);
}
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/store/TestRAMDirectory.java Thu Dec 9 14:33:25 2010
@@ -51,7 +51,7 @@ public class TestRAMDirectory extends Lu
super.setUp();
indexDir = new File(TEMP_DIR, "RAMDirIndex");
- Directory dir = FSDirectory.open(indexDir);
+ Directory dir = newFSDirectory(indexDir);
IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
// add some documents
@@ -68,7 +68,7 @@ public class TestRAMDirectory extends Lu
public void testRAMDirectory () throws IOException {
- Directory dir = FSDirectory.open(indexDir);
+ Directory dir = newFSDirectory(indexDir);
MockDirectoryWrapper ramDir = new MockDirectoryWrapper(random, new RAMDirectory(dir));
// close the underlaying directory
@@ -100,7 +100,7 @@ public class TestRAMDirectory extends Lu
public void testRAMDirectorySize() throws IOException, InterruptedException {
- Directory dir = FSDirectory.open(indexDir);
+ Directory dir = newFSDirectory(indexDir);
final MockDirectoryWrapper ramDir = new MockDirectoryWrapper(random, new RAMDirectory(dir));
dir.close();
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java Thu Dec 9 14:33:25 2010
@@ -31,7 +31,8 @@ import org.apache.lucene.search.BooleanQ
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.FieldCache.CacheEntry;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.MMapDirectory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
import org.junit.Assume;
@@ -48,8 +49,6 @@ import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
@@ -231,7 +230,17 @@ public abstract class LuceneTestCase ext
for (MockDirectoryWrapper d : stores.keySet()) {
if (d.isOpen()) {
StackTraceElement elements[] = stores.get(d);
- StackTraceElement element = (elements.length > 1) ? elements[1] : null;
+ // Look for the first class that is not LuceneTestCase that requested
+ // a Directory. The first two items are of Thread's, so skipping over
+ // them.
+ StackTraceElement element = null;
+ for (int i = 2; i < elements.length; i++) {
+ StackTraceElement ste = elements[i];
+ if (ste.getClassName().indexOf("LuceneTestCase") == -1) {
+ element = ste;
+ break;
+ }
+ }
fail("directory of test was not closed, opened from: " + element);
}
}
@@ -552,7 +561,7 @@ public abstract class LuceneTestCase ext
}
/**
- * Returns a new Dictionary instance. Use this when the test does not
+ * Returns a new Directory instance. Use this when the test does not
* care about the specific Directory implementation (most tests).
* <p>
* The Directory is wrapped with {@link MockDirectoryWrapper}.
@@ -566,15 +575,14 @@ public abstract class LuceneTestCase ext
}
public static MockDirectoryWrapper newDirectory(Random r) throws IOException {
- StackTraceElement[] stack = new Exception().getStackTrace();
Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
MockDirectoryWrapper dir = new MockDirectoryWrapper(r, impl);
- stores.put(dir, stack);
+ stores.put(dir, Thread.currentThread().getStackTrace());
return dir;
}
/**
- * Returns a new Dictionary instance, with contents copied from the
+ * Returns a new Directory instance, with contents copied from the
* provided directory. See {@link #newDirectory()} for more
* information.
*/
@@ -582,14 +590,46 @@ public abstract class LuceneTestCase ext
return newDirectory(random, d);
}
+ /** Returns a new FSDirectory instance over the given file, which must be a folder. */
+ public static MockDirectoryWrapper newFSDirectory(File f) throws IOException {
+ return newFSDirectory(f, null);
+ }
+
+ /** Returns a new FSDirectory instance over the given file, which must be a folder. */
+ public static MockDirectoryWrapper newFSDirectory(File f, LockFactory lf) throws IOException {
+ String fsdirClass = TEST_DIRECTORY;
+ if (fsdirClass.equals("random")) {
+ fsdirClass = FS_DIRECTORIES[random.nextInt(FS_DIRECTORIES.length)];
+ }
+
+ if (fsdirClass.indexOf(".") == -1) {// if not fully qualified, assume .store
+ fsdirClass = "org.apache.lucene.store." + fsdirClass;
+ }
+
+ Class<? extends FSDirectory> clazz;
+ try {
+ try {
+ clazz = Class.forName(fsdirClass).asSubclass(FSDirectory.class);
+ } catch (ClassCastException e) {
+ // TEST_DIRECTORY is not a sub-class of FSDirectory, so draw one at random
+ fsdirClass = FS_DIRECTORIES[random.nextInt(FS_DIRECTORIES.length)];
+ clazz = Class.forName(fsdirClass).asSubclass(FSDirectory.class);
+ }
+ MockDirectoryWrapper dir = new MockDirectoryWrapper(random, newFSDirectoryImpl(clazz, f, lf));
+ stores.put(dir, Thread.currentThread().getStackTrace());
+ return dir;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
- StackTraceElement[] stack = new Exception().getStackTrace();
Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
for (String file : d.listAll()) {
d.copy(impl, file, file);
}
MockDirectoryWrapper dir = new MockDirectoryWrapper(r, impl);
- stores.put(dir, stack);
+ stores.put(dir, Thread.currentThread().getStackTrace());
return dir;
}
@@ -665,12 +705,16 @@ public abstract class LuceneTestCase ext
}
}
- private static String CORE_DIRECTORIES[] = {
- "RAMDirectory",
+ private static final String FS_DIRECTORIES[] = {
"SimpleFSDirectory",
"NIOFSDirectory",
"MMapDirectory"
};
+
+ private static final String CORE_DIRECTORIES[] = {
+ "RAMDirectory",
+ FS_DIRECTORIES[0], FS_DIRECTORIES[1], FS_DIRECTORIES[2]
+ };
public static String randomDirectory(Random random) {
if (random.nextInt(10) == 0) {
@@ -679,6 +723,23 @@ public abstract class LuceneTestCase ext
return "RAMDirectory";
}
}
+
+ private static Directory newFSDirectoryImpl(
+ Class<? extends FSDirectory> clazz, File file, LockFactory lockFactory)
+ throws IOException {
+ try {
+ // Assuming every FSDirectory has a ctor(File), but not all may take a
+ // LockFactory too, so setting it afterwards.
+ Constructor<? extends FSDirectory> ctor = clazz.getConstructor(File.class);
+ FSDirectory d = ctor.newInstance(file);
+ if (lockFactory != null) {
+ d.setLockFactory(lockFactory);
+ }
+ return d;
+ } catch (Exception e) {
+ return FSDirectory.open(file);
+ }
+ }
static Directory newDirectoryImpl(Random random, String clazzName) {
if (clazzName.equals("random"))
@@ -687,27 +748,22 @@ public abstract class LuceneTestCase ext
clazzName = "org.apache.lucene.store." + clazzName;
try {
final Class<? extends Directory> clazz = Class.forName(clazzName).asSubclass(Directory.class);
- try {
- // try empty ctor
- return clazz.newInstance();
- } catch (Exception e) {
+ // If it is a FSDirectory type, try its ctor(File)
+ if (FSDirectory.class.isAssignableFrom(clazz)) {
final File tmpFile = File.createTempFile("test", "tmp", TEMP_DIR);
tmpFile.delete();
tmpFile.mkdir();
- try {
- Constructor<? extends Directory> ctor = clazz.getConstructor(File.class);
- return ctor.newInstance(tmpFile);
- } catch (Exception e2) {
- // try .open(File)
- Method method = clazz.getMethod("open", new Class[] { File.class });
- return (Directory) method.invoke(null, tmpFile);
- }
+ return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), tmpFile, null);
}
+
+ // try empty ctor
+ return clazz.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+
public String getName() {
return this.name;
}
@@ -716,6 +772,7 @@ public abstract class LuceneTestCase ext
* if a real file is needed. To get a stream, code should prefer
* {@link Class#getResourceAsStream} using {@code this.getClass()}.
*/
+
protected File getDataFile(String name) throws IOException {
try {
return new File(this.getClass().getResource(name).toURI());
Modified: lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/AlternateDirectoryTest.java Thu Dec 9 14:33:25 2010
@@ -42,14 +42,20 @@ public class AlternateDirectoryTest exte
assertQ(req("q","*:*","qt","standard"));
assertTrue(TestFSDirectoryFactory.openCalled);
assertTrue(TestIndexReaderFactory.newReaderCalled);
+ TestFSDirectoryFactory.dir.close();
}
static public class TestFSDirectoryFactory extends DirectoryFactory {
public static volatile boolean openCalled = false;
-
- public FSDirectory open(String path) throws IOException {
+ public static volatile Directory dir;
+
+ public Directory open(String path) throws IOException {
openCalled = true;
- return FSDirectory.open(new File(path));
+ // need to close the directory, or otherwise the test fails.
+ if (dir != null) {
+ dir.close();
+ }
+ return dir = newFSDirectory(new File(path));
}
}
Modified: lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java Thu Dec 9 14:33:25 2010
@@ -97,7 +97,7 @@ public class TestArbitraryIndexDir exten
}
//add a doc in the new index dir
- Directory dir = FSDirectory.open(newDir);
+ Directory dir = newFSDirectory(newDir);
IndexWriter iw = new IndexWriter(
dir,
new IndexWriterConfig(TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)).
@@ -109,7 +109,8 @@ public class TestArbitraryIndexDir exten
iw.addDocument(doc);
iw.commit();
iw.close();
-
+ dir.close();
+
//commit will cause searcher to open with the new index dir
assertU(commit());
//new index dir contains just 1 doc.
Modified: lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java?rev=1043979&r1=1043978&r2=1043979&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java Thu Dec 9 14:33:25 2010
@@ -30,6 +30,7 @@ import org.apache.lucene.search.spell.Sp
import org.apache.lucene.search.spell.StringDistance;
import org.apache.lucene.search.spell.SuggestWord;
import org.apache.lucene.search.spell.SuggestWordFrequencyComparator;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.NamedList;
@@ -284,8 +285,9 @@ public class IndexBasedSpellCheckerTest
File indexDir = new File(TEMP_DIR, "spellingIdx" + new Date().getTime());
//create a standalone index
File altIndexDir = new File(TEMP_DIR, "alternateIdx" + new Date().getTime());
+ Directory dir = newFSDirectory(altIndexDir);
IndexWriter iw = new IndexWriter(
- FSDirectory.open(altIndexDir),
+ dir,
new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).
setMaxFieldLength(IndexWriterConfig.UNLIMITED_FIELD_LENGTH)
);
@@ -296,6 +298,7 @@ public class IndexBasedSpellCheckerTest
}
iw.optimize();
iw.close();
+ dir.close();
indexDir.mkdirs();
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath());
spellchecker.add(AbstractLuceneSpellChecker.LOCATION, altIndexDir.getAbsolutePath());