Skip to content

Commit c72d00f

Browse files
authored
Don't start a new node in InternalTestCluster#getClient (#127318)
This method would default to starting a new node when the cluster was empty. This is pretty trappy as `getClient()` (or things like `getMaster()` that depend on `getClient()`) don't look at all like something that would start a new node. In any case, the intention of tests is much clearer when they explicitly define a cluster configuration.
1 parent 15b6e85 commit c72d00f

File tree

47 files changed

+91
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+91
-72
lines changed

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/IngestFailureStoreMetricsIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
/**
5858
* An integration test that verifies how different paths/scenarios affect the APM metrics for failure stores.
5959
*/
60-
@ESIntegTestCase.ClusterScope(numDataNodes = 0, numClientNodes = 0, scope = ESIntegTestCase.Scope.SUITE)
60+
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1, numClientNodes = 0, supportsDedicatedMasters = false)
6161
public class IngestFailureStoreMetricsIT extends ESIntegTestCase {
6262

6363
private static final List<String> METRICS = List.of(

qa/smoke-test-http/src/internalClusterTest/java/org/elasticsearch/http/snapshots/AbstractSnapshotRestTestCase.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
import org.elasticsearch.http.HttpSmokeTestCase;
1515
import org.elasticsearch.plugins.Plugin;
1616
import org.elasticsearch.snapshots.mockstore.MockRepository;
17-
import org.elasticsearch.test.ESIntegTestCase;
1817

1918
import java.util.Collection;
2019

21-
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0)
2220
public abstract class AbstractSnapshotRestTestCase extends HttpSmokeTestCase {
2321

2422
/**

qa/smoke-test-http/src/internalClusterTest/java/org/elasticsearch/http/snapshots/RestGetSnapshotsCancellationIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.client.Response;
1818
import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase;
1919
import org.elasticsearch.snapshots.mockstore.MockRepository;
20+
import org.elasticsearch.test.ESIntegTestCase;
2021

2122
import java.util.concurrent.CancellationException;
2223
import java.util.concurrent.TimeUnit;
@@ -27,6 +28,7 @@
2728
import static org.elasticsearch.test.TaskAssertions.awaitTaskWithPrefix;
2829
import static org.hamcrest.core.IsEqual.equalTo;
2930

31+
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0)
3032
public class RestGetSnapshotsCancellationIT extends AbstractSnapshotRestTestCase {
3133

3234
public void testGetSnapshotsCancellation() throws Exception {

qa/smoke-test-http/src/internalClusterTest/java/org/elasticsearch/http/snapshots/RestSnapshotsStatusCancellationIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.client.Response;
1818
import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase;
1919
import org.elasticsearch.snapshots.mockstore.MockRepository;
20+
import org.elasticsearch.test.ESIntegTestCase;
2021

2122
import java.util.Collection;
2223
import java.util.concurrent.CancellationException;
@@ -27,6 +28,7 @@
2728
import static org.elasticsearch.test.TaskAssertions.assertAllTasksHaveFinished;
2829
import static org.elasticsearch.test.TaskAssertions.awaitTaskWithPrefix;
2930

31+
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0)
3032
public class RestSnapshotsStatusCancellationIT extends AbstractSnapshotRestTestCase {
3133

3234
public void testSnapshotStatusCancellation() throws Exception {

server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/AutoCreateSystemIndexIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import static org.hamcrest.Matchers.is;
5151
import static org.hamcrest.Matchers.notNullValue;
5252

53-
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0)
5453
public class AutoCreateSystemIndexIT extends ESIntegTestCase {
5554

5655
@Override

server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/CreateSystemIndicesIT.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import static org.hamcrest.Matchers.is;
5757
import static org.hamcrest.Matchers.nullValue;
5858

59-
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0)
6059
public class CreateSystemIndicesIT extends ESIntegTestCase {
6160

6261
@Before
@@ -104,7 +103,6 @@ public void testSystemIndexIsAutoCreatedViaConcreteName() {
104103
*/
105104
public void testNonPrimarySystemIndexIsAutoCreatedViaConcreteName() throws Exception {
106105
final String nonPrimarySystemIndex = INDEX_NAME + "-2";
107-
internalCluster().startNodes(1);
108106

109107
// Trigger the creation of the system index
110108
indexDoc(nonPrimarySystemIndex, "1", "foo", "bar");
@@ -132,7 +130,6 @@ public void testNonPrimarySystemIndexIsAutoCreatedViaConcreteName() throws Excep
132130
*/
133131
public void testNonPrimarySystemIndexCreationThrowsError() {
134132
final String nonPrimarySystemIndex = INDEX_NAME + "-2";
135-
internalCluster().startNodes(1);
136133

137134
// Create the system index
138135
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createIndex(nonPrimarySystemIndex));
@@ -269,8 +266,6 @@ public void testCreateSystemAliasViaComposableTemplateWithAllowsTemplates() thro
269266
}
270267

271268
private void doCreateTest(Runnable runnable, String concreteIndex) {
272-
internalCluster().startNodes(1);
273-
274269
// Trigger the creation of the system index
275270
runnable.run();
276271
ensureGreen(INDEX_NAME);
@@ -293,8 +288,6 @@ private void doCreateTest(Runnable runnable, String concreteIndex) {
293288
}
294289

295290
public void testConcurrentAutoCreates() throws InterruptedException {
296-
internalCluster().startNodes(3);
297-
298291
final Client client = client();
299292
final int count = randomIntBetween(5, 30);
300293
final CountDownLatch latch = new CountDownLatch(count);

server/src/internalClusterTest/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void testBulkProcessorAutoCreateRestrictions() {
5151
}
5252

5353
public void testIndexWithDisabledAutoCreateIndex() {
54+
internalCluster().startNode();
5455
updateClusterSettings(Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), randomFrom("-*", "+.*")));
5556
final BulkItemResponse itemResponse = client().prepareBulk()
5657
.add(prepareIndex("test-index").setSource("foo", "bar"))

server/src/internalClusterTest/java/org/elasticsearch/cluster/allocation/AwarenessAllocationIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public void testAwarenessZonesIncrementalNodes() {
251251
}
252252

253253
public void testForceAwarenessSettingValidation() {
254+
internalCluster().startNode();
254255
final String prefix = AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey();
255256

256257
final IllegalArgumentException illegalArgumentException = expectThrows(

server/src/internalClusterTest/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ public void testDisablingAllocationFiltering() {
186186
}
187187

188188
public void testInvalidIPFilterClusterSettings() {
189+
logger.info("--> starting 2 nodes");
190+
internalCluster().startNodes(2);
189191
String ipKey = randomFrom("_ip", "_host_ip", "_publish_ip");
190192
var filterSetting = randomFrom(
191193
FilterAllocationDecider.CLUSTER_ROUTING_REQUIRE_GROUP_SETTING,

server/src/internalClusterTest/java/org/elasticsearch/health/node/ShardsCapacityHealthIndicatorServiceIT.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.health.HealthStatus;
1717
import org.elasticsearch.health.metadata.HealthMetadata;
1818
import org.elasticsearch.test.ESIntegTestCase;
19-
import org.elasticsearch.test.InternalTestCluster;
2019
import org.junit.After;
2120
import org.junit.Before;
2221

@@ -27,16 +26,14 @@
2726
import static org.hamcrest.Matchers.empty;
2827
import static org.hamcrest.Matchers.hasSize;
2928

30-
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0)
29+
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1, numClientNodes = 0, supportsDedicatedMasters = false)
3130
public class ShardsCapacityHealthIndicatorServiceIT extends ESIntegTestCase {
3231

3332
private static final String INDEX_NAME = "index-name";
34-
private InternalTestCluster internalCluster;
3533

3634
@Before
3735
public void setUp() throws Exception {
3836
super.setUp();
39-
internalCluster = internalCluster();
4037
updateClusterSettings(Settings.builder().put(SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), 30));
4138
}
4239

@@ -53,7 +50,7 @@ public void testGreen() throws Exception {
5350
// index: 4 shards + 1 replica = 8 shards used (30 - 8 = 22 > 10 available shards)
5451
createIndex(4, 1);
5552

56-
var result = fetchShardsCapacityIndicatorResult(internalCluster);
53+
var result = fetchShardsCapacityIndicatorResult();
5754
assertEquals(result.status(), HealthStatus.GREEN);
5855
assertEquals(result.symptom(), "The cluster has enough room to add new shards.");
5956
assertThat(result.diagnosisList(), empty());
@@ -64,7 +61,7 @@ public void testYellow() throws Exception {
6461
// index: 11 shards + 1 replica = 22 shards used (30 - 22 < 10 available shards)
6562
createIndex(10, 1);
6663

67-
var result = fetchShardsCapacityIndicatorResult(internalCluster);
64+
var result = fetchShardsCapacityIndicatorResult();
6865
assertEquals(result.status(), HealthStatus.YELLOW);
6966
assertEquals(result.symptom(), "Cluster is close to reaching the configured maximum number of shards for data nodes.");
7067
assertThat(result.diagnosisList(), hasSize(1));
@@ -75,7 +72,7 @@ public void testRed() throws Exception {
7572
// index: 13 shards + 1 replica = 26 shards used (30 - 26 < 5 available shards)
7673
createIndex(13, 1);
7774

78-
var result = fetchShardsCapacityIndicatorResult(internalCluster);
75+
var result = fetchShardsCapacityIndicatorResult();
7976
assertEquals(result.status(), HealthStatus.RED);
8077
assertEquals(result.symptom(), "Cluster is close to reaching the configured maximum number of shards for data nodes.");
8178
assertThat(result.diagnosisList(), hasSize(1));
@@ -86,15 +83,15 @@ private void createIndex(int shards, int replicas) {
8683
createIndex(INDEX_NAME, indexSettings(shards, replicas).build());
8784
}
8885

89-
private HealthIndicatorResult fetchShardsCapacityIndicatorResult(InternalTestCluster internalCluster) throws Exception {
90-
ensureStableCluster(internalCluster.getNodeNames().length);
91-
var healthNode = ESIntegTestCase.waitAndGetHealthNode(internalCluster);
86+
private HealthIndicatorResult fetchShardsCapacityIndicatorResult() throws Exception {
87+
ensureStableCluster(internalCluster().getNodeNames().length);
88+
var healthNode = ESIntegTestCase.waitAndGetHealthNode(internalCluster());
9289
assertNotNull(healthNode);
9390

94-
var randomNode = internalCluster.getRandomNodeName();
91+
var randomNode = internalCluster().getRandomNodeName();
9592
waitForShardLimitsMetadata(randomNode);
9693

97-
var healthService = internalCluster.getInstance(HealthService.class, randomNode);
94+
var healthService = internalCluster().getInstance(HealthService.class, randomNode);
9895
var healthIndicatorResults = getHealthServiceResults(healthService, randomNode);
9996
assertThat(healthIndicatorResults, hasSize(1));
10097
return healthIndicatorResults.get(0);

0 commit comments

Comments
 (0)