Skip to content

Commit f890805

Browse files
authored
Simplify CsvTestsDataLoader (#142717)
1 parent e7fdbba commit f890805

File tree

9 files changed

+247
-449
lines changed

9 files changed

+247
-449
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
import java.util.Locale;
4242
import java.util.Set;
4343
import java.util.regex.Pattern;
44-
import java.util.stream.Collectors;
4544

45+
import static java.util.stream.Collectors.toSet;
4646
import static org.elasticsearch.xpack.esql.CsvSpecReader.specParser;
4747
import static org.elasticsearch.xpack.esql.CsvTestUtils.isEnabled;
4848
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.CSV_DATASET_MAP;
49-
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.ENRICH_SOURCE_INDICES;
49+
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.ENRICH_POLICIES;
5050
import static org.elasticsearch.xpack.esql.EsqlTestUtils.classpathResources;
5151
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.COMPLETION;
5252
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.ENABLE_FORK_FOR_REMOTE_INDICES_V2;
@@ -266,13 +266,11 @@ protected RestClient buildClient(Settings settings, HttpHost[] localHosts) throw
266266
.stream()
267267
.filter(td -> td.settingFileName() != null && td.settingFileName().equals("lookup-settings.json"))
268268
.map(CsvTestsDataLoader.TestDataset::indexName)
269-
.collect(Collectors.toSet());
269+
.collect(toSet());
270270

271-
public static final Set<String> LOOKUP_ENDPOINTS = LOOKUP_INDICES.stream().map(i -> "/" + i + "/_bulk").collect(Collectors.toSet());
271+
public static final Set<String> LOOKUP_ENDPOINTS = LOOKUP_INDICES.stream().map(i -> "/" + i + "/_bulk").collect(toSet());
272272

273-
public static final Set<String> ENRICH_ENDPOINTS = ENRICH_SOURCE_INDICES.stream()
274-
.map(i -> "/" + i + "/_bulk")
275-
.collect(Collectors.toSet());
273+
public static final Set<String> ENRICH_ENDPOINTS = ENRICH_POLICIES.stream().map(p -> "/" + p.index() + "/_bulk").collect(toSet());
276274

277275
/**
278276
* Creates a new mock client that dispatches every request to both the local and remote clusters, excluding _bulk, _query,
@@ -357,7 +355,8 @@ static CsvSpecReader.CsvTestCase convertToRemoteIndices(CsvSpecReader.CsvTestCas
357355
boolean onlyRemotes = canUseRemoteIndicesOnly() && randomBoolean();
358356
// Check if query contains enrich source indices - these are loaded into both clusters,
359357
// so we should use onlyRemotes=true to avoid duplicates
360-
if (onlyRemotes == false && EsqlTestUtils.queryContainsIndices(query, Set.copyOf(ENRICH_SOURCE_INDICES))) {
358+
var enrichSourceIndices = ENRICH_POLICIES.stream().map(CsvTestsDataLoader.EnrichConfig::index).collect(toSet());
359+
if (onlyRemotes == false && EsqlTestUtils.queryContainsIndices(query, enrichSourceIndices)) {
361360
onlyRemotes = true;
362361
}
363362
testCase.query = EsqlTestUtils.addRemoteIndices(testCase.query, LOOKUP_INDICES, onlyRemotes);

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,16 @@ private void setupIndex() throws IOException {
137137
}
138138

139139
private void setupInferenceEndpoints() throws IOException {
140-
CsvTestsDataLoader.createTextEmbeddingInferenceEndpoint(client());
141-
CsvTestsDataLoader.createSparseEmbeddingInferenceEndpoint(client());
140+
CsvTestsDataLoader.createInferenceEndpoint(client(), CsvTestsDataLoader.INFERENCE_CONFIGS.get("test_dense_inference"));
141+
CsvTestsDataLoader.createInferenceEndpoint(client(), CsvTestsDataLoader.INFERENCE_CONFIGS.get("test_sparse_inference"));
142142
}
143143

144144
@After
145145
public void tearDown() throws Exception {
146146
super.tearDown();
147147
client().performRequest(new Request("DELETE", "semantic-test"));
148-
149-
if (CsvTestsDataLoader.clusterHasTextEmbeddingInferenceEndpoint(client())) {
150-
CsvTestsDataLoader.deleteTextEmbeddingInferenceEndpoint(client());
151-
}
152-
if (CsvTestsDataLoader.clusterHasSparseEmbeddingInferenceEndpoint(client())) {
153-
CsvTestsDataLoader.deleteSparseEmbeddingInferenceEndpoint(client());
154-
}
148+
CsvTestsDataLoader.deleteInferenceEndpoint(client(), "test_dense_inference");
149+
CsvTestsDataLoader.deleteInferenceEndpoint(client(), "test_sparse_inference");
155150
}
156151

157152
private Map<String, Object> runEsqlQuery(String query) throws IOException {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.client.ResponseException;
1212
import org.elasticsearch.test.rest.ESRestTestCase;
1313
import org.elasticsearch.xpack.esql.AssertWarnings;
14+
import org.elasticsearch.xpack.esql.CsvTestsDataLoader;
1415
import org.junit.After;
1516
import org.junit.Before;
1617
import org.junit.Rule;
@@ -19,8 +20,6 @@
1920
import java.util.List;
2021
import java.util.Map;
2122

22-
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.createRerankInferenceEndpoint;
23-
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.deleteRerankInferenceEndpoint;
2423
import static org.hamcrest.core.StringContains.containsString;
2524

2625
public class RestRerankTestCase extends ESRestTestCase {
@@ -36,7 +35,7 @@ public void assertRequestBreakerEmpty() throws Exception {
3635

3736
@Before
3837
public void setUpInferenceEndpoint() throws IOException {
39-
createRerankInferenceEndpoint(adminClient());
38+
CsvTestsDataLoader.createInferenceEndpoint(adminClient(), CsvTestsDataLoader.INFERENCE_CONFIGS.get("test_reranker"));
4039
}
4140

4241
@Before
@@ -77,7 +76,7 @@ public void wipeData() throws IOException {
7776
}
7877
}
7978

80-
deleteRerankInferenceEndpoint(adminClient());
79+
CsvTestsDataLoader.deleteInferenceEndpoint(adminClient(), "test_reranker");
8180
}
8281

8382
public void testRerankWithSingleField() throws IOException {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ private static List<String> originalTypes(Map<String, ?> x) {
433433

434434
private List<String> availableIndices() throws IOException {
435435
return availableDatasetsForEs(true, supportsSourceFieldMapping(), false, requiresTimeSeries(), cap -> false).stream()
436-
.filter(x -> x.requiresInferenceEndpoint() == false)
436+
.filter(x -> x.inferenceEndpoints().isEmpty())
437437
.map(x -> x.indexName())
438438
.toList();
439439
}

0 commit comments

Comments
 (0)