Search in sources :

Example 6 with PendingClusterStatesQueue

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue in project elasticsearch by elastic.

the class PendingClusterStatesQueueTests method testFailAllAndClear.

public void testFailAllAndClear() {
    List<ClusterState> states = randomStates(scaledRandomIntBetween(10, 50), "master1", "master2", "master3", "master4");
    PendingClusterStatesQueue queue = createQueueWithStates(states);
    List<ClusterStateContext> committedContexts = randomCommitStates(queue);
    queue.failAllStatesAndClear(new ElasticsearchException("boo!"));
    assertThat(queue.pendingStates, empty());
    assertThat(queue.getNextClusterStateToProcess(), nullValue());
    for (ClusterStateContext context : committedContexts) {
        assertThat("state was failed with wrong exception", ((MockListener) context.listener).failure, notNullValue());
        assertThat("state was failed with wrong exception", ((MockListener) context.listener).failure.getMessage(), containsString("boo"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PendingClusterStatesQueue(org.elasticsearch.discovery.zen.PendingClusterStatesQueue) ElasticsearchException(org.elasticsearch.ElasticsearchException) ClusterStateContext(org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext)

Example 7 with PendingClusterStatesQueue

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue in project elasticsearch by elastic.

the class PendingClusterStatesQueueTests method createQueueWithStates.

PendingClusterStatesQueue createQueueWithStates(List<ClusterState> states, int maxQueueSize) {
    PendingClusterStatesQueue queue;
    queue = new PendingClusterStatesQueue(logger, maxQueueSize);
    for (ClusterState state : states) {
        queue.addPending(state);
    }
    return queue;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PendingClusterStatesQueue(org.elasticsearch.discovery.zen.PendingClusterStatesQueue)

Example 8 with PendingClusterStatesQueue

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue in project elasticsearch by elastic.

the class PendingClusterStatesQueueTests method testDroppingStatesAtCapacity.

public void testDroppingStatesAtCapacity() {
    List<ClusterState> states = randomStates(scaledRandomIntBetween(10, 300), "master1", "master2", "master3", "master4");
    Collections.shuffle(states, random());
    // insert half of the states
    final int numberOfStateToDrop = states.size() / 2;
    List<ClusterState> stateToDrop = states.subList(0, numberOfStateToDrop);
    final int queueSize = states.size() - numberOfStateToDrop;
    PendingClusterStatesQueue queue = createQueueWithStates(stateToDrop, queueSize);
    List<ClusterStateContext> committedContexts = randomCommitStates(queue);
    for (ClusterState state : states.subList(numberOfStateToDrop, states.size())) {
        queue.addPending(state);
    }
    assertThat(queue.pendingClusterStates().length, equalTo(queueSize));
    // check all committed states got a failure due to the drop
    for (ClusterStateContext context : committedContexts) {
        assertThat(((MockListener) context.listener).failure, notNullValue());
    }
    // all states that should have dropped are indeed dropped.
    for (ClusterState state : stateToDrop) {
        assertThat(queue.findState(state.stateUUID()), nullValue());
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PendingClusterStatesQueue(org.elasticsearch.discovery.zen.PendingClusterStatesQueue) ClusterStateContext(org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext)

Aggregations

PendingClusterStatesQueue (org.elasticsearch.discovery.zen.PendingClusterStatesQueue)8 ClusterState (org.elasticsearch.cluster.ClusterState)7 ClusterStateContext (org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 HashMap (java.util.HashMap)1