|
|
@@ -222,11 +222,11 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
ClusterStateTaskConfig.build(Priority.NORMAL),
|
|
|
new ClusterStateTaskExecutor<>() {
|
|
|
@Override
|
|
|
- public ClusterState execute(ClusterState currentState, List<TaskContext<ExpectSuccessTask>> taskContexts) {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ public ClusterState execute(BatchExecutionContext<ExpectSuccessTask> batchExecutionContext) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(() -> {});
|
|
|
}
|
|
|
- return ClusterState.builder(currentState).build();
|
|
|
+ return ClusterState.builder(batchExecutionContext.initialState()).build();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -341,11 +341,11 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
ClusterStateTaskConfig.build(Priority.NORMAL),
|
|
|
new ClusterStateTaskExecutor<>() {
|
|
|
@Override
|
|
|
- public ClusterState execute(ClusterState currentState, List<TaskContext<ExpectSuccessTask>> taskContexts) {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ public ClusterState execute(BatchExecutionContext<ExpectSuccessTask> batchExecutionContext) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(() -> { throw new RuntimeException("testing exception handling"); });
|
|
|
}
|
|
|
- return ClusterState.builder(currentState).build();
|
|
|
+ return ClusterState.builder(batchExecutionContext.initialState()).build();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -542,14 +542,14 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ClusterState execute(ClusterState currentState, List<TaskContext<ExpectSuccessTask>> taskContexts) {
|
|
|
+ public ClusterState execute(BatchExecutionContext<ExpectSuccessTask> batchExecutionContext) {
|
|
|
assertTrue("Should execute all tasks at once", executed.compareAndSet(false, true));
|
|
|
- assertThat("Should execute all tasks at once", taskContexts.size(), equalTo(expectedTaskCount));
|
|
|
+ assertThat("Should execute all tasks at once", batchExecutionContext.taskContexts().size(), equalTo(expectedTaskCount));
|
|
|
executionCountDown.countDown();
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(() -> {});
|
|
|
}
|
|
|
- return currentState;
|
|
|
+ return batchExecutionContext.initialState();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -566,13 +566,13 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
"block",
|
|
|
new ExpectSuccessTask(),
|
|
|
ClusterStateTaskConfig.build(Priority.NORMAL),
|
|
|
- (currentState, taskContexts) -> {
|
|
|
+ batchExecutionContext -> {
|
|
|
executionBarrier.await(10, TimeUnit.SECONDS); // notify test thread that the master service is blocked
|
|
|
executionBarrier.await(10, TimeUnit.SECONDS); // wait for test thread to release us
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(() -> {});
|
|
|
}
|
|
|
- return currentState;
|
|
|
+ return batchExecutionContext.initialState();
|
|
|
}
|
|
|
);
|
|
|
|
|
|
@@ -707,19 +707,19 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
private final List<Task> assignments = new ArrayList<>();
|
|
|
|
|
|
@Override
|
|
|
- public ClusterState execute(ClusterState currentState, List<TaskContext<Task>> taskContexts) {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ public ClusterState execute(BatchExecutionContext<Task> batchExecutionContext) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
assertThat("All tasks should belong to this executor", assignments, hasItem(taskContext.getTask()));
|
|
|
}
|
|
|
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.getTask().execute();
|
|
|
}
|
|
|
|
|
|
- executed.addAndGet(taskContexts.size());
|
|
|
- ClusterState maybeUpdatedClusterState = currentState;
|
|
|
+ executed.addAndGet(batchExecutionContext.taskContexts().size());
|
|
|
+ ClusterState maybeUpdatedClusterState = batchExecutionContext.initialState();
|
|
|
if (randomBoolean()) {
|
|
|
- maybeUpdatedClusterState = ClusterState.builder(currentState).build();
|
|
|
+ maybeUpdatedClusterState = ClusterState.builder(batchExecutionContext.initialState()).build();
|
|
|
batches.incrementAndGet();
|
|
|
assertThat(
|
|
|
"All cluster state modifications should be executed on a single thread",
|
|
|
@@ -728,7 +728,7 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(() -> {
|
|
|
processedStates.incrementAndGet();
|
|
|
processedStatesLatch.get().countDown();
|
|
|
@@ -845,14 +845,14 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- final ClusterStateTaskExecutor<Task> executor = (currentState, taskContexts) -> {
|
|
|
+ final ClusterStateTaskExecutor<Task> executor = batchExecutionContext -> {
|
|
|
if (randomBoolean()) {
|
|
|
throw new RuntimeException("simulated");
|
|
|
} else {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.onFailure(new RuntimeException("simulated"));
|
|
|
}
|
|
|
- return currentState;
|
|
|
+ return batchExecutionContext.initialState();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -924,11 +924,11 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
final var executor = new ClusterStateTaskExecutor<Task>() {
|
|
|
@Override
|
|
|
@SuppressForbidden(reason = "consuming published cluster state for legacy reasons")
|
|
|
- public ClusterState execute(ClusterState currentState, List<TaskContext<Task>> taskContexts) {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ public ClusterState execute(BatchExecutionContext<Task> batchExecutionContext) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(taskContext.getTask().publishListener::onResponse);
|
|
|
}
|
|
|
- return ClusterState.builder(currentState).build();
|
|
|
+ return ClusterState.builder(batchExecutionContext.initialState()).build();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -1043,8 +1043,8 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
"testBlockingCallInClusterStateTaskListenerFails",
|
|
|
new ExpectSuccessTask(),
|
|
|
ClusterStateTaskConfig.build(Priority.NORMAL),
|
|
|
- (currentState, taskContexts) -> {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ batchExecutionContext -> {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(() -> {
|
|
|
BaseFuture<Void> future = new BaseFuture<Void>() {
|
|
|
};
|
|
|
@@ -1062,7 +1062,7 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- return ClusterState.builder(currentState).build();
|
|
|
+ return ClusterState.builder(batchExecutionContext.initialState()).build();
|
|
|
}
|
|
|
);
|
|
|
|
|
|
@@ -1399,11 +1399,13 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
"success-test",
|
|
|
new Task(),
|
|
|
ClusterStateTaskConfig.build(Priority.NORMAL),
|
|
|
- (currentState, taskContexts) -> {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ batchExecutionContext -> {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(latch::countDown, taskContext.getTask());
|
|
|
}
|
|
|
- return randomBoolean() ? currentState : ClusterState.builder(currentState).build();
|
|
|
+ return randomBoolean()
|
|
|
+ ? batchExecutionContext.initialState()
|
|
|
+ : ClusterState.builder(batchExecutionContext.initialState()).build();
|
|
|
}
|
|
|
);
|
|
|
|
|
|
@@ -1439,11 +1441,13 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
"success-test",
|
|
|
new Task(),
|
|
|
ClusterStateTaskConfig.build(Priority.NORMAL),
|
|
|
- (currentState, taskContexts) -> {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ batchExecutionContext -> {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(latch::countDown, new LatchAckListener(latch));
|
|
|
}
|
|
|
- return randomBoolean() ? currentState : ClusterState.builder(currentState).build();
|
|
|
+ return randomBoolean()
|
|
|
+ ? batchExecutionContext.initialState()
|
|
|
+ : ClusterState.builder(batchExecutionContext.initialState()).build();
|
|
|
}
|
|
|
);
|
|
|
|
|
|
@@ -1479,11 +1483,13 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
"success-test",
|
|
|
new Task(),
|
|
|
ClusterStateTaskConfig.build(Priority.NORMAL),
|
|
|
- (currentState, taskContexts) -> {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ batchExecutionContext -> {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(new LatchAckListener(latch));
|
|
|
}
|
|
|
- return randomBoolean() ? currentState : ClusterState.builder(currentState).build();
|
|
|
+ return randomBoolean()
|
|
|
+ ? batchExecutionContext.initialState()
|
|
|
+ : ClusterState.builder(batchExecutionContext.initialState()).build();
|
|
|
}
|
|
|
);
|
|
|
|
|
|
@@ -1755,11 +1761,11 @@ public class MasterServiceTests extends ESTestCase {
|
|
|
final Semaphore semaphore = new Semaphore(0);
|
|
|
|
|
|
@Override
|
|
|
- public ClusterState execute(ClusterState currentState, List<TaskContext<Task>> taskContexts) {
|
|
|
- for (final var taskContext : taskContexts) {
|
|
|
+ public ClusterState execute(BatchExecutionContext<Task> batchExecutionContext) {
|
|
|
+ for (final var taskContext : batchExecutionContext.taskContexts()) {
|
|
|
taskContext.success(() -> semaphore.release());
|
|
|
}
|
|
|
- return currentState;
|
|
|
+ return batchExecutionContext.initialState();
|
|
|
}
|
|
|
}
|
|
|
|