浏览代码

Add number of nodes accessor to test cluster handle (#108484)

Local test clusters have several methods allowing interaction with nodes
by ordinal number. However, there is currently no way to know how mnany
nodes were actually configured for the cluster. This commit adds an
accessor for the number of nodes the cluster handle knows about.
Ryan Ernst 1 年之前
父节点
当前提交
1bc64745f2

+ 5 - 0
test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/DefaultLocalClusterHandle.java

@@ -65,6 +65,11 @@ public class DefaultLocalClusterHandle implements LocalClusterHandle {
         this.nodes = nodes;
     }
 
+    @Override
+    public int getNumNodes() {
+        return nodes.size();
+    }
+
     @Override
     public void start() {
         if (started.getAndSet(true) == false) {

+ 5 - 0
test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/DefaultLocalElasticsearchCluster.java

@@ -54,6 +54,11 @@ public class DefaultLocalElasticsearchCluster<S extends LocalClusterSpec, H exte
         };
     }
 
+    @Override
+    public int getNumNodes() {
+        return handle.getNumNodes();
+    }
+
     @Override
     public void start() {
         checkHandle();

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

@@ -16,6 +16,12 @@ import org.elasticsearch.test.cluster.util.Version;
 import java.io.InputStream;
 
 public interface LocalClusterHandle extends ClusterHandle {
+
+    /**
+     * Returns the number of nodes that are part of this cluster.
+     */
+    int getNumNodes();
+
     /**
      * Stops the node at a given index.
      * @param index of the node to stop