Skip to content

Commit 44ce64c

Browse files
authored
Stop invidual nodes and get node names in test clusters (#97402)
Adds `public String getName(int index)` `public void stopNode(int index)` To the cluster handle.
1 parent c0553c4 commit 44ce64c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/ClusterHandle.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public interface ClusterHandle extends Closeable {
2929
*/
3030
void stop(boolean forcibly);
3131

32+
/**
33+
* Stops the node at a given index.
34+
* @param index of the node to stop
35+
*/
36+
void stopNode(int index);
37+
3238
/**
3339
* Restarts the cluster. Effectively the same as calling {@link #stop(boolean)} followed by {@link #start()}
3440
*
@@ -60,6 +66,11 @@ public interface ClusterHandle extends Closeable {
6066
*/
6167
String getHttpAddress(int index);
6268

69+
/**
70+
* Get the name of the node for the given index.
71+
*/
72+
String getName(int index);
73+
6374
/**
6475
* Returns a comma-separated list of TCP transport endpoints for cluster. If this method is called on an unstarted cluster, the cluster
6576
* will be started. This method is thread-safe and subsequent calls will wait for cluster start and availability.

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/DefaultElasticsearchCluster.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public void stop(boolean forcibly) {
5353
handle.stop(forcibly);
5454
}
5555

56+
@Override
57+
public void stopNode(int index) {
58+
checkHandle();
59+
handle.stopNode(index);
60+
}
61+
5662
@Override
5763
public void restart(boolean forcibly) {
5864
checkHandle();
@@ -83,6 +89,12 @@ public String getHttpAddress(int index) {
8389
return handle.getHttpAddress(index);
8490
}
8591

92+
@Override
93+
public String getName(int index) {
94+
checkHandle();
95+
return handle.getName(index);
96+
}
97+
8698
@Override
8799
public String getTransportEndpoints() {
88100
checkHandle();

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalClusterHandle.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ public void upgradeToVersion(Version version) {
156156
waitUntilReady();
157157
}
158158

159+
public String getName(int index) {
160+
return nodes.get(index).getName();
161+
}
162+
163+
public void stopNode(int index) {
164+
nodes.get(index).stop(false);
165+
}
166+
159167
protected void waitUntilReady() {
160168
writeUnicastHostsFile();
161169
try {

0 commit comments

Comments
 (0)