Skip to content

Commit 74d3e0d

Browse files
committed
adapt to CCS test with partial results
1 parent 6dd97ce commit 74d3e0d

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/RequestIndexFilteringIT.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static org.elasticsearch.test.MapMatcher.matchesMap;
3838
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3939
import static org.hamcrest.Matchers.hasSize;
40+
import static org.hamcrest.Matchers.is;
4041
import static org.hamcrest.Matchers.instanceOf;
4142

4243
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
@@ -91,14 +92,20 @@ protected String from(String... indexName) {
9192

9293
@Override
9394
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException {
95+
return runEsql(requestObject, true);
96+
}
97+
98+
@Override
99+
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, boolean checkPartialResults)
100+
throws IOException {
94101
if (requestObject.allowPartialResults() != null) {
95102
assumeTrue(
96103
"require allow_partial_results on local cluster",
97104
clusterHasCapability("POST", "/_query", List.of(), List.of("support_partial_results")).orElse(false)
98105
);
99106
}
100107
requestObject.includeCCSMetadata(true);
101-
return super.runEsql(requestObject);
108+
return super.runEsql(requestObject, checkPartialResults);
102109
}
103110

104111
@After
@@ -154,8 +161,13 @@ public void testIndicesDontExistRemote() throws IOException {
154161
indexTimestampData(docsTest1, "test1", "2024-11-26", "id1");
155162

156163
Map<String, Object> result = runEsql(
157-
timestampFilter("gte", "2020-01-01").query("FROM *:foo,*:test1 METADATA _index | SORT id1 | KEEP _index, id*")
164+
timestampFilter("gte", "2020-01-01").query("FROM *:foo,*:test1 METADATA _index | SORT id1 | KEEP _index, id*"),
165+
false
158166
);
167+
168+
// `foo` index doesn't exist, so the request will currently be successful, but with partial results
169+
var isPartial = result.get("is_partial");
170+
assertThat(isPartial, is(true));
159171
@SuppressWarnings("unchecked")
160172
var columns = (List<List<Object>>) result.get("columns");
161173
assertThat(

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import static org.elasticsearch.test.ListMatcher.matchesList;
5353
import static org.elasticsearch.test.MapMatcher.assertMap;
5454
import static org.elasticsearch.test.MapMatcher.matchesMap;
55-
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.entityToMapNoPartialCheck;
55+
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.entityToMap;
5656
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.runEsqlSync;
5757
import static org.hamcrest.Matchers.closeTo;
5858
import static org.hamcrest.Matchers.containsString;
@@ -1738,7 +1738,7 @@ private static void index(String name, String... docs) throws IOException {
17381738
}
17391739
request.setJsonEntity(bulk.toString());
17401740
Response response = client().performRequest(request);
1741-
Map<String, Object> result = entityToMapNoPartialCheck(response.getEntity(), XContentType.JSON);
1741+
Map<String, Object> result = entityToMap(response.getEntity(), XContentType.JSON);
17421742
assertMap(result, matchesMap().extraOk().entry("errors", false));
17431743
}
17441744

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RequestIndexFilteringTestCase.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import static org.elasticsearch.test.ListMatcher.matchesList;
3131
import static org.elasticsearch.test.MapMatcher.matchesMap;
32-
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.entityToMapNoPartialCheck;
32+
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.entityToMap;
3333
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.requestObjectBuilder;
3434
import static org.hamcrest.Matchers.allOf;
3535
import static org.hamcrest.Matchers.anyOf;
@@ -249,6 +249,11 @@ public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder request
249249
return RestEsqlTestCase.runEsql(requestObject, new AssertWarnings.NoWarnings(), RestEsqlTestCase.Mode.SYNC);
250250
}
251251

