[TEST] Waits for security template to be created in XPackRestIT
This commit applies the same fix merged in elastic/elasticsearch#4179 for XDocsClientYamlTestSuiteIT. It adds a waitForSecurityTemplate() method in order to wait for the security-index-template to be created by the SecurityTemplateService. Original commit: elastic/x-pack-elasticsearch@1476f30e2d
This commit is contained in:
parent
0673d6b3d6
commit
a414e3a7d9
|
@ -5,7 +5,19 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.test.rest;
|
package org.elasticsearch.xpack.test.rest;
|
||||||
|
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
|
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
|
||||||
|
import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse;
|
||||||
|
import org.elasticsearch.xpack.security.SecurityTemplateService;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
|
|
||||||
/** Runs rest tests against external cluster */
|
/** Runs rest tests against external cluster */
|
||||||
public class XPackRestIT extends XPackRestTestCase {
|
public class XPackRestIT extends XPackRestTestCase {
|
||||||
|
@ -14,4 +26,32 @@ public class XPackRestIT extends XPackRestTestCase {
|
||||||
super(testCandidate);
|
super(testCandidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waits for the Security template to be created by the {@link SecurityTemplateService}.
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void waitForSecurityTemplate() throws Exception {
|
||||||
|
String templateApi = "indices.exists_template";
|
||||||
|
Map<String, String> params = singletonMap("name", SecurityTemplateService.SECURITY_TEMPLATE_NAME);
|
||||||
|
|
||||||
|
AtomicReference<IOException> exceptionHolder = new AtomicReference<>();
|
||||||
|
awaitBusy(() -> {
|
||||||
|
try {
|
||||||
|
ClientYamlTestResponse response = getAdminExecutionContext().callApi(templateApi, params, emptyList(), emptyMap());
|
||||||
|
// We don't check the version of the template - it is the right one when testing documentation.
|
||||||
|
if (response.getStatusCode() == HttpStatus.SC_OK) {
|
||||||
|
exceptionHolder.set(null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
exceptionHolder.set(e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
IOException exception = exceptionHolder.get();
|
||||||
|
if (exception != null) {
|
||||||
|
throw new IllegalStateException("Exception when waiting for security template to be created", exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue