Skip to content

Commit

Permalink
Consolidate randomIncludeCCSMetadata to a single method (#119037)
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev authored Dec 19, 2024
1 parent 97e6bb6 commit a2e035e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.ingest.common.IngestCommonPlugin;
import org.elasticsearch.injection.guice.Inject;
import org.elasticsearch.license.LicenseService;
Expand Down Expand Up @@ -244,15 +243,6 @@ protected EsqlQueryResponse runQuery(String query, Boolean ccsMetadataInResponse
return client(LOCAL_CLUSTER).execute(EsqlQueryAction.INSTANCE, request).actionGet(30, TimeUnit.SECONDS);
}

public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
return switch (randomIntBetween(1, 3)) {
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
case 3 -> new Tuple<>(null, Boolean.FALSE);
default -> throw new AssertionError("should not get here");
};
}

public static class LocalStateEnrich extends LocalStateCompositeXPackPlugin {
public LocalStateEnrich(final Settings settings, final Path configPath) throws Exception {
super(settings, configPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.compute.data.BlockFactory;
import org.elasticsearch.compute.operator.exchange.ExchangeService;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.health.node.selection.HealthNode;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
Expand Down Expand Up @@ -233,4 +234,18 @@ protected static void assertValuesInAnyOrder(Iterator<Iterator<Object>> actualVa
}
assertThat(getValuesList(actualValues), containsInAnyOrder(items.toArray()));
}

/**
* v1: value to send to runQuery (can be null; null means use default value)
* v2: whether to expect CCS Metadata in the response (cannot be null)
* @return
*/
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
return switch (randomIntBetween(1, 3)) {
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
case 3 -> new Tuple<>(null, Boolean.FALSE);
default -> throw new AssertionError("should not get here");
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import static org.elasticsearch.core.TimeValue.timeValueMillis;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -355,20 +356,6 @@ private static void assertClusterMetadataInResponse(EsqlQueryResponse resp, bool
}
}

/**
* v1: value to send to runQuery (can be null; null means use default value)
* v2: whether to expect CCS Metadata in the response (cannot be null)
* @return
*/
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
return switch (randomIntBetween(1, 3)) {
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
case 3 -> new Tuple<>(null, Boolean.FALSE);
default -> throw new AssertionError("should not get here");
};
}

Map<String, Object> setupClusters(int numClusters) throws IOException {
assert numClusters == 2 || numClusters == 3 : "2 or 3 clusters supported not: " + numClusters;
int numShardsLocal = randomIntBetween(1, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;

import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void testEnrichWithHostsPolicyAndDisconnectedRemotesWithSkipUnavailableTr
// close remote-cluster-1 so that it is unavailable
cluster(REMOTE_CLUSTER_1).close();

Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
Boolean requestIncludeMeta = includeCCSMetadata.v1();
boolean responseExpectMeta = includeCCSMetadata.v2();

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

Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
Boolean requestIncludeMeta = includeCCSMetadata.v1();
boolean responseExpectMeta = includeCCSMetadata.v2();

Expand Down Expand Up @@ -188,7 +189,7 @@ public void testEnrichWithHostsPolicyAndDisconnectedRemotesWithSkipUnavailableFa
}

public void testEnrichTwiceThenAggsWithUnavailableRemotes() throws IOException {
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
Boolean requestIncludeMeta = includeCCSMetadata.v1();
boolean responseExpectMeta = includeCCSMetadata.v2();

Expand Down Expand Up @@ -292,7 +293,7 @@ public void testEnrichTwiceThenAggsWithUnavailableRemotes() throws IOException {
}

public void testEnrichCoordinatorThenAnyWithSingleUnavailableRemoteAndLocal() throws IOException {
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
Boolean requestIncludeMeta = includeCCSMetadata.v1();
boolean responseExpectMeta = includeCCSMetadata.v2();

Expand Down Expand Up @@ -345,7 +346,7 @@ public void testEnrichCoordinatorThenAnyWithSingleUnavailableRemoteAndLocal() th
}

public void testEnrichCoordinatorThenAnyWithSingleUnavailableRemoteAndNotLocal() throws IOException {
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
Boolean requestIncludeMeta = includeCCSMetadata.v1();
boolean responseExpectMeta = includeCCSMetadata.v2();

Expand Down Expand Up @@ -394,7 +395,7 @@ public void testEnrichCoordinatorThenAnyWithSingleUnavailableRemoteAndNotLocal()
}

public void testEnrichRemoteWithVendor() throws IOException {
Tuple<Boolean, Boolean> includeCCSMetadata = CrossClustersEnrichIT.randomIncludeCCSMetadata();
Tuple<Boolean, Boolean> includeCCSMetadata = randomIncludeCCSMetadata();
Boolean requestIncludeMeta = includeCCSMetadata.v1();
boolean responseExpectMeta = includeCCSMetadata.v2();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

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

/**
* v1: value to send to runQuery (can be null; null means use default value)
* v2: whether to expect CCS Metadata in the response (cannot be null)
* @return
*/
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
return switch (randomIntBetween(1, 3)) {
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
case 3 -> new Tuple<>(null, Boolean.FALSE);
default -> throw new AssertionError("should not get here");
};
}

Map<String, Object> setupClusters(int numClusters) {
assert numClusters == 2 || numClusters == 3 : "2 or 3 clusters supported not: " + numClusters;
String localIndex = "logs-1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.stream.Collectors;

import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Set;

import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
import static org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase.randomIncludeCCSMetadata;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

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

/**
* v1: value to send to runQuery (can be null; null means use default value)
* v2: whether to expect CCS Metadata in the response (cannot be null)
* @return
*/
public static Tuple<Boolean, Boolean> randomIncludeCCSMetadata() {
return switch (randomIntBetween(1, 3)) {
case 1 -> new Tuple<>(Boolean.TRUE, Boolean.TRUE);
case 2 -> new Tuple<>(Boolean.FALSE, Boolean.FALSE);
case 3 -> new Tuple<>(null, Boolean.FALSE);
default -> throw new AssertionError("should not get here");
};
}

void waitForNoInitializingShards(Client client, TimeValue timeout, String... indices) {
ClusterHealthResponse resp = client.admin()
.cluster()
Expand Down

0 comments on commit a2e035e

Please sign in to comment.