Search in sources :

Example 11 with IngestService

use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.

the class TransportBulkActionIngestTests method testIngestSkipped.

public void testIngestSkipped() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    IndexRequest indexRequest = new IndexRequest("index").id("id");
    indexRequest.source(emptyMap());
    bulkRequest.add(indexRequest);
    action.execute(null, bulkRequest, ActionListener.wrap(response -> {
    }, exception -> {
        throw new AssertionError(exception);
    }));
    assertTrue(action.isExecuted);
    verifyNoInteractions(ingestService);
}
Also used : ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) IndexResponse(org.opensearch.action.index.IndexResponse) Version(org.opensearch.Version) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterStateApplier(org.opensearch.cluster.ClusterStateApplier) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ActionListener(org.opensearch.action.ActionListener) TimeValue(org.opensearch.common.unit.TimeValue) IndexingPressureService(org.opensearch.index.IndexingPressureService) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Settings(org.opensearch.common.settings.Settings) Task(org.opensearch.tasks.Task) TransportService(org.opensearch.transport.TransportService) Nullable(org.opensearch.common.Nullable) ActionFilters(org.opensearch.action.support.ActionFilters) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) IndexSettings(org.opensearch.index.IndexSettings) IndexAction(org.opensearch.action.index.IndexAction) UpdateRequest(org.opensearch.action.update.UpdateRequest) Mockito.any(org.mockito.Mockito.any) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) MapBuilder(org.opensearch.common.collect.MapBuilder) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) DocWriteRequest(org.opensearch.action.DocWriteRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Template(org.opensearch.cluster.metadata.Template) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) OpenSearchExecutors(org.opensearch.common.util.concurrent.OpenSearchExecutors) AutoCreateIndex(org.opensearch.action.support.AutoCreateIndex) ClusterState(org.opensearch.cluster.ClusterState) ArgumentCaptor(org.mockito.ArgumentCaptor) VersionUtils(org.opensearch.test.VersionUtils) BiConsumer(java.util.function.BiConsumer) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Mockito.anyString(org.mockito.Mockito.anyString) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) IngestService(org.opensearch.ingest.IngestService) Iterator(java.util.Iterator) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) SystemIndices(org.opensearch.indices.SystemIndices) Mockito.never(org.mockito.Mockito.never) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) Mockito.anyInt(org.mockito.Mockito.anyInt) IndexRequest(org.opensearch.action.index.IndexRequest) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ClusterChangedEvent(org.opensearch.cluster.ClusterChangedEvent) IndexRequest(org.opensearch.action.index.IndexRequest)

Example 12 with IngestService

use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.

the class TransportBulkActionIngestTests method testNotFindDefaultPipelineFromTemplateMatches.

