Apache Lucene open-source search software
fix rare test fail
Michael McCandlesscf4eb04a21da
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.javaindex 310219047c0..e81b5052629 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java@@ -1940,44 +1940,56 @@ public class TestIndexWriterExceptions extends LuceneTestCase {shouldFail.set(true);boolean doClose = false;-+ int updatingDocID = -1;+ long updatingValue = -1;try {-boolean defaultCodecSupportsFieldUpdates = defaultCodecSupportsFieldUpdates();for(int i=0;i<numDocs;i++) {if (random().nextInt(10) == 7) {boolean fieldUpdate = defaultCodecSupportsFieldUpdates && random().nextBoolean();+ int docid = docBase + i;if (fieldUpdate) {long value = iter;if (VERBOSE) {- System.out.println(" update id=" + (docBase+i) + " to value " + value);+ System.out.println(" update id=" + docid + " to value " + value);}+ Term idTerm = new Term("id", Integer.toString(docid));+ updatingDocID = docid; // record that we're updating that document+ updatingValue = value; // and its updating valueif (random().nextBoolean()) { // update only numeric field- w.updateNumericDocValue(new Term("id", Integer.toString(docBase + i)), "f", value);- w.updateNumericDocValue(new Term("id", Integer.toString(docBase + i)), "cf", value * 2);+ w.updateNumericDocValue(idTerm, "f", value);+ w.updateNumericDocValue(idTerm, "cf", value * 2);} else if (random().nextBoolean()) {- w.updateBinaryDocValue(new Term("id", Integer.toString(docBase + i)), "bf", TestBinaryDocValuesUpdates.toBytes(value));- w.updateBinaryDocValue(new Term("id", Integer.toString(docBase + i)), "bcf", TestBinaryDocValuesUpdates.toBytes(value * 2));+ w.updateBinaryDocValue(idTerm, "bf", TestBinaryDocValuesUpdates.toBytes(value));+ w.updateBinaryDocValue(idTerm, "bcf", TestBinaryDocValuesUpdates.toBytes(value * 2));} else {- w.updateNumericDocValue(new Term("id", Integer.toString(docBase + i)), "f", value);- w.updateNumericDocValue(new Term("id", Integer.toString(docBase + i)), "cf", value * 2);- w.updateBinaryDocValue(new Term("id", Integer.toString(docBase + i)), "bf", TestBinaryDocValuesUpdates.toBytes(value));- w.updateBinaryDocValue(new Term("id", Integer.toString(docBase + i)), "bcf", TestBinaryDocValuesUpdates.toBytes(value * 2));+ w.updateNumericDocValue(idTerm, "f", value);+ w.updateNumericDocValue(idTerm, "cf", value * 2);+ w.updateBinaryDocValue(idTerm, "bf", TestBinaryDocValuesUpdates.toBytes(value));+ w.updateBinaryDocValue(idTerm, "bcf", TestBinaryDocValuesUpdates.toBytes(value * 2));}+ // record that we successfully updated the document. this is+ // important when we later assert the value of the DV fields of+ // that document - since we update two fields that depend on each+ // other, could be that one of the fields successfully updates,+ // while the other fails (since we turn on random exceptions).+ // while this is supported, it makes the test raise false alarms.+ updatingDocID = -1;+ updatingValue = -1;}// sometimes do both deletes and updatesif (!fieldUpdate || random().nextBoolean()) {if (VERBOSE) {- System.out.println(" delete id=" + (docBase+i));+ System.out.println(" delete id=" + docid);}deleteCount++;- w.deleteDocuments(new Term("id", ""+(docBase+i)));+ w.deleteDocuments(new Term("id", ""+docid));}}}- // Trigger writeLiveDocs so we hit fake exc:+ // Trigger writeLiveDocs + writeFieldUpdates so we hit fake exc:IndexReader r = w.getReader(true);// Sometimes we will make it here (we only randomly@@ -2011,6 +2023,18 @@ public class TestIndexWriterExceptions extends LuceneTestCase {}shouldFail.set(false);+ if (updatingDocID != -1) {+ // Updating this document did not succeed. Since the fields we assert on+ // depend on each other, and the update may have gone through halfway,+ // replay the update on both numeric and binary DV fields, so later+ // asserts succeed.+ Term idTerm = new Term("id", ""+updatingDocID);+ w.updateNumericDocValue(idTerm, "f", updatingValue);+ w.updateNumericDocValue(idTerm, "cf", updatingValue * 2);+ w.updateBinaryDocValue(idTerm, "bf", TestBinaryDocValuesUpdates.toBytes(updatingValue));+ w.updateBinaryDocValue(idTerm, "bcf", TestBinaryDocValuesUpdates.toBytes(updatingValue * 2));+ }+IndexReader r;if (doClose && w != null) {