Search in sources :

Example 6 with ClusterStateContext

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext 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

ClusterState (org.elasticsearch.cluster.ClusterState)6 PendingClusterStatesQueue (org.elasticsearch.discovery.zen.PendingClusterStatesQueue)6 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