Skip to content

Commit a2e035e

Browse files
authored
Consolidate randomIncludeCCSMetadata to a single method (#119037)
1 parent 97e6bb6 commit a2e035e

File tree

8 files changed

+27
-58
lines changed

8 files changed

+27
-58
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/AbstractEnrichBasedCrossClusterTestCase.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.client.internal.node.NodeClient;
1515
import org.elasticsearch.common.settings.Settings;
1616
import org.elasticsearch.common.util.CollectionUtils;
17-
import org.elasticsearch.core.Tuple;
1817
import org.elasticsearch.ingest.common.IngestCommonPlugin;
1918
import org.elasticsearch.injection.guice.Inject;
2019
import org.elasticsearch.license.LicenseService;
@@ -244,15 +243,6 @@ protected EsqlQueryResponse runQuery(String query, Boolean ccsMetadataInResponse
244243
return client(LOCAL_CLUSTER).execute(EsqlQueryAction.INSTANCE, request).actionGet(30, TimeUnit.SECONDS);
245244
}
246245

247-
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
248-
return switch (randomIntBetween(1, 3)) {
249-
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
250-
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
251-
case 3 -> new Tuple<>(null, Boolean.FALSE);
252-
default -> throw new AssertionError("should not get here");
253-
};
254-
}
255-
256246
public static class LocalStateEnrich extends LocalStateCompositeXPackPlugin {
257247
public LocalStateEnrich(final Settings settings, final Path configPath) throws Exception {
258248
super(settings, configPath);

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/AbstractEsqlIntegTestCase.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.compute.data.BlockFactory;
2020
import org.elasticsearch.compute.operator.exchange.ExchangeService;
2121
import org.elasticsearch.core.TimeValue;
22+
import org.elasticsearch.core.Tuple;
2223
import org.elasticsearch.health.node.selection.HealthNode;
2324
import org.elasticsearch.index.query.QueryBuilder;
2425
import org.elasticsearch.indices.breaker.CircuitBreakerService;
@@ -233,4 +234,18 @@ protected static void assertValuesInAnyOrder(Iterator<Iterator<Object>> actualVa
233234
}
234235
assertThat(getValuesList(actualValues), containsInAnyOrder(items.toArray()));
235236
}
237+
238+
/**
239+
* v1: value to send to runQuery (can be null; null means use default value)
240+
* v2: whether to expect CCS Metadata in the response (cannot be null)
241+
* @return
242+
*/
243+
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
244+
return switch (randomIntBetween(1, 3)) {
245+
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
246+
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
247+
case 3 -> new Tuple<>(null, Boolean.FALSE);
248+
default -> throw new AssertionError("should not get here");
249+
};
250+
}
236251
}

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterAsyncQueryIT.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import static org.elasticsearch.core.TimeValue.timeValueMillis;
4545
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
46+
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
4647
import static org.hamcrest.Matchers.equalTo;
4748
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4849
import static org.hamcrest.Matchers.is;
@@ -355,20 +356,6 @@ private static void assertClusterMetadataInResponse(EsqlQueryResponse resp, bool
355356
}
356357
}
357358

358-
/**
359-
* v1: value to send to runQuery (can be null; null means use default value)
360-
* v2: whether to expect CCS Metadata in the response (cannot be null)
361-
* @return
362-
*/
363-
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
364-
return switch (randomIntBetween(1, 3)) {
365-
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
366-
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
367-
case 3 -> new Tuple<>(null, Boolean.FALSE);
368-
default -> throw new AssertionError("should not get here");
369-
};
370-
}
371-
372359
Map<String, Object> setupClusters(int numClusters) throws IOException {
373360
assert numClusters == 2 || numClusters == 3 : "2 or 3 clusters supported not: " + numClusters;
374361
int numShardsLocal = randomIntBetween(1, 5);

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterEnrichUnavailableClustersIT.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Set;
2424

2525
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
26+
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
2627
import static org.hamcrest.Matchers.equalTo;
2728
import static org.hamcrest.Matchers.greaterThan;
2829
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -60,7 +61,7 @@ public void testEnrichWithHostsPolicyAndDisconnectedRemotesWithSkipUnavailableTr
6061
// close remote-cluster-1 so that it is unavailable
6162
cluster(REMOTE_CLUSTER_1).close();
6263

63-
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
64+
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
6465
Boolean requestIncludeMeta = includeCCSMetadata.v1();
6566
boolean responseExpectMeta = includeCCSMetadata.v2();
6667

@@ -142,7 +143,7 @@ public void testEnrichWithHostsPolicyAndDisconnectedRemotesWithSkipUnavailableFa
142143
// close remote-cluster-1 so that it is unavailable
143144
cluster(REMOTE_CLUSTER_1).close();
144145

145-
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
146+
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
146147
Boolean requestIncludeMeta = includeCCSMetadata.v1();
147148
boolean responseExpectMeta = includeCCSMetadata.v2();
148149

@@ -188,7 +189,7 @@ public void testEnrichWithHostsPolicyAndDisconnectedRemotesWithSkipUnavailableFa
188189
}
189190

