@Test
  public void testBackupMasters() throws Exception {
    final ServerName sn =
      ServerName.valueOf("localhost", 5678, EnvironmentEdgeManager.currentTime());
    final MasterAddressTracker addressTracker = setupMasterTracker(sn, 1111);
    assertTrue(addressTracker.hasMaster());
    ServerName activeMaster = addressTracker.getMasterAddress();
    assertEquals(activeMaster, sn);
    // No current backup masters
    List<ServerName> backupMasters = addressTracker.getBackupMasters();
    assertEquals(0, backupMasters.size());
    ServerName backupMaster1 = ServerName.valueOf("localhost", 2222, -1);
    ServerName backupMaster2 = ServerName.valueOf("localhost", 3333, -1);
    String backupZNode1 =
      ZNodePaths.joinZNode(zk.getZNodePaths().backupMasterAddressesZNode, backupMaster1.toString());
    String backupZNode2 =
      ZNodePaths.joinZNode(zk.getZNodePaths().backupMasterAddressesZNode, backupMaster2.toString());
    // Add backup masters
    MasterAddressTracker.setMasterAddress(zk, backupZNode1, backupMaster1, 2222);
    MasterAddressTracker.setMasterAddress(zk, backupZNode2, backupMaster2, 3333);
    TEST_UTIL.waitFor(30000, () -> addressTracker.getBackupMasters().size() == 2);
    backupMasters = addressTracker.getBackupMasters();
    assertEquals(2, backupMasters.size());
    assertTrue(backupMasters.contains(backupMaster1));
    assertTrue(backupMasters.contains(backupMaster2));
  }
Unit tests that uses ZooKeeper but does not use the master-side methods but rather acts
directly on ZK.
hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestMasterAddressTracker.java