use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class TransportBulkActionIngestTests method testSingleItemBulkActionIngestSkipped.
public void testSingleItemBulkActionIngestSkipped() throws Exception {
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
indexRequest.source(Collections.emptyMap());
singleItemBulkWriteAction.execute(null, indexRequest, ActionListener.wrap(response -> {
}, exception -> {
throw new AssertionError(exception);
}));
assertTrue(action.isExecuted);
verifyZeroInteractions(ingestService);
}
use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class TransportBulkActionIngestTests method testIngestLocal.
public void testIngestLocal() throws Exception {
Exception exception = new Exception("fake exception");
BulkRequest bulkRequest = new BulkRequest();
IndexRequest indexRequest1 = new IndexRequest("index", "type", "id");
indexRequest1.source(Collections.emptyMap());
indexRequest1.setPipeline("testpipeline");
IndexRequest indexRequest2 = new IndexRequest("index", "type", "id");
indexRequest2.source(Collections.emptyMap());
indexRequest2.setPipeline("testpipeline");
bulkRequest.add(indexRequest1);
bulkRequest.add(indexRequest2);
AtomicBoolean responseCalled = new AtomicBoolean(false);
AtomicBoolean failureCalled = new AtomicBoolean(false);
action.execute(null, bulkRequest, ActionListener.wrap(response -> {
BulkItemResponse itemResponse = response.iterator().next();
assertThat(itemResponse.getFailure().getMessage(), containsString("fake exception"));
responseCalled.set(true);
}, e -> {
assertThat(e, sameInstance(exception));
failureCalled.set(true);
}));
// check failure works, and passes through to the listener
// haven't executed yet
assertFalse(action.isExecuted);
assertFalse(responseCalled.get());
assertFalse(failureCalled.get());
verify(executionService).executeBulkRequest(bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture());
completionHandler.getValue().accept(exception);
assertTrue(failureCalled.get());
// now check success
Iterator<DocWriteRequest> req = bulkDocsItr.getValue().iterator();
// have an exception for our one index request
failureHandler.getValue().accept((IndexRequest) req.next(), exception);
// this is done by the real pipeline execution service when processing
indexRequest2.setPipeline(null);
completionHandler.getValue().accept(null);
assertTrue(action.isExecuted);
// listener would only be called by real index action, not our mocked one
assertFalse(responseCalled.get());
verifyZeroInteractions(transportService);
}
use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class TransportBulkActionIngestTests method testIngestForward.
public void testIngestForward() throws Exception {
localIngest = false;
BulkRequest bulkRequest = new BulkRequest();
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
indexRequest.source(Collections.emptyMap());
indexRequest.setPipeline("testpipeline");
bulkRequest.add(indexRequest);
BulkResponse bulkResponse = mock(BulkResponse.class);
AtomicBoolean responseCalled = new AtomicBoolean(false);
ActionListener<BulkResponse> listener = ActionListener.wrap(response -> {
responseCalled.set(true);
assertSame(bulkResponse, response);
}, e -> {
throw new AssertionError(e);
});
action.execute(null, bulkRequest, listener);
// should not have executed ingest locally
verify(executionService, never()).executeBulkRequest(any(), any(), any());
// but instead should have sent to a remote node with the transport service
ArgumentCaptor<DiscoveryNode> node = ArgumentCaptor.forClass(DiscoveryNode.class);
verify(transportService).sendRequest(node.capture(), eq(BulkAction.NAME), any(), remoteResponseHandler.capture());
// make sure we used one of the nodes
boolean usedNode1 = node.getValue() == remoteNode1;
if (usedNode1 == false) {
assertSame(remoteNode2, node.getValue());
}
// no local index execution
assertFalse(action.isExecuted);
// listener not called yet
assertFalse(responseCalled.get());
// call the listener for the remote node
remoteResponseHandler.getValue().handleResponse(bulkResponse);
// now the listener we passed should have been delegated to by the remote listener
assertTrue(responseCalled.get());
// still no local index execution
assertFalse(action.isExecuted);
// now make sure ingest nodes are rotated through with a subsequent request
reset(transportService);
action.execute(null, bulkRequest, listener);
verify(transportService).sendRequest(node.capture(), eq(BulkAction.NAME), any(), remoteResponseHandler.capture());
if (usedNode1) {
assertSame(remoteNode2, node.getValue());
} else {
assertSame(remoteNode1, node.getValue());
}
}
use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class TransportBulkActionIngestTests method testIngestSkipped.
public void testIngestSkipped() throws Exception {
BulkRequest bulkRequest = new BulkRequest();
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
indexRequest.source(Collections.emptyMap());
bulkRequest.add(indexRequest);
action.execute(null, bulkRequest, ActionListener.wrap(response -> {
}, exception -> {
throw new AssertionError(exception);
}));
assertTrue(action.isExecuted);
verifyZeroInteractions(ingestService);
}
use of org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class TransportBulkActionIngestTests method testSingleItemBulkActionIngestForward.
public void testSingleItemBulkActionIngestForward() throws Exception {
localIngest = false;
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
indexRequest.source(Collections.emptyMap());
indexRequest.setPipeline("testpipeline");
IndexResponse indexResponse = mock(IndexResponse.class);
AtomicBoolean responseCalled = new AtomicBoolean(false);
ActionListener<IndexResponse> listener = ActionListener.wrap(response -> {
responseCalled.set(true);
assertSame(indexResponse, response);
}, e -> {
throw new AssertionError(e);
});
singleItemBulkWriteAction.execute(null, indexRequest, listener);
// should not have executed ingest locally
verify(executionService, never()).executeBulkRequest(any(), any(), any());
// but instead should have sent to a remote node with the transport service
ArgumentCaptor<DiscoveryNode> node = ArgumentCaptor.forClass(DiscoveryNode.class);
verify(transportService).sendRequest(node.capture(), eq(BulkAction.NAME), any(), remoteResponseHandler.capture());
// make sure we used one of the nodes
boolean usedNode1 = node.getValue() == remoteNode1;
if (usedNode1 == false) {
assertSame(remoteNode2, node.getValue());
}
// no local index execution
assertFalse(action.isExecuted);
// listener not called yet
assertFalse(responseCalled.get());
BulkItemResponse itemResponse = new BulkItemResponse(0, DocWriteRequest.OpType.CREATE, indexResponse);
BulkItemResponse[] bulkItemResponses = new BulkItemResponse[1];
bulkItemResponses[0] = itemResponse;
// call the listener for the remote node
remoteResponseHandler.getValue().handleResponse(new BulkResponse(bulkItemResponses, 0));
// now the listener we passed should have been delegated to by the remote listener
assertTrue(responseCalled.get());
// still no local index execution
assertFalse(action.isExecuted);
// now make sure ingest nodes are rotated through with a subsequent request
reset(transportService);
singleItemBulkWriteAction.execute(null, indexRequest, listener);
verify(transportService).sendRequest(node.capture(), eq(BulkAction.NAME), any(), remoteResponseHandler.capture());
if (usedNode1) {
assertSame(remoteNode2, node.getValue());
} else {
assertSame(remoteNode1, node.getValue());
}
}
Aggregations