Search in sources :

Example 6 with CloseIndexRequest

use of org.elasticsearch.action.admin.indices.close.CloseIndexRequest in project elasticsearch by elastic.

the class TransportReplicationActionTests method testClosedIndexOnReroute.

public void testClosedIndexOnReroute() throws InterruptedException {
    final String index = "test";
    // no replicas in oder to skip the replication part
    setState(clusterService, new ClusterStateChanges(xContentRegistry(), threadPool).closeIndices(state(index, true, ShardRoutingState.UNASSIGNED), new CloseIndexRequest(index)));
    logger.debug("--> using initial state:\n{}", clusterService.state());
    Request request = new Request(new ShardId("test", "_na_", 0)).timeout("1ms");
    PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
    ReplicationTask task = maybeTask();
    ClusterBlockLevel indexBlockLevel = randomBoolean() ? ClusterBlockLevel.WRITE : null;
    TestAction action = new TestAction(Settings.EMPTY, "testActionWithBlocks", transportService, clusterService, shardStateAction, threadPool) {

        @Override
        protected ClusterBlockLevel indexBlockLevel() {
            return indexBlockLevel;
        }
    };
    TestAction.ReroutePhase reroutePhase = action.new ReroutePhase(task, request, listener);
    reroutePhase.run();
    if (indexBlockLevel == ClusterBlockLevel.WRITE) {
        assertListenerThrows("must throw block exception", listener, ClusterBlockException.class);
    } else {
        assertListenerThrows("must throw index closed exception", listener, IndexClosedException.class);
    }
    assertPhase(task, "failed");
    assertFalse(request.isRetrySet.get());
}
Also used : TransportRequest(org.elasticsearch.transport.TransportRequest) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) ClusterStateChanges(org.elasticsearch.indices.cluster.ClusterStateChanges) ShardId(org.elasticsearch.index.shard.ShardId) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture)

Aggregations

CloseIndexRequest (org.elasticsearch.action.admin.indices.close.CloseIndexRequest)6 GetIndexRequest (org.elasticsearch.action.admin.indices.get.GetIndexRequest)2 Settings (org.elasticsearch.common.settings.Settings)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ClusterRerouteRequest (org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest)1 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)1 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)1 OpenIndexRequest (org.elasticsearch.action.admin.indices.open.OpenIndexRequest)1 UpdateSettingsRequest (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 ClusterBlockLevel (org.elasticsearch.cluster.block.ClusterBlockLevel)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)1 FailedShard (org.elasticsearch.cluster.routing.allocation.FailedShard)1