Skip to content

Commit 7a42638

Browse files
committed
Fix documentation test
1 parent 755acfe commit 7a42638

File tree

1 file changed

+56
-49
lines changed

1 file changed

+56
-49
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.http.util.EntityUtils;
2323
import org.elasticsearch.action.ActionListener;
2424
import org.elasticsearch.action.LatchedActionListener;
25+
import org.elasticsearch.action.admin.indices.alias.Alias;
2526
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
2627
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
2728
import org.elasticsearch.client.RequestOptions;
@@ -39,17 +40,17 @@
3940
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest;
4041
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusResponse;
4142
import org.elasticsearch.client.indexlifecycle.LifecyclePolicy;
42-
import org.elasticsearch.client.indexlifecycle.OperationMode;
4343
import org.elasticsearch.client.indexlifecycle.LifecyclePolicyMetadata;
44+
import org.elasticsearch.client.indexlifecycle.OperationMode;
4445
import org.elasticsearch.client.indexlifecycle.Phase;
4546
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
4647
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
4748
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyResponse;
4849
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
4950
import org.elasticsearch.client.indexlifecycle.RolloverAction;
51+
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
5052
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
5153
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
52-
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
5354
import org.elasticsearch.cluster.metadata.IndexMetaData;
5455
import org.elasticsearch.common.Strings;
5556
import org.elasticsearch.common.collect.ImmutableOpenMap;
@@ -337,11 +338,13 @@ public void testExplainLifecycle() throws Exception {
337338
new PutLifecyclePolicyRequest(policy);
338339
client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT);
339340

340-
CreateIndexRequest createIndexRequest = new CreateIndexRequest("my_index",
341+
CreateIndexRequest createIndexRequest = new CreateIndexRequest("my_index-1",
341342
Settings.builder()
342343
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
343344
.put("index.lifecycle.name", "my_policy")
345+
.put("index.lifecycle.rollover_alias", "my_alias")
344346
.build());
347+
createIndexRequest.alias(new Alias("my_alias").writeIndex(true));
345348
client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
346349
CreateIndexRequest createOtherIndexRequest = new CreateIndexRequest("other_index",
347350
Settings.builder()
@@ -352,58 +355,62 @@ public void testExplainLifecycle() throws Exception {
352355

353356
// wait for the policy to become active
354357
assertBusy(() -> assertNotNull(client.indexLifecycle()
355-
.explainLifecycle(new ExplainLifecycleRequest("my_index"), RequestOptions.DEFAULT)
356-
.getIndexResponses().get("my_index").getAction()));
358+
.explainLifecycle(new ExplainLifecycleRequest("my_index-1"), RequestOptions.DEFAULT)
359+
.getIndexResponses().get("my_index-1").getAction()));
357360
}
358361

359362
// tag::ilm-explain-lifecycle-request
360363
ExplainLifecycleRequest request =
361-
new ExplainLifecycleRequest("my_index", "other_index"); // <1>
364+
new ExplainLifecycleRequest("my_index-1", "other_index"); // <1>
362365
// end::ilm-explain-lifecycle-request
363366

364-
// tag::ilm-explain-lifecycle-execute
365-
ExplainLifecycleResponse response = client.indexLifecycle()
366-
.explainLifecycle(request, RequestOptions.DEFAULT);
367-
// end::ilm-explain-lifecycle-execute
368-
assertNotNull(response);
369-
370-
// tag::ilm-explain-lifecycle-response
371-
Map<String, IndexLifecycleExplainResponse> indices =
372-
response.getIndexResponses();
373-
IndexLifecycleExplainResponse myIndex = indices.get("my_index");
374-
String policyName = myIndex.getPolicyName(); // <1>
375-
boolean isManaged = myIndex.managedByILM(); // <2>
376-
377-
String phase = myIndex.getPhase(); // <3>
378-
long phaseTime = myIndex.getPhaseTime(); // <4>
379-
String action = myIndex.getAction(); // <5>
380-
long actionTime = myIndex.getActionTime();
381-
String step = myIndex.getStep(); // <6>
382-
long stepTime = myIndex.getStepTime();
383-
384-
String failedStep = myIndex.getFailedStep(); // <7>
385-
// end::ilm-explain-lifecycle-response
386-
assertEquals("my_policy", policyName);
387-
assertTrue(isManaged);
388-
389-
assertEquals("hot", phase);
390-
assertNotEquals(0, phaseTime);
391-
assertEquals("rollover", action);
392-
assertNotEquals(0, actionTime);
393-
assertEquals("check-rollover-ready", step);
394-
assertNotEquals(0, stepTime);
395-
396-
assertNull(failedStep);
397-
398-
IndexLifecycleExplainResponse otherIndex = indices.get("other_index");
399-
assertFalse(otherIndex.managedByILM());
400-
assertNull(otherIndex.getPolicyName());
401-
assertNull(otherIndex.getPhase());
402-
assertNull(otherIndex.getAction());
403-
assertNull(otherIndex.getStep());
404-
assertNull(otherIndex.getFailedStep());
405-
assertNull(otherIndex.getPhaseExecutionInfo());
406-
assertNull(otherIndex.getStepInfo());
367+
368+
assertBusy(() -> {
369+
// tag::ilm-explain-lifecycle-execute
370+
ExplainLifecycleResponse response = client.indexLifecycle()
371+
.explainLifecycle(request, RequestOptions.DEFAULT);
372+
// end::ilm-explain-lifecycle-execute
373+
assertNotNull(response);
374+
375+
// tag::ilm-explain-lifecycle-response
376+
Map<String, IndexLifecycleExplainResponse> indices =
377+
response.getIndexResponses();
378+
IndexLifecycleExplainResponse myIndex = indices.get("my_index-1");
379+
String policyName = myIndex.getPolicyName(); // <1>
380+
boolean isManaged = myIndex.managedByILM(); // <2>
381+
382+
String phase = myIndex.getPhase(); // <3>
383+
long phaseTime = myIndex.getPhaseTime(); // <4>
384+
String action = myIndex.getAction(); // <5>
385+
long actionTime = myIndex.getActionTime();
386+
String step = myIndex.getStep(); // <6>
387+
long stepTime = myIndex.getStepTime();
388+
389+
String failedStep = myIndex.getFailedStep(); // <7>
390+
// end::ilm-explain-lifecycle-response
391+
392+
assertEquals("my_policy", policyName);
393+
assertTrue(isManaged);
394+
395+
assertEquals("hot", phase);
396+
assertNotEquals(0, phaseTime);
397+
assertEquals("rollover", action);
398+
assertNotEquals(0, actionTime);
399+
assertEquals("check-rollover-ready", step);
400+
assertNotEquals(0, stepTime);
401+
402+
assertNull(failedStep);
403+
404+
IndexLifecycleExplainResponse otherIndex = indices.get("other_index");
405+
assertFalse(otherIndex.managedByILM());
406+
assertNull(otherIndex.getPolicyName());
407+
assertNull(otherIndex.getPhase());
408+
assertNull(otherIndex.getAction());
409+
assertNull(otherIndex.getStep());
410+
assertNull(otherIndex.getFailedStep());
411+
assertNull(otherIndex.getPhaseExecutionInfo());
412+
assertNull(otherIndex.getStepInfo());
413+
});
407414

408415
// tag::ilm-explain-lifecycle-execute-listener
409416
ActionListener<ExplainLifecycleResponse> listener =

0 commit comments

Comments
 (0)