LUCENE-2858: Port test-framework to new API

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2858@1237296 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2012-01-29 14:15:43 +00:00
parent 2c92a3ce87
commit eb4abbb000
6 changed files with 31 additions and 28 deletions
lucene/src

View File

@ -3954,7 +3954,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit {
* <p><b>NOTE</b>: warm is called before any deletes have
* been carried over to the merged segment. */
public static abstract class IndexReaderWarmer {
public abstract void warm(IndexReader reader) throws IOException;
public abstract void warm(AtomicIndexReader reader) throws IOException;
}
private void handleOOM(OutOfMemoryError oom, String location) {

View File

@ -455,7 +455,7 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCas
conf.setMergedSegmentWarmer(new IndexWriter.IndexReaderWarmer() {
@Override
public void warm(IndexReader reader) throws IOException {
public void warm(AtomicIndexReader reader) throws IOException {
if (VERBOSE) {
System.out.println("TEST: now warm merged reader=" + reader);
}

View File

@ -116,7 +116,8 @@ public class CheckHits {
Assert.assertEquals("Wrap Reader " + i + ": " +
query.toString(defaultFieldName),
correct, actual);
FieldCache.DEFAULT.purge(s.getIndexReader()); // our wrapping can create insanity otherwise
// nocommit: I removed that as we can never get insanity by composite readers anymore... Is this ok?
//FieldCache.DEFAULT.purge(s.getIndexReader()); // our wrapping can create insanity otherwise
}
}

View File

@ -24,7 +24,9 @@ import junit.framework.Assert;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.AtomicIndexReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
@ -114,11 +116,14 @@ public class QueryUtils {
if (wrap) {
IndexSearcher wrapped;
check(random, q1, wrapped = wrapUnderlyingReader(random, s, -1), false);
FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // // our wrapping can create insanity otherwise
// nocommit: I removed that as we can never get insanity by composite readers anymore... Is this ok?
//FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // our wrapping can create insanity otherwise
check(random, q1, wrapped = wrapUnderlyingReader(random, s, 0), false);
FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // // our wrapping can create insanity otherwise
// nocommit: I removed that as we can never get insanity by composite readers anymore... Is this ok?
//FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // our wrapping can create insanity otherwise
check(random, q1, wrapped = wrapUnderlyingReader(random, s, +1), false);
FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // // our wrapping can create insanity otherwise
// nocommit: I removed that as we can never get insanity by composite readers anymore... Is this ok?
//FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // our wrapping can create insanity otherwise
}
checkExplanations(q1,s);
@ -176,7 +181,7 @@ public class QueryUtils {
}
}
private static IndexReader makeEmptyIndex(Random random, final int numDeletedDocs)
private static DirectoryReader makeEmptyIndex(Random random, final int numDeletedDocs)
throws IOException {
Directory d = new MockDirectoryWrapper(random, new RAMDirectory());
IndexWriter w = new IndexWriter(d, new IndexWriterConfig(
@ -197,7 +202,7 @@ public class QueryUtils {
Assert.assertEquals("writer has non-deleted docs",
0, w.numDocs());
w.close();
IndexReader r = IndexReader.open(d);
DirectoryReader r = DirectoryReader.open(d);
Assert.assertEquals("reader has wrong number of deleted docs",
numDeletedDocs, r.numDeletedDocs());
return r;
@ -234,7 +239,7 @@ public class QueryUtils {
// FUTURE: ensure scorer.doc()==-1
final float maxDiff = 1e-5f;
final IndexReader lastReader[] = {null};
final AtomicIndexReader lastReader[] = {null};
s.search(q, new Collector() {
private Scorer sc;
@ -296,11 +301,11 @@ public class QueryUtils {
// confirm that skipping beyond the last doc, on the
// previous reader, hits NO_MORE_DOCS
if (lastReader[0] != null) {
final IndexReader previousReader = lastReader[0];
final AtomicIndexReader previousReader = lastReader[0];
IndexSearcher indexSearcher = LuceneTestCase.newSearcher(previousReader);
Weight w = indexSearcher.createNormalizedWeight(q);
AtomicReaderContext ctx = (AtomicReaderContext)indexSearcher.getTopReaderContext();
Scorer scorer = w.scorer(ctx, true, false, ctx.reader.getLiveDocs());
Scorer scorer = w.scorer(ctx, true, false, ctx.reader().getLiveDocs());
if (scorer != null) {
boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS;
Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but skipTo("+(lastDoc[0]+1)+") got to "+scorer.docID(),more);
@ -308,7 +313,7 @@ public class QueryUtils {
leafPtr++;
}
lastReader[0] = context.reader();
assert readerContextArray[leafPtr].reader == context.reader();
assert readerContextArray[leafPtr].reader() == context.reader();
this.scorer = null;
lastDoc[0] = -1;
}
@ -322,11 +327,11 @@ public class QueryUtils {
if (lastReader[0] != null) {
// confirm that skipping beyond the last doc, on the
// previous reader, hits NO_MORE_DOCS
final IndexReader previousReader = lastReader[0];
final AtomicIndexReader previousReader = lastReader[0];
IndexSearcher indexSearcher = LuceneTestCase.newSearcher(previousReader, false);
Weight w = indexSearcher.createNormalizedWeight(q);
AtomicReaderContext ctx = (AtomicReaderContext)previousReader.getTopReaderContext();
Scorer scorer = w.scorer(ctx, true, false, ctx.reader.getLiveDocs());
AtomicReaderContext ctx = previousReader.getTopReaderContext();
Scorer scorer = w.scorer(ctx, true, false, ctx.reader().getLiveDocs());
if (scorer != null) {
boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS;
Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but skipTo("+(lastDoc[0]+1)+") got to "+scorer.docID(),more);
@ -340,7 +345,7 @@ public class QueryUtils {
//System.out.println("checkFirstSkipTo: "+q);
final float maxDiff = 1e-3f;
final int lastDoc[] = {-1};
final IndexReader lastReader[] = {null};
final AtomicIndexReader lastReader[] = {null};
final AtomicReaderContext[] context = ReaderUtil.leaves(s.getTopReaderContext());
s.search(q,new Collector() {
private Scorer scorer;
@ -381,7 +386,7 @@ public class QueryUtils {
// confirm that skipping beyond the last doc, on the
// previous reader, hits NO_MORE_DOCS
if (lastReader[0] != null) {
final IndexReader previousReader = lastReader[0];
final AtomicIndexReader previousReader = lastReader[0];
IndexSearcher indexSearcher = LuceneTestCase.newSearcher(previousReader);
Weight w = indexSearcher.createNormalizedWeight(q);
Scorer scorer = w.scorer((AtomicReaderContext)indexSearcher.getTopReaderContext(), true, false, previousReader.getLiveDocs());
@ -405,7 +410,7 @@ public class QueryUtils {
if (lastReader[0] != null) {
// confirm that skipping beyond the last doc, on the
// previous reader, hits NO_MORE_DOCS
final IndexReader previousReader = lastReader[0];
final AtomicIndexReader previousReader = lastReader[0];
IndexSearcher indexSearcher = LuceneTestCase.newSearcher(previousReader);
Weight w = indexSearcher.createNormalizedWeight(q);
Scorer scorer = w.scorer((AtomicReaderContext)indexSearcher.getTopReaderContext(), true, false, previousReader.getLiveDocs());

View File

@ -33,7 +33,7 @@ import java.util.Random;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.util.LuceneTestCase;
@ -559,7 +559,7 @@ public class MockDirectoryWrapper extends Directory {
}
open = false;
if (checkIndexOnClose) {
if (IndexReader.indexExists(this)) {
if (DirectoryReader.indexExists(this)) {
if (LuceneTestCase.VERBOSE) {
System.out.println("\nNOTE: MockDirectoryWrapper: now crash");
}
@ -582,11 +582,11 @@ public class MockDirectoryWrapper extends Directory {
assert false : "unreferenced files: before delete:\n " + Arrays.toString(startFiles) + "\n after delete:\n " + Arrays.toString(endFiles);
}
IndexReader ir1 = IndexReader.open(this);
DirectoryReader ir1 = DirectoryReader.open(this);
int numDocs1 = ir1.numDocs();
ir1.close();
new IndexWriter(this, new IndexWriterConfig(LuceneTestCase.TEST_VERSION_CURRENT, null)).close();
IndexReader ir2 = IndexReader.open(this);
DirectoryReader ir2 = DirectoryReader.open(this);
int numDocs2 = ir2.numDocs();
ir2.close();
assert numDocs1 == numDocs2 : "numDocs changed after opening/closing IW: before=" + numDocs1 + " after=" + numDocs2;

View File

@ -189,14 +189,11 @@ public abstract class LuceneTestCase extends Assert {
* Some tests expect the directory to contain a single segment, and want to do tests on that segment's reader.
* This is an utility method to help them.
*/
public static SegmentReader getOnlySegmentReader(IndexReader reader) {
if (reader instanceof SegmentReader)
return (SegmentReader) reader;
public static SegmentReader getOnlySegmentReader(DirectoryReader reader) {
IndexReader[] subReaders = reader.getSequentialSubReaders();
if (subReaders.length != 1)
throw new IllegalArgumentException(reader + " has " + subReaders.length + " segments instead of exactly one");
assertTrue(subReaders[0] instanceof SegmentReader);
return (SegmentReader) subReaders[0];
}
@ -1239,7 +1236,7 @@ public abstract class LuceneTestCase extends Assert {
public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap) throws IOException {
if (usually()) {
if (maybeWrap && rarely()) {
r = new SlowMultiReaderWrapper(r);
r = SlowCompositeReaderWrapper.wrap(r);
}
IndexSearcher ret = random.nextBoolean() ? new AssertingIndexSearcher(random, r) : new AssertingIndexSearcher(random, r.getTopReaderContext());
ret.setSimilarityProvider(similarityProvider);