use of org.opensearch.plugins.IngestPlugin in project OpenSearch by opensearch-project.
the class IngestServiceTests method testIngestClusterStateListeners_orderOfExecution.
public void testIngestClusterStateListeners_orderOfExecution() {
final AtomicInteger counter = new AtomicInteger(0);
// Ingest cluster state listener state should be invoked first:
Consumer<ClusterState> ingestClusterStateListener = clusterState -> {
assertThat(counter.compareAndSet(0, 1), is(true));
};
// Processor factory should be invoked secondly after ingest cluster state listener:
IngestPlugin testPlugin = new IngestPlugin() {
@Override
public Map<String, Processor.Factory> getProcessors(Processor.Parameters parameters) {
return Collections.singletonMap("test", (factories, tag, description, config) -> {
assertThat(counter.compareAndSet(1, 2), is(true));
return new FakeProcessor("test", tag, description, ingestDocument -> {
});
});
}
};
// Create ingest service:
Client client = mock(Client.class);
IngestService ingestService = new IngestService(mock(ClusterService.class), threadPool, null, null, null, Arrays.asList(testPlugin), client);
ingestService.addIngestClusterStateListener(ingestClusterStateListener);
// Create pipeline and apply the resulting cluster state, which should update the counter in the right order:
PutPipelineRequest putRequest = new PutPipelineRequest("_id", new BytesArray("{\"processors\": [{\"test\" : {}}]}"), XContentType.JSON);
// Start empty
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
ClusterState previousClusterState = clusterState;
clusterState = IngestService.innerPut(putRequest, clusterState);
ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState));
// Sanity check that counter has been updated twice:
assertThat(counter.get(), equalTo(2));
}
use of org.opensearch.plugins.IngestPlugin in project OpenSearch by opensearch-project.
the class IngestServiceTests method createWithProcessors.
private static IngestService createWithProcessors(Map<String, Processor.Factory> processors) {
Client client = mock(Client.class);
ThreadPool threadPool = mock(ThreadPool.class);
ExecutorService executorService = OpenSearchExecutors.newDirectExecutorService();
when(threadPool.generic()).thenReturn(executorService);
when(threadPool.executor(anyString())).thenReturn(executorService);
return new IngestService(mock(ClusterService.class), threadPool, null, null, null, Collections.singletonList(new IngestPlugin() {
@Override
public Map<String, Processor.Factory> getProcessors(final Processor.Parameters parameters) {
return processors;
}
}), client);
}
Aggregations