fix false failures from test bugs

This commit is contained in:
Mike McCandless 2016-01-28 11:29:37 -05:00
parent 79e384bac5
commit 47fb35c20a
2 changed files with 21 additions and 6 deletions

View File

@ -19,6 +19,7 @@ package org.apache.lucene.index;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockAnalyzer;
@ -80,7 +81,9 @@ public class TestAllFilesCheckIndexHeader extends LuceneTestCase {
private void checkIndexHeader(Directory dir) throws IOException { private void checkIndexHeader(Directory dir) throws IOException {
for(String name : dir.listAll()) { 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) { if (name.equals(victim) == false) {
dirCopy.copyFrom(dir, name, name, IOContext.DEFAULT); dirCopy.copyFrom(dir, name, name, IOContext.DEFAULT);
} else { } 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: // keeps same file length, but replaces the first wrongBytes with random bytes:
byte[] bytes = new byte[wrongBytes]; byte[] bytes = new byte[wrongBytes];
random().nextBytes(bytes); random().nextBytes(bytes);
out.writeBytes(bytes, 0, bytes.length); out.writeBytes(bytes, 0, bytes.length);
in.seek(wrongBytes); byte[] bytes2 = new byte[wrongBytes];
out.copyBytes(in, victimLength - 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)); dirCopy.sync(Collections.singleton(name));
} }

View File

@ -80,7 +80,9 @@ public class TestAllFilesDetectTruncation extends LuceneTestCase {
private void checkTruncation(Directory dir) throws IOException { private void checkTruncation(Directory dir) throws IOException {
for(String name : dir.listAll()) { for(String name : dir.listAll()) {
truncateOneFile(dir, name); if (name.equals(IndexWriter.WRITE_LOCK_NAME) == false) {
truncateOneFile(dir, name);
}
} }
} }