@Test
public void testUpgradeOrchestrationWithHostsInMM() throws Exception {

  Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("foo", "bar");
  assertTrue(upgrades.isEmpty());
  upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
  ServiceInfo si = ambariMetaInfo.getService("HDP", "2.1.1", "ZOOKEEPER");
  si.setDisplayName("Zk");
  ComponentInfo ci = si.getComponentByName("ZOOKEEPER_SERVER");
  ci.setDisplayName("ZooKeeper1 Server2");
  assertTrue(upgrades.containsKey("upgrade_test"));
  UpgradePack upgrade = upgrades.get("upgrade_test");
  assertNotNull(upgrade);
  // turn on MM for the first host
  Cluster cluster = makeCluster();
  Host hostInMaintenanceMode = cluster.getHosts().iterator().next();
  hostInMaintenanceMode.setMaintenanceState(cluster.getClusterId(), MaintenanceState.ON);
  // use a "real" master host resolver here so that we can actually test MM
  MasterHostResolver masterHostResolver = new MasterHostResolver(null, cluster, "");
  UpgradeContext context = m_upgradeContextFactory.create(cluster, UpgradeType.ROLLING,
      Direction.UPGRADE, UPGRADE_VERSION, new HashMap<String, Object>());
  context.setResolver(masterHostResolver);
  List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
  assertEquals(7, groups.size());
  for (UpgradeGroupHolder group : groups) {
    for (StageWrapper stageWrapper : group.items) {
      Set<String> hosts = stageWrapper.getHosts();
      assertFalse(hosts.contains(hostInMaintenanceMode.getHostName()));
    }
  }
  // Do stacks cleanup
  stackManagerMock.invalidateCurrentPaths();
  ambariMetaInfo.init();
}