Skip to content

Commit 94fe480

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 379e847 commit 94fe480

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
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;
15+
import org.elasticsearch.client.ResponseException;
1516
import org.elasticsearch.client.RestClient;
1617
import org.elasticsearch.common.Strings;
1718
import org.elasticsearch.common.settings.Settings;
@@ -108,7 +109,6 @@ public void testBasicCCRAndILMIntegration() throws Exception {
108109
}
109110
}
110111

111-
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/48461")
112112
public void testCCRUnfollowDuringSnapshot() throws Exception {
113113
String indexName = "unfollow-test-index";
114114
if ("leader".equals(targetCluster)) {
@@ -746,10 +746,27 @@ private static Object getIndexSetting(RestClient client, String index, String se
746746
return settings.get(setting);
747747
}
748748

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

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

0 commit comments

Comments
 (0)