|
22 | 22 | import org.elasticsearch.index.Index; |
23 | 23 | import org.elasticsearch.node.Node; |
24 | 24 | import org.elasticsearch.test.ESTestCase; |
| 25 | +import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; |
25 | 26 | import org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState; |
26 | 27 | import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; |
27 | 28 | import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; |
@@ -253,6 +254,44 @@ public void testOnFailure() throws IOException { |
253 | 254 | assertSame(expectedException, exception.getCause()); |
254 | 255 | } |
255 | 256 |
|
| 257 | + public void testClusterActionStepThrowsException() throws IOException { |
| 258 | + RuntimeException thrownException = new RuntimeException("error"); |
| 259 | + firstStep.setException(thrownException); |
| 260 | + setStateToKey(firstStepKey); |
| 261 | + Step startStep = policyStepsRegistry.getStep(indexMetaData, firstStepKey); |
| 262 | + long now = randomNonNegativeLong(); |
| 263 | + ExecuteStepsUpdateTask task = new ExecuteStepsUpdateTask(mixedPolicyName, index, startStep, policyStepsRegistry, null, () -> now); |
| 264 | + ClusterState newState = task.execute(clusterState); |
| 265 | + LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(newState.getMetaData().index(index)); |
| 266 | + StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(lifecycleState); |
| 267 | + assertThat(currentStepKey, equalTo(new StepKey(firstStepKey.getPhase(), firstStepKey.getAction(), ErrorStep.NAME))); |
| 268 | + assertThat(firstStep.getExecuteCount(), equalTo(1L)); |
| 269 | + assertThat(secondStep.getExecuteCount(), equalTo(0L)); |
| 270 | + assertThat(task.getNextStepKey(), equalTo(secondStep.getKey())); |
| 271 | + assertThat(lifecycleState.getPhaseTime(), nullValue()); |
| 272 | + assertThat(lifecycleState.getActionTime(), nullValue()); |
| 273 | + assertThat(lifecycleState.getStepInfo(), equalTo("{\"type\":\"runtime_exception\",\"reason\":\"error\"}")); |
| 274 | + } |
| 275 | + |
| 276 | + public void testClusterWaitStepThrowsException() throws IOException { |
| 277 | + RuntimeException thrownException = new RuntimeException("error"); |
| 278 | + secondStep.setException(thrownException); |
| 279 | + setStateToKey(firstStepKey); |
| 280 | + Step startStep = policyStepsRegistry.getStep(indexMetaData, firstStepKey); |
| 281 | + long now = randomNonNegativeLong(); |
| 282 | + ExecuteStepsUpdateTask task = new ExecuteStepsUpdateTask(mixedPolicyName, index, startStep, policyStepsRegistry, null, () -> now); |
| 283 | + ClusterState newState = task.execute(clusterState); |
| 284 | + LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(newState.getMetaData().index(index)); |
| 285 | + StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(lifecycleState); |
| 286 | + assertThat(currentStepKey, equalTo(new StepKey(firstStepKey.getPhase(), firstStepKey.getAction(), ErrorStep.NAME))); |
| 287 | + assertThat(firstStep.getExecuteCount(), equalTo(1L)); |
| 288 | + assertThat(secondStep.getExecuteCount(), equalTo(1L)); |
| 289 | + assertThat(task.getNextStepKey(), equalTo(thirdStepKey)); |
| 290 | + assertThat(lifecycleState.getPhaseTime(), nullValue()); |
| 291 | + assertThat(lifecycleState.getActionTime(), nullValue()); |
| 292 | + assertThat(lifecycleState.getStepInfo(), equalTo("{\"type\":\"runtime_exception\",\"reason\":\"error\"}")); |
| 293 | + } |
| 294 | + |
256 | 295 | private void setStateToKey(StepKey stepKey) throws IOException { |
257 | 296 | LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder( |
258 | 297 | LifecycleExecutionState.fromIndexMetadata(clusterState.getMetaData().index(index))); |
|
0 commit comments