### Question:
NetworkTopologyWithNodeGroup extends NetworkTopology { @Override public void pseudoSortByDistance( Node reader, Node[] nodes ) { 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; } } int tempIndex = 0; int localRackNode = -1; int localNodeGroupNode = -1; if (reader != null) { for (int i = 0; i < nodes.length; i++) { if (tempIndex == 0 && reader == nodes[i]) { if (i != 0) { swap(nodes, tempIndex, i); } tempIndex=1; if (localRackNode != -1 && (localNodeGroupNode !=-1)) { if (localRackNode == 0) { localRackNode = i; } if (localNodeGroupNode == 0) { localNodeGroupNode = i; } break; } } else if (localNodeGroupNode == -1 && isOnSameNodeGroup(reader, nodes[i])) { localNodeGroupNode = i; if(tempIndex != 0 && localRackNode != -1) break; } else if (localRackNode == -1 && isOnSameRack(reader, nodes[i])) { localRackNode = i; if (tempIndex != 0 && localNodeGroupNode != -1) break; } } if(localNodeGroupNode != -1 && localNodeGroupNode != tempIndex) { swap(nodes, tempIndex, localNodeGroupNode); if (localRackNode == tempIndex) { localRackNode = localNodeGroupNode; } tempIndex++; } if(localRackNode != -1 && localRackNode != tempIndex) { swap(nodes, tempIndex, localRackNode); tempIndex++; } } if (tempIndex == 0 && localNodeGroupNode == -1 && localRackNode == -1 && nodes.length != 0) { swap(nodes, 0, r.nextInt(nodes.length)); } } 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 pseudoSortByDistance( Node reader, Node[] nodes ); final static String DEFAULT_NODEGROUP; }### Answer:
@Test public void testPseudoSortByDistance() throws Exception { NodeBase[] testNodes = new NodeBase[4]; testNodes[0] = dataNodes[1]; testNodes[1] = dataNodes[2]; testNodes[2] = dataNodes[3]; testNodes[3] = dataNodes[0]; cluster.pseudoSortByDistance(dataNodes[0], testNodes ); 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.pseudoSortByDistance(dataNodes[0], testNodes ); 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.pseudoSortByDistance(dataNodes[0], testNodes ); 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.pseudoSortByDistance(computeNode, testNodes ); assertTrue(testNodes[0] == dataNodes[0]); assertTrue(testNodes[1] == dataNodes[2]); }