Skip to content

Commit eccf7fa

Browse files
committed
Separate client and csv loading into 2 class rules
1 parent bbb51a5 commit eccf7fa

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

x-pack/plugin/esql/qa/server/mixed-cluster/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/mixed/MixedClusterEsqlSpecIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020

2121
public class MixedClusterEsqlSpecIT extends EsqlSpecTestCase {
2222
public static ElasticsearchCluster cluster = Clusters.mixedVersionCluster();
23-
public static CsvLoader loader = new CsvLoader(cluster);
23+
public static TestRuleRestClient client = new TestRuleRestClient(cluster);
24+
public static CsvLoader loader = new CsvLoader(client);
2425

2526
@ClassRule
26-
public static TestRule clusterRule = RuleChain.outerRule(cluster).around(loader);
27+
public static TestRule clusterRule = RuleChain.outerRule(cluster).around(client).around(loader);
2728

2829
@Override
2930
protected String getTestRestCluster() {

x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/EsqlSpecIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
public class EsqlSpecIT extends EsqlSpecTestCase {
1818
public static ElasticsearchCluster cluster = Clusters.testCluster();
19-
public static CsvLoader loader = new CsvLoader(cluster);
19+
public static TestRuleRestClient client = new TestRuleRestClient(cluster);
20+
public static CsvLoader loader = new CsvLoader(client);
2021

2122
@ClassRule
22-
public static TestRule clusterRule = RuleChain.outerRule(cluster).around(loader);
23+
public static TestRule clusterRule = RuleChain.outerRule(cluster).around(client).around(loader);
2324

2425
@Override
2526
protected String getTestRestCluster() {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
2121
public class EsqlSpecIT extends EsqlSpecTestCase {
2222
public static ElasticsearchCluster cluster = Clusters.testCluster();
23-
public static CsvLoader loader = new CsvLoader(cluster);
23+
public static TestRuleRestClient client = new TestRuleRestClient(cluster);
24+
public static CsvLoader loader = new CsvLoader(client);
2425

2526
@ClassRule
26-
public static TestRule clusterRule = RuleChain.outerRule(cluster).around(loader);
27+
public static TestRule clusterRule = RuleChain.outerRule(cluster).around(client).around(loader);
2728

2829
@Override
2930
protected String getTestRestCluster() {

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected boolean supportsAsync() {
109109
}
110110

111111
@AfterClass
112-
// TODO: This should become of a classrule for consistency.
112+
// TODO: This should become part of a classrule for consistency.
113113
public static void wipeTestData() throws IOException {
114114
try {
115115
adminClient().performRequest(new Request("DELETE", "/*"));
@@ -244,29 +244,50 @@ public static void assertRequestBreakerEmpty() throws Exception {
244244
}
245245

246246
public static class CsvLoader implements TestRule {
247-
private static final long CLIENT_TIMEOUT = 40L;
247+
TestRuleRestClient client;
248+
249+
public CsvLoader(TestRuleRestClient client) {
250+
this.client = client;
251+
}
252+
253+
@Override
254+
public Statement apply(Statement base, Description description) {
255+
return new Statement() {
256+
@Override
257+
public void evaluate() throws Throwable {
258+
loadDataSetIntoEs(client.client());
259+
base.evaluate();
260+
}
261+
};
262+
}
263+
}
248264

249-
ElasticsearchCluster cluster;
250-
Settings clientAuthSettings;
251-
RestClient client;
265+
public static class TestRuleRestClient implements TestRule {
266+
private static final long CLIENT_TIMEOUT = 40L;
267+
private ElasticsearchCluster cluster;
268+
private Settings clientAuthSettings;
269+
private RestClient client;
252270

253-
public CsvLoader(ElasticsearchCluster cluster, Settings clientAuthSettings) {
271+
public TestRuleRestClient(ElasticsearchCluster cluster, Settings clientAuthSettings) {
254272
this.cluster = cluster;
255273
this.clientAuthSettings = clientAuthSettings;
256274
}
257275

258-
public CsvLoader(ElasticsearchCluster cluster) {
276+
public TestRuleRestClient(ElasticsearchCluster cluster) {
259277
this(cluster, Settings.builder().build());
260278
}
261279

280+
public RestClient client() {
281+
return client;
282+
}
283+
262284
@Override
263285
public Statement apply(Statement base, Description description) {
264286
return new Statement() {
265287
@Override
266288
public void evaluate() throws Throwable {
267289
try {
268290
client = doStartClient();
269-
loadDataSetIntoEs(client);
270291
base.evaluate();
271292
} finally {
272293
IOUtils.close(client);

0 commit comments

Comments
 (0)