Skip to content

Apache Lucene open-source search software

LUCENE-5268: fix test failures: bloom must first call delegate.write, then write its own

Michael McCandless6ffeda5472d3
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/bloom/BloomFilteringPostingsFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/bloom/BloomFilteringPostingsFormat.java
index c1941ef16dc..69603876bc6 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/bloom/BloomFilteringPostingsFormat.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/bloom/BloomFilteringPostingsFormat.java
@@ -405,6 +405,15 @@ public final class BloomFilteringPostingsFormat extends PostingsFormat {
@Override
public void write(Fields fields) throws IOException {
+
+ // Delegate must write first: it may have opened files
+ // on creating the class
+ // (e.g. Lucene41PostingsConsumer), and write() will
+ // close them; alternatively, if we delayed pulling
+ // the fields consumer until here, we could do it
+ // afterwards:
+ delegateFieldsConsumer.write(fields);
+
try {
for(String field : fields) {
Terms terms = fields.terms(field);
@@ -441,8 +450,6 @@ public final class BloomFilteringPostingsFormat extends PostingsFormat {
} finally {
close();
}
-
- delegateFieldsConsumer.write(fields);
}
public void close() throws IOException {
@@ -492,4 +499,9 @@ public final class BloomFilteringPostingsFormat extends PostingsFormat {
rightSizedSet.serialize(bloomOutput);
}
}
+
+ @Override
+ public String toString() {
+ return "BloomFilteringPostingsFormat(" + delegatePostingsFormat + ")";
+ }
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTransactions.java b/lucene/core/src/test/org/apache/lucene/index/TestTransactions.java
index 6750ad6276e..450992bbff0 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestTransactions.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestTransactions.java
@@ -38,6 +38,10 @@ public class TestTransactions extends LuceneTestCase {
@Override
public void eval(MockDirectoryWrapper dir) throws IOException {
if (TestTransactions.doFail && random().nextInt() % 10 <= 3) {
+ if (VERBOSE) {
+ System.out.println(Thread.currentThread().getName() + " TEST: now fail on purpose");
+ new Throwable().printStackTrace(System.out);
+ }
throw new IOException("now failing randomly but on purpose");
}
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/bloom/TestBloomFilteredLucene41Postings.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/bloom/TestBloomFilteredLucene41Postings.java
index d5229f6f496..c9f4ec8ba76 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/bloom/TestBloomFilteredLucene41Postings.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/bloom/TestBloomFilteredLucene41Postings.java
@@ -71,4 +71,9 @@ public final class TestBloomFilteredLucene41Postings extends PostingsFormat {
throws IOException {
return delegate.fieldsProducer(state);
}
+
+ @Override
+ public String toString() {
+ return "TestBloomFilteredLucene41Postings(" + delegate + ")";
+ }
}