allow tests to turn off term vector cross checking in CheckIndex; turn it off for this one test since it changes postings intentionally

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1231971 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-01-16 12:17:27 +00:00
parent 57adb4371a
commit 43c6d8a843
3 changed files with 22 additions and 2 deletions

View File

@ -68,6 +68,7 @@ public class MockDirectoryWrapper extends Directory {
boolean noDeleteOpenFile = true;
boolean preventDoubleWrite = true;
boolean checkIndexOnClose = true;
boolean crossCheckTermVectorsOnClose = true;
boolean trackDiskUsage = false;
private Set<String> unSyncedFiles;
private Set<String> createdFiles;
@ -310,6 +311,15 @@ public class MockDirectoryWrapper extends Directory {
public boolean getCheckIndexOnClose() {
return checkIndexOnClose;
}
public void setCrossCheckTermVectorsOnClose(boolean value) {
this.crossCheckTermVectorsOnClose = value;
}
public boolean getCrossCheckTermVectorsOnClose() {
return crossCheckTermVectorsOnClose;
}
/**
* If 0.0, no exceptions will be thrown. Else this should
* be a double 0.0 - 1.0. We will randomly throw an
@ -557,7 +567,7 @@ public class MockDirectoryWrapper extends Directory {
if (LuceneTestCase.VERBOSE) {
System.out.println("\nNOTE: MockDirectoryWrapper: now run CheckIndex");
}
_TestUtil.checkIndex(this);
_TestUtil.checkIndex(this, crossCheckTermVectorsOnClose);
if (assertNoUnreferencedFilesOnClose) {
// now look for unreferenced files:

View File

@ -155,9 +155,13 @@ public class _TestUtil {
* issues are hit, a RuntimeException is thrown; else,
* true is returned. */
public static CheckIndex.Status checkIndex(Directory dir) throws IOException {
return checkIndex(dir, true);
}
public static CheckIndex.Status checkIndex(Directory dir, boolean crossCheckTermVectors) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
CheckIndex checker = new CheckIndex(dir);
checker.setCrossCheckTermVectors(true);
checker.setCrossCheckTermVectors(crossCheckTermVectors);
checker.setInfoStream(new PrintStream(bos), false);
CheckIndex.Status indexStatus = checker.checkIndex(null);
if (indexStatus == null || indexStatus.clean == false) {

View File

@ -27,6 +27,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.TextField;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
@ -134,6 +135,7 @@ public class TestFilterIndexReader extends LuceneTestCase {
*/
public void testFilterIndexReader() throws Exception {
Directory directory = newDirectory();
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
Document d1 = new Document();
@ -151,6 +153,10 @@ public class TestFilterIndexReader extends LuceneTestCase {
writer.close();
Directory target = newDirectory();
// We mess with the postings so this can fail:
((MockDirectoryWrapper) target).setCrossCheckTermVectorsOnClose(false);
writer = new IndexWriter(target, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
IndexReader reader = new TestReader(IndexReader.open(directory));
writer.addIndexes(reader);