Skip to content

Commit e5a71ba

Browse files
committed
Start adding a rest test
1 parent 19c26e8 commit e5a71ba

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

x-pack/plugin/esql/qa/server/single-node/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ apply plugin: 'elasticsearch.internal-test-artifact'
66
dependencies {
77
javaRestTestImplementation project(xpackModule('esql:qa:testFixtures'))
88
javaRestTestImplementation project(xpackModule('esql:qa:server'))
9+
javaRestTestImplementation project(xpackModule('esql:tools'))
910
yamlRestTestImplementation project(xpackModule('esql:qa:server'))
1011

1112
javaRestTestImplementation('org.apache.arrow:arrow-vector:16.1.0')

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,34 @@
1717
import org.elasticsearch.client.ResponseException;
1818
import org.elasticsearch.common.io.Streams;
1919
import org.elasticsearch.common.settings.Settings;
20+
import org.elasticsearch.common.xcontent.XContentHelper;
2021
import org.elasticsearch.test.ListMatcher;
2122
import org.elasticsearch.test.MapMatcher;
2223
import org.elasticsearch.test.TestClustersThreadFilter;
2324
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2425
import org.elasticsearch.test.cluster.LogType;
26+
import org.elasticsearch.xcontent.XContentBuilder;
2527
import org.elasticsearch.xcontent.XContentType;
28+
import org.elasticsearch.xcontent.json.JsonXContent;
2629
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
2730
import org.hamcrest.Matchers;
2831
import org.junit.Assert;
2932
import org.junit.ClassRule;
3033

34+
import java.io.ByteArrayOutputStream;
3135
import java.io.IOException;
3236
import java.io.InputStream;
37+
import java.io.PipedInputStream;
38+
import java.io.PipedOutputStream;
39+
import java.nio.charset.Charset;
3340
import java.nio.charset.StandardCharsets;
3441
import java.util.ArrayList;
3542
import java.util.Arrays;
3643
import java.util.List;
3744
import java.util.Locale;
3845
import java.util.Map;
3946

47+
import static org.elasticsearch.xpack.esql.tools.ProfileParser.parseProfile;
4048
import static org.elasticsearch.test.ListMatcher.matchesList;
4149
import static org.elasticsearch.test.MapMatcher.assertMap;
4250
import static org.elasticsearch.test.MapMatcher.matchesMap;
@@ -330,6 +338,22 @@ public void testProfile() throws IOException {
330338
}
331339
}
332340

341+
public void testProfileParsing() throws IOException {
342+
indexTimestampData(1);
343+
344+
RequestObjectBuilder builder = requestObjectBuilder().query(fromIndex() + " | stats avg(value)");
345+
builder.profile(true);
346+
Map<String, Object> result = runEsql(builder);
347+
348+
ByteArrayOutputStream os = new ByteArrayOutputStream();
349+
try (XContentBuilder jsonOutputBuilder = new XContentBuilder(JsonXContent.jsonXContent, os)) {
350+
parseProfile(result, jsonOutputBuilder);
351+
}
352+
String parsedProfile = os.toString(Charset.defaultCharset());
353+
354+
assertFalse(true);
355+
}
356+
333357
public void testProfileOrdinalsGroupingOperator() throws IOException {
334358
assumeTrue("requires pragmas", Build.current().isSnapshot());
335359
indexTimestampData(1);

x-pack/plugin/esql/tools/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apply plugin: 'elasticsearch.java'
33
dependencies {
44
implementation project(":libs:x-content")
55
implementation project(':libs:logging')
6+
// Required for log4j, there's probably a more direct way to depend on it.
67
implementation project(':test:framework')
78
}
89

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static void main(String[] args) throws IOException {
6565
* out to be tricky to use.
6666
*/
6767
@SuppressWarnings("unchecked")
68-
private static void parseProfile(Map<String, Object> parsedQueryResponseWithProfile, XContentBuilder outputBuilder) throws IOException {
68+
public static void parseProfile(Map<String, Object> parsedQueryResponseWithProfile, XContentBuilder outputBuilder) throws IOException {
6969
Map<String, Object> profile = (Map<String, Object>) parsedQueryResponseWithProfile.get("profile");
7070
List<Map<String, Object>> drivers = (List<Map<String, Object>>) profile.get("drivers");
7171

x-pack/plugin/esql/tools/src/test/java/org/elasticsearch/xpack/esql/tools/ProfileParserTests.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)