ClusterStateView { static Set<Integer> getIndicesOfUpNodes(ClusterState clusterState, NodeType type) { int nodeCount = clusterState.getNodeCount(type); Set<Integer> nodesBeingUp = new HashSet<>(); for (int i = 0; i < nodeCount; ++i) { Node node = new Node(type, i); NodeState nodeState = clusterState.getNodeState(node); State state = nodeState.getState(); if (state == State.UP || state == State.INITIALIZING || state == State.RETIRED || state == State.MAINTENANCE) { nodesBeingUp.add(i); } } return nodesBeingUp; } ClusterStateView(ClusterState clusterState, ClusterStatsAggregator statsAggregator); static ClusterStateView create(String serializedClusterState); static ClusterStateView create(final ClusterState clusterState); ClusterStateView cloneForNewState(); ClusterState getClusterState(); void handleUpdatedHostInfo(NodeInfo node, HostInfo hostInfo); ClusterStatsAggregator getStatsAggregator(); String toString();  }
@Test public void testIndicesOfUpNodes() { when(clusterState.getNodeCount(NodeType.DISTRIBUTOR)).thenReturn(7); NodeState nodeState = mock(NodeState.class); when(nodeState.getState()). thenReturn(State.MAINTENANCE). thenReturn(State.RETIRED). thenReturn(State.INITIALIZING). thenReturn(State.DOWN). thenReturn(State.STOPPING). thenReturn(State.UNKNOWN). thenReturn(State.UP); when(clusterState.getNodeState(any())).thenReturn(nodeState); Set<Integer> indices = ClusterStateView.getIndicesOfUpNodes(clusterState, NodeType.DISTRIBUTOR); assertEquals(4, indices.size()); assert(indices.contains(0)); assert(indices.contains(1)); assert(indices.contains(2)); assert(indices.contains(6)); }