Skip to content

Commit

Permalink
Avoid spawn new nodes in EsqlActionIT (elastic#102363) (elastic#102384)
Browse files Browse the repository at this point in the history
We don't need to launch new nodes in these tests if we already
have at least two data nodes.
  • Loading branch information
dnhatn authored Nov 20, 2023
1 parent b640348 commit 26ebf63
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
Expand Down Expand Up @@ -1235,8 +1236,15 @@ public void testFilterNestedFields() {
}

public void testStatsNestFields() {
String node1 = internalCluster().startDataOnlyNode();
String node2 = internalCluster().startDataOnlyNode();
final String node1, node2;
if (randomBoolean()) {
internalCluster().ensureAtLeastNumDataNodes(2);
node1 = randomDataNode().getName();
node2 = randomValueOtherThan(node1, () -> randomDataNode().getName());
} else {
node1 = randomDataNode().getName();
node2 = randomDataNode().getName();
}
assertAcked(
client().admin()
.indices()
Expand Down Expand Up @@ -1269,8 +1277,15 @@ public void testStatsNestFields() {
}

public void testStatsMissingFields() {
String node1 = internalCluster().startDataOnlyNode();
String node2 = internalCluster().startDataOnlyNode();
final String node1, node2;
if (randomBoolean()) {
internalCluster().ensureAtLeastNumDataNodes(2);
node1 = randomDataNode().getName();
node2 = randomValueOtherThan(node1, () -> randomDataNode().getName());
} else {
node1 = randomDataNode().getName();
node2 = randomDataNode().getName();
}
assertAcked(
client().admin()
.indices()
Expand All @@ -1285,7 +1300,6 @@ public void testStatsMissingFields() {
.setSettings(Settings.builder().put("index.routing.allocation.require._name", node2))
.setMapping("bar_int", "type=integer", "bar_long", "type=long", "bar_float", "type=float", "bar_double", "type=double")
);

var fields = List.of("foo_int", "foo_long", "foo_float", "foo_double");
var functions = List.of("sum", "count", "avg", "count_distinct");
for (String field : fields) {
Expand Down Expand Up @@ -1505,4 +1519,8 @@ private void clearPersistentSettings(Setting<?>... settings) {
var clearSettingsRequest = new ClusterUpdateSettingsRequest().persistentSettings(clearedSettings.build());
admin().cluster().updateSettings(clearSettingsRequest).actionGet();
}

private DiscoveryNode randomDataNode() {
return randomFrom(clusterService().state().nodes().getDataNodes().values());
}
}

0 comments on commit 26ebf63

Please sign in to comment.