@Test
  public void testCreateCrossStackUpgrade() throws Exception {
    Cluster cluster = clusters.getCluster("c1");
    StackId oldStack = repoVersionEntity2110.getStackId();
    assertEquals(cluster.getDesiredStackVersion(), oldStack);

    for (Service s : cluster.getServices().values()) {
      assertEquals(oldStack, s.getDesiredStackId());

      for (ServiceComponent sc : s.getServiceComponents().values()) {
        assertEquals(oldStack, sc.getDesiredStackId());

        for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
          assertEquals(repoVersionEntity2110.getVersion(), sch.getVersion());
        }
      }
    }


    Config config = configFactory.createNew(cluster, "zoo.cfg", "abcdefg", Collections.singletonMap("a", "b"), null);
    cluster.addDesiredConfig("admin", Collections.singleton(config));

    // create the upgrade across major versions
    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");
    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name());

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

    List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
    assertEquals(1, upgrades.size());

    UpgradeEntity upgrade = upgrades.get(0);
    assertEquals(3, upgrade.getUpgradeGroups().size());

    UpgradeGroupEntity group = upgrade.getUpgradeGroups().get(2);
    assertEquals(2, group.getItems().size());

    group = upgrade.getUpgradeGroups().get(0);
    assertEquals(2, group.getItems().size());

    assertTrue(cluster.getDesiredConfigs().containsKey("zoo.cfg"));
    assertTrue(cluster.getDesiredStackVersion().getStackId().equals("HDP-2.2.0"));

    for (Service s : cluster.getServices().values()) {
      assertEquals(repoVersionEntity2200, s.getDesiredRepositoryVersion());

      for (ServiceComponent sc : s.getServiceComponents().values()) {
        assertEquals(repoVersionEntity2200, sc.getDesiredRepositoryVersion());
      }
    }
  }
Test Downgrade from the partially completed upgrade
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java