Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Add an IT which verifies that the RCA REST endpoint can be queried (#157
Browse files Browse the repository at this point in the history
)

* Add an IT which verifies that the RCA REST endpoint can be queried

* Add try-catch to handle 404 exceptions
  • Loading branch information
Sid Narayan authored Jul 29, 2020
1 parent 19e3b4a commit f89a956
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Objects;
import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.util.EntityUtils;
Expand All @@ -14,7 +15,7 @@
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.AfterClass;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -130,8 +131,22 @@ public void checkMetrics() throws Exception {
});
}

@AfterClass
public static void closePaClient() throws Exception {
@Test
public void testRcaIsRunning() throws Exception {
ensurePaAndRcaEnabled();
WaitFor.waitFor(() -> {
Request request = new Request("GET", "/_opendistro/_performanceanalyzer/rca");
try {
Response resp = paClient.performRequest(request);
return Objects.equals(HttpStatus.SC_OK, resp.getStatusLine().getStatusCode());
} catch (Exception e) { // 404, RCA context hasn't been set up yet
return false;
}
}, 2, TimeUnit.MINUTES);
}

@After
public void closePaClient() throws Exception {
ESRestTestCase.closeClients();
paClient.close();
LOG.debug("AfterClass has run");
Expand Down

0 comments on commit f89a956

Please sign in to comment.