Remove PipelineExecutionService#executeIndexRequest (#29537)
With the move long ago to execute all single-document indexing requests as bulk indexing request, the method PipelineExecutionService#executeIndexRequest is unused and will never be used in production code. This commit removes this method and cuts over all tests to use PipelineExecutionService#executeBulkRequest.
This commit is contained in:
parent
e334baf6fc
commit
a8d4ee1620
|
@ -53,23 +53,6 @@ public class PipelineExecutionService implements ClusterStateApplier {
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeIndexRequest(IndexRequest request, Consumer<Exception> failureHandler, Consumer<Boolean> completionHandler) {
|
|
||||||
Pipeline pipeline = getPipeline(request.getPipeline());
|
|
||||||
threadPool.executor(ThreadPool.Names.INDEX).execute(new AbstractRunnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(Exception e) {
|
|
||||||
failureHandler.accept(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doRun() throws Exception {
|
|
||||||
innerExecute(request, pipeline);
|
|
||||||
completionHandler.accept(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void executeBulkRequest(Iterable<DocWriteRequest> actionRequests,
|
public void executeBulkRequest(Iterable<DocWriteRequest> actionRequests,
|
||||||
BiConsumer<IndexRequest, Exception> itemFailureHandler,
|
BiConsumer<IndexRequest, Exception> itemFailureHandler,
|
||||||
Consumer<Exception> completionHandler) {
|
Consumer<Exception> completionHandler) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -48,9 +49,10 @@ import java.util.function.Consumer;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.hasKey;
|
import static org.hamcrest.Matchers.hasKey;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.Matchers.sameInstance;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyBoolean;
|
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.Matchers.argThat;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
@ -78,19 +80,23 @@ public class PipelineExecutionServiceTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteIndexPipelineDoesNotExist() {
|
public void testExecuteIndexPipelineDoesNotExist() {
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final SetOnce<Boolean> failure = new SetOnce<>();
|
||||||
@SuppressWarnings("unchecked")
|
final BiConsumer<IndexRequest, Exception> failureHandler = (request, e) -> {
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
failure.set(true);
|
||||||
try {
|
assertThat(request, sameInstance(indexRequest));
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
assertThat(e, instanceOf(IllegalArgumentException.class));
|
||||||
fail("IllegalArgumentException expected");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertThat(e.getMessage(), equalTo("pipeline with id [_id] does not exist"));
|
assertThat(e.getMessage(), equalTo("pipeline with id [_id] does not exist"));
|
||||||
}
|
};
|
||||||
verify(failureHandler, never()).accept(any(Exception.class));
|
|
||||||
verify(completionHandler, never()).accept(anyBoolean());
|
@SuppressWarnings("unchecked")
|
||||||
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
|
|
||||||
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
|
|
||||||
|
assertTrue(failure.get());
|
||||||
|
verify(completionHandler, times(1)).accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteIndexPipelineExistsButFailedParsing() {
|
public void testExecuteIndexPipelineExistsButFailedParsing() {
|
||||||
|
@ -106,17 +112,23 @@ public class PipelineExecutionServiceTests extends ESTestCase {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
SetOnce<Boolean> failed = new SetOnce<>();
|
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
final SetOnce<Boolean> failure = new SetOnce<>();
|
||||||
Consumer<Exception> failureHandler = (e) -> {
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
assertThat(e.getCause().getClass(), equalTo(IllegalArgumentException.class));
|
final BiConsumer<IndexRequest, Exception> failureHandler = (request, e) -> {
|
||||||
assertThat(e.getCause().getCause().getClass(), equalTo(IllegalStateException.class));
|
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
|
||||||
|
assertThat(e.getCause().getCause(), instanceOf(IllegalStateException.class));
|
||||||
assertThat(e.getCause().getCause().getMessage(), equalTo("error"));
|
assertThat(e.getCause().getCause().getMessage(), equalTo("error"));
|
||||||
failed.set(true);
|
failure.set(true);
|
||||||
};
|
};
|
||||||
Consumer<Boolean> completionHandler = (e) -> failed.set(false);
|
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
@SuppressWarnings("unchecked")
|
||||||
assertTrue(failed.get());
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
|
|
||||||
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
|
|
||||||
|
assertTrue(failure.get());
|
||||||
|
verify(completionHandler, times(1)).accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteBulkPipelineDoesNotExist() {
|
public void testExecuteBulkPipelineDoesNotExist() {
|
||||||
|
@ -152,41 +164,40 @@ public class PipelineExecutionServiceTests extends ESTestCase {
|
||||||
verify(completionHandler, times(1)).accept(null);
|
verify(completionHandler, times(1)).accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteSuccess() throws Exception {
|
public void testExecuteSuccess() {
|
||||||
CompoundProcessor processor = mock(CompoundProcessor.class);
|
final CompoundProcessor processor = mock(CompoundProcessor.class);
|
||||||
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
|
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
|
||||||
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
verify(failureHandler, never()).accept(any());
|
verify(failureHandler, never()).accept(any(), any());
|
||||||
verify(completionHandler, times(1)).accept(true);
|
verify(completionHandler, times(1)).accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteEmptyPipeline() throws Exception {
|
public void testExecuteEmptyPipeline() throws Exception {
|
||||||
CompoundProcessor processor = mock(CompoundProcessor.class);
|
final CompoundProcessor processor = mock(CompoundProcessor.class);
|
||||||
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
|
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
|
||||||
when(processor.getProcessors()).thenReturn(Collections.emptyList());
|
when(processor.getProcessors()).thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
verify(processor, never()).execute(any());
|
verify(processor, never()).execute(any());
|
||||||
verify(failureHandler, never()).accept(any());
|
verify(failureHandler, never()).accept(any(), any());
|
||||||
verify(completionHandler, times(1)).accept(true);
|
verify(completionHandler, times(1)).accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecutePropagateAllMetaDataUpdates() throws Exception {
|
public void testExecutePropagateAllMetaDataUpdates() throws Exception {
|
||||||
CompoundProcessor processor = mock(CompoundProcessor.class);
|
final CompoundProcessor processor = mock(CompoundProcessor.class);
|
||||||
when(processor.getProcessors()).thenReturn(Collections.singletonList(mock(Processor.class)));
|
when(processor.getProcessors()).thenReturn(Collections.singletonList(mock(Processor.class)));
|
||||||
long newVersion = randomLong();
|
final long newVersion = randomLong();
|
||||||
String versionType = randomFrom("internal", "external", "external_gt", "external_gte");
|
final String versionType = randomFrom("internal", "external", "external_gt", "external_gte");
|
||||||
doAnswer((InvocationOnMock invocationOnMock) -> {
|
doAnswer((InvocationOnMock invocationOnMock) -> {
|
||||||
IngestDocument ingestDocument = (IngestDocument) invocationOnMock.getArguments()[0];
|
IngestDocument ingestDocument = (IngestDocument) invocationOnMock.getArguments()[0];
|
||||||
for (IngestDocument.MetaData metaData : IngestDocument.MetaData.values()) {
|
for (IngestDocument.MetaData metaData : IngestDocument.MetaData.values()) {
|
||||||
|
@ -202,15 +213,15 @@ public class PipelineExecutionServiceTests extends ESTestCase {
|
||||||
}).when(processor).execute(any());
|
}).when(processor).execute(any());
|
||||||
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
|
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
|
||||||
|
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
verify(processor).execute(any());
|
verify(processor).execute(any());
|
||||||
verify(failureHandler, never()).accept(any());
|
verify(failureHandler, never()).accept(any(), any());
|
||||||
verify(completionHandler, times(1)).accept(true);
|
verify(completionHandler, times(1)).accept(null);
|
||||||
assertThat(indexRequest.index(), equalTo("update_index"));
|
assertThat(indexRequest.index(), equalTo("update_index"));
|
||||||
assertThat(indexRequest.type(), equalTo("update_type"));
|
assertThat(indexRequest.type(), equalTo("update_type"));
|
||||||
assertThat(indexRequest.id(), equalTo("update_id"));
|
assertThat(indexRequest.id(), equalTo("update_id"));
|
||||||
|
@ -220,89 +231,94 @@ public class PipelineExecutionServiceTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteFailure() throws Exception {
|
public void testExecuteFailure() throws Exception {
|
||||||
CompoundProcessor processor = mock(CompoundProcessor.class);
|
final CompoundProcessor processor = mock(CompoundProcessor.class);
|
||||||
when(processor.getProcessors()).thenReturn(Collections.singletonList(mock(Processor.class)));
|
when(processor.getProcessors()).thenReturn(Collections.singletonList(mock(Processor.class)));
|
||||||
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
|
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, processor));
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
doThrow(new RuntimeException()).when(processor).execute(eqID("_index", "_type", "_id",
|
doThrow(new RuntimeException())
|
||||||
indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
.when(processor)
|
||||||
|
.execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
verify(processor).execute(eqID("_index", "_type", "_id",
|
verify(processor).execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
verify(failureHandler, times(1)).accept(eq(indexRequest), any(RuntimeException.class));
|
||||||
verify(failureHandler, times(1)).accept(any(RuntimeException.class));
|
verify(completionHandler, times(1)).accept(null);
|
||||||
verify(completionHandler, never()).accept(anyBoolean());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteSuccessWithOnFailure() throws Exception {
|
public void testExecuteSuccessWithOnFailure() throws Exception {
|
||||||
Processor processor = mock(Processor.class);
|
final Processor processor = mock(Processor.class);
|
||||||
when(processor.getType()).thenReturn("mock_processor_type");
|
when(processor.getType()).thenReturn("mock_processor_type");
|
||||||
when(processor.getTag()).thenReturn("mock_processor_tag");
|
when(processor.getTag()).thenReturn("mock_processor_tag");
|
||||||
Processor onFailureProcessor = mock(Processor.class);
|
final Processor onFailureProcessor = mock(Processor.class);
|
||||||
CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.singletonList(processor),
|
final CompoundProcessor compoundProcessor = new CompoundProcessor(
|
||||||
Collections.singletonList(new CompoundProcessor(onFailureProcessor)));
|
false, Collections.singletonList(processor), Collections.singletonList(new CompoundProcessor(onFailureProcessor)));
|
||||||
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, compoundProcessor));
|
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, compoundProcessor));
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id")
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
.source(Collections.emptyMap()).setPipeline("_id");
|
doThrow(new RuntimeException()).when(processor).execute(eqIndexTypeId(Collections.emptyMap()));
|
||||||
doThrow(new RuntimeException()).when(processor).execute(eqID("_index", "_type", "_id", Collections.emptyMap()));
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
verify(failureHandler, never()).accept(any(ElasticsearchException.class));
|
verify(failureHandler, never()).accept(eq(indexRequest), any(ElasticsearchException.class));
|
||||||
verify(completionHandler, times(1)).accept(true);
|
verify(completionHandler, times(1)).accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteFailureWithOnFailure() throws Exception {
|
public void testExecuteFailureWithOnFailure() throws Exception {
|
||||||
Processor processor = mock(Processor.class);
|
final Processor processor = mock(Processor.class);
|
||||||
Processor onFailureProcessor = mock(Processor.class);
|
final Processor onFailureProcessor = mock(Processor.class);
|
||||||
CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.singletonList(processor),
|
final CompoundProcessor compoundProcessor = new CompoundProcessor(
|
||||||
Collections.singletonList(new CompoundProcessor(onFailureProcessor)));
|
false, Collections.singletonList(processor), Collections.singletonList(new CompoundProcessor(onFailureProcessor)));
|
||||||
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, compoundProcessor));
|
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, compoundProcessor));
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
doThrow(new RuntimeException()).when(processor).execute(eqID("_index", "_type", "_id",
|
doThrow(new RuntimeException())
|
||||||
indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
.when(processor)
|
||||||
doThrow(new RuntimeException()).when(onFailureProcessor).execute(eqID("_index", "_type", "_id", indexRequest.version(),
|
.execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
indexRequest.versionType(), Collections.emptyMap()));
|
doThrow(new RuntimeException())
|
||||||
|
.when(onFailureProcessor)
|
||||||
|
.execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
verify(processor).execute(eqID("_index", "_type", "_id",
|
verify(processor).execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
verify(failureHandler, times(1)).accept(eq(indexRequest), any(RuntimeException.class));
|
||||||
verify(failureHandler, times(1)).accept(any(RuntimeException.class));
|
verify(completionHandler, times(1)).accept(null);
|
||||||
verify(completionHandler, never()).accept(anyBoolean());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteFailureWithNestedOnFailure() throws Exception {
|
public void testExecuteFailureWithNestedOnFailure() throws Exception {
|
||||||
Processor processor = mock(Processor.class);
|
final Processor processor = mock(Processor.class);
|
||||||
Processor onFailureProcessor = mock(Processor.class);
|
final Processor onFailureProcessor = mock(Processor.class);
|
||||||
Processor onFailureOnFailureProcessor = mock(Processor.class);
|
final Processor onFailureOnFailureProcessor = mock(Processor.class);
|
||||||
CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.singletonList(processor),
|
final List<Processor> processors = Collections.singletonList(onFailureProcessor);
|
||||||
Collections.singletonList(new CompoundProcessor(false, Collections.singletonList(onFailureProcessor),
|
final List<Processor> onFailureProcessors = Collections.singletonList(onFailureOnFailureProcessor);
|
||||||
Collections.singletonList(onFailureOnFailureProcessor))));
|
final CompoundProcessor compoundProcessor = new CompoundProcessor(
|
||||||
|
false,
|
||||||
|
Collections.singletonList(processor),
|
||||||
|
Collections.singletonList(new CompoundProcessor(false, processors, onFailureProcessors)));
|
||||||
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, compoundProcessor));
|
when(store.get("_id")).thenReturn(new Pipeline("_id", "_description", version, compoundProcessor));
|
||||||
IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(Collections.emptyMap()).setPipeline("_id");
|
||||||
doThrow(new RuntimeException()).when(onFailureOnFailureProcessor).execute(eqID("_index", "_type", "_id",
|
doThrow(new RuntimeException())
|
||||||
indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
.when(onFailureOnFailureProcessor)
|
||||||
doThrow(new RuntimeException()).when(onFailureProcessor).execute(eqID("_index", "_type", "_id",
|
.execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
doThrow(new RuntimeException())
|
||||||
doThrow(new RuntimeException()).when(processor).execute(eqID("_index", "_type", "_id",
|
.when(onFailureProcessor)
|
||||||
indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
.execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
|
doThrow(new RuntimeException())
|
||||||
|
.when(processor)
|
||||||
|
.execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
verify(processor).execute(eqID("_index", "_type", "_id",
|
verify(processor).execute(eqIndexTypeId(indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
||||||
indexRequest.version(), indexRequest.versionType(), Collections.emptyMap()));
|
verify(failureHandler, times(1)).accept(eq(indexRequest), any(RuntimeException.class));
|
||||||
verify(failureHandler, times(1)).accept(any(RuntimeException.class));
|
verify(completionHandler, times(1)).accept(null);
|
||||||
verify(completionHandler, never()).accept(anyBoolean());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBulkRequestExecutionWithFailures() throws Exception {
|
public void testBulkRequestExecutionWithFailures() throws Exception {
|
||||||
|
@ -344,7 +360,7 @@ public class PipelineExecutionServiceTests extends ESTestCase {
|
||||||
verify(completionHandler, times(1)).accept(null);
|
verify(completionHandler, times(1)).accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBulkRequestExecution() throws Exception {
|
public void testBulkRequestExecution() {
|
||||||
BulkRequest bulkRequest = new BulkRequest();
|
BulkRequest bulkRequest = new BulkRequest();
|
||||||
String pipelineId = "_id";
|
String pipelineId = "_id";
|
||||||
|
|
||||||
|
@ -367,47 +383,47 @@ public class PipelineExecutionServiceTests extends ESTestCase {
|
||||||
verify(completionHandler, times(1)).accept(null);
|
verify(completionHandler, times(1)).accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStats() throws Exception {
|
public void testStats() {
|
||||||
IngestStats ingestStats = executionService.stats();
|
final IngestStats initialStats = executionService.stats();
|
||||||
assertThat(ingestStats.getStatsPerPipeline().size(), equalTo(0));
|
assertThat(initialStats.getStatsPerPipeline().size(), equalTo(0));
|
||||||
assertThat(ingestStats.getTotalStats().getIngestCount(), equalTo(0L));
|
assertThat(initialStats.getTotalStats().getIngestCount(), equalTo(0L));
|
||||||
assertThat(ingestStats.getTotalStats().getIngestCurrent(), equalTo(0L));
|
assertThat(initialStats.getTotalStats().getIngestCurrent(), equalTo(0L));
|
||||||
assertThat(ingestStats.getTotalStats().getIngestFailedCount(), equalTo(0L));
|
assertThat(initialStats.getTotalStats().getIngestFailedCount(), equalTo(0L));
|
||||||
assertThat(ingestStats.getTotalStats().getIngestTimeInMillis(), equalTo(0L));
|
assertThat(initialStats.getTotalStats().getIngestTimeInMillis(), equalTo(0L));
|
||||||
|
|
||||||
when(store.get("_id1")).thenReturn(new Pipeline("_id1", null, version, new CompoundProcessor(mock(Processor.class))));
|
when(store.get("_id1")).thenReturn(new Pipeline("_id1", null, version, new CompoundProcessor(mock(Processor.class))));
|
||||||
when(store.get("_id2")).thenReturn(new Pipeline("_id2", null, null, new CompoundProcessor(mock(Processor.class))));
|
when(store.get("_id2")).thenReturn(new Pipeline("_id2", null, null, new CompoundProcessor(mock(Processor.class))));
|
||||||
|
|
||||||
Map<String, PipelineConfiguration> configurationMap = new HashMap<>();
|
final Map<String, PipelineConfiguration> configurationMap = new HashMap<>();
|
||||||
configurationMap.put("_id1", new PipelineConfiguration("_id1", new BytesArray("{}"), XContentType.JSON));
|
configurationMap.put("_id1", new PipelineConfiguration("_id1", new BytesArray("{}"), XContentType.JSON));
|
||||||
configurationMap.put("_id2", new PipelineConfiguration("_id2", new BytesArray("{}"), XContentType.JSON));
|
configurationMap.put("_id2", new PipelineConfiguration("_id2", new BytesArray("{}"), XContentType.JSON));
|
||||||
executionService.updatePipelineStats(new IngestMetadata(configurationMap));
|
executionService.updatePipelineStats(new IngestMetadata(configurationMap));
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Exception> failureHandler = mock(Consumer.class);
|
final BiConsumer<IndexRequest, Exception> failureHandler = mock(BiConsumer.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Consumer<Boolean> completionHandler = mock(Consumer.class);
|
final Consumer<Exception> completionHandler = mock(Consumer.class);
|
||||||
|
|
||||||
IndexRequest indexRequest = new IndexRequest("_index");
|
final IndexRequest indexRequest = new IndexRequest("_index");
|
||||||
indexRequest.setPipeline("_id1");
|
indexRequest.setPipeline("_id1");
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
ingestStats = executionService.stats();
|
final IngestStats afterFirstRequestStats = executionService.stats();
|
||||||
assertThat(ingestStats.getStatsPerPipeline().size(), equalTo(2));
|
assertThat(afterFirstRequestStats.getStatsPerPipeline().size(), equalTo(2));
|
||||||
assertThat(ingestStats.getStatsPerPipeline().get("_id1").getIngestCount(), equalTo(1L));
|
assertThat(afterFirstRequestStats.getStatsPerPipeline().get("_id1").getIngestCount(), equalTo(1L));
|
||||||
assertThat(ingestStats.getStatsPerPipeline().get("_id2").getIngestCount(), equalTo(0L));
|
assertThat(afterFirstRequestStats.getStatsPerPipeline().get("_id2").getIngestCount(), equalTo(0L));
|
||||||
assertThat(ingestStats.getTotalStats().getIngestCount(), equalTo(1L));
|
assertThat(afterFirstRequestStats.getTotalStats().getIngestCount(), equalTo(1L));
|
||||||
|
|
||||||
indexRequest.setPipeline("_id2");
|
indexRequest.setPipeline("_id2");
|
||||||
executionService.executeIndexRequest(indexRequest, failureHandler, completionHandler);
|
executionService.executeBulkRequest(Collections.singletonList(indexRequest), failureHandler, completionHandler);
|
||||||
ingestStats = executionService.stats();
|
final IngestStats afterSecondRequestStats = executionService.stats();
|
||||||
assertThat(ingestStats.getStatsPerPipeline().size(), equalTo(2));
|
assertThat(afterSecondRequestStats.getStatsPerPipeline().size(), equalTo(2));
|
||||||
assertThat(ingestStats.getStatsPerPipeline().get("_id1").getIngestCount(), equalTo(1L));
|
assertThat(afterSecondRequestStats.getStatsPerPipeline().get("_id1").getIngestCount(), equalTo(1L));
|
||||||
assertThat(ingestStats.getStatsPerPipeline().get("_id2").getIngestCount(), equalTo(1L));
|
assertThat(afterSecondRequestStats.getStatsPerPipeline().get("_id2").getIngestCount(), equalTo(1L));
|
||||||
assertThat(ingestStats.getTotalStats().getIngestCount(), equalTo(2L));
|
assertThat(afterSecondRequestStats.getTotalStats().getIngestCount(), equalTo(2L));
|
||||||
}
|
}
|
||||||
|
|
||||||
// issue: https://github.com/elastic/elasticsearch/issues/18126
|
// issue: https://github.com/elastic/elasticsearch/issues/18126
|
||||||
public void testUpdatingStatsWhenRemovingPipelineWorks() throws Exception {
|
public void testUpdatingStatsWhenRemovingPipelineWorks() {
|
||||||
Map<String, PipelineConfiguration> configurationMap = new HashMap<>();
|
Map<String, PipelineConfiguration> configurationMap = new HashMap<>();
|
||||||
configurationMap.put("_id1", new PipelineConfiguration("_id1", new BytesArray("{}"), XContentType.JSON));
|
configurationMap.put("_id1", new PipelineConfiguration("_id1", new BytesArray("{}"), XContentType.JSON));
|
||||||
configurationMap.put("_id2", new PipelineConfiguration("_id2", new BytesArray("{}"), XContentType.JSON));
|
configurationMap.put("_id2", new PipelineConfiguration("_id2", new BytesArray("{}"), XContentType.JSON));
|
||||||
|
@ -422,12 +438,12 @@ public class PipelineExecutionServiceTests extends ESTestCase {
|
||||||
assertThat(executionService.stats().getStatsPerPipeline(), not(hasKey("_id2")));
|
assertThat(executionService.stats().getStatsPerPipeline(), not(hasKey("_id2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IngestDocument eqID(String index, String type, String id, Map<String, Object> source) {
|
private IngestDocument eqIndexTypeId(final Map<String, Object> source) {
|
||||||
return argThat(new IngestDocumentMatcher(index, type, id, source));
|
return argThat(new IngestDocumentMatcher("_index", "_type", "_id", source));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IngestDocument eqID(String index, String type, String id, Long version, VersionType versionType, Map<String, Object> source) {
|
private IngestDocument eqIndexTypeId(final Long version, final VersionType versionType, final Map<String, Object> source) {
|
||||||
return argThat(new IngestDocumentMatcher(index, type, id, version, versionType, source));
|
return argThat(new IngestDocumentMatcher("_index", "_type", "_id", version, versionType, source));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class IngestDocumentMatcher extends ArgumentMatcher<IngestDocument> {
|
private class IngestDocumentMatcher extends ArgumentMatcher<IngestDocument> {
|
||||||
|
|
Loading…
Reference in New Issue