Search in sources :

Example 6 with FakeIOException

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

the class BaseFieldInfoFormatTestCase method testExceptionOnCloseInput.

/** 
   * Test field infos read that hits exception on close.
   * make sure we get our exception back, no file handle leaks, etc. 
   */
public void testExceptionOnCloseInput() throws Exception {
    Failure fail = new Failure() {

        @Override
        public void eval(MockDirectoryWrapper dir) throws IOException {
            for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
                if (doFail && "close".equals(e.getMethodName())) {
                    throw new FakeIOException();
                }
            }
        }
    };
    MockDirectoryWrapper dir = newMockDirectory();
    dir.failOn(fail);
    Codec codec = getCodec();
    SegmentInfo segmentInfo = newSegmentInfo(dir, "_123");
    FieldInfos.Builder builder = new FieldInfos.Builder();
    FieldInfo fi = builder.getOrAdd("field");
    fi.setIndexOptions(TextField.TYPE_STORED.indexOptions());
    addAttributes(fi);
    FieldInfos infos = builder.finish();
    codec.fieldInfosFormat().write(dir, segmentInfo, "", infos, IOContext.DEFAULT);
    fail.setDoFail();
    expectThrows(FakeIOException.class, () -> {
        codec.fieldInfosFormat().read(dir, segmentInfo, "", IOContext.DEFAULT);
    });
    fail.clearDoFail();
    dir.close();
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) FakeIOException(org.apache.lucene.store.MockDirectoryWrapper.FakeIOException) Codec(org.apache.lucene.codecs.Codec) Failure(org.apache.lucene.store.MockDirectoryWrapper.Failure)

Example 7 with FakeIOException

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

the class BaseFieldInfoFormatTestCase method testExceptionOnCloseOutput.

/** 
   * Test field infos write that hits exception on close.
   * make sure we get our exception back, no file handle leaks, etc. 
   */
public void testExceptionOnCloseOutput() throws Exception {
    Failure fail = new Failure() {

        @Override
        public void eval(MockDirectoryWrapper dir) throws IOException {
            for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
                if (doFail && "close".equals(e.getMethodName())) {
                    throw new FakeIOException();
                }
            }
        }
    };
    MockDirectoryWrapper dir = newMockDirectory();
    dir.failOn(fail);
    Codec codec = getCodec();
    SegmentInfo segmentInfo = newSegmentInfo(dir, "_123");
    FieldInfos.Builder builder = new FieldInfos.Builder();
    FieldInfo fi = builder.getOrAdd("field");
    fi.setIndexOptions(TextField.TYPE_STORED.indexOptions());
    addAttributes(fi);
    FieldInfos infos = builder.finish();
    fail.setDoFail();
    expectThrows(FakeIOException.class, () -> {
        codec.fieldInfosFormat().write(dir, segmentInfo, "", infos, IOContext.DEFAULT);
    });
    fail.clearDoFail();
    dir.close();
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) FakeIOException(org.apache.lucene.store.MockDirectoryWrapper.FakeIOException) Codec(org.apache.lucene.codecs.Codec) Failure(org.apache.lucene.store.MockDirectoryWrapper.Failure)

Example 8 with FakeIOException

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

the class BaseFieldInfoFormatTestCase method testExceptionOnCreateOutput.

/** 
   * Test field infos write that hits exception immediately on open.
   * make sure we get our exception back, no file handle leaks, etc. 
   */
public void testExceptionOnCreateOutput() throws Exception {
    Failure fail = new Failure() {

        @Override
        public void eval(MockDirectoryWrapper dir) throws IOException {
            for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
                if (doFail && "createOutput".equals(e.getMethodName())) {
                    throw new FakeIOException();
                }
            }
        }
    };
    MockDirectoryWrapper dir = newMockDirectory();
    dir.failOn(fail);
    Codec codec = getCodec();
    SegmentInfo segmentInfo = newSegmentInfo(dir, "_123");
    FieldInfos.Builder builder = new FieldInfos.Builder();
    FieldInfo fi = builder.getOrAdd("field");
    fi.setIndexOptions(TextField.TYPE_STORED.indexOptions());
    addAttributes(fi);
    FieldInfos infos = builder.finish();
    fail.setDoFail();
    expectThrows(FakeIOException.class, () -> {
        codec.fieldInfosFormat().write(dir, segmentInfo, "", infos, IOContext.DEFAULT);
    });
    fail.clearDoFail();
    dir.close();
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) FakeIOException(org.apache.lucene.store.MockDirectoryWrapper.FakeIOException) Codec(org.apache.lucene.codecs.Codec) Failure(org.apache.lucene.store.MockDirectoryWrapper.Failure)

Example 9 with FakeIOException

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

the class BaseFieldInfoFormatTestCase method testExceptionOnOpenInput.

/** 
   * Test field infos read that hits exception immediately on open.
   * make sure we get our exception back, no file handle leaks, etc. 
   */
