@Test()
  public void testCreateHostOrderedUpgradeThrowsExceptions() throws Exception {

    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
    requestProps.put(UpgradeResourceProvider.UPGRADE_REPO_VERSION_ID, String.valueOf(repoVersionEntity2200.getId()));
    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test_host_ordered");
    requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.HOST_ORDERED.toString());
    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, Boolean.TRUE.toString());
    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name());

    ResourceProvider upgradeResourceProvider = createProvider(amc);
    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);

    try {
      upgradeResourceProvider.createResources(request);
      Assert.fail("The request should have failed due to the missing Upgrade/host_order property");
    } catch (SystemException systemException) {
      // expected
    }

    // stick a bad host_ordered_hosts in there which has the wrong hosts
    Set<Map<String, List<String>>> hostsOrder = new LinkedHashSet<>();
    Map<String, List<String>> hostGrouping = new HashMap<>();
    hostGrouping.put("hosts", Lists.newArrayList("invalid-host"));
    hostsOrder.add(hostGrouping);

    requestProps.put(UpgradeResourceProvider.UPGRADE_HOST_ORDERED_HOSTS, hostsOrder);

    try {
      upgradeResourceProvider.createResources(request);
      Assert.fail("The request should have failed due to invalid hosts");
    } catch (SystemException systemException) {
      // expected
    }

    // use correct hosts now
    hostsOrder = new LinkedHashSet<>();
    hostGrouping = new HashMap<>();
    hostGrouping.put("hosts", Lists.newArrayList("h1"));
    hostsOrder.add(hostGrouping);

    requestProps.put(UpgradeResourceProvider.UPGRADE_HOST_ORDERED_HOSTS, hostsOrder);
    upgradeResourceProvider.createResources(request);


    // make sure that the desired versions are updated
    Cluster cluster = clusters.getCluster("c1");
    assertNotNull(cluster);

    Service service = cluster.getService("ZOOKEEPER");
    assertEquals(repoVersionEntity2200, service.getDesiredRepositoryVersion());
  }
Tests that a {@link UpgradeType#HOST_ORDERED} upgrade throws an exception
on missing hosts.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java