Skip to content

Commit 4cf4be4

Browse files
authored
Expose pid in new test clusters (elastic#97590)
Sometimes it is necessary for an integ test to poke at the Java process of Elasticsearch. This commit makes a node's pid available through ClusterHandle.
1 parent f6e41e9 commit 4cf4be4

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public interface ClusterHandle extends Closeable {
7171
*/
7272
String getName(int index);
7373

74+
/**
75+
* Get the pid of the node for the given index.
76+
*/
77+
long getPid(int index);
78+
7479
/**
7580
* Returns a comma-separated list of TCP transport endpoints for cluster. If this method is called on an unstarted cluster, the cluster
7681
* 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ public String getName(int index) {
9595
return handle.getName(index);
9696
}
9797

98+
@Override
99+
public long getPid(int index) {
100+
checkHandle();
101+
return handle.getPid(index);
102+
}
103+
98104
@Override
99105
public String getTransportEndpoints() {
100106
checkHandle();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ public String getName() {
222222
return name;
223223
}
224224

225+
public long getPid() {
226+
if (process == null) {
227+
throw new IllegalStateException("Process has not been started, cannot get pid");
228+
}
229+
return process.pid();
230+
}
231+
225232
public LocalNodeSpec getSpec() {
226233
return spec;
227234
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public String getName(int index) {
160160
return nodes.get(index).getName();
161161
}
162162

163+
@Override
164+
public long getPid(int index) {
165+
return nodes.get(index).getPid();
166+
}
167+
163168
public void stopNode(int index) {
164169
nodes.get(index).stop(false);
165170
}

0 commit comments

Comments
 (0)