public void testNotFindDefaultPipelineFromTemplateMatches() {
    Exception exception = new Exception("fake exception");
    IndexRequest indexRequest = new IndexRequest("missing_index").id("id");
    indexRequest.source(emptyMap());
    AtomicBoolean responseCalled = new AtomicBoolean(false);
    AtomicBoolean failureCalled = new AtomicBoolean(false);
    singleItemBulkWriteAction.execute(null, indexRequest, ActionListener.wrap(response -> responseCalled.set(true), e -> {
        assertThat(e, sameInstance(exception));
        failureCalled.set(true);
    }));
    assertEquals(IngestService.NOOP_PIPELINE_NAME, indexRequest.getPipeline());
    verifyNoInteractions(ingestService);
}
Also used : ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) IndexResponse(org.opensearch.action.index.IndexResponse) Version(org.opensearch.Version) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterStateApplier(org.opensearch.cluster.ClusterStateApplier) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ActionListener(org.opensearch.action.ActionListener) TimeValue(org.opensearch.common.unit.TimeValue) IndexingPressureService(org.opensearch.index.IndexingPressureService) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Settings(org.opensearch.common.settings.Settings) Task(org.opensearch.tasks.Task) TransportService(org.opensearch.transport.TransportService) Nullable(org.opensearch.common.Nullable) ActionFilters(org.opensearch.action.support.ActionFilters) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) IndexSettings(org.opensearch.index.IndexSettings) IndexAction(org.opensearch.action.index.IndexAction) UpdateRequest(org.opensearch.action.update.UpdateRequest) Mockito.any(org.mockito.Mockito.any) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) MapBuilder(org.opensearch.common.collect.MapBuilder) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) DocWriteRequest(org.opensearch.action.DocWriteRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Template(org.opensearch.cluster.metadata.Template) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) OpenSearchExecutors(org.opensearch.common.util.concurrent.OpenSearchExecutors) AutoCreateIndex(org.opensearch.action.support.AutoCreateIndex) ClusterState(org.opensearch.cluster.ClusterState) ArgumentCaptor(org.mockito.ArgumentCaptor) VersionUtils(org.opensearch.test.VersionUtils) BiConsumer(java.util.function.BiConsumer) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Mockito.anyString(org.mockito.Mockito.anyString) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) IngestService(org.opensearch.ingest.IngestService) Iterator(java.util.Iterator) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) SystemIndices(org.opensearch.indices.SystemIndices) Mockito.never(org.mockito.Mockito.never) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) Mockito.anyInt(org.mockito.Mockito.anyInt) IndexRequest(org.opensearch.action.index.IndexRequest) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ClusterChangedEvent(org.opensearch.cluster.ClusterChangedEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexRequest(org.opensearch.action.index.IndexRequest) IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 13 with IngestService

use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.

the class TransportBulkActionIngestTests method validateDefaultPipeline.

private void validateDefaultPipeline(IndexRequest indexRequest) {
    Exception exception = new Exception("fake exception");
    indexRequest.source(emptyMap());
    AtomicBoolean responseCalled = new AtomicBoolean(false);
    AtomicBoolean failureCalled = new AtomicBoolean(false);
    assertNull(indexRequest.getPipeline());
    singleItemBulkWriteAction.execute(null, indexRequest, ActionListener.wrap(response -> {
        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(ingestService).executeBulkRequest(eq(1), bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture(), any(), eq(Names.WRITE));
    assertEquals(indexRequest.getPipeline(), "default_pipeline");
    completionHandler.getValue().accept(null, exception);
    assertTrue(failureCalled.get());
    // now check success
    // this is done by the real pipeline execution service when processing
    indexRequest.setPipeline(IngestService.NOOP_PIPELINE_NAME);
    completionHandler.getValue().accept(DUMMY_WRITE_THREAD, null);
    assertTrue(action.isExecuted);
    // listener would only be called by real index action, not our mocked one
    assertFalse(responseCalled.get());
    verifyNoInteractions(transportService);
}
Also used : ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) IndexResponse(org.opensearch.action.index.IndexResponse) Version(org.opensearch.Version) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterStateApplier(org.opensearch.cluster.ClusterStateApplier) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ActionListener(org.opensearch.action.ActionListener) TimeValue(org.opensearch.common.unit.TimeValue) IndexingPressureService(org.opensearch.index.IndexingPressureService) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Settings(org.opensearch.common.settings.Settings) Task(org.opensearch.tasks.Task) TransportService(org.opensearch.transport.TransportService) Nullable(org.opensearch.common.Nullable) ActionFilters(org.opensearch.action.support.ActionFilters) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) IndexSettings(org.opensearch.index.IndexSettings) IndexAction(org.opensearch.action.index.IndexAction) UpdateRequest(org.opensearch.action.update.UpdateRequest) Mockito.any(org.mockito.Mockito.any) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) MapBuilder(org.opensearch.common.collect.MapBuilder) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) DocWriteRequest(org.opensearch.action.DocWriteRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Template(org.opensearch.cluster.metadata.Template) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) OpenSearchExecutors(org.opensearch.common.util.concurrent.OpenSearchExecutors) AutoCreateIndex(org.opensearch.action.support.AutoCreateIndex) ClusterState(org.opensearch.cluster.ClusterState) ArgumentCaptor(org.mockito.ArgumentCaptor) VersionUtils(org.opensearch.test.VersionUtils) BiConsumer(java.util.function.BiConsumer) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Mockito.anyString(org.mockito.Mockito.anyString) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) IngestService(org.opensearch.ingest.IngestService) Iterator(java.util.Iterator) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) SystemIndices(org.opensearch.indices.SystemIndices) Mockito.never(org.mockito.Mockito.never) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) Mockito.anyInt(org.mockito.Mockito.anyInt) IndexRequest(org.opensearch.action.index.IndexRequest) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ClusterChangedEvent(org.opensearch.cluster.ClusterChangedEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 14 with IngestService

use of org.opensearch.ingest.IngestService in project OpenSearch by opensearch-project.

the class SimulatePipelineRequestParsingTests method init.

@Before
public void init() throws IOException {
    TestProcessor processor = new TestProcessor(ingestDocument -> {
    });
    CompoundProcessor pipelineCompoundProcessor = new CompoundProcessor(processor);
    Pipeline pipeline = new Pipeline(SIMULATED_PIPELINE_ID, null, null, pipelineCompoundProcessor);
    Map<String, Processor.Factory> registry = Collections.singletonMap("mock_processor", (factories, tag, description, config) -> processor);
    ingestService = mock(IngestService.class);
    when(ingestService.getPipeline(SIMULATED_PIPELINE_ID)).thenReturn(pipeline);
    when(ingestService.getProcessorFactories()).thenReturn(registry);
}
Also used : IngestService(org.opensearch.ingest.IngestService) CompoundProcessor(org.opensearch.ingest.CompoundProcessor) TestProcessor(org.opensearch.ingest.TestProcessor) Matchers.containsString(org.hamcrest.Matchers.containsString) Pipeline(org.opensearch.ingest.Pipeline) Before(org.junit.Before)

Aggregations

IngestService (org.opensearch.ingest.IngestService)14 Matchers.containsString (org.hamcrest.Matchers.containsString)13 Before (org.junit.Before)13 ExecutorService (java.util.concurrent.ExecutorService)12 BiConsumer (java.util.function.BiConsumer)12 Mockito.anyString (org.mockito.Mockito.anyString)12 ClusterChangedEvent (org.opensearch.cluster.ClusterChangedEvent)12 ClusterState (org.opensearch.cluster.ClusterState)12 ClusterStateApplier (org.opensearch.cluster.ClusterStateApplier)12 AliasMetadata (org.opensearch.cluster.metadata.AliasMetadata)12 Arrays (java.util.Arrays)11 Collections (java.util.Collections)11 Collections.emptyMap (java.util.Collections.emptyMap)11 Iterator (java.util.Iterator)11 Map (java.util.Map)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)11 ArgumentCaptor (org.mockito.ArgumentCaptor)11 Mockito.any (org.mockito.Mockito.any)11 Mockito.anyInt (org.mockito.Mockito.anyInt)11