NetworkTopologyWithNodeGroup extends NetworkTopology { @Override public boolean isOnSameRack( Node node1, Node node2) { if (node1 == null || node2 == null || node1.getParent() == null || node2.getParent() == null) { return false; } netlock.readLock().lock(); try { return isSameParents(node1.getParent(), node2.getParent()); } finally { netlock.readLock().unlock(); } } 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 testRacks() throws Exception { assertEquals(3, cluster.getNumOfRacks()); assertTrue(cluster.isOnSameRack(dataNodes[0], dataNodes[1])); assertTrue(cluster.isOnSameRack(dataNodes[1], dataNodes[2])); assertFalse(cluster.isOnSameRack(dataNodes[2], dataNodes[3])); assertTrue(cluster.isOnSameRack(dataNodes[3], dataNodes[4])); assertTrue(cluster.isOnSameRack(dataNodes[4], dataNodes[5])); assertFalse(cluster.isOnSameRack(dataNodes[5], dataNodes[6])); assertTrue(cluster.isOnSameRack(dataNodes[6], dataNodes[7])); }