|
13 | 13 | import org.elasticsearch.cluster.ClusterChangedEvent;
|
14 | 14 | import org.elasticsearch.cluster.ClusterName;
|
15 | 15 | import org.elasticsearch.cluster.ClusterState;
|
| 16 | +import org.elasticsearch.cluster.block.ClusterBlocks; |
16 | 17 | import org.elasticsearch.cluster.metadata.IndexMetadata;
|
17 | 18 | import org.elasticsearch.cluster.metadata.Metadata;
|
18 | 19 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
59 | 60 | import java.util.concurrent.ExecutorService;
|
60 | 61 | import java.util.concurrent.TimeUnit;
|
61 | 62 |
|
| 63 | +import static java.time.Clock.systemUTC; |
| 64 | +import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK; |
62 | 65 | import static org.elasticsearch.xpack.core.ilm.AbstractStepTestCase.randomStepKey;
|
63 | 66 | import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
64 | 67 | import static org.elasticsearch.xpack.ilm.LifecyclePolicyTestsUtils.newTestLifecyclePolicy;
|
@@ -449,6 +452,27 @@ public void doTestExceptionStillProcessesOtherIndices(boolean useOnMaster) {
|
449 | 452 | }
|
450 | 453 | }
|
451 | 454 |
|
| 455 | + public void testClusterChangedWaitsForTheStateToBeRecovered() { |
| 456 | + IndexLifecycleService ilmService = new IndexLifecycleService(Settings.EMPTY, mock(Client.class), clusterService, threadPool, |
| 457 | + systemUTC(), () -> now, null, null) { |
| 458 | + |
| 459 | + @Override |
| 460 | + void onMaster(ClusterState clusterState) { |
| 461 | + fail("IndexLifecycleService ignored the global [state not recovered / initialized] cluster block"); |
| 462 | + } |
| 463 | + |
| 464 | + @Override |
| 465 | + void triggerPolicies(ClusterState clusterState, boolean fromClusterStateChange) { |
| 466 | + fail("IndexLifecycleService ignored the global [state not recovered / initialized] cluster block"); |
| 467 | + } |
| 468 | + }; |
| 469 | + |
| 470 | + ClusterState currentState = ClusterState.builder(ClusterName.DEFAULT) |
| 471 | + .blocks(ClusterBlocks.builder().addGlobalBlock(STATE_NOT_RECOVERED_BLOCK).build()) |
| 472 | + .build(); |
| 473 | + ilmService.clusterChanged(new ClusterChangedEvent("_source", currentState, ClusterState.EMPTY_STATE)); |
| 474 | + } |
| 475 | + |
452 | 476 | public void testTriggeredDifferentJob() {
|
453 | 477 | Mockito.reset(clusterService);
|
454 | 478 | SchedulerEngine.Event schedulerEvent = new SchedulerEngine.Event("foo", randomLong(), randomLong());
|
|
0 commit comments