Search in sources :

Example 11 with FilterDirectory

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

the class BaseCompoundFormatTestCase method testPassIOContext.

// LUCENE-5724: things like NRTCachingDir rely upon IOContext being properly passed down
public void testPassIOContext() throws IOException {
    final String testfile = "_123.test";
    final IOContext myContext = new IOContext();
    Directory dir = new FilterDirectory(newDirectory()) {

        @Override
        public IndexOutput createOutput(String name, IOContext context) throws IOException {
            assertSame(myContext, context);
            return super.createOutput(name, context);
        }
    };
    SegmentInfo si = newSegmentInfo(dir, "_123");
    try (IndexOutput out = dir.createOutput(testfile, myContext)) {
        CodecUtil.writeIndexHeader(out, "Foo", 0, si.getId(), "suffix");
        out.writeInt(3);
        CodecUtil.writeFooter(out);
    }
    si.setFiles(Collections.singleton(testfile));
    si.getCodec().compoundFormat().write(dir, si, myContext);
    dir.close();
}
Also used : FilterDirectory(org.apache.lucene.store.FilterDirectory) IOContext(org.apache.lucene.store.IOContext) IndexOutput(org.apache.lucene.store.IndexOutput) FilterDirectory(org.apache.lucene.store.FilterDirectory) Directory(org.apache.lucene.store.Directory) NRTCachingDirectory(org.apache.lucene.store.NRTCachingDirectory)

Example 12 with FilterDirectory

use of org.apache.lucene.store.FilterDirectory 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

FilterDirectory (org.apache.lucene.store.FilterDirectory)12 Directory (org.apache.lucene.store.Directory)10 IOContext (org.apache.lucene.store.IOContext)9 IndexOutput (org.apache.lucene.store.IndexOutput)7 CorruptingIndexOutput (org.apache.lucene.store.CorruptingIndexOutput)6 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)5 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 IndexInput (org.apache.lucene.store.IndexInput)2 RAMDirectory (org.apache.lucene.store.RAMDirectory)2 ForwardingListeningExecutorService (com.google.common.util.concurrent.ForwardingListeningExecutorService)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 Path (java.nio.file.Path)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 CopyOnReadDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.CopyOnReadDirectory)1 Document (org.apache.lucene.document.Document)1