NetworkTopologyWithNodeGroup extends NetworkTopology { @Override public void sortByDistance(Node reader, Node[] nodes, int activeLen) { if (reader != null && !this.contains(reader)) { Node nodeGroup = getNode(reader.getNetworkLocation()); if (nodeGroup != null && nodeGroup instanceof InnerNode) { InnerNode parentNode = (InnerNode) nodeGroup; reader = parentNode.getLeaf(0, null); } else { return; } } super.sortByDistance(reader, nodes, activeLen); } NetworkTopologyWithNodeGroup(); @Override String getRack(String loc); String getNodeGroup(String loc); @Override boolean isOnSameRack( Node node1,  Node node2); @Override boolean isOnSameNodeGroup(Node node1, Node node2); @Override boolean isNodeGroupAware(); @Override void add(Node node); @Override void remove(Node node); @Override void sortByDistance(Node reader, Node[] nodes, int activeLen); final static String DEFAULT_NODEGROUP; }
@Test public void testSortByDistance() throws Exception { NodeBase[] testNodes = new NodeBase[4]; testNodes[0] = dataNodes[1]; testNodes[1] = dataNodes[2]; testNodes[2] = dataNodes[3]; testNodes[3] = dataNodes[0]; cluster.sortByDistance(dataNodes[0], testNodes, testNodes.length); assertTrue(testNodes[0] == dataNodes[0]); assertTrue(testNodes[1] == dataNodes[1]); assertTrue(testNodes[2] == dataNodes[2]); assertTrue(testNodes[3] == dataNodes[3]); testNodes[0] = dataNodes[3]; testNodes[1] = dataNodes[4]; testNodes[2] = dataNodes[1]; testNodes[3] = dataNodes[0]; cluster.sortByDistance(dataNodes[0], testNodes, testNodes.length); assertTrue(testNodes[0] == dataNodes[0]); assertTrue(testNodes[1] == dataNodes[1]); testNodes[0] = dataNodes[5]; testNodes[1] = dataNodes[3]; testNodes[2] = dataNodes[2]; testNodes[3] = dataNodes[0]; cluster.sortByDistance(dataNodes[0], testNodes, testNodes.length); assertTrue(testNodes[0] == dataNodes[0]); assertTrue(testNodes[1] == dataNodes[2]); testNodes[0] = dataNodes[6]; testNodes[1] = dataNodes[7]; testNodes[2] = dataNodes[2]; testNodes[3] = dataNodes[0]; cluster.sortByDistance(computeNode, testNodes, testNodes.length); assertTrue(testNodes[0] == dataNodes[0]); assertTrue(testNodes[1] == dataNodes[2]); }