Skip to content

Commit f35df02

Browse files
committed
ingestionEngine creation failure tes
Signed-off-by: Yupeng Fu <yupeng@uber.com>
1 parent c38c302 commit f35df02

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

server/src/test/java/org/opensearch/index/engine/IngestionEngineTests.java

+32
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.concurrent.atomic.AtomicLong;
3737

3838
import static org.awaitility.Awaitility.await;
39+
import static org.mockito.Mockito.doThrow;
40+
import static org.mockito.Mockito.mock;
3941

4042
public class IngestionEngineTests extends EngineTestCase {
4143

@@ -122,6 +124,36 @@ public void testRecovery() throws IOException {
122124
waitForResults(ingestionEngine, 4);
123125
}
124126

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+
125157
private IngestionEngine buildIngestionEngine(AtomicLong globalCheckpoint, Store store, IndexSettings settings) throws IOException {
126158
FakeIngestionSource.FakeIngestionConsumerFactory consumerFactory = new FakeIngestionSource.FakeIngestionConsumerFactory(messages);
127159
EngineConfig engineConfig = config(settings, store, createTempDir(), NoMergePolicy.INSTANCE, null, null, globalCheckpoint::get);

0 commit comments

Comments
 (0)