Search in sources :

Example 6 with CorruptingIndexOutput

use of org.apache.lucene.store.CorruptingIndexOutput in project lucene-solr by apache.

the class TestBKD method testBitFlippedOnPartition1.

/** Make sure corruption on an input sort file is caught, even if BKDWriter doesn't get angry */
public void testBitFlippedOnPartition1() 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);
                if (corrupted == false && prefix.equals("_0_bkd1") && suffix.equals("sort")) {
                    corrupted = true;
                    return new CorruptingIndexOutput(dir0, 22, out);
                } else {
                    return out;
                }
            }
        };
        CorruptIndexException e = expectThrows(CorruptIndexException.class, () -> {
            verify(dir, docValues, null, numDims, numBytesPerDim, 50, 0.1);
        });
        assertTrue(e.getMessage().contains("checksum failed (hardware problem?)"));
    }
}
Also used : FilterDirectory(org.apache.lucene.store.FilterDirectory) IOContext(org.apache.lucene.store.IOContext) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) CorruptingIndexOutput(org.apache.lucene.store.CorruptingIndexOutput) IndexOutput(org.apache.lucene.store.IndexOutput) FilterDirectory(org.apache.lucene.store.FilterDirectory) Directory(org.apache.lucene.store.Directory) CorruptingIndexOutput(org.apache.lucene.store.CorruptingIndexOutput)

Aggregations

CorruptingIndexOutput (org.apache.lucene.store.CorruptingIndexOutput)6 Directory (org.apache.lucene.store.Directory)6 FilterDirectory (org.apache.lucene.store.FilterDirectory)6 IOContext (org.apache.lucene.store.IOContext)6 IndexOutput (org.apache.lucene.store.IndexOutput)6 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)5 EOFException (java.io.EOFException)2 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)2 IndexInput (org.apache.lucene.store.IndexInput)2