Further test updates

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@821379 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-10-03 18:03:22 +00:00
parent 2e1d224615
commit 4898da205b
11 changed files with 32 additions and 216 deletions

View File

@ -320,9 +320,6 @@ public class TestFieldsReader extends LuceneTestCase {
public IndexInput openInput(String name) throws IOException {
return new FaultyIndexInput(fsDir.openInput(name));
}
public String[] list() throws IOException {
return fsDir.list();
}
public String[] listAll() throws IOException {
return fsDir.listAll();
}
@ -338,9 +335,6 @@ public class TestFieldsReader extends LuceneTestCase {
public void deleteFile(String name) throws IOException {
fsDir.deleteFile(name);
}
public void renameFile(String name, String newName) throws IOException {
fsDir.renameFile(name, newName);
}
public long fileLength(String name) throws IOException {
return fsDir.fileLength(name);
}

View File

@ -552,24 +552,24 @@ public class TestIndexReader extends LuceneTestCase
reader.setNorm(0, "content", (float) 2.0);
// we should be holding the write lock now:
assertTrue("locked", IndexReader.isLocked(dir));
assertTrue("locked", IndexWriter.isLocked(dir));
reader.commit();
// we should not be holding the write lock now:
assertTrue("not locked", !IndexReader.isLocked(dir));
assertTrue("not locked", !IndexWriter.isLocked(dir));
// open a 2nd reader:
IndexReader reader2 = IndexReader.open(dir, false);
// set norm again for doc 0
reader.setNorm(0, "content", (float) 3.0);
assertTrue("locked", IndexReader.isLocked(dir));
assertTrue("locked", IndexWriter.isLocked(dir));
reader.close();
// we should not be holding the write lock now:
assertTrue("not locked", !IndexReader.isLocked(dir));
assertTrue("not locked", !IndexWriter.isLocked(dir));
reader2.close();
dir.close();
@ -752,7 +752,6 @@ public class TestIndexReader extends LuceneTestCase
}
public void testLastModified() throws Exception {
assertFalse(IndexReader.indexExists("there_is_no_such_index"));
final File fileDir = new File(System.getProperty("tempDir"), "testIndex");
for(int i=0;i<2;i++) {
try {
@ -764,14 +763,14 @@ public class TestIndexReader extends LuceneTestCase
assertFalse(IndexReader.indexExists(dir));
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
addDocumentWithFields(writer);
assertTrue(IndexReader.isLocked(dir)); // writer open, so dir is locked
assertTrue(IndexWriter.isLocked(dir)); // writer open, so dir is locked
writer.close();
assertTrue(IndexReader.indexExists(dir));
IndexReader reader = IndexReader.open(dir, false);
assertFalse(IndexReader.isLocked(dir)); // reader only, no lock
assertFalse(IndexWriter.isLocked(dir)); // reader only, no lock
long version = IndexReader.lastModified(dir);
if (i == 1) {
long version2 = IndexReader.lastModified(fileDir);
long version2 = IndexReader.lastModified(dir);
assertEquals(version, version2);
}
reader.close();
@ -794,16 +793,15 @@ public class TestIndexReader extends LuceneTestCase
}
public void testVersion() throws IOException {
assertFalse(IndexReader.indexExists("there_is_no_such_index"));
Directory dir = new MockRAMDirectory();
assertFalse(IndexReader.indexExists(dir));
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
addDocumentWithFields(writer);
assertTrue(IndexReader.isLocked(dir)); // writer open, so dir is locked
assertTrue(IndexWriter.isLocked(dir)); // writer open, so dir is locked
writer.close();
assertTrue(IndexReader.indexExists(dir));
IndexReader reader = IndexReader.open(dir, false);
assertFalse(IndexReader.isLocked(dir)); // reader only, no lock
assertFalse(IndexWriter.isLocked(dir)); // reader only, no lock
long version = IndexReader.getCurrentVersion(dir);
reader.close();
// modify index and check version has been
@ -830,7 +828,7 @@ public class TestIndexReader extends LuceneTestCase
} catch(IOException e) {
// expected exception
}
IndexReader.unlock(dir); // this should not be done in the real world!
IndexWriter.unlock(dir); // this should not be done in the real world!
reader.deleteDocument(0);
reader.close();
writer.close();
@ -1153,7 +1151,7 @@ public class TestIndexReader extends LuceneTestCase
// expected
}
reader.close();
if (IndexReader.isLocked(dir)) {
if (IndexWriter.isLocked(dir)) {
fail("write lock is still held after close");
}
@ -1165,7 +1163,7 @@ public class TestIndexReader extends LuceneTestCase
// expected
}
reader.close();
if (IndexReader.isLocked(dir)) {
if (IndexWriter.isLocked(dir)) {
fail("write lock is still held after close");
}
dir.close();

View File

@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.FSDirectory;
/**
* This tests the patch for issue #LUCENE-715 (IndexWriter does not
@ -72,14 +73,16 @@ public class TestIndexWriterLockRelease extends LuceneTestCase {
public void testIndexWriterLockRelease() throws IOException {
IndexWriter im;
FSDirectory dir = FSDirectory.open(this.__test_dir);
try {
im = new IndexWriter(this.__test_dir, new org.apache.lucene.analysis.standard.StandardAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
im = new IndexWriter(dir, new org.apache.lucene.analysis.standard.StandardAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
} catch (FileNotFoundException e) {
try {
im = new IndexWriter(this.__test_dir, new org.apache.lucene.analysis.standard.StandardAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
im = new IndexWriter(dir, new org.apache.lucene.analysis.standard.StandardAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
} catch (FileNotFoundException e1) {
}
} finally {
dir.close();
}
}
}

View File

@ -402,7 +402,7 @@ public class CheckHits {
*/
public static class ExplanationAssertingSearcher extends IndexSearcher {
public ExplanationAssertingSearcher(Directory d) throws IOException {
super(d);
super(d, true);
}
public ExplanationAssertingSearcher(IndexReader r) throws IOException {
super(r);

View File

@ -222,7 +222,7 @@ implements Serializable {
* @throws IOException
*/
public CustomSearcher(Directory directory, int switcher) throws IOException {
super(directory);
super(directory, true);
this.switcher = switcher;
}
/**
@ -232,14 +232,6 @@ implements Serializable {
super(r);
this.switcher = switcher;
}
/**
* @param path
* @throws IOException
*/
public CustomSearcher(String path, int switcher) throws IOException {
super(path);
this.switcher = switcher;
}
/* (non-Javadoc)
* @see org.apache.lucene.search.Searchable#search(org.apache.lucene.search.Query, org.apache.lucene.search.Filter, int, org.apache.lucene.search.Sort)
*/

View File

@ -74,7 +74,7 @@ public class TestFilteredQuery extends LuceneTestCase {
writer.optimize ();
writer.close ();
searcher = new IndexSearcher (directory);
searcher = new IndexSearcher (directory, true);
query = new TermQuery (new Term ("field", "three"));
filter = newStaticFilterB();
}

View File

@ -52,7 +52,7 @@ public class TestScorerPerf extends LuceneTestCase {
IndexWriter iw = new IndexWriter(rd,new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
iw.addDocument(new Document());
iw.close();
s = new IndexSearcher(rd);
s = new IndexSearcher(rd, true);
}
public void createRandomTerms(int nDocs, int nTerms, double power, Directory dir) throws Exception {
@ -359,7 +359,7 @@ public class TestScorerPerf extends LuceneTestCase {
RAMDirectory dir = new RAMDirectory();
System.out.println("Creating index");
createRandomTerms(100000,25,.5, dir);
s = new IndexSearcher(dir);
s = new IndexSearcher(dir, true);
System.out.println("Starting performance test");
for (int i=0; i<bigIter; i++) {
long start = System.currentTimeMillis();
@ -376,7 +376,7 @@ public class TestScorerPerf extends LuceneTestCase {
RAMDirectory dir = new RAMDirectory();
System.out.println("Creating index");
createRandomTerms(100000,25,.2, dir);
s = new IndexSearcher(dir);
s = new IndexSearcher(dir, true);
System.out.println("Starting performance test");
for (int i=0; i<bigIter; i++) {
long start = System.currentTimeMillis();
@ -394,7 +394,7 @@ public class TestScorerPerf extends LuceneTestCase {
RAMDirectory dir = new RAMDirectory();
System.out.println("Creating index");
createRandomTerms(100000,25,2,dir);
s = new IndexSearcher(dir);
s = new IndexSearcher(dir, true);
System.out.println("Starting performance test");
for (int i=0; i<bigIter; i++) {
long start = System.currentTimeMillis();

View File

@ -128,7 +128,7 @@ public class TestSort extends LuceneTestCase implements Serializable {
}
//writer.optimize ();
writer.close ();
IndexSearcher s = new IndexSearcher (indexStore);
IndexSearcher s = new IndexSearcher (indexStore, true);
s.setDefaultFieldSortScoring(true, true);
return s;
}
@ -160,7 +160,7 @@ public class TestSort extends LuceneTestCase implements Serializable {
//writer.optimize ();
//System.out.println(writer.getSegmentCount());
writer.close ();
return new IndexSearcher (indexStore);
return new IndexSearcher (indexStore, true);
}
public String getRandomNumberString(int num, int low, int high) {

View File

@ -96,13 +96,13 @@ public class TestBufferedIndexInput extends LuceneTestCase {
inputBufferSize, 10), inputBufferSize, r);
// run test with chunk size of 100 MB - default
runReadBytesAndClose(new SimpleFSIndexInput(tmpInputFile,
inputBufferSize), inputBufferSize, r);
inputBufferSize, FSDirectory.DEFAULT_READ_CHUNK_SIZE), inputBufferSize, r);
// run test with chunk size of 10 bytes
runReadBytesAndClose(new NIOFSIndexInput(tmpInputFile,
inputBufferSize, 10), inputBufferSize, r);
// run test with chunk size of 100 MB - default
runReadBytesAndClose(new NIOFSIndexInput(tmpInputFile,
inputBufferSize), inputBufferSize, r);
inputBufferSize, FSDirectory.DEFAULT_READ_CHUNK_SIZE), inputBufferSize, r);
}
private void runReadBytesAndClose(IndexInput input, int bufferSize, Random r)
@ -352,11 +352,6 @@ public class TestBufferedIndexInput extends LuceneTestCase {
{
return dir.fileExists(name);
}
public String[] list()
throws IOException
{
return dir.list();
}
public String[] listAll()
throws IOException
{
@ -366,11 +361,6 @@ public class TestBufferedIndexInput extends LuceneTestCase {
public long fileLength(String name) throws IOException {
return dir.fileLength(name);
}
public void renameFile(String from, String to)
throws IOException
{
dir.renameFile(from, to);
}
}

View File

@ -128,175 +128,12 @@ public class TestLockFactory extends LuceneTestCase {
writer2.close();
}
}
// Verify: SimpleFSLockFactory is the default for FSDirectory
// Verify: FSDirectory does basic locking correctly
public void testDefaultFSDirectory() throws IOException {
File indexDirName = _TestUtil.getTempDir("index.TestLockFactory1");
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()) ||
NativeFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
IndexWriter writer2 = null;
// Create a 2nd IndexWriter. This should fail:
try {
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false,
IndexWriter.MaxFieldLength.LIMITED);
fail("Should have hit an IOException with two IndexWriters on default SimpleFSLockFactory");
} catch (IOException e) {
}
writer.close();
if (writer2 != null) {
writer2.close();
}
// Cleanup
_TestUtil.rmDir(indexDirName);
}
// Verify: FSDirectory's default lockFactory clears all locks correctly
public void testFSDirectoryTwoCreates() throws IOException {
File indexDirName = _TestUtil.getTempDir("index.TestLockFactory2");
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()) ||
NativeFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
// Intentionally do not close the first writer here.
// The goal is to "simulate" a crashed writer and
// ensure the second writer, with create=true, is
// able to remove the lock files. This works OK
// with SimpleFSLockFactory as the locking
// implementation. Note, however, that this test
// will not work on WIN32 when we switch to
// NativeFSLockFactory as the default locking for
// FSDirectory because the second IndexWriter cannot
// remove those lock files since they are held open
// by the first writer. This is because leaving the
// first IndexWriter open is not really a good way
// to simulate a crashed writer.
// Create a 2nd IndexWriter. This should not fail:
IndexWriter writer2 = null;
try {
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
} catch (IOException e) {
e.printStackTrace(System.out);
fail("Should not have hit an IOException with two IndexWriters with create=true, on default SimpleFSLockFactory");
}
writer.close();
if (writer2 != null) {
try {
writer2.close();
// expected
} catch (LockReleaseFailedException e) {
fail("writer2.close() should not have hit LockReleaseFailedException");
}
}
// Cleanup
_TestUtil.rmDir(indexDirName);
}
// Verify: setting custom lock factory class (as system property) works:
// Verify: all 4 builtin LockFactory implementations are
// settable this way
// Verify: FSDirectory does basic locking correctly
public void testLockClassProperty() throws IOException {
File indexDirName = _TestUtil.getTempDir("index.TestLockFactory3");
String prpName = "org.apache.lucene.store.FSDirectoryLockFactoryClass";
try {
// NoLockFactory:
System.setProperty(prpName, "org.apache.lucene.store.NoLockFactory");
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
writer.close();
// SingleInstanceLockFactory:
System.setProperty(prpName, "org.apache.lucene.store.SingleInstanceLockFactory");
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
SingleInstanceLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
writer.close();
// NativeFSLockFactory:
System.setProperty(prpName, "org.apache.lucene.store.NativeFSLockFactory");
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
NativeFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
writer.close();
// SimpleFSLockFactory:
System.setProperty(prpName, "org.apache.lucene.store.SimpleFSLockFactory");
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
writer.close();
} finally {
// Put back to the correct default for subsequent tests:
System.setProperty("org.apache.lucene.store.FSDirectoryLockFactoryClass", "");
}
// Cleanup
_TestUtil.rmDir(indexDirName);
}
public void testSimpleFSLockFactory() throws IOException {
// test string file instantiation
new SimpleFSLockFactory("test");
}
// Verify: setDisableLocks works
public void testDisableLocks() throws IOException {
File indexDirName = _TestUtil.getTempDir("index.TestLockFactory4");
assertTrue("Locks are already disabled", !FSDirectory.getDisableLocks());
FSDirectory.setDisableLocks(true);
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
IndexWriter.MaxFieldLength.LIMITED);
assertTrue("FSDirectory did not use correct default LockFactory: got " + writer.getDirectory().getLockFactory(),
NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
// Should be no error since locking is disabled:
IndexWriter writer2 = null;
try {
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false,
IndexWriter.MaxFieldLength.LIMITED);
} catch (IOException e) {
e.printStackTrace(System.out);
fail("Should not have hit an IOException with locking disabled");
}
FSDirectory.setDisableLocks(false);
writer.close();
if (writer2 != null) {
writer2.close();
}
// Cleanup
_TestUtil.rmDir(indexDirName);
}
// Verify: do stress test, by opening IndexReaders and
// IndexWriters over & over in 2 threads and making sure
// no unexpected exceptions are raised:

View File

@ -56,7 +56,8 @@ public class TestRAMDirectory extends LuceneTestCase {
throw new IOException("java.io.tmpdir undefined, cannot run test");
indexDir = new File(tempDir, "RAMDirIndex");
IndexWriter writer = new IndexWriter(indexDir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Directory dir = FSDirectory.open(indexDir);
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
// add some documents
Document doc = null;
for (int i = 0; i < docsToAdd; i++) {
@ -66,6 +67,7 @@ public class TestRAMDirectory extends LuceneTestCase {
}
assertEquals(docsToAdd, writer.docCount());
writer.close();
dir.close();
}
public void testRAMDirectory () throws IOException {