Skip to content

Apache Lucene open-source search software

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

Michael McCandless43c6d8a84375
diff --git a/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java
index beff7ab3191..205ef5b4a95 100644
--- a/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java
+++ b/lucene/src/test-framework/java/org/apache/lucene/store/MockDirectoryWrapper.java
@@ -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:
diff --git a/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java b/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java
index b86c4923121..ff1325529c3 100644
--- a/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java
+++ b/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java
@@ -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) {
diff --git a/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java b/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java
index e2eda9f612f..6659c8a20c3 100644
--- a/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java
+++ b/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java
@@ -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);