private TestClusterTopology.NodeElement GetNewNode(string name, string rackLocation ) { TestClusterTopology.NodeElement node = new TestClusterTopology.NodeElement(name); node.SetNetworkLocation(rackLocation); return(node); }
public virtual void TestCountNumNodes() { // create the topology NetworkTopology cluster = new NetworkTopology(); cluster.Add(GetNewNode("node1", "/d1/r1")); TestClusterTopology.NodeElement node2 = GetNewNode("node2", "/d1/r2"); cluster.Add(node2); cluster.Add(GetNewNode("node3", "/d1/r3")); TestClusterTopology.NodeElement node3 = GetNewNode("node4", "/d1/r4"); cluster.Add(node3); // create exclude list IList <Node> excludedNodes = new AList <Node>(); Assert.Equal("4 nodes should be available", 4, cluster.CountNumOfAvailableNodes (NodeBase.Root, excludedNodes)); TestClusterTopology.NodeElement deadNode = GetNewNode("node5", "/d1/r2"); excludedNodes.AddItem(deadNode); Assert.Equal("4 nodes should be available with extra excluded Node" , 4, cluster.CountNumOfAvailableNodes(NodeBase.Root, excludedNodes)); // add one existing node to exclude list excludedNodes.AddItem(node3); Assert.Equal("excluded nodes with ROOT scope should be considered" , 3, cluster.CountNumOfAvailableNodes(NodeBase.Root, excludedNodes)); Assert.Equal("excluded nodes without ~ scope should be considered" , 2, cluster.CountNumOfAvailableNodes("~" + deadNode.GetNetworkLocation(), excludedNodes )); Assert.Equal("excluded nodes with rack scope should be considered" , 1, cluster.CountNumOfAvailableNodes(deadNode.GetNetworkLocation(), excludedNodes )); // adding the node in excluded scope to excluded list excludedNodes.AddItem(node2); Assert.Equal("excluded nodes with ~ scope should be considered" , 2, cluster.CountNumOfAvailableNodes("~" + deadNode.GetNetworkLocation(), excludedNodes )); // getting count with non-exist scope. Assert.Equal("No nodes should be considered for non-exist scope" , 0, cluster.CountNumOfAvailableNodes("/non-exist", excludedNodes)); }