190191
public void testEnrichTwiceThenAggsWithUnavailableRemotes() throws IOException {
191-
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
192+
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
192193
Boolean requestIncludeMeta = includeCCSMetadata.v1();
193194
boolean responseExpectMeta = includeCCSMetadata.v2();
194195

@@ -292,7 +293,7 @@ public void testEnrichTwiceThenAggsWithUnavailableRemotes() throws IOException {
292293
}
293294

294295
public void testEnrichCoordinatorThenAnyWithSingleUnavailableRemoteAndLocal() throws IOException {
295-
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
296+
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
296297
Boolean requestIncludeMeta = includeCCSMetadata.v1();
297298
boolean responseExpectMeta = includeCCSMetadata.v2();
298299

@@ -345,7 +346,7 @@ public void testEnrichCoordinatorThenAnyWithSingleUnavailableRemoteAndLocal() th
345346
}
346347

347348
public void testEnrichCoordinatorThenAnyWithSingleUnavailableRemoteAndNotLocal() throws IOException {
348-
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
349+
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
349350
Boolean requestIncludeMeta = includeCCSMetadata.v1();
350351
boolean responseExpectMeta = includeCCSMetadata.v2();
351352

@@ -394,7 +395,7 @@ public void testEnrichCoordinatorThenAnyWithSingleUnavailableRemoteAndNotLocal()
394395
}
395396

396397
public void testEnrichRemoteWithVendor() throws IOException {
397-
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
398+
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
398399
Boolean requestIncludeMeta = includeCCSMetadata.v1();
399400
boolean responseExpectMeta = includeCCSMetadata.v2();
400401

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterQueryUnavailableRemotesIT.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3232
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
33+
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
3334
import static org.hamcrest.Matchers.equalTo;
3435
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3536
import static org.hamcrest.Matchers.hasSize;
@@ -452,20 +453,6 @@ protected EsqlQueryResponse runQuery(EsqlQueryRequest request) {
452453
return client(LOCAL_CLUSTER).execute(EsqlQueryAction.INSTANCE, request).actionGet(30, TimeUnit.SECONDS);
453454
}
454455

455-
/**
456-
* v1: value to send to runQuery (can be null; null means use default value)
457-
* v2: whether to expect CCS Metadata in the response (cannot be null)
458-
* @return
459-
*/
460-
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
461-
return switch (randomIntBetween(1, 3)) {
462-
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
463-
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
464-
case 3 -> new Tuple<>(null, Boolean.FALSE);
465-
default -> throw new AssertionError("should not get here");
466-
};
467-
}
468-
469456
Map<String, Object> setupClusters(int numClusters) {
470457
assert numClusters == 2 || numClusters == 3 : "2 or 3 clusters supported not: " + numClusters;
471458
String localIndex = "logs-1";

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClustersEnrichIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.stream.Collectors;
2323

2424
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
25+
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
2526
import static org.hamcrest.Matchers.containsString;
2627
import static org.hamcrest.Matchers.equalTo;
2728
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClustersQueriesWithInvalidLicenseIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Set;
2121

2222
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
23+
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
2324
import static org.hamcrest.Matchers.containsString;
2425
import static org.hamcrest.Matchers.equalTo;
2526
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClustersQueryIT.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5050
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
51+
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
5152
import static org.hamcrest.Matchers.containsString;
5253
import static org.hamcrest.Matchers.equalTo;
5354
import static org.hamcrest.Matchers.greaterThan;
@@ -1251,20 +1252,6 @@ protected EsqlQueryResponse runQuery(EsqlQueryRequest request) {
12511252
return client(LOCAL_CLUSTER).execute(EsqlQueryAction.INSTANCE, request).actionGet(30, TimeUnit.SECONDS);
12521253
}
12531254

1254-
/**
1255-
* v1: value to send to runQuery (can be null; null means use default value)
1256-
* v2: whether to expect CCS Metadata in the response (cannot be null)
1257-
* @return
1258-
*/
1259-
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
1260-
return switch (randomIntBetween(1, 3)) {
1261-
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
1262-
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
1263-
case 3 -> new Tuple<>(null, Boolean.FALSE);
1264-
default -> throw new AssertionError("should not get here");
1265-
};
1266-
}
1267-
12681255
void waitForNoInitializingShards(Client client, TimeValue timeout, String... indices) {
12691256
ClusterHealthResponse resp = client.admin()
12701257
.cluster()

0 commit comments

Comments
 (0)