Search in sources :

Example 1 with ActionFilters

use of org.elasticsearch.action.support.ActionFilters in project elasticsearch by elastic.

the class GlobalCheckpointSyncActionTests method testTranslogSyncAfterGlobalCheckpointSync.

public void testTranslogSyncAfterGlobalCheckpointSync() throws Exception {
    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 Translog translog = mock(Translog.class);
    when(indexShard.getTranslog()).thenReturn(translog);
    final GlobalCheckpointSyncAction action = new GlobalCheckpointSyncAction(Settings.EMPTY, transportService, clusterService, indicesService, threadPool, shardStateAction, new ActionFilters(Collections.emptySet()), new IndexNameExpressionResolver(Settings.EMPTY));
    final ShardId shardId = new ShardId(index, id);
    final GlobalCheckpointSyncAction.PrimaryRequest primaryRequest = new GlobalCheckpointSyncAction.PrimaryRequest(shardId);
    if (randomBoolean()) {
        action.shardOperationOnPrimary(primaryRequest, indexShard);
    } else {
        action.shardOperationOnReplica(new GlobalCheckpointSyncAction.ReplicaRequest(primaryRequest, randomNonNegativeLong()), indexShard);
    }
    verify(translog).sync();
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) ActionFilters(org.elasticsearch.action.support.ActionFilters) Translog(org.elasticsearch.index.translog.Translog) ShardId(org.elasticsearch.index.shard.ShardId) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Example 2 with ActionFilters

use of org.elasticsearch.action.support.ActionFilters in project elasticsearch by elastic.

the class BroadcastReplicationTests method setUp.

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

Example 3 with ActionFilters

use of org.elasticsearch.action.support.ActionFilters in project elasticsearch by elastic.

the class TransportBroadcastByNodeActionTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    transport = new CapturingTransport();
    clusterService = createClusterService(THREAD_POOL);
    final TransportService transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    setClusterState(clusterService, TEST_INDEX);
    action = new TestTransportBroadcastByNodeAction(Settings.EMPTY, transportService, new ActionFilters(new HashSet<>()), new MyResolver(), Request::new, ThreadPool.Names.SAME);
}
Also used : TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ActionFilters(org.elasticsearch.action.support.ActionFilters) Before(org.junit.Before)

Example 4 with ActionFilters

use of org.elasticsearch.action.support.ActionFilters in project crate by crate.

the class RepositoryServiceTest method testRepositoryIsDroppedOnFailure.

@Test
public void testRepositoryIsDroppedOnFailure() throws Throwable {
    expectedException.expect(RepositoryException.class);
    // add repo to cluster service so that it exists..
    RepositoriesMetaData repos = new RepositoriesMetaData(new RepositoryMetaData("repo1", "fs", Settings.EMPTY));
    ClusterState state = ClusterState.builder(new ClusterName("dummy")).metaData(MetaData.builder().putCustom(RepositoriesMetaData.TYPE, repos)).build();
    ClusterService clusterService = new NoopClusterService(state);
    final ActionFilters actionFilters = mock(ActionFilters.class, Answers.RETURNS_MOCKS.get());
    IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
    final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
    TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {

        @Override
        protected void doExecute(Task task, DeleteRepositoryRequest request, ActionListener<DeleteRepositoryResponse> listener) {
            deleteRepoCalled.set(true);
            listener.onResponse(mock(DeleteRepositoryResponse.class));
        }
    };
    TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {

        @Override
        protected void doExecute(Task task, PutRepositoryRequest request, ActionListener<PutRepositoryResponse> listener) {
            listener.onFailure(new RepositoryException(request.name(), "failure"));
        }
    };
    RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
    try {
        repositoryService.execute(new CreateRepositoryAnalyzedStatement("repo1", "fs", Settings.EMPTY)).get(10, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        assertThat(deleteRepoCalled.get(), is(true));
        throw e.getCause();
    }
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) ClusterState(org.elasticsearch.cluster.ClusterState) Task(org.elasticsearch.tasks.Task) TransportDeleteRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction) DeleteRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) RepositoryException(org.elasticsearch.repositories.RepositoryException) ActionFilters(org.elasticsearch.action.support.ActionFilters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateRepositoryAnalyzedStatement(io.crate.analyze.CreateRepositoryAnalyzedStatement) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) DeleteRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportPutRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction) ExecutionException(java.util.concurrent.ExecutionException) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with ActionFilters

use of org.elasticsearch.action.support.ActionFilters in project elasticsearch by elastic.

the class TransportBulkActionTookTests method createAction.

private TransportBulkAction createAction(boolean controlled, AtomicLong expected) {
    CapturingTransport capturingTransport = new CapturingTransport();
    TransportService transportService = new TransportService(clusterService.getSettings(), capturingTransport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    IndexNameExpressionResolver resolver = new Resolver(Settings.EMPTY);
    ActionFilters actionFilters = new ActionFilters(new HashSet<>());
    TransportCreateIndexAction createIndexAction = new TransportCreateIndexAction(Settings.EMPTY, transportService, clusterService, threadPool, null, actionFilters, resolver);
    if (controlled) {
        return new TestTransportBulkAction(Settings.EMPTY, threadPool, transportService, clusterService, null, createIndexAction, actionFilters, resolver, null, expected::get) {

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

            @Override
            void executeBulk(Task task, BulkRequest bulkRequest, long startTimeNanos, ActionListener<BulkResponse> listener, AtomicArray<BulkItemResponse> responses) {
                long elapsed = spinForAtLeastOneMillisecond();
                expected.set(elapsed);
                super.executeBulk(task, bulkRequest, startTimeNanos, listener, responses);
            }
        };
    }
}
Also used : Task(org.elasticsearch.tasks.Task) AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ActionFilters(org.elasticsearch.action.support.ActionFilters) TransportCreateIndexAction(org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Aggregations

ActionFilters (org.elasticsearch.action.support.ActionFilters)12 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)8 TransportService (org.elasticsearch.transport.TransportService)8 ActionListener (org.elasticsearch.action.ActionListener)6 ExecutionException (java.util.concurrent.ExecutionException)5 ClusterState (org.elasticsearch.cluster.ClusterState)5 Settings (org.elasticsearch.common.settings.Settings)5 ClusterService (org.elasticsearch.cluster.service.ClusterService)4 ShardId (org.elasticsearch.index.shard.ShardId)4 ThreadPool (org.elasticsearch.threadpool.ThreadPool)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 TimeUnit (java.util.concurrent.TimeUnit)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)3 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)3 Collections (java.util.Collections)2 TimeoutException (java.util.concurrent.TimeoutException)2 ActionResponse (org.elasticsearch.action.ActionResponse)2 IndicesRequest (org.elasticsearch.action.IndicesRequest)2