|
36 | 36 | import java.util.concurrent.atomic.AtomicLong;
|
37 | 37 |
|
38 | 38 | import static org.awaitility.Awaitility.await;
|
| 39 | +import static org.mockito.Mockito.doThrow; |
| 40 | +import static org.mockito.Mockito.mock; |
39 | 41 |
|
40 | 42 | public class IngestionEngineTests extends EngineTestCase {
|
41 | 43 |
|
@@ -122,6 +124,36 @@ public void testRecovery() throws IOException {
|
122 | 124 | waitForResults(ingestionEngine, 4);
|
123 | 125 | }
|
124 | 126 |
|
| 127 | + public void testCreationFailure() throws IOException { |
| 128 | + // Simulate an error scenario |
| 129 | + Store mockStore = mock(Store.class); |
| 130 | + doThrow(new IOException("Simulated IOException")).when(mockStore).readLastCommittedSegmentsInfo(); |
| 131 | + |
| 132 | + final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED); |
| 133 | + |
| 134 | + FakeIngestionSource.FakeIngestionConsumerFactory consumerFactory = new FakeIngestionSource.FakeIngestionConsumerFactory(messages); |
| 135 | + EngineConfig engineConfig = config( |
| 136 | + indexSettings, |
| 137 | + store, |
| 138 | + createTempDir(), |
| 139 | + NoMergePolicy.INSTANCE, |
| 140 | + null, |
| 141 | + null, |
| 142 | + globalCheckpoint::get |
| 143 | + ); |
| 144 | + // overwrite the config with ingestion engine settings |
| 145 | + String mapping = "{\"properties\":{\"name\":{\"type\": \"text\"},\"age\":{\"type\": \"integer\"}}}}"; |
| 146 | + MapperService mapperService = createMapperService(mapping); |
| 147 | + engineConfig = config(engineConfig, () -> new DocumentMapperForType(mapperService.documentMapper(), null)); |
| 148 | + try { |
| 149 | + new IngestionEngine(engineConfig, consumerFactory); |
| 150 | + fail("Expected EngineException to be thrown"); |
| 151 | + } catch (EngineException e) { |
| 152 | + assertEquals("failed to create engine", e.getMessage()); |
| 153 | + assertTrue(e.getCause() instanceof IOException); |
| 154 | + } |
| 155 | + } |
| 156 | + |
125 | 157 | private IngestionEngine buildIngestionEngine(AtomicLong globalCheckpoint, Store store, IndexSettings settings) throws IOException {
|
126 | 158 | FakeIngestionSource.FakeIngestionConsumerFactory consumerFactory = new FakeIngestionSource.FakeIngestionConsumerFactory(messages);
|
127 | 159 | EngineConfig engineConfig = config(settings, store, createTempDir(), NoMergePolicy.INSTANCE, null, null, globalCheckpoint::get);
|
|
0 commit comments