Skip to content

Commit

Permalink
review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhniebergall committed May 8, 2024
1 parent 95b4c62 commit 1e586fe
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 41 deletions.
Expand Up @@ -128,7 +128,6 @@ private static ListMultimap<Class<?>, String> createLegacyRestTestBasePluginUsag
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ilm:qa:multi-cluster");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ilm:qa:multi-node");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ilm:qa:rest");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:inference:qa:mixed-cluster");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ml:qa:basic-multi-node");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ml:qa:disabled");
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ml:qa:ml-with-security");
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugin/inference/build.gradle
Expand Up @@ -27,7 +27,6 @@ base {

dependencies {
implementation project(path: ':libs:elasticsearch-logging')
testImplementation project(path: ':test:framework')
compileOnly project(":server")
compileOnly project(path: xpackModule('core'))
testImplementation(testArtifact(project(xpackModule('core'))))
Expand Down
9 changes: 0 additions & 9 deletions x-pack/plugin/inference/qa/mixed-cluster/build.gradle
Expand Up @@ -8,15 +8,6 @@ apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-test-artifact-base'
apply plugin: 'elasticsearch.bwc-test'

restResources {
restApi {
include '_common', 'bulk', 'get', 'indices', 'inference', 'xpack', 'cluster'
}
restTests {
includeXpack 'inference'
}
}

dependencies {
testImplementation project(path: ':x-pack:plugin:inference:qa:inference-service-tests')
compileOnly project(':x-pack:plugin:core')
Expand Down
Expand Up @@ -13,8 +13,6 @@
import org.elasticsearch.inference.TaskType;
import org.elasticsearch.test.http.MockResponse;
import org.elasticsearch.test.http.MockWebServer;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.io.IOException;
import java.util.List;
Expand Down
Expand Up @@ -15,10 +15,12 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.inference.TaskType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.http.MockWebServer;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.hamcrest.Matchers;
import org.junit.ClassRule;

import java.io.IOException;
Expand All @@ -28,9 +30,8 @@
import static org.elasticsearch.core.Strings.format;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;

public class BaseMixedIT extends ESRestTestCase {
public abstract class BaseMixedIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
Expand All @@ -46,58 +47,58 @@ protected String getTestRestCluster() {
}

protected static String getUrl(MockWebServer webServer) {
return format("http://%s:%s", webServer.getHostName(), webServer.getPort());
return Strings.format("http://%s:%s", webServer.getHostName(), webServer.getPort());
}

@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password".toCharArray()));
String token = ESRestTestCase.basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password".toCharArray()));
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
}

protected void delete(String inferenceId, TaskType taskType) throws IOException {
var request = new Request("DELETE", Strings.format("_inference/%s/%s", taskType, inferenceId));
var response = client().performRequest(request);
assertOK(response);
var response = ESRestTestCase.client().performRequest(request);
ESRestTestCase.assertOK(response);
}

protected void delete(String inferenceId) throws IOException {
var request = new Request("DELETE", Strings.format("_inference/%s", inferenceId));
var response = client().performRequest(request);
assertOK(response);
var response = ESRestTestCase.client().performRequest(request);
ESRestTestCase.assertOK(response);
}

protected Map<String, Object> getAll() throws IOException {
var request = new Request("GET", "_inference/_all");
var response = client().performRequest(request);
assertOK(response);
return entityAsMap(response);
var response = ESRestTestCase.client().performRequest(request);
ESRestTestCase.assertOK(response);
return ESRestTestCase.entityAsMap(response);
}

protected Map<String, Object> get(String inferenceId) throws IOException {
var endpoint = Strings.format("_inference/%s", inferenceId);
var request = new Request("GET", endpoint);
var response = client().performRequest(request);
assertOK(response);
return entityAsMap(response);
var response = ESRestTestCase.client().performRequest(request);
ESRestTestCase.assertOK(response);
return ESRestTestCase.entityAsMap(response);
}

protected Map<String, Object> get(TaskType taskType, String inferenceId) throws IOException {
var endpoint = Strings.format("_inference/%s/%s", taskType, inferenceId);
var request = new Request("GET", endpoint);
var response = client().performRequest(request);
assertOK(response);
return entityAsMap(response);
var response = ESRestTestCase.client().performRequest(request);
ESRestTestCase.assertOK(response);
return ESRestTestCase.entityAsMap(response);
}

protected Map<String, Object> inference(String inferenceId, TaskType taskType, String input) throws IOException {
var endpoint = Strings.format("_inference/%s/%s", taskType, inferenceId);
var request = new Request("POST", endpoint);
request.setJsonEntity("{\"input\": [" + '"' + input + '"' + "]}");

var response = client().performRequest(request);
assertOK(response);
return entityAsMap(response);
var response = ESRestTestCase.client().performRequest(request);
ESRestTestCase.assertOK(response);
return ESRestTestCase.entityAsMap(response);
}

protected Map<String, Object> rerank(String inferenceId, List<String> inputs, String query) throws IOException {
Expand All @@ -116,17 +117,17 @@ protected Map<String, Object> rerank(String inferenceId, List<String> inputs, St
body.append("]}");
request.setJsonEntity(body.toString());

var response = client().performRequest(request);
assertOK(response);
return entityAsMap(response);
var response = ESRestTestCase.client().performRequest(request);
ESRestTestCase.assertOK(response);
return ESRestTestCase.entityAsMap(response);
}

protected void put(String inferenceId, String modelConfig, TaskType taskType) throws IOException {
String endpoint = Strings.format("_inference/%s/%s?error_trace", taskType, inferenceId);
var request = new Request("PUT", endpoint);
request.setJsonEntity(modelConfig);
var response = client().performRequest(request);
assertOKAndConsume(response);
var response = ESRestTestCase.client().performRequest(request);
ESRestTestCase.assertOKAndConsume(response);
logger.warn("PUT response: {}", response.toString());
}

Expand All @@ -139,6 +140,10 @@ protected static void assertOkOrCreated(Response response) throws IOException {
}

String responseStr = EntityUtils.toString(response.getEntity());
assertThat(responseStr, response.getStatusLine().getStatusCode(), anyOf(equalTo(200), equalTo(201)));
ESTestCase.assertThat(
responseStr,
response.getStatusLine().getStatusCode(),
Matchers.anyOf(Matchers.equalTo(200), Matchers.equalTo(201))
);
}
}
Expand Up @@ -18,8 +18,6 @@ public static ElasticsearchCluster mixedVersionCluster() {
.distribution(DistributionType.DEFAULT)
.withNode(node -> node.version(oldVersion))
.withNode(node -> node.version(Version.CURRENT))
.withNode(node -> node.version(oldVersion))
.withNode(node -> node.version(Version.CURRENT))
.setting("xpack.security.enabled", "false")
.setting("xpack.license.self_generated.type", "trial")
.setting("cluster.routing.rebalance.enable", "none") // disable relocation until we have retry in ESQL
Expand Down

0 comments on commit 1e586fe

Please sign in to comment.