List of usage examples for org.apache.lucene.store MockDirectoryWrapper setRandomIOExceptionRateOnOpen
public void setRandomIOExceptionRateOnOpen(double rate)
From source file:org.elasticsearch.index.engine.InternalEngineTests.java
License:Apache License
/** * Random test that throws random exception and ensures all references are * counted down / released and resources are closed. *//* w ww . j av a2 s . c o m*/ @Test public void testFailStart() throws IOException { // this test fails if any reader, searcher or directory is not closed - MDW FTW final int iters = scaledRandomIntBetween(10, 100); for (int i = 0; i < iters; i++) { MockDirectoryWrapper wrapper = newMockDirectory(); wrapper.setFailOnOpenInput(randomBoolean()); wrapper.setAllowRandomFileNotFoundException(randomBoolean()); wrapper.setRandomIOExceptionRate(randomDouble()); wrapper.setRandomIOExceptionRateOnOpen(randomDouble()); final Path translogPath = createTempDir("testFailStart"); try (Store store = createStore(wrapper)) { int refCount = store.refCount(); assertTrue("refCount: " + store.refCount(), store.refCount() > 0); InternalEngine holder; try { holder = createEngine(store, translogPath); } catch (EngineCreationFailureException ex) { assertEquals(store.refCount(), refCount); continue; } assertEquals(store.refCount(), refCount + 1); final int numStarts = scaledRandomIntBetween(1, 5); for (int j = 0; j < numStarts; j++) { try { assertEquals(store.refCount(), refCount + 1); holder.close(); holder = createEngine(store, translogPath); assertEquals(store.refCount(), refCount + 1); } catch (EngineCreationFailureException ex) { // all is fine assertEquals(store.refCount(), refCount); break; } } holder.close(); assertEquals(store.refCount(), refCount); } } }
From source file:org.elasticsearch.index.engine.ShadowEngineTests.java
License:Apache License
@Test public void testFailEngineOnCorruption() { ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), B_1, false);/*w w w. j a v a2s. co m*/ primaryEngine.create(new Engine.Create(null, newUid("1"), doc)); primaryEngine.flush(); MockDirectoryWrapper leaf = DirectoryUtils.getLeaf(replicaEngine.config().getStore().directory(), MockDirectoryWrapper.class); leaf.setRandomIOExceptionRate(1.0); leaf.setRandomIOExceptionRateOnOpen(1.0); try { replicaEngine.refresh("foo"); fail("exception expected"); } catch (Exception ex) { } try { Engine.Searcher searchResult = replicaEngine.acquireSearcher("test"); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher .engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1)); searchResult.close(); fail("exception expected"); } catch (EngineClosedException ex) { // all is well } }
From source file:org.elasticsearch.index.engine.ShadowEngineTests.java
License:Apache License
/** * Random test that throws random exception and ensures all references are * counted down / released and resources are closed. *///from w w w.java2 s .c om @Test public void testFailStart() throws IOException { // Need a commit point for this ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), B_1, false); primaryEngine.create(new Engine.Create(null, newUid("1"), doc)); primaryEngine.flush(); // this test fails if any reader, searcher or directory is not closed - MDW FTW final int iters = scaledRandomIntBetween(10, 100); for (int i = 0; i < iters; i++) { MockDirectoryWrapper wrapper = newMockFSDirectory(dirPath.toFile()); wrapper.setFailOnOpenInput(randomBoolean()); wrapper.setAllowRandomFileNotFoundException(randomBoolean()); wrapper.setRandomIOExceptionRate(randomDouble()); wrapper.setRandomIOExceptionRateOnOpen(randomDouble()); try (Store store = createStore(wrapper)) { int refCount = store.refCount(); assertTrue("refCount: " + store.refCount(), store.refCount() > 0); Translog translog = createTranslog(); ShadowEngine holder; try { holder = createShadowEngine(store, translog); } catch (EngineCreationFailureException ex) { assertEquals(store.refCount(), refCount); continue; } holder.config().setFailEngineOnCorruption(true); assertEquals(store.refCount(), refCount + 1); final int numStarts = scaledRandomIntBetween(1, 5); for (int j = 0; j < numStarts; j++) { try { assertEquals(store.refCount(), refCount + 1); holder.close(); holder = createShadowEngine(store, translog); holder.config().setFailEngineOnCorruption(true); assertEquals(store.refCount(), refCount + 1); } catch (EngineCreationFailureException ex) { // all is fine assertEquals(store.refCount(), refCount); break; } } translog.close(); holder.close(); assertEquals(store.refCount(), refCount); } } }
From source file:org.elasticsearch.index.store.mock.MockDirectoryHelper.java
License:Apache License
public Directory wrap(Directory dir) { final MockDirectoryWrapper w = new MockDirectoryWrapper(random, dir); w.setRandomIOExceptionRate(randomIOExceptionRate); w.setRandomIOExceptionRateOnOpen(randomIOExceptionRateOnOpen); w.setThrottling(throttle);//www. ja v a 2 s . com w.setCheckIndexOnClose(checkIndexOnClose); wrappers.add(w); return new FilterDirectory(w) { @Override public Directory getDelegate() { // TODO we should port this FilterDirectory to Lucene return w.getDelegate(); } }; }
From source file:org.elasticsearch.test.store.mock.MockDirectoryHelper.java
License:Apache License
public Directory wrap(Directory dir) { final MockDirectoryWrapper w = new MockDirectoryWrapper(random, dir); w.setRandomIOExceptionRate(randomIOExceptionRate); w.setRandomIOExceptionRateOnOpen(randomIOExceptionRateOnOpen); w.setThrottling(throttle);//from w ww . j ava 2 s .c o m w.setCheckIndexOnClose(checkIndexOnClose); w.setPreventDoubleWrite(preventDoubleWrite); w.setNoDeleteOpenFile(noDeleteOpenFile); wrappers.add(w); return new FilterDirectory(w) { @Override public Directory getDelegate() { // TODO we should port this FilterDirectory to Lucene return w.getDelegate(); } }; }