Search in sources :

Example 1 with ActionFilters

use of org.opensearch.action.support.ActionFilters in project OpenSearch by opensearch-project.

the class UpdateByQueryWithScriptTests method action.

@Override
protected TransportUpdateByQueryAction.AsyncIndexBySearchAction action(ScriptService scriptService, UpdateByQueryRequest request) {
    TransportService transportService = mock(TransportService.class);
    TransportUpdateByQueryAction transportAction = new TransportUpdateByQueryAction(threadPool, new ActionFilters(Collections.emptySet()), null, transportService, scriptService, null);
    return new TransportUpdateByQueryAction.AsyncIndexBySearchAction(task, logger, null, threadPool, scriptService, request, ClusterState.EMPTY_STATE, listener());
}
Also used : TransportService(org.opensearch.transport.TransportService) ActionFilters(org.opensearch.action.support.ActionFilters)

Example 2 with ActionFilters

use of org.opensearch.action.support.ActionFilters in project OpenSearch by opensearch-project.

the class RetentionLeaseBackgroundSyncActionTests method testBlocks.

public void testBlocks() {
    final IndicesService indicesService = mock(IndicesService.class);
    final Index index = new Index("index", "uuid");
    final IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
    final int id = randomIntBetween(0, 4);
    final IndexShard indexShard = mock(IndexShard.class);
    when(indexService.getShard(id)).thenReturn(indexShard);
    final ShardId shardId = new ShardId(index, id);
    when(indexShard.shardId()).thenReturn(shardId);
    final RetentionLeaseBackgroundSyncAction action = new RetentionLeaseBackgroundSyncAction(Settings.EMPTY, transportService, clusterService, indicesService, threadPool, shardStateAction, new ActionFilters(Collections.emptySet()));
    assertNull(action.indexBlockLevel());
}
Also used : ShardId(org.opensearch.index.shard.ShardId) IndexService(org.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) IndicesService(org.opensearch.indices.IndicesService) Index(org.opensearch.index.Index) ActionFilters(org.opensearch.action.support.ActionFilters)

Example 3 with ActionFilters

use of org.opensearch.action.support.ActionFilters in project OpenSearch by opensearch-project.

the class TransportMultiSearchActionTests method testParentTaskId.

