### Question:
HQuorumPeer { static void writeMyID(Properties properties) throws IOException { long myId = -1; Configuration conf = HBaseConfiguration.create(); String myAddress = DNS.getDefaultHost( conf.get("hbase.zookeeper.dns.interface","default"), conf.get("hbase.zookeeper.dns.nameserver","default")); List<String> ips = new ArrayList<String>(); ips.add(myAddress.contains(".") ? myAddress : StringUtils.simpleHostname(myAddress)); Enumeration<?> nics = NetworkInterface.getNetworkInterfaces(); while(nics.hasMoreElements()) { Enumeration<?> rawAdrs = ((NetworkInterface)nics.nextElement()).getInetAddresses(); while(rawAdrs.hasMoreElements()) { InetAddress inet = (InetAddress) rawAdrs.nextElement(); ips.add(StringUtils.simpleHostname(inet.getHostName())); ips.add(inet.getHostAddress()); } } for (Entry<Object, Object> entry : properties.entrySet()) { String key = entry.getKey().toString().trim(); String value = entry.getValue().toString().trim(); if (key.startsWith("server.")) { int dot = key.indexOf('.'); long id = Long.parseLong(key.substring(dot + 1)); String[] parts = value.split(":"); String address = parts[0]; if (addressIsLocalHost(address) || ips.contains(address)) { myId = id; break; } } } properties.setProperty("maxSessionTimeout", conf.get("zookeeper.session.timeout", "180000")); if (myId == -1) { throw new IOException("Could not find my address: " + myAddress + " in list of ZooKeeper quorum servers"); } String dataDirStr = properties.get("dataDir").toString().trim(); File dataDir = new File(dataDirStr); if (!dataDir.isDirectory()) { if (!dataDir.mkdirs()) { throw new IOException("Unable to create data dir " + dataDir); } } File myIdFile = new File(dataDir, "myid"); PrintWriter w = new PrintWriter(myIdFile); w.println(myId); w.close(); }  static void main(String[] args);  }### Answer:
@Test public void testConfigInjection() throws Exception { String s = "dataDir=" + this.dataDir.toString() + "\n" + "clientPort=2181\n" + "initLimit=2\n" + "syncLimit=2\n" + "server.0=${hbase.master.hostname}:2888:3888\n" + "server.1=server1:2888:3888\n" + "server.2=server2:2888:3888\n"; System.setProperty("hbase.master.hostname", "localhost"); InputStream is = new ByteArrayInputStream(s.getBytes()); Configuration conf = TEST_UTIL.getConfiguration(); Properties properties = ZKConfig.parseZooCfg(conf, is); assertEquals(this.dataDir.toString(), properties.get("dataDir")); assertEquals(Integer.valueOf(2181), Integer.valueOf(properties.getProperty("clientPort"))); assertEquals("localhost:2888:3888", properties.get("server.0")); HQuorumPeer.writeMyID(properties); QuorumPeerConfig config = new QuorumPeerConfig(); config.parseProperties(properties); assertEquals(this.dataDir.toString(), config.getDataDir()); assertEquals(2181, config.getClientPortAddress().getPort()); Map<Long,QuorumServer> servers = config.getServers(); assertEquals(3, servers.size()); assertTrue(servers.containsKey(Long.valueOf(0))); QuorumServer server = servers.get(Long.valueOf(0)); assertEquals("localhost", server.addr.getHostName()); System.setProperty("hbase.master.hostname", "foo.bar"); is = new ByteArrayInputStream(s.getBytes()); properties = ZKConfig.parseZooCfg(conf, is); assertEquals("foo.bar:2888:3888", properties.get("server.0")); config.parseProperties(properties); servers = config.getServers(); server = servers.get(Long.valueOf(0)); assertEquals("foo.bar", server.addr.getHostName()); }