ClusterStateView { public void handleUpdatedHostInfo(NodeInfo node, HostInfo hostInfo) { if ( ! node.isDistributor()) return; final int hostVersion; if (hostInfo.getClusterStateVersionOrNull() == null) { return; } else { hostVersion = hostInfo.getClusterStateVersionOrNull(); } int currentStateVersion = clusterState.getVersion(); if (hostVersion != currentStateVersion) { log.log(Level.FINE, "Current state version is " + currentStateVersion + ", while host info received from distributor " + node.getNodeIndex() + " is " + hostVersion); return; } statsAggregator.updateForDistributor(node.getNodeIndex(), StorageNodeStatsBridge.generate(hostInfo.getDistributor())); } 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 testWrongNodeType() { when(nodeInfo.isDistributor()).thenReturn(false); clusterStateView.handleUpdatedHostInfo(nodeInfo, createHostInfo("101")); verify(statsAggregator, never()).updateForDistributor(anyInt(), any()); }
@Test public void testStateVersionMismatch() { when(nodeInfo.isDistributor()).thenReturn(true); when(clusterState.getVersion()).thenReturn(101); clusterStateView.handleUpdatedHostInfo(nodeInfo, createHostInfo("22")); verify(statsAggregator, never()).updateForDistributor(anyInt(), any()); }
@Test public void testFailToGetStats() { when(nodeInfo.isDistributor()).thenReturn(true); when(clusterState.getVersion()).thenReturn(101); clusterStateView.handleUpdatedHostInfo(nodeInfo, createHostInfo("22")); verify(statsAggregator, never()).updateForDistributor(anyInt(), any()); }
@Test public void testSuccessCase() { when(nodeInfo.isDistributor()).thenReturn(true); HostInfo hostInfo = HostInfo.createHostInfo( "{" + " \"cluster-state-version\": 101," + " \"distributor\": {\n" + " \"storage-nodes\": [\n" + " {\n" + " \"node-index\": 3\n" + " }\n" + " ]}}"); when(nodeInfo.getNodeIndex()).thenReturn(3); when(clusterState.getVersion()).thenReturn(101); clusterStateView.handleUpdatedHostInfo(nodeInfo, hostInfo); verify(statsAggregator).updateForDistributor(3, StorageNodeStatsBridge.generate(hostInfo.getDistributor())); }