public void testExceptionOnOpenInput() throws Exception {
    Failure fail = new Failure() {

        @Override
        public void eval(MockDirectoryWrapper dir) throws IOException {
            for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
                if (doFail && "openInput".equals(e.getMethodName())) {
                    throw new FakeIOException();
                }
            }
        }
    };
    MockDirectoryWrapper dir = newMockDirectory();
    dir.failOn(fail);
    Codec codec = getCodec();
    SegmentInfo segmentInfo = newSegmentInfo(dir, "_123");
    FieldInfos.Builder builder = new FieldInfos.Builder();
    FieldInfo fi = builder.getOrAdd("field");
    fi.setIndexOptions(TextField.TYPE_STORED.indexOptions());
    addAttributes(fi);
    FieldInfos infos = builder.finish();
    codec.fieldInfosFormat().write(dir, segmentInfo, "", infos, IOContext.DEFAULT);
    fail.setDoFail();
    expectThrows(FakeIOException.class, () -> {
        codec.fieldInfosFormat().read(dir, segmentInfo, "", IOContext.DEFAULT);
    });
    fail.clearDoFail();
    dir.close();
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) FakeIOException(org.apache.lucene.store.MockDirectoryWrapper.FakeIOException) Codec(org.apache.lucene.codecs.Codec) Failure(org.apache.lucene.store.MockDirectoryWrapper.Failure)

Example 10 with FakeIOException

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

the class TestIndexWriterExceptions method testMergeExceptionIsTragic.

public void testMergeExceptionIsTragic() throws Exception {
    MockDirectoryWrapper dir = newMockDirectory();
    final AtomicBoolean didFail = new AtomicBoolean();
    dir.failOn(new MockDirectoryWrapper.Failure() {

        @Override
        public void eval(MockDirectoryWrapper dir) throws IOException {
            if (random().nextInt(10) != 0) {
                return;
            }
            if (didFail.get()) {
                // Already failed
                return;
            }
            StackTraceElement[] trace = Thread.currentThread().getStackTrace();
            for (int i = 0; i < trace.length; i++) {
                if ("merge".equals(trace[i].getMethodName())) {
                    if (VERBOSE) {
                        System.out.println("TEST: now fail; thread=" + Thread.currentThread().getName() + " exc:");
                        new Throwable().printStackTrace(System.out);
                    }
                    didFail.set(true);
                    throw new FakeIOException();
                }
            }
        }
    });
    IndexWriterConfig iwc = newIndexWriterConfig();
    MergePolicy mp = iwc.getMergePolicy();
    if (mp instanceof TieredMergePolicy) {
        TieredMergePolicy tmp = (TieredMergePolicy) mp;
        if (tmp.getMaxMergedSegmentMB() < 0.2) {
            tmp.setMaxMergedSegmentMB(0.2);
        }
    }
    MergeScheduler ms = iwc.getMergeScheduler();
    if (ms instanceof ConcurrentMergeScheduler) {
        ((ConcurrentMergeScheduler) ms).setSuppressExceptions();
    }
    IndexWriter w = new IndexWriter(dir, iwc);
    while (true) {
        try {
            Document doc = new Document();
            doc.add(newStringField("field", "string", Field.Store.NO));
            w.addDocument(doc);
            if (random().nextInt(10) == 7) {
                // Flush new segment:
                DirectoryReader.open(w).close();
            }
        } catch (AlreadyClosedException ace) {
            // OK: e.g. CMS hit the exc in BG thread and closed the writer
            break;
        } catch (FakeIOException fioe) {
            // OK: e.g. SMS hit the exception
            break;
        }
    }
    assertNotNull(w.getTragicException());
    assertFalse(w.isOpen());
    assertTrue(didFail.get());
    if (ms instanceof ConcurrentMergeScheduler) {
        // Sneaky: CMS's merge thread will be concurrently rolling back IW due
        // to the tragedy, with this main thread, so we have to wait here
        // to ensure the rollback has finished, else MDW still sees open files:
        ((ConcurrentMergeScheduler) ms).sync();
    }
    dir.close();
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) FakeIOException(org.apache.lucene.store.MockDirectoryWrapper.FakeIOException) IOException(java.io.IOException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Document(org.apache.lucene.document.Document) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FakeIOException(org.apache.lucene.store.MockDirectoryWrapper.FakeIOException)

Aggregations

MockDirectoryWrapper (org.apache.lucene.store.MockDirectoryWrapper)13 FakeIOException (org.apache.lucene.store.MockDirectoryWrapper.FakeIOException)13 Codec (org.apache.lucene.codecs.Codec)8 Failure (org.apache.lucene.store.MockDirectoryWrapper.Failure)8 IOException (java.io.IOException)5 Document (org.apache.lucene.document.Document)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)3 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)3 BinaryDocValuesField (org.apache.lucene.document.BinaryDocValuesField)1 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)1 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)1 StringField (org.apache.lucene.document.StringField)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 TermQuery (org.apache.lucene.search.TermQuery)1 Bits (org.apache.lucene.util.Bits)1 BytesRef (org.apache.lucene.util.BytesRef)1 ThreadInterruptedException (org.apache.lucene.util.ThreadInterruptedException)1 Test (org.junit.Test)1