|
26 | 26 | import org.apache.logging.log4j.core.LogEvent; |
27 | 27 | import org.apache.logging.log4j.core.appender.AbstractAppender; |
28 | 28 | import org.apache.logging.log4j.core.filter.RegexFilter; |
| 29 | +import org.apache.lucene.analysis.Analyzer; |
| 30 | +import org.apache.lucene.analysis.Tokenizer; |
29 | 31 | import org.apache.lucene.analysis.standard.StandardAnalyzer; |
30 | 32 | import org.apache.lucene.codecs.Codec; |
31 | 33 | import org.apache.lucene.document.Field; |
|
112 | 114 | import org.junit.After; |
113 | 115 | import org.junit.Before; |
114 | 116 |
|
| 117 | +import java.io.IOError; |
115 | 118 | import java.io.IOException; |
116 | 119 | import java.io.InputStream; |
117 | 120 | import java.nio.charset.Charset; |
@@ -208,8 +211,12 @@ public void setUp() throws Exception { |
208 | 211 | } |
209 | 212 |
|
210 | 213 | public EngineConfig copy(EngineConfig config, EngineConfig.OpenMode openMode) { |
| 214 | + return copy(config, openMode, config.getAnalyzer()); |
| 215 | + } |
| 216 | + |
| 217 | + public EngineConfig copy(EngineConfig config, EngineConfig.OpenMode openMode, Analyzer analyzer) { |
211 | 218 | return new EngineConfig(openMode, config.getShardId(), config.getThreadPool(), config.getIndexSettings(), config.getWarmer(), |
212 | | - config.getStore(), config.getDeletionPolicy(), config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), |
| 219 | + config.getStore(), config.getDeletionPolicy(), config.getMergePolicy(), analyzer, config.getSimilarity(), |
213 | 220 | new CodecService(null, logger), config.getEventListener(), config.getTranslogRecoveryPerformer(), config.getQueryCache(), |
214 | 221 | config.getQueryCachingPolicy(), config.getTranslogConfig(), config.getFlushMergesAfter(), config.getRefreshListeners(), |
215 | 222 | config.getMaxUnsafeAutoIdTimestamp()); |
@@ -2521,4 +2528,40 @@ public void afterRefresh(boolean didRefresh) throws IOException { |
2521 | 2528 | assertTrue(internalEngine.failedEngine.get() instanceof MockDirectoryWrapper.FakeIOException); |
2522 | 2529 | } |
2523 | 2530 | } |
| 2531 | + |
| 2532 | + public void testTragicEventErrorBubblesUp() throws IOException { |
| 2533 | + engine.close(); |
| 2534 | + final AtomicBoolean failWithFatalError = new AtomicBoolean(true); |
| 2535 | + final VirtualMachineError error = randomFrom( |
| 2536 | + new InternalError(), |
| 2537 | + new OutOfMemoryError(), |
| 2538 | + new StackOverflowError(), |
| 2539 | + new UnknownError()); |
| 2540 | + engine = new InternalEngine(copy(engine.config(), EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG, new Analyzer() { |
| 2541 | + @Override |
| 2542 | + protected TokenStreamComponents createComponents(String fieldName) { |
| 2543 | + return new TokenStreamComponents(new Tokenizer() { |
| 2544 | + @Override |
| 2545 | + public boolean incrementToken() throws IOException { |
| 2546 | + if (failWithFatalError.get()) { |
| 2547 | + throw error; |
| 2548 | + } else { |
| 2549 | + throw new AssertionError("should not get to this point"); |
| 2550 | + } |
| 2551 | + } |
| 2552 | + }); |
| 2553 | + } |
| 2554 | + })); |
| 2555 | + final Document document = testDocument(); |
| 2556 | + document.add(new TextField("value", "test", Field.Store.YES)); |
| 2557 | + final ParsedDocument firstDoc = testParsedDocument("1", "1", "test", null, -1, -1, document, B_1, null); |
| 2558 | + final Engine.Index first = new Engine.Index(newUid("1"), firstDoc); |
| 2559 | + expectThrows(error.getClass(), () -> engine.index(first)); |
| 2560 | + failWithFatalError.set(false); |
| 2561 | + final ParsedDocument secondDoc = testParsedDocument("2", "2", "test", null, -1, -1, document, B_1, null); |
| 2562 | + final Engine.Index second = new Engine.Index(newUid("2"), secondDoc); |
| 2563 | + expectThrows(error.getClass(), () -> engine.index(second)); |
| 2564 | + assertNull(engine.failedEngine.get()); |
| 2565 | + } |
| 2566 | + |
2524 | 2567 | } |
0 commit comments