Skip to content

Commit fdd3812

Browse files
authored
Add metadata checking to RequestIndexFilteringIT (#122322) (#122416)
(cherry picked from commit 2c846e7) # Conflicts: # x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/RequestIndexFilteringIT.java
1 parent a72650e commit fdd3812

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838

3939
import static org.elasticsearch.test.MapMatcher.assertMap;
4040
import static org.elasticsearch.xpack.esql.ccq.Clusters.REMOTE_CLUSTER_NAME;
41-
import static org.hamcrest.Matchers.*;
41+
import static org.hamcrest.Matchers.any;
42+
import static org.hamcrest.Matchers.equalTo;
43+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
44+
import static org.hamcrest.Matchers.hasKey;
4245

4346
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
4447
public class MultiClustersIT extends ESRestTestCase {

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

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
import org.elasticsearch.client.ResponseException;
1616
import org.elasticsearch.client.RestClient;
1717
import org.elasticsearch.core.IOUtils;
18+
import org.elasticsearch.test.MapMatcher;
1819
import org.elasticsearch.test.TestClustersThreadFilter;
1920
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2021
import org.elasticsearch.xpack.esql.qa.rest.RequestIndexFilteringTestCase;
22+
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
23+
import org.hamcrest.Matcher;
2124
import org.junit.After;
2225
import org.junit.AfterClass;
2326
import org.junit.Before;
@@ -27,6 +30,12 @@
2730
import org.junit.rules.TestRule;
2831

2932
import java.io.IOException;
33+
import java.util.Map;
34+
35+
import static org.elasticsearch.test.MapMatcher.assertMap;
36+
import static org.elasticsearch.test.MapMatcher.matchesMap;
37+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
38+
import static org.hamcrest.Matchers.instanceOf;
3039

3140
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
3241
public class RequestIndexFilteringIT extends RequestIndexFilteringTestCase {
@@ -51,6 +60,8 @@ public void setRemoteClient() throws IOException {
5160
}
5261
}
5362

63+
private boolean isCCSRequest;
64+
5465
@BeforeClass
5566
public static void checkVersion() {
5667
assumeTrue("skip if version before 8.18", Clusters.localClusterVersion().onOrAfter(Version.V_8_18_0));
@@ -73,13 +84,20 @@ protected void indexTimestampData(int docs, String indexName, String date, Strin
7384

7485
@Override
7586
protected String from(String... indexName) {
76-
if (randomBoolean()) {
87+
isCCSRequest = randomBoolean();
88+
if (isCCSRequest) {
7789
return "FROM *:" + String.join(",*:", indexName);
7890
} else {
7991
return "FROM " + String.join(",", indexName);
8092
}
8193
}
8294

95+
@Override
96+
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException {
97+
requestObject.includeCCSMetadata(true);
98+
return super.runEsql(requestObject);
99+
}
100+
83101
@After
84102
public void wipeRemoteTestData() throws IOException {
85103
try {
@@ -89,4 +107,35 @@ public void wipeRemoteTestData() throws IOException {
89107
assertEquals(404, re.getResponse().getStatusLine().getStatusCode());
90108
}
91109
}
110+
111+
private MapMatcher getClustersMetadataMatcher() {
112+
MapMatcher mapMatcher = matchesMap();
113+
mapMatcher = mapMatcher.entry("running", 0);
114+
mapMatcher = mapMatcher.entry("total", 1);
115+
mapMatcher = mapMatcher.entry("failed", 0);
116+
mapMatcher = mapMatcher.entry("partial", 0);
117+
mapMatcher = mapMatcher.entry("successful", 1);
118+
mapMatcher = mapMatcher.entry("skipped", 0);
119+
mapMatcher = mapMatcher.entry(
120+
"details",
121+
matchesMap().entry(
122+
Clusters.REMOTE_CLUSTER_NAME,
123+
matchesMap().entry("_shards", matchesMap().extraOk())
124+
.entry("took", greaterThanOrEqualTo(0))
125+
.entry("indices", instanceOf(String.class))
126+
.entry("status", "successful")
127+
)
128+
);
129+
return mapMatcher;
130+
}
131+
132+
@Override
133+
protected void assertQueryResult(Map<String, Object> result, Matcher<?> columnMatcher, Matcher<?> valuesMatcher) {
134+
var matcher = getResultMatcher(result).entry("columns", columnMatcher).entry("values", valuesMatcher);
135+
if (isCCSRequest) {
136+
matcher = matcher.entry("_clusters", getClustersMetadataMatcher());
137+
}
138+
assertMap(result, matcher);
139+
}
140+
92141
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.xcontent.XContentType;
1818
import org.elasticsearch.xpack.esql.AssertWarnings;
1919
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
20+
import org.hamcrest.Matcher;
2021
import org.junit.After;
2122
import org.junit.Assert;
2223

@@ -62,7 +63,7 @@ public void testTimestampFilterFromQuery() throws IOException {
6263

6364
// filter includes both indices in the result (all columns, all rows)
6465
RestEsqlTestCase.RequestObjectBuilder builder = timestampFilter("gte", "2023-01-01").query(from("test*"));
65-
assertResultMap(
66+
assertQueryResult(
6667
runEsql(builder),
6768
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date"))
6869
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
@@ -73,7 +74,7 @@ public void testTimestampFilterFromQuery() throws IOException {
7374

7475
// filter includes only test1. Columns from test2 are filtered out, as well (not only rows)!
7576
builder = timestampFilter("gte", "2024-01-01").query(from("test*"));
76-
assertResultMap(
77+
assertQueryResult(
7778
runEsql(builder),
7879
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date"))
7980
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
@@ -84,7 +85,7 @@ public void testTimestampFilterFromQuery() throws IOException {
8485
// filter excludes both indices (no rows); the first analysis step fails because there are no columns, a second attempt succeeds
8586
// after eliminating the index filter. All columns are returned.
8687
builder = timestampFilter("gte", "2025-01-01").query(from("test*"));
87-
assertResultMap(
88+
assertQueryResult(
8889
runEsql(builder),
8990
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date"))
9091
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
@@ -102,7 +103,7 @@ public void testFieldExistsFilter_KeepWildcard() throws IOException {
102103

103104
// filter includes only test1. Columns and rows of test2 are filtered out
104105
RestEsqlTestCase.RequestObjectBuilder builder = existsFilter("id1").query(from("test*"));
105-
assertResultMap(
106+
assertQueryResult(
106107
runEsql(builder),
107108
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date"))
108109
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
@@ -113,7 +114,7 @@ public void testFieldExistsFilter_KeepWildcard() throws IOException {
113114
// filter includes only test1. Columns from test2 are filtered out, as well (not only rows)!
114115
builder = existsFilter("id1").query(from("test*") + " METADATA _index | KEEP _index, id*");
115116
Map<String, Object> result = runEsql(builder);
116-
assertResultMap(
117+
assertQueryResult(
117118
result,
118119
matchesList().item(matchesMap().entry("name", "_index").entry("type", "keyword"))
119120
.item(matchesMap().entry("name", "id1").entry("type", "integer")),
@@ -138,7 +139,7 @@ public void testFieldExistsFilter_With_ExplicitUseOfDiscardedIndexFields() throw
138139
from("test*") + " METADATA _index | SORT id2 | KEEP _index, id*"
139140
);
140141
Map<String, Object> result = runEsql(builder);
141-
assertResultMap(
142+
assertQueryResult(
142143
result,
143144
matchesList().item(matchesMap().entry("name", "_index").entry("type", "keyword"))
144145
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
@@ -298,4 +299,9 @@ protected void indexTimestampDataForClient(RestClient client, int docs, String i
298299
Assert.assertEquals("{\"errors\":false}", EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
299300
}
300301
}
302+
303+
protected void assertQueryResult(Map<String, Object> result, Matcher<?> columnMatcher, Matcher<?> valuesMatcher) {
304+
assertResultMap(result, columnMatcher, valuesMatcher);
305+
}
306+
301307
}

0 commit comments

Comments
 (0)