Search in sources :

Example 1 with IngestService

use of org.elasticsearch.ingest.IngestService in project elasticsearch by elastic.

the class TransportBulkActionIngestTests method setupAction.

@Before
public void setupAction() {
    // initialize captors, which must be members to use @Capture because of generics
    MockitoAnnotations.initMocks(this);
    // setup services that will be called by action
    transportService = mock(TransportService.class);
    clusterService = mock(ClusterService.class);
    localIngest = true;
    // setup nodes for local and remote
    DiscoveryNode localNode = mock(DiscoveryNode.class);
    when(localNode.isIngestNode()).thenAnswer(stub -> localIngest);
    when(clusterService.localNode()).thenReturn(localNode);
    remoteNode1 = mock(DiscoveryNode.class);
    remoteNode2 = mock(DiscoveryNode.class);
    nodes = mock(DiscoveryNodes.class);
    ImmutableOpenMap<String, DiscoveryNode> ingestNodes = ImmutableOpenMap.<String, DiscoveryNode>builder(2).fPut("node1", remoteNode1).fPut("node2", remoteNode2).build();
    when(nodes.getIngestNodes()).thenReturn(ingestNodes);
    ClusterState state = mock(ClusterState.class);
    when(state.getNodes()).thenReturn(nodes);
    when(clusterService.state()).thenReturn(state);
    doAnswer(invocation -> {
        ClusterChangedEvent event = mock(ClusterChangedEvent.class);
        when(event.state()).thenReturn(state);
        ((ClusterStateApplier) invocation.getArguments()[0]).applyClusterState(event);
        return null;
    }).when(clusterService).addStateApplier(any(ClusterStateApplier.class));
    // setup the mocked ingest service for capturing calls
    ingestService = mock(IngestService.class);
    executionService = mock(PipelineExecutionService.class);
    when(ingestService.getPipelineExecutionService()).thenReturn(executionService);
    action = new TestTransportBulkAction();
    singleItemBulkWriteAction = new TestSingleItemBulkWriteAction(action);
    // call on construction of action
    reset(transportService);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IngestService(org.elasticsearch.ingest.IngestService) PipelineExecutionService(org.elasticsearch.ingest.PipelineExecutionService) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterService(org.elasticsearch.cluster.service.ClusterService) TransportService(org.elasticsearch.transport.TransportService) ClusterStateApplier(org.elasticsearch.cluster.ClusterStateApplier) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Before(org.junit.Before)

Example 2 with IngestService

use of org.elasticsearch.ingest.IngestService 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);
}
Also used : IngestService(org.elasticsearch.ingest.IngestService) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) PipelineExecutionService(org.elasticsearch.ingest.PipelineExecutionService) ClusterService(org.elasticsearch.cluster.service.ClusterService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Captor(org.mockito.Captor) Supplier(java.util.function.Supplier) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) MockitoAnnotations(org.mockito.MockitoAnnotations) IndexRequest(org.elasticsearch.action.index.IndexRequest) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) BiConsumer(java.util.function.BiConsumer) IndexResponse(org.elasticsearch.action.index.IndexResponse) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IndicesService(org.elasticsearch.indices.IndicesService) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) ClusterStateApplier(org.elasticsearch.cluster.ClusterStateApplier) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) ActionFilters(org.elasticsearch.action.support.ActionFilters) Iterator(java.util.Iterator) AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) Mockito.when(org.mockito.Mockito.when) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Matchers.any(org.mockito.Matchers.any) IndexAction(org.elasticsearch.action.index.IndexAction) Mockito.never(org.mockito.Mockito.never) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Task(org.elasticsearch.tasks.Task) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.reset(org.mockito.Mockito.reset) ActionListener(org.elasticsearch.action.ActionListener) Mockito.mock(org.mockito.Mockito.mock) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 3 with IngestService

use of org.elasticsearch.ingest.IngestService 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);
}
Also used : IngestService(org.elasticsearch.ingest.IngestService) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) PipelineExecutionService(org.elasticsearch.ingest.PipelineExecutionService) ClusterService(org.elasticsearch.cluster.service.ClusterService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Captor(org.mockito.Captor) Supplier(java.util.function.Supplier) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) MockitoAnnotations(org.mockito.MockitoAnnotations) IndexRequest(org.elasticsearch.action.index.IndexRequest) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) BiConsumer(java.util.function.BiConsumer) IndexResponse(org.elasticsearch.action.index.IndexResponse) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IndicesService(org.elasticsearch.indices.IndicesService) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) ClusterStateApplier(org.elasticsearch.cluster.ClusterStateApplier) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) ActionFilters(org.elasticsearch.action.support.ActionFilters) Iterator(java.util.Iterator) AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) Mockito.when(org.mockito.Mockito.when) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Matchers.any(org.mockito.Matchers.any) IndexAction(org.elasticsearch.action.index.IndexAction) Mockito.never(org.mockito.Mockito.never) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Task(org.elasticsearch.tasks.Task) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.reset(org.mockito.Mockito.reset) ActionListener(org.elasticsearch.action.ActionListener) Mockito.mock(org.mockito.Mockito.mock) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Aggregations

ClusterChangedEvent (org.elasticsearch.cluster.ClusterChangedEvent)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 ClusterStateApplier (org.elasticsearch.cluster.ClusterStateApplier)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)3 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)3 ClusterService (org.elasticsearch.cluster.service.ClusterService)3 IngestService (org.elasticsearch.ingest.IngestService)3 PipelineExecutionService (org.elasticsearch.ingest.PipelineExecutionService)3 TransportService (org.elasticsearch.transport.TransportService)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Before (org.junit.Before)3 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 BiConsumer (java.util.function.BiConsumer)2 Consumer (java.util.function.Consumer)2 Supplier (java.util.function.Supplier)2 ActionListener (org.elasticsearch.action.ActionListener)2 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)2 IndexAction (org.elasticsearch.action.index.IndexAction)2