Source:
public void testScmRegisterNodeWith4LayerNetworkTopology() throws IOException, InterruptedException, AuthenticationException { OzoneConfiguration conf = getConf(); conf.setTimeDuration(OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 1000, MILLISECONDS); String[] hostNames = {"host1", "host2", "host3", "host4"}; String[] IpAddress = {"1.2.3.4", "2.3.4.5", "3.4.5.6", "4.5.6.7"}; File mapFile = File.createTempFile(getClass().getSimpleName() + ".testResolve", ".txt"); BufferedWriter writer = Files.newWriter(mapFile, Charsets.UTF_8); writer.write(IpAddress[0] + " /dc1/rack1\n" + IpAddress[1] + "\t/dc1/rack1\n" + IpAddress[2] + " /dc1/rack2\n" + IpAddress[3] + "\t/dc1/rack2\n"); writer.close(); mapFile.deleteOnExit(); conf.set(NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY, "org.apache.hadoop.net.TableMapping"); conf.set(NET_TOPOLOGY_TABLE_MAPPING_FILE_KEY, mapFile.getCanonicalPath()); conf.set(ScmConfigKeys.OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE, "network-topology-nodegroup.xml"); final int nodeCount = hostNames.length; try (SCMNodeManager nodeManager = createNodeManager(conf)) { DatanodeDetails[] nodes = new DatanodeDetails[nodeCount]; for (int i = 0; i < nodeCount; i++) { DatanodeDetails node = TestUtils.createDatanodeDetails( UUID.randomUUID().toString(), hostNames[i], IpAddress[i], null); nodeManager.register(node, null, null); nodes[i] = node; } Thread.sleep(4 * 1000); NetworkTopology clusterMap = scm.getClusterMap(); assertEquals(nodeCount, nodeManager.getNodeCount(HEALTHY)); assertEquals(nodeCount, clusterMap.getNumOfLeafNode("")); assertEquals(4, clusterMap.getMaxLevel()); List<DatanodeDetails> nodeList = nodeManager.getAllNodes(); nodeList.stream().forEach(node -> Assert.assertTrue(node.getNetworkLocation().startsWith("/dc1"))); } }

Target:
public void testScmRegisterNodeWith4LayerNetworkTopology() throws IOException, InterruptedException, AuthenticationException { OzoneConfiguration conf = getConf(); conf.setTimeDuration(OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 1000, MILLISECONDS); String[] hostNames = {"host1", "host2", "host3", "host4"}; String[] ipAddress = {"1.2.3.4", "2.3.4.5", "3.4.5.6", "4.5.6.7"}; String mapFile = this.getClass().getClassLoader() .getResource("nodegroup-mapping").getPath(); conf.set(NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY, "org.apache.hadoop.net.TableMapping"); conf.set(NET_TOPOLOGY_TABLE_MAPPING_FILE_KEY, mapFile); conf.set(ScmConfigKeys.OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE, "network-topology-nodegroup.xml"); final int nodeCount = hostNames.length; try (SCMNodeManager nodeManager = createNodeManager(conf)) { DatanodeDetails[] nodes = new DatanodeDetails[nodeCount]; for (int i = 0; i < nodeCount; i++) { DatanodeDetails node = TestUtils.createDatanodeDetails( UUID.randomUUID().toString(), hostNames[i], ipAddress[i], null); nodeManager.register(node, null, null); nodes[i] = node; } Thread.sleep(4 * 1000); NetworkTopology clusterMap = scm.getClusterMap(); assertEquals(nodeCount, nodeManager.getNodeCount(HEALTHY)); assertEquals(nodeCount, clusterMap.getNumOfLeafNode("")); assertEquals(4, clusterMap.getMaxLevel()); List<DatanodeDetails> nodeList = nodeManager.getAllNodes(); nodeList.stream().forEach(node -> Assert.assertTrue(node.getNetworkLocation().startsWith("/rack1/ng"))); } }