Search in sources :

Example 96 with TransportService

use of org.opensearch.transport.TransportService in project OpenSearch by opensearch-project.

the class TransportAddVotingConfigExclusionsActionTests method setupForTest.

@Before
public void setupForTest() {
    final MockTransport transport = new MockTransport();
    transportService = transport.createTransportService(Settings.EMPTY, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet());
    final Settings.Builder nodeSettingsBuilder = Settings.builder();
    if (randomBoolean()) {
        staticMaximum = between(5, 15);
        nodeSettingsBuilder.put(MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.getKey(), staticMaximum);
    } else {
        staticMaximum = MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.get(Settings.EMPTY);
    }
    final Settings nodeSettings = nodeSettingsBuilder.build();
    clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    new TransportAddVotingConfigExclusionsAction(nodeSettings, clusterSettings, transportService, clusterService, threadPool, new ActionFilters(emptySet()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)));
    // registers action
    transportService.start();
    transportService.acceptIncomingRequests();
    final VotingConfiguration allNodesConfig = VotingConfiguration.of(localNode, otherNode1, otherNode2);
    setState(clusterService, builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).add(otherDataNode).localNodeId(localNode.getId()).masterNodeId(localNode.getId())).metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().lastAcceptedConfiguration(allNodesConfig).lastCommittedConfiguration(allNodesConfig).build())));
    clusterStateObserver = new ClusterStateObserver(clusterService, null, logger, threadPool.getThreadContext());
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Strings(org.opensearch.common.Strings) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Collections.singleton(java.util.Collections.singleton) AfterClass(org.junit.AfterClass) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) TransportException(org.opensearch.transport.TransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) BeforeClass(org.junit.BeforeClass) ThreadPool(org.opensearch.threadpool.ThreadPool) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) MockTransport(org.opensearch.test.transport.MockTransport) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) SetOnce(org.apache.lucene.util.SetOnce) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) IOException(java.io.IOException) ClusterState.builder(org.opensearch.cluster.ClusterState.builder) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ActionFilters(org.opensearch.action.support.ActionFilters) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) MockTransport(org.opensearch.test.transport.MockTransport) ClusterName(org.opensearch.cluster.ClusterName) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before)

Example 97 with TransportService

use of org.opensearch.transport.TransportService in project OpenSearch by opensearch-project.

the class TransportBulkActionTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(getClass().getName());
    DiscoveryNode discoveryNode = new DiscoveryNode("node", OpenSearchTestCase.buildNewFakeTransportAddress(), emptyMap(), DiscoveryNodeRole.BUILT_IN_ROLES, VersionUtils.randomCompatibleVersion(random(), Version.CURRENT));
    clusterService = createClusterService(threadPool, discoveryNode);
    CapturingTransport capturingTransport = new CapturingTransport();
    transportService = capturingTransport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    bulkAction = new TestTransportBulkAction();
}
Also used : OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) Arrays(java.util.Arrays) IndexAbstraction(org.opensearch.cluster.metadata.IndexAbstraction) Resolver(org.opensearch.action.bulk.TransportBulkActionTookTests.Resolver) Metadata(org.opensearch.cluster.metadata.Metadata) DataStream(org.opensearch.cluster.metadata.DataStream) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) Collections.singletonList(java.util.Collections.singletonList) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) After(org.junit.After) ActionListener(org.opensearch.action.ActionListener) DeleteRequest(org.opensearch.action.delete.DeleteRequest) TimeValue(org.opensearch.common.unit.TimeValue) IndexingPressureService(org.opensearch.index.IndexingPressureService) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) ActionFilters(org.opensearch.action.support.ActionFilters) VersionType(org.opensearch.index.VersionType) List(java.util.List) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) SystemIndexDescriptor(org.opensearch.indices.SystemIndexDescriptor) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ResourceAlreadyExistsException(org.opensearch.ResourceAlreadyExistsException) UpdateRequest(org.opensearch.action.update.UpdateRequest) Matchers.is(org.hamcrest.Matchers.is) SortedMap(java.util.SortedMap) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) DocWriteRequest(org.opensearch.action.DocWriteRequest) Index(org.opensearch.cluster.metadata.IndexAbstraction.Index) AutoCreateIndex(org.opensearch.action.support.AutoCreateIndex) ClusterState(org.opensearch.cluster.ClusterState) VersionUtils(org.opensearch.test.VersionUtils) Collections.singletonMap(java.util.Collections.singletonMap) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) TransportBulkAction.prohibitCustomRoutingOnDataStream(org.opensearch.action.bulk.TransportBulkAction.prohibitCustomRoutingOnDataStream) TimeUnit(java.util.concurrent.TimeUnit) MetadataCreateDataStreamServiceTests.createDataStream(org.opensearch.cluster.metadata.MetadataCreateDataStreamServiceTests.createDataStream) SystemIndices(org.opensearch.indices.SystemIndices) TreeMap(java.util.TreeMap) ClusterService(org.opensearch.cluster.service.ClusterService) IndexRequest(org.opensearch.action.index.IndexRequest) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) CapturingTransport(org.opensearch.test.transport.CapturingTransport) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 98 with TransportService

