Search in sources :

Example 1 with ClusterStateChanges

use of org.elasticsearch.indices.cluster.ClusterStateChanges 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)1 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)1 ClusterBlockLevel (org.elasticsearch.cluster.block.ClusterBlockLevel)1 ShardId (org.elasticsearch.index.shard.ShardId)1 ClusterStateChanges (org.elasticsearch.indices.cluster.ClusterStateChanges)1 TransportRequest (org.elasticsearch.transport.TransportRequest)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1