public void testParentTaskId() throws Exception {
    // Initialize dependencies of TransportMultiSearchAction
    Settings settings = Settings.builder().put("node.name", TransportMultiSearchActionTests.class.getSimpleName()).build();
    ActionFilters actionFilters = mock(ActionFilters.class);
    when(actionFilters.filters()).thenReturn(new ActionFilter[0]);
    ThreadPool threadPool = new ThreadPool(settings);
    try {
        TransportService transportService = new TransportService(Settings.EMPTY, mock(Transport.class), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> DiscoveryNode.createLocal(settings, boundAddress.publishAddress(), UUIDs.randomBase64UUID()), null, Collections.emptySet()) {

            @Override
            public TaskManager getTaskManager() {
                return taskManager;
            }
        };
        ClusterService clusterService = mock(ClusterService.class);
        when(clusterService.state()).thenReturn(ClusterState.builder(new ClusterName("test")).build());
        String localNodeId = randomAlphaOfLengthBetween(3, 10);
        int numSearchRequests = randomIntBetween(1, 100);
        MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
        for (int i = 0; i < numSearchRequests; i++) {
            multiSearchRequest.add(new SearchRequest());
        }
        AtomicInteger counter = new AtomicInteger(0);
        Task task = multiSearchRequest.createTask(randomLong(), "type", "action", null, Collections.emptyMap());
        NodeClient client = new NodeClient(settings, threadPool) {

            @Override
            public void search(final SearchRequest request, final ActionListener<SearchResponse> listener) {
                assertEquals(task.getId(), request.getParentTask().getId());
                assertEquals(localNodeId, request.getParentTask().getNodeId());
                counter.incrementAndGet();
                listener.onResponse(SearchResponse.empty(() -> 1L, SearchResponse.Clusters.EMPTY));
            }

            @Override
            public String getLocalNodeId() {
                return localNodeId;
            }
        };
        TransportMultiSearchAction action = new TransportMultiSearchAction(threadPool, actionFilters, transportService, clusterService, 10, System::nanoTime, client);
        PlainActionFuture<MultiSearchResponse> future = newFuture();
        action.execute(task, multiSearchRequest, future);
        future.get();
        assertEquals(numSearchRequests, counter.get());
    } finally {
        assertTrue(OpenSearchTestCase.terminate(threadPool));
    }
}
Also used : Task(org.opensearch.tasks.Task) NodeClient(org.opensearch.client.node.NodeClient) ThreadPool(org.opensearch.threadpool.ThreadPool) ActionFilters(org.opensearch.action.support.ActionFilters) ClusterService(org.opensearch.cluster.service.ClusterService) ActionListener(org.opensearch.action.ActionListener) TransportService(org.opensearch.transport.TransportService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterName(org.opensearch.cluster.ClusterName) Transport(org.opensearch.transport.Transport) Settings(org.opensearch.common.settings.Settings)

Example 4 with ActionFilters

use of org.opensearch.action.support.ActionFilters in project OpenSearch by opensearch-project.

the class TransportBulkActionTookTests method createAction.

private TransportBulkAction createAction(boolean controlled, AtomicLong expected) {
    CapturingTransport capturingTransport = new CapturingTransport();
    TransportService transportService = capturingTransport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    IndexNameExpressionResolver resolver = new Resolver();
    ActionFilters actionFilters = new ActionFilters(new HashSet<>());
    NodeClient client = new NodeClient(Settings.EMPTY, threadPool) {

        @Override
        public <Request extends ActionRequest, Response extends ActionResponse> void doExecute(ActionType<Response> action, Request request, ActionListener<Response> listener) {
            listener.onResponse((Response) new CreateIndexResponse(false, false, null));
        }
    };
    if (controlled) {
        return new TestTransportBulkAction(threadPool, transportService, clusterService, null, client, actionFilters, resolver, null, expected::get) {

            @Override
            void executeBulk(Task task, BulkRequest bulkRequest, long startTimeNanos, ActionListener<BulkResponse> listener, AtomicArray<BulkItemResponse> responses, Map<String, IndexNotFoundException> indicesThatCannotBeCreated) {
                expected.set(1000000);
                super.executeBulk(task, bulkRequest, startTimeNanos, listener, responses, indicesThatCannotBeCreated);
            }
        };
    } else {
        return new TestTransportBulkAction(threadPool, transportService, clusterService, null, client, actionFilters, resolver, null, System::nanoTime) {

            @Override
            void executeBulk(Task task, BulkRequest bulkRequest, long startTimeNanos, ActionListener<BulkResponse> listener, AtomicArray<BulkItemResponse> responses, Map<String, IndexNotFoundException> indicesThatCannotBeCreated) {
                long elapsed = spinForAtLeastOneMillisecond();
                expected.set(elapsed);
                super.executeBulk(task, bulkRequest, startTimeNanos, listener, responses, indicesThatCannotBeCreated);
            }
        };
    }
}
Also used : NodeClient(org.opensearch.client.node.NodeClient) Task(org.opensearch.tasks.Task) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) ActionType(org.opensearch.action.ActionType) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) CapturingTransport(org.opensearch.test.transport.CapturingTransport) ActionRequest(org.opensearch.action.ActionRequest) IndicesRequest(org.opensearch.action.IndicesRequest) ActionFilters(org.opensearch.action.support.ActionFilters) ActionResponse(org.opensearch.action.ActionResponse) ActionListener(org.opensearch.action.ActionListener) TransportService(org.opensearch.transport.TransportService) ActionRequest(org.opensearch.action.ActionRequest) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 5 with ActionFilters

use of org.opensearch.action.support.ActionFilters in project OpenSearch by opensearch-project.

