@Test
public void testServiceCheckUpgradeStages() throws Exception {

  Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.2.0");
  assertTrue(upgrades.containsKey("upgrade_test_checks"));
  UpgradePack upgrade = upgrades.get("upgrade_test_checks");
  assertNotNull(upgrade);
  Cluster c = makeCluster();
  // HBASE and PIG have service checks, but not TEZ.
  Set<String> additionalServices = new HashSet<String>() {{ add("HBASE"); add("PIG"); add("TEZ"); add("AMBARI_METRICS"); }};
  for(String service : additionalServices) {
    c.addService(service);
  }
  int numServiceChecksExpected = 0;
  Collection<Service> services = c.getServices().values();
  for(Service service : services) {
    ServiceInfo si = ambariMetaInfo.getService(c.getCurrentStackVersion().getStackName(),
        c.getCurrentStackVersion().getStackVersion(), service.getName());
    if (null == si.getCommandScript()) {
      continue;
    }
    if (service.getName().equalsIgnoreCase("TEZ")) {
      assertTrue("Expect Tez to not have any service checks", false);
    }
    // Expect AMS to not run any service checks because it is excluded
    if (service.getName().equalsIgnoreCase("AMBARI_METRICS")) {
      continue;
    }
    numServiceChecksExpected++;
  }
  UpgradeContext context = m_upgradeContextFactory.create(c, 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 holder = groups.get(3);
  assertEquals(holder.name, "SERVICE_CHECK_1");
  assertEquals(7, holder.items.size());
  int numServiceChecksActual = 0;
  for (StageWrapper sw : holder.items) {
    for(Service service : services) {
      Pattern p = Pattern.compile(".*" + service.getName(), Pattern.CASE_INSENSITIVE);
      Matcher matcher = p.matcher(sw.getText());
      if (matcher.matches()) {
        numServiceChecksActual++;
        continue;
      }
    }
  }
  assertEquals(numServiceChecksActual, numServiceChecksExpected);
  // grab the manual task out of ZK which has placeholder text
  UpgradeGroupHolder zookeeperGroup = groups.get(1);
  assertEquals("ZOOKEEPER", zookeeperGroup.name);
  ManualTask manualTask = (ManualTask) zookeeperGroup.items.get(0).getTasks().get(
      0).getTasks().get(0);
  assertEquals(1, manualTask.messages.size());
  assertEquals(
      "This is a manual task with a placeholder of placeholder-rendered-properly",
      manualTask.messages.get(0));
}