Skip to content

Commit 0d26edd

Browse files
committed
Test works now
1 parent f6f56b4 commit 0d26edd

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

x-pack/plugin/esql/qa/server/extra-checkers/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ esplugin {
1818
dependencies {
1919
compileOnly project(':x-pack:plugin:esql')
2020
compileOnly project(':x-pack:plugin:esql-core')
21+
clusterPlugins project(':x-pack:plugin:esql:qa:server:extra-checkers')
2122
}
2223

2324
tasks.named('javaRestTest') {

x-pack/plugin/esql/qa/server/extra-checkers/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/extra/ExtraCheckersIT.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99

1010
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
1111

12+
import org.apache.http.util.EntityUtils;
1213
import org.elasticsearch.client.Request;
14+
import org.elasticsearch.client.Response;
1315
import org.elasticsearch.client.ResponseException;
1416
import org.elasticsearch.test.TestClustersThreadFilter;
1517
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1618
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1719
import org.elasticsearch.test.rest.ESRestTestCase;
1820
import org.junit.ClassRule;
1921

22+
import javax.swing.text.html.parser.Entity;
23+
2024
import java.io.IOException;
2125

26+
import static org.hamcrest.Matchers.containsString;
2227
import static org.hamcrest.Matchers.equalTo;
2328

2429
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
@@ -32,15 +37,42 @@ public class ExtraCheckersIT extends ESRestTestCase {
3237
.plugin("extra-checkers")
3338
.build();
3439

35-
public void testIncludesCategorize() throws IOException {
36-
Request request = new Request("POST", "/_query");
37-
request.setJsonEntity("""
40+
public void testWithCategorize() {
41+
ResponseException e = expectThrows(ResponseException.class, () -> runEsql("""
42+
{
43+
"query": "ROW message=\\"foo bar\\" | STATS COUNT(*) BY CATEGORIZE(message) | LIMIT 1"
44+
}"""));
45+
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(400));
46+
assertThat(e.getMessage(), containsString("line 1:43: CATEGORIZE is unsupported"));
47+
}
48+
49+
public void testWithoutCategorize() throws IOException {
50+
String result = runEsql("""
3851
{
39-
"query": "ROW message=\\"foo bar\\" | STATS COUNT(*) BY CATEGORIZE(message)"
52+
"query": "ROW message=\\"foo bar\\" | STATS COUNT(*) | LIMIT 1"
4053
}""");
54+
assertThat(result, containsString("""
55+
"columns" : [
56+
{
57+
"name" : "COUNT(*)",
58+
"type" : "long"
59+
}
60+
],
61+
"values" : [
62+
[
63+
1
64+
]
65+
]
66+
"""));
67+
}
68+
69+
private String runEsql(String json) throws IOException {
70+
Request request = new Request("POST", "/_query");
71+
request.setJsonEntity(json);
4172
request.addParameter("error_trace", "");
42-
Exception e = expectThrows(ResponseException.class, () -> client().performRequest(request));
43-
assertThat(e.getMessage(), equalTo("ADFSADF"));
73+
request.addParameter("pretty", "");
74+
Response response = client().performRequest(request);
75+
return EntityUtils.toString(response.getEntity());
4476
}
4577

4678
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/EsqlPlugin.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.esql.plugin;
88

9-
import org.apache.lucene.util.SetOnce;
109
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1110
import org.elasticsearch.cluster.node.DiscoveryNodes;
1211
import org.elasticsearch.common.breaker.CircuitBreaker;
@@ -190,7 +189,7 @@ public class EsqlPlugin extends Plugin implements ActionPlugin, ExtensiblePlugin
190189
Setting.Property.Dynamic
191190
);
192191

193-
private SetOnce<List<Verifier.ExtraCheckers>> extraCheckers = new SetOnce<>();
192+
private final List<Verifier.ExtraCheckers> extraCheckers = new ArrayList<>();
194193

195194
@Override
196195
public Collection<?> createComponents(PluginServices services) {
@@ -210,7 +209,7 @@ public Collection<?> createComponents(PluginServices services) {
210209
services.telemetryProvider().getMeterRegistry(),
211210
getLicenseState(),
212211
new EsqlQueryLog(services.clusterService().getClusterSettings(), services.slowLogFieldProvider()),
213-
extraCheckers.get()
212+
extraCheckers
214213
),
215214
new ExchangeService(
216215
services.clusterService().getSettings(),
@@ -343,6 +342,6 @@ public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
343342

344343
@Override
345344
public void loadExtensions(ExtensionLoader loader) {
346-
extraCheckers.set(loader.loadExtensions(Verifier.ExtraCheckers.class));
345+
extraCheckers.addAll(loader.loadExtensions(Verifier.ExtraCheckers.class));
347346
}
348347
}

0 commit comments

Comments
 (0)