LUCENE-7326: don't use postings format by name in this test

This commit is contained in:
Mike McCandless 2016-06-10 11:57:14 -04:00
parent 0eacfe87c2
commit 816fae9622

View File

@ -16,13 +16,6 @@
*/
package org.apache.lucene.index;
import static org.apache.lucene.index.PostingsEnum.ALL;
import static org.apache.lucene.index.PostingsEnum.FREQS;
import static org.apache.lucene.index.PostingsEnum.NONE;
import static org.apache.lucene.index.PostingsEnum.OFFSETS;
import static org.apache.lucene.index.PostingsEnum.PAYLOADS;
import static org.apache.lucene.index.PostingsEnum.POSITIONS;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
@ -38,9 +31,8 @@ import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.codecs.FieldsConsumer;
import org.apache.lucene.codecs.FieldsProducer;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.asserting.AssertingCodec;
import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
@ -51,13 +43,19 @@ import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LineFileDocs;
import org.apache.lucene.util.RamUsageTester;
import org.apache.lucene.util.TestUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import static org.apache.lucene.index.PostingsEnum.ALL;
import static org.apache.lucene.index.PostingsEnum.FREQS;
import static org.apache.lucene.index.PostingsEnum.NONE;
import static org.apache.lucene.index.PostingsEnum.OFFSETS;
import static org.apache.lucene.index.PostingsEnum.PAYLOADS;
import static org.apache.lucene.index.PostingsEnum.POSITIONS;
/**
* Abstract class to do basic tests for a postings format.
* NOTE: This test focuses on the postings
@ -165,8 +163,9 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTest
te.seekExact(fieldAndTerm.term);
checkReuse(te, PostingsEnum.FREQS, PostingsEnum.ALL, false);
if (isPostingsEnumReuseImplemented())
if (isPostingsEnumReuseImplemented()) {
checkReuse(te, PostingsEnum.ALL, PostingsEnum.ALL, true);
}
fieldsProducer.close();
dir.close();
@ -175,11 +174,12 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTest
protected static void checkReuse(TermsEnum termsEnum, int firstFlags, int secondFlags, boolean shouldReuse) throws IOException {
PostingsEnum postings1 = termsEnum.postings(null, firstFlags);
PostingsEnum postings2 = termsEnum.postings(postings1, secondFlags);
if (shouldReuse)
if (shouldReuse) {
assertSame("Expected PostingsEnum " + postings1.getClass().getName() + " to be reused", postings1, postings2);
else
} else {
assertNotSame("Expected PostingsEnum " + postings1.getClass().getName() + " to not be reused", postings1, postings2);
}
}
public void testJustEmptyField() throws Exception {
Directory dir = newDirectory();
@ -337,20 +337,14 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTest
// TODO: would be better to use / delegate to the current
// Codec returned by getCodec()
iwc.setCodec(new AssertingCodec() {
iwc.setCodec(new FilterCodec(getCodec().getName(), getCodec()) {
@Override
public PostingsFormat getPostingsFormatForField(String field) {
public PostingsFormat postingsFormat() {
PostingsFormat p = getCodec().postingsFormat();
if (p instanceof PerFieldPostingsFormat) {
p = ((PerFieldPostingsFormat) p).getPostingsFormatForField(field);
}
final PostingsFormat defaultPostingsFormat = p;
final PostingsFormat defaultPostingsFormat = delegate.postingsFormat();
final Thread mainThread = Thread.currentThread();
if (field.equals("body")) {
// A PF that counts up some stats and then in
// the end we verify the stats match what the
// final IndexReader says, just to exercise the
@ -499,9 +493,6 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTest
return defaultPostingsFormat.fieldsProducer(state);
}
};
} else {
return defaultPostingsFormat;
}
}
});
@ -512,8 +503,10 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTest
int bytesIndexed = 0;
while (bytesIndexed < bytesToIndex) {
Document doc = docs.nextDoc();
w.addDocument(doc);
bytesIndexed += RamUsageTester.sizeOf(doc);
Document justBodyDoc = new Document();
justBodyDoc.add(doc.getField("body"));
w.addDocument(justBodyDoc);
bytesIndexed += RamUsageTester.sizeOf(justBodyDoc);
}
IndexReader r = w.getReader();