the class BroadcastReplicationTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    MockNioTransport transport = new MockNioTransport(Settings.EMPTY, Version.CURRENT, threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_RECYCLING_INSTANCE, new NamedWriteableRegistry(Collections.emptyList()), circuitBreakerService);
    clusterService = createClusterService(threadPool);
    transportService = new TransportService(clusterService.getSettings(), transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet());
    transportService.start();
    transportService.acceptIncomingRequests();
    broadcastReplicationAction = new TestBroadcastReplicationAction(clusterService, transportService, new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), null);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) Date(java.util.Date) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ConcurrentCollections(org.opensearch.common.util.concurrent.ConcurrentCollections) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) After(org.junit.After) ActionListener(org.opensearch.action.ActionListener) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) AfterClass(org.junit.AfterClass) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) Task(org.opensearch.tasks.Task) RestStatus(org.opensearch.rest.RestStatus) ClusterStateCreationUtils.state(org.opensearch.action.support.replication.ClusterStateCreationUtils.state) TransportService(org.opensearch.transport.TransportService) Tuple(org.opensearch.common.collect.Tuple) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) List(java.util.List) ActionTestUtils(org.opensearch.action.support.ActionTestUtils) Matchers.equalTo(org.hamcrest.Matchers.equalTo) BroadcastResponse(org.opensearch.action.support.broadcast.BroadcastResponse) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) FlushResponse(org.opensearch.action.admin.indices.flush.FlushResponse) BroadcastRequest(org.opensearch.action.support.broadcast.BroadcastRequest) BeforeClass(org.junit.BeforeClass) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) ThreadPool(org.opensearch.threadpool.ThreadPool) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) ClusterStateCreationUtils.stateWithAssignedPrimariesAndOneReplica(org.opensearch.action.support.replication.ClusterStateCreationUtils.stateWithAssignedPrimariesAndOneReplica) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) TransportFlushAction(org.opensearch.action.admin.indices.flush.TransportFlushAction) IOException(java.io.IOException) IOUtils(org.opensearch.core.internal.io.IOUtils) ShardId(org.opensearch.index.shard.ShardId) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ClusterStateCreationUtils.stateWithNoShard(org.opensearch.action.support.replication.ClusterStateCreationUtils.stateWithNoShard) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) ClusterService(org.opensearch.cluster.service.ClusterService) NetworkService(org.opensearch.common.network.NetworkService) NoShardAvailableActionException(org.opensearch.action.NoShardAvailableActionException) Collections(java.util.Collections) PageCacheRecycler(org.opensearch.common.util.PageCacheRecycler) TransportService(org.opensearch.transport.TransportService) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) NetworkService(org.opensearch.common.network.NetworkService) ActionFilters(org.opensearch.action.support.ActionFilters) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Before(org.junit.Before)

Aggregations

ActionFilters (org.opensearch.action.support.ActionFilters)30 TransportService (org.opensearch.transport.TransportService)18 ShardId (org.opensearch.index.shard.ShardId)17 ClusterService (org.opensearch.cluster.service.ClusterService)15 ActionListener (org.opensearch.action.ActionListener)14 Settings (org.opensearch.common.settings.Settings)13 Task (org.opensearch.tasks.Task)13 ThreadPool (org.opensearch.threadpool.ThreadPool)13 IndexNameExpressionResolver (org.opensearch.cluster.metadata.IndexNameExpressionResolver)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 NodeClient (org.opensearch.client.node.NodeClient)10 ClusterServiceUtils.createClusterService (org.opensearch.test.ClusterServiceUtils.createClusterService)10 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)10 TestThreadPool (org.opensearch.threadpool.TestThreadPool)10 ClusterState (org.opensearch.cluster.ClusterState)9 Index (org.opensearch.index.Index)9 IndicesService (org.opensearch.indices.IndicesService)9 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)8 Collections.emptyMap (java.util.Collections.emptyMap)7 BeforeClass (org.junit.BeforeClass)7