Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

fix false failures from test bugs

Mike McCandless47fb35c20ac2
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java
index 9dffaa8df6c..3d8aeffe3b9 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java
@@ -19,6 +19,7 @@ package org.apache.lucene.index;
import java.io.EOFException;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Collections;
import org.apache.lucene.analysis.MockAnalyzer;
@@ -80,7 +81,9 @@ public class TestAllFilesCheckIndexHeader extends LuceneTestCase {
private void checkIndexHeader(Directory dir) throws IOException {
for(String name : dir.listAll()) {
- checkOneFile(dir, name);
+ if (name.equals(IndexWriter.WRITE_LOCK_NAME) == false) {
+ checkOneFile(dir, name);
+ }
}
}
@@ -99,15 +102,25 @@ public class TestAllFilesCheckIndexHeader extends LuceneTestCase {
if (name.equals(victim) == false) {
dirCopy.copyFrom(dir, name, name, IOContext.DEFAULT);
} else {
- try(IndexOutput out = dirCopy.createOutput(name, IOContext.DEFAULT);
- IndexInput in = dir.openInput(name, IOContext.DEFAULT)) {
+
+ // Iterate until our randomly generated bytes are indeed different from the first bytes of the file ... the vast majority of the
+ // time this will only require one iteration!
+ while (true) {
+ try(IndexOutput out = dirCopy.createOutput(name, IOContext.DEFAULT);
+ IndexInput in = dir.openInput(name, IOContext.DEFAULT)) {
// keeps same file length, but replaces the first wrongBytes with random bytes:
byte[] bytes = new byte[wrongBytes];
random().nextBytes(bytes);
out.writeBytes(bytes, 0, bytes.length);
- in.seek(wrongBytes);
- out.copyBytes(in, victimLength - wrongBytes);
+ byte[] bytes2 = new byte[wrongBytes];
+ in.readBytes(bytes2, 0, bytes2.length);
+ if (Arrays.equals(bytes, bytes2) == false) {
+ // We successfully randomly generated bytes that differ from the bytes in the file:
+ out.copyBytes(in, victimLength - wrongBytes);
+ break;
+ }
}
+ }
}
dirCopy.sync(Collections.singleton(name));
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java
index bda5857a7a7..e5aa6c7f9ad 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java
@@ -80,7 +80,9 @@ public class TestAllFilesDetectTruncation extends LuceneTestCase {
private void checkTruncation(Directory dir) throws IOException {
for(String name : dir.listAll()) {
- truncateOneFile(dir, name);
+ if (name.equals(IndexWriter.WRITE_LOCK_NAME) == false) {
+ truncateOneFile(dir, name);
+ }
}
}