252+
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject, boolean checkPartialResults)
253+
throws IOException {
254+
return RestEsqlTestCase.runEsql(requestObject, new AssertWarnings.NoWarnings(), RestEsqlTestCase.Mode.SYNC, checkPartialResults);
255+
}
256+
252257
protected void indexTimestampData(int docs, String indexName, String date, String differentiatorFieldName) throws IOException {
253258
indexTimestampDataForClient(client(), docs, indexName, date, differentiatorFieldName);
254259
}
@@ -279,7 +284,7 @@ protected void indexTimestampDataForClient(RestClient client, int docs, String i
279284
}""".replace("%differentiator_field_name%", differentiatorFieldName));
280285
Response response = client.performRequest(createIndex);
281286
assertThat(
282-
entityToMapNoPartialCheck(response.getEntity(), XContentType.JSON),
287+
entityToMap(response.getEntity(), XContentType.JSON),
283288
matchesMap().entry("shards_acknowledged", true).entry("index", indexName).entry("acknowledged", true)
284289
);
285290

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,13 +1249,22 @@ public static Map<String, Object> runEsqlAsync(RequestObjectBuilder requestObjec
12491249
return runEsqlAsync(requestObject, randomBoolean(), new AssertWarnings.NoWarnings());
12501250
}
12511251

1252+
public static Map<String, Object> runEsql(
1253+
RequestObjectBuilder requestObject,
1254+
AssertWarnings assertWarnings,
1255+
Mode mode,
1256+
boolean checkPartialResults
1257+
)
1258+
throws IOException {
1259+
var results = mode == ASYNC
1260+
? runEsqlAsync(requestObject, randomBoolean(), assertWarnings)
1261+
: runEsqlSync(requestObject, assertWarnings);
1262+
return checkPartialResults ? assertNotPartial(results) : results;
1263+
}
1264+
12521265
public static Map<String, Object> runEsql(RequestObjectBuilder requestObject, AssertWarnings assertWarnings, Mode mode)
12531266
throws IOException {
1254-
if (mode == ASYNC) {
1255-
return runEsqlAsync(requestObject, randomBoolean(), assertWarnings);
1256-
} else {
1257-
return runEsqlSync(requestObject, assertWarnings);
1258-
}
1267+
return runEsql(requestObject, assertWarnings, mode, true);
12591268
}
12601269

12611270
public static Map<String, Object> runEsqlSync(RequestObjectBuilder requestObject, AssertWarnings assertWarnings) throws IOException {
@@ -1511,7 +1520,7 @@ static Map<String, Object> removeAsyncProperties(Map<String, Object> map) {
15111520
return Collections.unmodifiableMap(copy);
15121521
}
15131522

1514-
protected static Map<String, Object> entityToMapNoPartialCheck(HttpEntity entity, XContentType expectedContentType) throws IOException {
1523+
protected static Map<String, Object> entityToMap(HttpEntity entity, XContentType expectedContentType) throws IOException {
15151524
var result = EsqlTestUtils.entityToMap(entity, expectedContentType);
15161525
if (shouldLog()) {
15171526
LOGGER.info("entity={}", result);
@@ -1520,12 +1529,10 @@ protected static Map<String, Object> entityToMapNoPartialCheck(HttpEntity entity
15201529
return result;
15211530
}
15221531

1523-
/**
1524-
* Converts the entity to a map and asserts that this is not a partial response (`is_partial` field is absent or `false`).
1525-
* Use {@link #entityToMapNoPartialCheck} if you want to skip this check.
1526-
*/
1527-
protected static Map<String, Object> entityToMap(HttpEntity entity, XContentType expectedContentType) throws IOException {
1528-
return assertNotPartial(entityToMapNoPartialCheck(entity, expectedContentType));
1532+
protected static Map<String, Object> entityToMap(HttpEntity entity, XContentType expectedContentType, boolean allowPartialResults)
1533+
throws IOException {
1534+
var response = EsqlTestUtils.entityToMap(entity, expectedContentType);
1535+
return allowPartialResults ? response : assertNotPartial(response);
15291536
}
15301537

15311538
static void addAsyncParameters(RequestObjectBuilder requestObject, boolean keepOnCompletion) throws IOException {
@@ -1859,7 +1866,7 @@ protected void indexTimestampData(int shards) throws IOException {
18591866
}""".replace("%shards%", Integer.toString(shards)));
18601867
Response response = client().performRequest(createIndex);
18611868
assertThat(
1862-
entityToMapNoPartialCheck(response.getEntity(), XContentType.JSON),
1869+
entityToMap(response.getEntity(), XContentType.JSON),
18631870
matchesMap().entry("shards_acknowledged", true).entry("index", testIndexName()).entry("acknowledged", true)
18641871
);
18651872

0 commit comments

Comments
 (0)