fix rare test fail

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1593976 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-05-12 14:32:51 +00:00
parent 3d5aea2c1d
commit cf4eb04a21
1 changed files with 38 additions and 14 deletions

View File

@ -1940,44 +1940,56 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
shouldFail.set(true); shouldFail.set(true);
boolean doClose = false; boolean doClose = false;
int updatingDocID = -1;
long updatingValue = -1;
try { try {
boolean defaultCodecSupportsFieldUpdates = defaultCodecSupportsFieldUpdates(); boolean defaultCodecSupportsFieldUpdates = defaultCodecSupportsFieldUpdates();
for(int i=0;i<numDocs;i++) { for(int i=0;i<numDocs;i++) {
if (random().nextInt(10) == 7) { if (random().nextInt(10) == 7) {
boolean fieldUpdate = defaultCodecSupportsFieldUpdates && random().nextBoolean(); boolean fieldUpdate = defaultCodecSupportsFieldUpdates && random().nextBoolean();
int docid = docBase + i;
if (fieldUpdate) { if (fieldUpdate) {
long value = iter; long value = iter;
if (VERBOSE) { 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 value
if (random().nextBoolean()) { // update only numeric field if (random().nextBoolean()) { // update only numeric field
w.updateNumericDocValue(new Term("id", Integer.toString(docBase + i)), "f", value); w.updateNumericDocValue(idTerm, "f", value);
w.updateNumericDocValue(new Term("id", Integer.toString(docBase + i)), "cf", value * 2); w.updateNumericDocValue(idTerm, "cf", value * 2);
} else if (random().nextBoolean()) { } else if (random().nextBoolean()) {
w.updateBinaryDocValue(new Term("id", Integer.toString(docBase + i)), "bf", TestBinaryDocValuesUpdates.toBytes(value)); w.updateBinaryDocValue(idTerm, "bf", TestBinaryDocValuesUpdates.toBytes(value));
w.updateBinaryDocValue(new Term("id", Integer.toString(docBase + i)), "bcf", TestBinaryDocValuesUpdates.toBytes(value * 2)); w.updateBinaryDocValue(idTerm, "bcf", TestBinaryDocValuesUpdates.toBytes(value * 2));
} else { } else {
w.updateNumericDocValue(new Term("id", Integer.toString(docBase + i)), "f", value); w.updateNumericDocValue(idTerm, "f", value);
w.updateNumericDocValue(new Term("id", Integer.toString(docBase + i)), "cf", value * 2); w.updateNumericDocValue(idTerm, "cf", value * 2);
w.updateBinaryDocValue(new Term("id", Integer.toString(docBase + i)), "bf", TestBinaryDocValuesUpdates.toBytes(value)); w.updateBinaryDocValue(idTerm, "bf", TestBinaryDocValuesUpdates.toBytes(value));
w.updateBinaryDocValue(new Term("id", Integer.toString(docBase + i)), "bcf", TestBinaryDocValuesUpdates.toBytes(value * 2)); 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 updates // sometimes do both deletes and updates
if (!fieldUpdate || random().nextBoolean()) { if (!fieldUpdate || random().nextBoolean()) {
if (VERBOSE) { if (VERBOSE) {
System.out.println(" delete id=" + (docBase+i)); System.out.println(" delete id=" + docid);
} }
deleteCount++; 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); IndexReader r = w.getReader(true);
// Sometimes we will make it here (we only randomly // Sometimes we will make it here (we only randomly
@ -2011,6 +2023,18 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
} }
shouldFail.set(false); 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; IndexReader r;
if (doClose && w != null) { if (doClose && w != null) {