use of org.opensearch.transport.TransportService in project OpenSearch by opensearch-project.

the class TransportBulkActionIngestTests method validatePipelineWithBulkUpsert.

private void validatePipelineWithBulkUpsert(@Nullable String indexRequestIndexName, String updateRequestIndexName) throws Exception {
    Exception exception = new Exception("fake exception");
    BulkRequest bulkRequest = new BulkRequest();
    IndexRequest indexRequest1 = new IndexRequest(indexRequestIndexName).id("id1").source(emptyMap());
    IndexRequest indexRequest2 = new IndexRequest(indexRequestIndexName).id("id2").source(emptyMap());
    IndexRequest indexRequest3 = new IndexRequest(indexRequestIndexName).id("id3").source(emptyMap());
    UpdateRequest upsertRequest = new UpdateRequest(updateRequestIndexName, "id1").upsert(indexRequest1).script(mockScript("1"));
    UpdateRequest docAsUpsertRequest = new UpdateRequest(updateRequestIndexName, "id2").doc(indexRequest2).docAsUpsert(true);
    // this test only covers the mechanics that scripted bulk upserts will execute a default pipeline. However, in practice scripted
    // bulk upserts with a default pipeline are a bit surprising since the script executes AFTER the pipeline.
    UpdateRequest scriptedUpsert = new UpdateRequest(updateRequestIndexName, "id2").upsert(indexRequest3).script(mockScript("1")).scriptedUpsert(true);
    bulkRequest.add(upsertRequest).add(docAsUpsertRequest).add(scriptedUpsert);
    AtomicBoolean responseCalled = new AtomicBoolean(false);
    AtomicBoolean failureCalled = new AtomicBoolean(false);
    assertNull(indexRequest1.getPipeline());
    assertNull(indexRequest2.getPipeline());
    assertNull(indexRequest3.getPipeline());
    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(ingestService).executeBulkRequest(eq(bulkRequest.numberOfActions()), bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture(), any(), eq(Names.WRITE));
    assertEquals(indexRequest1.getPipeline(), "default_pipeline");
    assertEquals(indexRequest2.getPipeline(), "default_pipeline");
    assertEquals(indexRequest3.getPipeline(), "default_pipeline");
    completionHandler.getValue().accept(null, exception);
    assertTrue(failureCalled.get());
    // now check success of the transport bulk action
    // this is done by the real pipeline execution service when processing
    indexRequest1.setPipeline(IngestService.NOOP_PIPELINE_NAME);
    // this is done by the real pipeline execution service when processing
    indexRequest2.setPipeline(IngestService.NOOP_PIPELINE_NAME);
    // this is done by the real pipeline execution service when processing
    indexRequest3.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) UpdateRequest(org.opensearch.action.update.UpdateRequest) IndexRequest(org.opensearch.action.index.IndexRequest) IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 99 with TransportService

use of org.opensearch.transport.TransportService 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 100 with TransportService

use of org.opensearch.transport.TransportService in project OpenSearch by opensearch-project.

