Search in sources :

Example 11 with LocalClusterUpdateTask

use of org.elasticsearch.cluster.LocalClusterUpdateTask in project crate by crate.

the class MasterServiceTests method testMasterAwareExecution.

public void testMasterAwareExecution() throws Exception {
    final MasterService nonMaster = createMasterService(false);
    final boolean[] taskFailed = { false };
    final CountDownLatch latch1 = new CountDownLatch(1);
    nonMaster.submitStateUpdateTask("test", new ClusterStateUpdateTask() {

        @Override
        public ClusterState execute(ClusterState currentState) {
            latch1.countDown();
            return currentState;
        }

        @Override
        public void onFailure(String source, Exception e) {
            taskFailed[0] = true;
            latch1.countDown();
        }
    });
    latch1.await();
    assertTrue("cluster state update task was executed on a non-master", taskFailed[0]);
    final CountDownLatch latch2 = new CountDownLatch(1);
    nonMaster.submitStateUpdateTask("test", new LocalClusterUpdateTask() {

        @Override
        public ClusterTasksResult<LocalClusterUpdateTask> execute(ClusterState currentState) {
            taskFailed[0] = false;
            latch2.countDown();
            return unchanged();
        }

        @Override
        public void onFailure(String source, Exception e) {
            taskFailed[0] = true;
            latch2.countDown();
        }
    });
    latch2.await();
    assertFalse("non-master cluster state update task was not executed", taskFailed[0]);
    nonMaster.close();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) LocalClusterUpdateTask(org.elasticsearch.cluster.LocalClusterUpdateTask) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) AckedClusterStateUpdateTask(org.elasticsearch.cluster.AckedClusterStateUpdateTask) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) ElasticsearchException(org.elasticsearch.ElasticsearchException) FailedToCommitClusterStateException(org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Aggregations

ClusterState (org.elasticsearch.cluster.ClusterState)11 LocalClusterUpdateTask (org.elasticsearch.cluster.LocalClusterUpdateTask)11 IOException (java.io.IOException)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 ExecutionException (java.util.concurrent.ExecutionException)5 NotMasterException (org.elasticsearch.cluster.NotMasterException)4 TransportException (org.elasticsearch.transport.TransportException)4 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)3 Supplier (org.apache.logging.log4j.util.Supplier)3 ClusterService (org.elasticsearch.cluster.service.ClusterService)3 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)2 ClusterStateUpdateTask (org.elasticsearch.cluster.ClusterStateUpdateTask)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)1 TransportClusterHealthAction (org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1