You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/05/12 16:31:11 UTC
svn commit: r1593975 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/core/
lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
Author: mikemccand
Date: Mon May 12 14:31:10 2014
New Revision: 1593975
URL: http://svn.apache.org/r1593975
Log:
fix rare test fail
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java?rev=1593975&r1=1593974&r2=1593975&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java Mon May 12 14:31:10 2014
@@ -1953,44 +1953,56 @@ public class TestIndexWriterExceptions e
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 value
if (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 updates
if (!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
@@ -2023,6 +2035,18 @@ public class TestIndexWriterExceptions e
}
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) {