@Test
public void testNamenodeOrder() throws Exception {

  Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
  assertTrue(upgrades.containsKey("upgrade_test"));
  UpgradePack upgrade = upgrades.get("upgrade_test");
  assertNotNull(upgrade);
  Cluster cluster = makeCluster();
  UpgradeContext context = m_upgradeContextFactory.create(cluster, UpgradeType.ROLLING,
      Direction.UPGRADE, UPGRADE_VERSION, new HashMap<String, Object>());
  context.setResolver(m_masterHostResolver);
  List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
  assertEquals(7, groups.size());
  UpgradeGroupHolder mastersGroup = groups.get(2);
  assertEquals("CORE_MASTER", mastersGroup.name);
  List<String> orderedNameNodes = new LinkedList<>();
  for (StageWrapper sw : mastersGroup.items) {
    if (sw.getType().equals(StageWrapper.Type.RESTART) && sw.getText().toLowerCase().contains("NameNode".toLowerCase())) {
      for (TaskWrapper tw : sw.getTasks()) {
        for (String hostName : tw.getHosts()) {
          orderedNameNodes.add(hostName);
        }
      }
    }
  }
  assertEquals(2, orderedNameNodes.size());
  // Order is standby, then active.
  assertEquals("h2", orderedNameNodes.get(0));
  assertEquals("h1", orderedNameNodes.get(1));
}