Search in sources :

Example 11 with ActionFilters

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

the class TransportInstanceSingleOperationActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    transport = new CapturingTransport();
    clusterService = createClusterService(THREAD_POOL);
    transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    action = new TestTransportInstanceSingleOperationAction(Settings.EMPTY, "indices:admin/test", transportService, new ActionFilters(new HashSet<ActionFilter>()), new MyResolver(), Request::new);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) BeforeClass(org.junit.BeforeClass) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) ClusterService(org.elasticsearch.cluster.service.ClusterService) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) IndicesRequest(org.elasticsearch.action.IndicesRequest) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) Supplier(java.util.function.Supplier) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) TimeValue(org.elasticsearch.common.unit.TimeValue) After(org.junit.After) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) ClusterStateCreationUtils(org.elasticsearch.action.support.replication.ClusterStateCreationUtils) Before(org.junit.Before) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) AfterClass(org.junit.AfterClass) ActionFilter(org.elasticsearch.action.support.ActionFilter) ActionFilters(org.elasticsearch.action.support.ActionFilters) ActionResponse(org.elasticsearch.action.ActionResponse) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ExceptionsHelper(org.elasticsearch.ExceptionsHelper) RestStatus(org.elasticsearch.rest.RestStatus) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportException(org.elasticsearch.transport.TransportException) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ActionFilters(org.elasticsearch.action.support.ActionFilters) ActionFilter(org.elasticsearch.action.support.ActionFilter) Before(org.junit.Before)

Example 12 with ActionFilters

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

the class TransportInstanceSingleOperationActionTests method testUnresolvableRequestDoesNotHang.

public void testUnresolvableRequestDoesNotHang() throws InterruptedException, ExecutionException, TimeoutException {
    action = new TestTransportInstanceSingleOperationAction(Settings.EMPTY, "indices:admin/test_unresolvable", transportService, new ActionFilters(new HashSet<>()), new MyResolver(), Request::new) {

        @Override
        protected void resolveRequest(ClusterState state, Request request) {
            throw new IllegalStateException("request cannot be resolved");
        }
    };
    Request request = new Request().index("test");
    request.shardId = new ShardId("test", "_na_", 0);
    PlainActionFuture<Response> listener = new PlainActionFuture<>();
    setState(clusterService, ClusterStateCreationUtils.state("test", randomBoolean(), ShardRoutingState.STARTED));
    action.new AsyncSingleAction(request, listener).start();
    assertThat(transport.capturedRequests().length, equalTo(0));
    try {
        listener.get();
    } catch (Exception e) {
        if (ExceptionsHelper.unwrap(e, IllegalStateException.class) == null) {
            logger.info("expected IllegalStateException  but got ", e);
            fail("expected and IllegalStateException");
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndicesRequest(org.elasticsearch.action.IndicesRequest) ActionFilters(org.elasticsearch.action.support.ActionFilters) TimeoutException(java.util.concurrent.TimeoutException) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ExecutionException(java.util.concurrent.ExecutionException) TransportException(org.elasticsearch.transport.TransportException) ShardId(org.elasticsearch.index.shard.ShardId) ActionResponse(org.elasticsearch.action.ActionResponse) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture)

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