use of org.apache.lucene.store.CorruptingIndexOutput in project lucene-solr by apache.
the class TestOfflineSorter method testBitFlippedOnPartition1.
/** Make sure corruption on a temp file (partition) is caught, even if the corruption didn't confuse OfflineSorter! */
public void testBitFlippedOnPartition1() throws Exception {
try (Directory dir0 = newMockDirectory()) {
Directory dir = new FilterDirectory(dir0) {
boolean corrupted;
@Override
public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
IndexOutput out = in.createTempOutput(prefix, suffix, context);
if (corrupted == false && suffix.equals("sort")) {
corrupted = true;
return new CorruptingIndexOutput(dir0, 544677, out);
} else {
return out;
}
}
};
IndexOutput unsorted = dir.createTempOutput("unsorted", "tmp", IOContext.DEFAULT);
writeAll(unsorted, generateFixed((int) (OfflineSorter.MB * 3)));
CorruptIndexException e = expectThrows(CorruptIndexException.class, () -> {
new OfflineSorter(dir, "foo", OfflineSorter.DEFAULT_COMPARATOR, BufferSize.megabytes(1), 10, -1, null, 0).sort(unsorted.getName());
});
assertTrue(e.getMessage().contains("checksum failed (hardware problem?)"));
}
}
use of org.apache.lucene.store.CorruptingIndexOutput in project lucene-solr by apache.
the class TestOfflineSorter method testBitFlippedOnPartition2.
/** Make sure corruption on a temp file (partition) is caught, if the corruption did confuse OfflineSorter! */
public void testBitFlippedOnPartition2() throws Exception {
try (Directory dir0 = newMockDirectory()) {
Directory dir = new FilterDirectory(dir0) {
boolean corrupted;
@Override
public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
IndexOutput out = in.createTempOutput(prefix, suffix, context);
if (corrupted == false && suffix.equals("sort")) {
corrupted = true;
return new CorruptingIndexOutput(dir0, 544677, out) {
@Override
protected void corruptFile() throws IOException {
String newTempName;
try (IndexOutput tmpOut = dir0.createTempOutput("tmp", "tmp", IOContext.DEFAULT);
IndexInput in = dir0.openInput(out.getName(), IOContext.DEFAULT)) {
newTempName = tmpOut.getName();
tmpOut.copyBytes(in, 1025905);
short v = in.readShort();
assertEquals(254, v);
tmpOut.writeShort(Short.MAX_VALUE);
tmpOut.copyBytes(in, in.length() - 1025905 - Short.BYTES);
}
// Delete original and copy corrupt version back:
dir0.deleteFile(out.getName());
dir0.copyFrom(dir0, newTempName, out.getName(), IOContext.DEFAULT);
dir0.deleteFile(newTempName);
}
};
} else {
return out;
}
}
};
IndexOutput unsorted = dir.createTempOutput("unsorted", "tmp", IOContext.DEFAULT);
writeAll(unsorted, generateFixed((int) (OfflineSorter.MB * 3)));
EOFException e = expectThrows(EOFException.class, () -> {
new OfflineSorter(dir, "foo", OfflineSorter.DEFAULT_COMPARATOR, BufferSize.megabytes(1), 10, -1, null, 0).sort(unsorted.getName());
});
assertEquals(1, e.getSuppressed().length);
assertTrue(e.getSuppressed()[0] instanceof CorruptIndexException);
assertTrue(e.getSuppressed()[0].getMessage().contains("checksum failed (hardware problem?)"));
}
}
use of org.apache.lucene.store.CorruptingIndexOutput in project lucene-solr by apache.
the class TestOfflineSorter method testBitFlippedOnInput1.
/** Make sure corruption on the incoming (unsorted) file is caught, even if the corruption didn't confuse OfflineSorter! */
public void testBitFlippedOnInput1() throws Exception {
try (Directory dir0 = newMockDirectory()) {
Directory dir = new FilterDirectory(dir0) {
@Override
public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
IndexOutput out = in.createTempOutput(prefix, suffix, context);
if (prefix.equals("unsorted")) {
return new CorruptingIndexOutput(dir0, 22, out);
} else {
return out;
}
}
};
IndexOutput unsorted = dir.createTempOutput("unsorted", "tmp", IOContext.DEFAULT);
writeAll(unsorted, generateFixed(10 * 1024));
CorruptIndexException e = expectThrows(CorruptIndexException.class, () -> {
new OfflineSorter(dir, "foo").sort(unsorted.getName());
});
assertTrue(e.getMessage().contains("checksum failed (hardware problem?)"));
}
}
use of org.apache.lucene.store.CorruptingIndexOutput in project lucene-solr by apache.
the class TestOfflineSorter method testBitFlippedOnInput2.
/** Make sure corruption on the incoming (unsorted) file is caught, if the corruption did confuse OfflineSorter! */
public void testBitFlippedOnInput2() throws Exception {
try (Directory dir0 = newMockDirectory()) {
Directory dir = new FilterDirectory(dir0) {
@Override
public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
IndexOutput out = in.createTempOutput(prefix, suffix, context);
if (prefix.equals("unsorted")) {
return new CorruptingIndexOutput(dir0, 22, out) {
@Override
protected void corruptFile() throws IOException {
String newTempName;
try (IndexOutput tmpOut = dir0.createTempOutput("tmp", "tmp", IOContext.DEFAULT);
IndexInput in = dir0.openInput(out.getName(), IOContext.DEFAULT)) {
newTempName = tmpOut.getName();
// Replace length at the end with a too-long value:
short v = in.readShort();
assertEquals(256, v);
tmpOut.writeShort(Short.MAX_VALUE);
tmpOut.copyBytes(in, in.length() - Short.BYTES);
}
// Delete original and copy corrupt version back:
dir0.deleteFile(out.getName());
dir0.copyFrom(dir0, newTempName, out.getName(), IOContext.DEFAULT);
dir0.deleteFile(newTempName);
}
};
} else {
return out;
}
}
};
IndexOutput unsorted = dir.createTempOutput("unsorted", "tmp", IOContext.DEFAULT);
writeAll(unsorted, generateFixed(5 * 1024));
// This corruption made OfflineSorter fail with its own exception, but we verify it also went and added (as suppressed) that the
// checksum was wrong:
EOFException e = expectThrows(EOFException.class, () -> {
new OfflineSorter(dir, "foo").sort(unsorted.getName());
});
assertEquals(1, e.getSuppressed().length);
assertTrue(e.getSuppressed()[0] instanceof CorruptIndexException);
assertTrue(e.getSuppressed()[0].getMessage().contains("checksum failed (hardware problem?)"));
}
}
use of org.apache.lucene.store.CorruptingIndexOutput in project lucene-solr by apache.
the class TestBKD method testBitFlippedOnPartition2.
/** Make sure corruption on a recursed partition is caught, when BKDWriter does get angry */
public void testBitFlippedOnPartition2() throws Exception {
// Generate fixed data set:
int numDocs = atLeast(10000);
int numBytesPerDim = 4;
int numDims = 3;
byte[][][] docValues = new byte[numDocs][][];
byte counter = 0;
for (int docID = 0; docID < numDocs; docID++) {
byte[][] values = new byte[numDims][];
for (int dim = 0; dim < numDims; dim++) {
values[dim] = new byte[numBytesPerDim];
for (int i = 0; i < values[dim].length; i++) {
values[dim][i] = counter;
counter++;
}
}
docValues[docID] = values;
}
try (Directory dir0 = newMockDirectory()) {
Directory dir = new FilterDirectory(dir0) {
boolean corrupted;
@Override
public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
IndexOutput out = in.createTempOutput(prefix, suffix, context);
//System.out.println("prefix=" + prefix + " suffix=" + suffix);
if (corrupted == false && suffix.equals("bkd_left1")) {
//System.out.println("now corrupt byte=" + x + " prefix=" + prefix + " suffix=" + suffix);
corrupted = true;
return new CorruptingIndexOutput(dir0, 22072, out);
} else {
return out;
}
}
};
Throwable t = expectThrows(CorruptIndexException.class, () -> {
verify(dir, docValues, null, numDims, numBytesPerDim, 50, 0.1);
});
assertCorruptionDetected(t);
}
}
Aggregations