|
|
@@ -18,6 +18,7 @@ import org.elasticsearch.plugins.MetadataUpgrader;
|
|
|
import org.elasticsearch.test.SecuritySettingsSourceField;
|
|
|
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
|
|
|
import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse;
|
|
|
+import org.elasticsearch.test.rest.yaml.ClientYamlTestResponseException;
|
|
|
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
|
|
|
import org.elasticsearch.xpack.core.ml.integration.MlRestTestStateCleaner;
|
|
|
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex;
|
|
|
@@ -89,6 +90,20 @@ public class AbstractXPackRestTest extends ESClientYamlSuiteTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Waits for the cluster's self-generated license to be created and installed
|
|
|
+ */
|
|
|
+ protected void waitForLicense() {
|
|
|
+ // GET _licence returns a 404 status up until the license exists
|
|
|
+ awaitCallApi(
|
|
|
+ "license.get",
|
|
|
+ Map.of(),
|
|
|
+ List.of(),
|
|
|
+ response -> true,
|
|
|
+ () -> "Exception when waiting for initial license to be generated"
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Cleanup after tests.
|
|
|
*
|
|
|
@@ -130,10 +145,16 @@ public class AbstractXPackRestTest extends ESClientYamlSuiteTestCase {
|
|
|
try {
|
|
|
final AtomicReference<ClientYamlTestResponse> response = new AtomicReference<>();
|
|
|
assertBusy(() -> {
|
|
|
- // The actual method call that sends the API requests returns a Future, but we immediately
|
|
|
- // call .get() on it so there's no need for this method to do any other awaiting.
|
|
|
- response.set(callApi(apiName, params, bodies, getApiCallHeaders()));
|
|
|
- assertEquals(HttpStatus.SC_OK, response.get().getStatusCode());
|
|
|
+ try {
|
|
|
+ // The actual method call that sends the API requests returns a Future, but we immediately
|
|
|
+ // call .get() on it so there's no need for this method to do any other awaiting.
|
|
|
+ response.set(callApi(apiName, params, bodies, getApiCallHeaders()));
|
|
|
+ assertEquals(HttpStatus.SC_OK, response.get().getStatusCode());
|
|
|
+ } catch (ClientYamlTestResponseException e) {
|
|
|
+ // Convert to an AssertionError so that "assertBusy" treats it as a failed assertion (and tries again)
|
|
|
+ // rather than a runtime failure (which terminates the loop)
|
|
|
+ throw new AssertionError("Failed to call API " + apiName, e);
|
|
|
+ }
|
|
|
});
|
|
|
success.apply(response.get());
|
|
|
} catch (Exception e) {
|