|
17 | 17 |
|
18 | 18 | import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
19 | 19 | import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionStateTests.createCustomMetadata;
|
| 20 | +import static org.hamcrest.Matchers.equalTo; |
20 | 21 |
|
21 | 22 | public class CopyExecutionStateStepTests extends AbstractStepTestCase<CopyExecutionStateStep> {
|
22 | 23 | @Override
|
@@ -86,4 +87,25 @@ public void testPerformAction() {
|
86 | 87 | assertEquals(oldIndexData.getAction(), newIndexData.getAction());
|
87 | 88 | assertEquals(ShrunkenIndexCheckStep.NAME, newIndexData.getStep());
|
88 | 89 | }
|
| 90 | + public void testPerformActionWithNoTarget() { |
| 91 | + CopyExecutionStateStep step = createRandomInstance(); |
| 92 | + String indexName = randomAlphaOfLengthBetween(5, 20); |
| 93 | + Map<String, String> customMetadata = createCustomMetadata(); |
| 94 | + |
| 95 | + IndexMetaData originalIndexMetaData = IndexMetaData.builder(indexName) |
| 96 | + .settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1,5)) |
| 97 | + .numberOfReplicas(randomIntBetween(1,5)) |
| 98 | + .putCustom(ILM_CUSTOM_METADATA_KEY, customMetadata) |
| 99 | + .build(); |
| 100 | + ClusterState originalClusterState = ClusterState.builder(ClusterName.DEFAULT) |
| 101 | + .metaData(MetaData.builder() |
| 102 | + .put(originalIndexMetaData, false)) |
| 103 | + .build(); |
| 104 | + |
| 105 | + IllegalStateException e = expectThrows(IllegalStateException.class, |
| 106 | + () -> step.performAction(originalIndexMetaData.getIndex(), originalClusterState)); |
| 107 | + |
| 108 | + assertThat(e.getMessage(), equalTo("unable to copy execution state from [" + |
| 109 | + indexName + "] to [" + step.getShrunkIndexPrefix() + indexName + "] as target index does not exist")); |
| 110 | + } |
89 | 111 | }
|
0 commit comments