Skip to content

Commit c353ad7

Browse files
authored
Wrap ResponseException in AssertionError in ILM/CCR tests (#48489)
When checking for the existence of a document in the ILM/CCR integration tests, `assertDocumentExists` makes an HTTP request and checks the response code. However, if the repsonse code is not successful, the call will throw a `ResponseException`. `assertDocumentExists` is often called inside an `assertBusy`, and wrapping the `ResponseException` in an `AssertionError` will allow the `assertBusy` to retry. In particular, this fixes an issue with `testCCRUnfollowDuringSnapshot` where the index in question may still be closed when the document is requested.
1 parent 124f6d0 commit c353ad7

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

x-pack/plugin/ilm/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ilm/CCRIndexLifecycleIT.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import org.apache.http.entity.ContentType;
99
import org.apache.http.entity.StringEntity;
10+
import org.apache.http.util.EntityUtils;
1011
import org.apache.logging.log4j.LogManager;
1112
import org.apache.logging.log4j.Logger;
12-
import org.apache.lucene.util.LuceneTestCase;
1313
import org.elasticsearch.client.Request;
1414
import org.elasticsearch.client.Response;
1515
import org.elasticsearch.client.ResponseException;
@@ -109,7 +109,6 @@ public void testBasicCCRAndILMIntegration() throws Exception {
109109
}
110110
}
111111

112-
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/48461")
113112
public void testCCRUnfollowDuringSnapshot() throws Exception {
114113
String indexName = "unfollow-test-index";
115114
if ("leader".equals(targetCluster)) {
@@ -750,10 +749,27 @@ private static Object getIndexSetting(RestClient client, String index, String se
750749
return settings.get(setting);
751750
}
752751

753-
private static void assertDocumentExists(RestClient client, String index, String id) throws IOException {
754-
Request request = new Request("HEAD", "/" + index + "/_doc/" + id);
755-
Response response = client.performRequest(request);
756-
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
752+
private void assertDocumentExists(RestClient client, String index, String id) throws IOException {
753+
Request request = new Request("GET", "/" + index + "/_doc/" + id);
754+
Response response;
755+
try {
756+
response = client.performRequest(request);
757+
if (response.getStatusLine().getStatusCode() != 200) {
758+
if (response.getEntity() != null) {
759+
logger.error(EntityUtils.toString(response.getEntity()));
760+
} else {
761+
logger.error("response body was null");
762+
}
763+
fail("HTTP response code expected to be [200] but was [" + response.getStatusLine().getStatusCode() + "]");
764+
}
765+
} catch (ResponseException ex) {
766+
if (ex.getResponse().getEntity() != null) {
767+
logger.error(EntityUtils.toString(ex.getResponse().getEntity()), ex);
768+
} else {
769+
logger.error("response body was null");
770+
}
771+
fail("HTTP response code expected to be [200] but was [" + ex.getResponse().getStatusLine().getStatusCode() + "]");
772+
}
757773
}
758774

759775
private void createNewSingletonPolicy(String policyName, String phaseName, LifecycleAction action, TimeValue after) throws IOException {

0 commit comments

Comments
 (0)