the class TransportMultiGetActionTests method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    threadPool = new TestThreadPool(TransportMultiGetActionTests.class.getSimpleName());
    transportService = new TransportService(Settings.EMPTY, mock(Transport.class), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> DiscoveryNode.createLocal(Settings.builder().put("node.name", "node1").build(), boundAddress.publishAddress(), randomBase64UUID()), null, emptySet()) {

        @Override
        public TaskManager getTaskManager() {
            return taskManager;
        }
    };
    final Index index1 = new Index("index1", randomBase64UUID());
    final Index index2 = new Index("index2", randomBase64UUID());
    final ClusterState clusterState = ClusterState.builder(new ClusterName(TransportMultiGetActionTests.class.getSimpleName())).metadata(new Metadata.Builder().put(new IndexMetadata.Builder(index1.getName()).settings(Settings.builder().put("index.version.created", Version.CURRENT).put("index.number_of_shards", 1).put("index.number_of_replicas", 1).put(IndexMetadata.SETTING_INDEX_UUID, index1.getUUID())).putMapping("_doc", XContentHelper.convertToJson(BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("_routing").field("required", false).endObject().endObject().endObject()), true, XContentType.JSON))).put(new IndexMetadata.Builder(index2.getName()).settings(Settings.builder().put("index.version.created", Version.CURRENT).put("index.number_of_shards", 1).put("index.number_of_replicas", 1).put(IndexMetadata.SETTING_INDEX_UUID, index1.getUUID())).putMapping("_doc", XContentHelper.convertToJson(BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("_routing").field("required", true).endObject().endObject().endObject()), true, XContentType.JSON)))).build();
    final ShardIterator index1ShardIterator = mock(ShardIterator.class);
    when(index1ShardIterator.shardId()).thenReturn(new ShardId(index1, randomInt()));
    final ShardIterator index2ShardIterator = mock(ShardIterator.class);
    when(index2ShardIterator.shardId()).thenReturn(new ShardId(index2, randomInt()));
    final OperationRouting operationRouting = mock(OperationRouting.class);
    when(operationRouting.getShards(eq(clusterState), eq(index1.getName()), anyString(), nullable(String.class), nullable(String.class))).thenReturn(index1ShardIterator);
    when(operationRouting.shardId(eq(clusterState), eq(index1.getName()), nullable(String.class), nullable(String.class))).thenReturn(new ShardId(index1, randomInt()));
    when(operationRouting.getShards(eq(clusterState), eq(index2.getName()), anyString(), nullable(String.class), nullable(String.class))).thenReturn(index2ShardIterator);
    when(operationRouting.shardId(eq(clusterState), eq(index2.getName()), nullable(String.class), nullable(String.class))).thenReturn(new ShardId(index2, randomInt()));
    clusterService = mock(ClusterService.class);
    when(clusterService.localNode()).thenReturn(transportService.getLocalNode());
    when(clusterService.state()).thenReturn(clusterState);
    when(clusterService.operationRouting()).thenReturn(operationRouting);
    shardAction = new TransportShardMultiGetAction(clusterService, transportService, mock(IndicesService.class), threadPool, new ActionFilters(emptySet()), new Resolver()) {

        @Override
        protected void doExecute(Task task, MultiGetShardRequest request, ActionListener<MultiGetShardResponse> listener) {
        }
    };
}
Also used : Metadata(org.opensearch.cluster.metadata.Metadata) BytesReference(org.opensearch.common.bytes.BytesReference) BeforeClass(org.junit.BeforeClass) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ShardIterator(org.opensearch.cluster.routing.ShardIterator) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) ThreadPool(org.opensearch.threadpool.ThreadPool) RoutingMissingException(org.opensearch.action.RoutingMissingException) TestThreadPool(org.opensearch.threadpool.TestThreadPool) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Version(org.opensearch.Version) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Transport(org.opensearch.transport.Transport) IndicesRequest(org.opensearch.action.IndicesRequest) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Map(java.util.Map) XContentFactory(org.opensearch.common.xcontent.XContentFactory) ActionListener(org.opensearch.action.ActionListener) Mockito.anyString(org.mockito.Mockito.anyString) Collections.emptyMap(java.util.Collections.emptyMap) AfterClass(org.junit.AfterClass) NodeClient(org.opensearch.client.node.NodeClient) Collections.emptySet(java.util.Collections.emptySet) Index(org.opensearch.index.Index) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) IndicesService(org.opensearch.indices.IndicesService) TaskId(org.opensearch.tasks.TaskId) Settings(org.opensearch.common.settings.Settings) Task(org.opensearch.tasks.Task) Mockito.when(org.mockito.Mockito.when) TransportService(org.opensearch.transport.TransportService) TaskManager(org.opensearch.tasks.TaskManager) XContentHelper(org.opensearch.common.xcontent.XContentHelper) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) OperationRouting(org.opensearch.cluster.routing.OperationRouting) UUIDs.randomBase64UUID(org.opensearch.common.UUIDs.randomBase64UUID) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) XContentType(org.opensearch.common.xcontent.XContentType) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) ClusterState(org.opensearch.cluster.ClusterState) Task(org.opensearch.tasks.Task) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Index(org.opensearch.index.Index) Mockito.anyString(org.mockito.Mockito.anyString) ActionFilters(org.opensearch.action.support.ActionFilters) TestThreadPool(org.opensearch.threadpool.TestThreadPool) ShardId(org.opensearch.index.shard.ShardId) TaskManager(org.opensearch.tasks.TaskManager) ClusterService(org.opensearch.cluster.service.ClusterService) TransportService(org.opensearch.transport.TransportService) OperationRouting(org.opensearch.cluster.routing.OperationRouting) ShardIterator(org.opensearch.cluster.routing.ShardIterator) ClusterName(org.opensearch.cluster.ClusterName) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) BeforeClass(org.junit.BeforeClass)

Aggregations

TransportService (org.opensearch.transport.TransportService)163 Settings (org.opensearch.common.settings.Settings)88 ClusterService (org.opensearch.cluster.service.ClusterService)85 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)82 ActionFilters (org.opensearch.action.support.ActionFilters)69 ActionListener (org.opensearch.action.ActionListener)68 ThreadPool (org.opensearch.threadpool.ThreadPool)67 IOException (java.io.IOException)47 Version (org.opensearch.Version)47 ClusterState (org.opensearch.cluster.ClusterState)46 ArrayList (java.util.ArrayList)44 Collections (java.util.Collections)41 Before (org.junit.Before)41 List (java.util.List)39 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)39 TimeValue (org.opensearch.common.unit.TimeValue)38 Map (java.util.Map)37 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)37 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)35 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)35