use of org.opensearch.ingest.AbstractProcessor in project OpenSearch by opensearch-project.
the class SimulateExecutionServiceTests method testAsyncSimulation.
public void testAsyncSimulation() throws Exception {
int numDocs = randomIntBetween(1, 64);
List<IngestDocument> documents = new ArrayList<>(numDocs);
for (int id = 0; id < numDocs; id++) {
documents.add(new IngestDocument("_index", Integer.toString(id), null, 0L, VersionType.INTERNAL, new HashMap<>()));
}
Processor processor1 = new AbstractProcessor(null, null) {
@Override
public void execute(IngestDocument ingestDocument, BiConsumer<IngestDocument, Exception> handler) {
threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> {
ingestDocument.setFieldValue("processed", true);
handler.accept(ingestDocument, null);
});
}
@Override
public IngestDocument execute(IngestDocument ingestDocument) throws Exception {
throw new UnsupportedOperationException();
}
@Override
public String getType() {
return "none-of-your-business";
}
};
Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor1));
SimulatePipelineRequest.Parsed request = new SimulatePipelineRequest.Parsed(pipeline, documents, false);
AtomicReference<SimulatePipelineResponse> responseHolder = new AtomicReference<>();
AtomicReference<Exception> errorHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
executionService.execute(request, ActionListener.wrap(response -> {
responseHolder.set(response);
latch.countDown();
}, e -> {
errorHolder.set(e);
latch.countDown();
}));
latch.await(1, TimeUnit.MINUTES);
assertThat(errorHolder.get(), nullValue());
SimulatePipelineResponse response = responseHolder.get();
assertThat(response, notNullValue());
assertThat(response.getResults().size(), equalTo(numDocs));
for (int id = 0; id < numDocs; id++) {
SimulateDocumentBaseResult result = (SimulateDocumentBaseResult) response.getResults().get(id);
assertThat(result.getIngestDocument().getMetadata().get(IngestDocument.Metadata.ID), equalTo(Integer.toString(id)));
assertThat(result.getIngestDocument().getSourceAndMetadata().get("processed"), is(true));
}
}
Aggregations