/** * Note, this test can only work as long as we have a single thread executor executing the state * update tasks! */ public void testPrioritizedTasks() throws Exception { BlockingTask block = new BlockingTask(Priority.IMMEDIATE); clusterService.submitStateUpdateTask("test", block); int taskCount = randomIntBetween(5, 20); // will hold all the tasks in the order in which they were executed List<PrioritizedTask> tasks = new ArrayList<>(taskCount); CountDownLatch latch = new CountDownLatch(taskCount); for (int i = 0; i < taskCount; i++) { Priority priority = randomFrom(Priority.values()); clusterService.submitStateUpdateTask("test", new PrioritizedTask(priority, latch, tasks)); } block.close(); latch.await(); Priority prevPriority = null; for (PrioritizedTask task : tasks) { if (prevPriority == null) { prevPriority = task.priority(); } else { assertThat(task.priority().sameOrAfter(prevPriority), is(true)); } } }