77package org .elasticsearch .xpack .slm ;
88
99import org .apache .http .util .EntityUtils ;
10- import org .apache .lucene .util .LuceneTestCase ;
1110import org .elasticsearch .ElasticsearchException ;
1211import org .elasticsearch .action .admin .cluster .settings .ClusterUpdateSettingsRequest ;
1312import org .elasticsearch .action .index .IndexRequestBuilder ;
2726import org .elasticsearch .common .xcontent .XContentParser ;
2827import org .elasticsearch .common .xcontent .XContentType ;
2928import org .elasticsearch .common .xcontent .json .JsonXContent ;
29+ import org .elasticsearch .test .junit .annotations .TestIssueLogging ;
3030import org .elasticsearch .test .rest .ESRestTestCase ;
3131import org .elasticsearch .xpack .core .ilm .LifecycleSettings ;
3232import org .elasticsearch .xpack .core .ilm .Step ;
@@ -195,6 +195,8 @@ public void testPolicyFailure() throws Exception {
195195 }
196196
197197 @ SuppressWarnings ("unchecked" )
198+ @ TestIssueLogging (value = "org.elasticsearch.xpack.slm:TRACE,org.elasticsearch.xpack.core.slm:TRACE,org.elasticsearch.snapshots:DEBUG" ,
199+ issueUrl = "https://github.com/elastic/elasticsearch/issues/48531" )
198200 public void testPolicyManualExecution () throws Exception {
199201 final String indexName = "test" ;
200202 final String policyName = "test-policy" ;
@@ -204,6 +206,8 @@ public void testPolicyManualExecution() throws Exception {
204206 index (client (), indexName , "" + i , "foo" , "bar" );
205207 }
206208
209+ logSLMPolicies ();
210+
207211 // Create a snapshot repo
208212 initializeRepo (repoId );
209213
@@ -216,6 +220,8 @@ public void testPolicyManualExecution() throws Exception {
216220
217221 final String snapshotName = executePolicy (policyName );
218222
223+ logSLMPolicies ();
224+
219225 // Check that the executed snapshot is created
220226 assertBusy (() -> {
221227 try {
@@ -336,7 +342,8 @@ public void testStartStopStatus() throws Exception {
336342 }
337343
338344 @ SuppressWarnings ("unchecked" )
339- @ LuceneTestCase .AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/48017" )
345+ @ TestIssueLogging (value = "org.elasticsearch.xpack.slm:TRACE,org.elasticsearch.xpack.core.slm:TRACE,org.elasticsearch.snapshots:TRACE" ,
346+ issueUrl = "https://github.com/elastic/elasticsearch/issues/48017" )
340347 public void testBasicTimeBasedRetenion () throws Exception {
341348 final String indexName = "test" ;
342349 final String policyName = "test-policy" ;
@@ -346,6 +353,7 @@ public void testBasicTimeBasedRetenion() throws Exception {
346353 for (int i = 0 ; i < docCount ; i ++) {
347354 index (client (), indexName , "" + i , "foo" , "bar" );
348355 }
356+ logSLMPolicies ();
349357
350358 // Create a snapshot repo
351359 initializeRepo (repoId );
@@ -383,8 +391,11 @@ public void testBasicTimeBasedRetenion() throws Exception {
383391 Request r = new Request ("PUT" , "/_cluster/settings" );
384392 r .setJsonEntity (Strings .toString (builder ));
385393 Response updateSettingsResp = client ().performRequest (r );
394+ assertAcked (updateSettingsResp );
386395 }
387396
397+ logSLMPolicies ();
398+
388399 try {
389400 // Check that the snapshot created by the policy has been removed by retention
390401 assertBusy (() -> {
@@ -618,7 +629,8 @@ private void createSnapshotPolicy(String policyName, String snapshotNamePattern,
618629 XContentBuilder lifecycleBuilder = JsonXContent .contentBuilder ();
619630 policy .toXContent (lifecycleBuilder , ToXContent .EMPTY_PARAMS );
620631 putLifecycle .setJsonEntity (Strings .toString (lifecycleBuilder ));
621- assertOK (client ().performRequest (putLifecycle ));
632+ final Response response = client ().performRequest (putLifecycle );
633+ assertAcked (response );
622634 }
623635
624636 private void initializeRepo (String repoName ) throws IOException {
@@ -659,4 +671,20 @@ private static Map<String, Object> policyStatsAsMap(Map<String, Object> stats) {
659671 m -> (String ) m .get (SnapshotLifecycleStats .SnapshotPolicyStats .POLICY_ID .getPreferredName ()),
660672 Function .identity ()));
661673 }
674+
675+ private void assertAcked (Response response ) throws IOException {
676+ assertOK (response );
677+ Map <String , Object > putLifecycleResponseMap ;
678+ try (InputStream is = response .getEntity ().getContent ()) {
679+ putLifecycleResponseMap = XContentHelper .convertToMap (XContentType .JSON .xContent (), is , true );
680+ }
681+ assertThat (putLifecycleResponseMap .get ("acknowledged" ), equalTo (true ));
682+ }
683+
684+ private void logSLMPolicies () throws IOException {
685+ Request request = new Request ("GET" , "/_slm/policy?human" );
686+ Response response = client ().performRequest (request );
687+ assertOK (response );
688+ logger .info ("SLM policies: {}" , EntityUtils .toString (response .getEntity ()));
689+ }
662690}
0 commit comments