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.
This commit is contained in:
parent
124f6d098b
commit
c353ad71fe
|
@ -7,9 +7,9 @@ package org.elasticsearch.xpack.ilm;
|
||||||
|
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
|
||||||
import org.elasticsearch.client.Request;
|
import org.elasticsearch.client.Request;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
import org.elasticsearch.client.ResponseException;
|
import org.elasticsearch.client.ResponseException;
|
||||||
|
@ -109,7 +109,6 @@ public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/48461")
|
|
||||||
public void testCCRUnfollowDuringSnapshot() throws Exception {
|
public void testCCRUnfollowDuringSnapshot() throws Exception {
|
||||||
String indexName = "unfollow-test-index";
|
String indexName = "unfollow-test-index";
|
||||||
if ("leader".equals(targetCluster)) {
|
if ("leader".equals(targetCluster)) {
|
||||||
|
@ -750,10 +749,27 @@ public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
|
||||||
return settings.get(setting);
|
return settings.get(setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertDocumentExists(RestClient client, String index, String id) throws IOException {
|
private void assertDocumentExists(RestClient client, String index, String id) throws IOException {
|
||||||
Request request = new Request("HEAD", "/" + index + "/_doc/" + id);
|
Request request = new Request("GET", "/" + index + "/_doc/" + id);
|
||||||
Response response = client.performRequest(request);
|
Response response;
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
try {
|
||||||
|
response = client.performRequest(request);
|
||||||
|
if (response.getStatusLine().getStatusCode() != 200) {
|
||||||
|
if (response.getEntity() != null) {
|
||||||
|
logger.error(EntityUtils.toString(response.getEntity()));
|
||||||
|
} else {
|
||||||
|
logger.error("response body was null");
|
||||||
|
}
|
||||||
|
fail("HTTP response code expected to be [200] but was [" + response.getStatusLine().getStatusCode() + "]");
|
||||||
|
}
|
||||||
|
} catch (ResponseException ex) {
|
||||||
|
if (ex.getResponse().getEntity() != null) {
|
||||||
|
logger.error(EntityUtils.toString(ex.getResponse().getEntity()), ex);
|
||||||
|
} else {
|
||||||
|
logger.error("response body was null");
|
||||||
|
}
|
||||||
|
fail("HTTP response code expected to be [200] but was [" + ex.getResponse().getStatusLine().getStatusCode() + "]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewSingletonPolicy(String policyName, String phaseName, LifecycleAction action, TimeValue after) throws IOException {
|
private void createNewSingletonPolicy(String policyName, String phaseName, LifecycleAction action, TimeValue after) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue