Search in sources :

Example 11 with Failure

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

the class TestIndexWriterOnVMError method testCheckpoint.

@Nightly
public void testCheckpoint() throws Exception {
    final Random r = new Random(random().nextLong());
    doTest(new Failure() {

        @Override
        public void eval(MockDirectoryWrapper dir) throws IOException {
            StackTraceElement[] stack = Thread.currentThread().getStackTrace();
            boolean ok = false;
            for (int i = 0; i < stack.length; i++) {
                if (stack[i].getClassName().equals(IndexFileDeleter.class.getName()) && stack[i].getMethodName().equals("checkpoint")) {
                    ok = true;
                }
            }
            if (ok && r.nextInt(4) == 0) {
                throw new OutOfMemoryError("Fake OutOfMemoryError");
            }
        }
    });
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) Random(java.util.Random) IOException(java.io.IOException) Failure(org.apache.lucene.store.MockDirectoryWrapper.Failure)

Aggregations

MockDirectoryWrapper (org.apache.lucene.store.MockDirectoryWrapper)11 Failure (org.apache.lucene.store.MockDirectoryWrapper.Failure)11 Codec (org.apache.lucene.codecs.Codec)8 FakeIOException (org.apache.lucene.store.MockDirectoryWrapper.FakeIOException)8 IOException (java.io.IOException)3 Random (java.util.Random)3