NetworkTopologyWithNodeGroup extends NetworkTopology { public String getNodeGroup(String loc) { netlock.readLock().lock(); try { loc = NodeBase.normalize(loc); Node locNode = getNode(loc); if (locNode instanceof InnerNodeWithNodeGroup) { InnerNodeWithNodeGroup node = (InnerNodeWithNodeGroup) locNode; if (node.isNodeGroup()) { return loc; } else if (node.isRack()) { return null; } else { if(!(node.getNetworkLocation() == null || node.getNetworkLocation().isEmpty())) { return getNodeGroup(node.getNetworkLocation()); } else { return NodeBase.ROOT; } } } else { return loc; } } 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 testNodeGroup() throws Exception { String res = cluster.getNodeGroup(""); assertTrue("NodeGroup should be NodeBase.ROOT for empty location", res.equals(NodeBase.ROOT)); try { cluster.getNodeGroup(null); } catch (IllegalArgumentException e) { assertTrue("Null Network Location should throw exception!", e.getMessage().contains("Network Location is null")); } }