@Test
  public void testAbortUpgrade() throws Exception {
    RequestStatus status = testCreateResources();

    Set<Resource> createdResources = status.getAssociatedResources();
    assertEquals(1, createdResources.size());
    Resource res = createdResources.iterator().next();
    Long id = (Long) res.getPropertyValue("Upgrade/request_id");
    assertNotNull(id);
    assertEquals(Long.valueOf(1), id);

    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put(UpgradeResourceProvider.UPGRADE_REQUEST_ID, id.toString());
    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
    requestProps.put(UpgradeResourceProvider.UPGRADE_REQUEST_STATUS, "ABORTED");
    requestProps.put(UpgradeResourceProvider.UPGRADE_SUSPENDED, "true");

    UpgradeResourceProvider urp = createProvider(amc);

    Request req = PropertyHelper.getUpdateRequest(requestProps, null);
    urp.updateResources(req, null);

    List<HostRoleCommandEntity> commands = hrcDAO.findByRequest(id);

    int i = 0;
    for (HostRoleCommandEntity command : commands) {
      if (i < 3) {
        command.setStatus(HostRoleStatus.COMPLETED);
      } else {
        command.setStatus(HostRoleStatus.ABORTED);
      }
      hrcDAO.merge(command);
      i++;
    }

    req = PropertyHelper.getReadRequest(
        UpgradeResourceProvider.UPGRADE_CLUSTER_NAME,
        UpgradeResourceProvider.UPGRADE_ID,
        UpgradeResourceProvider.REQUEST_PROGRESS_PERCENT_ID);

    Predicate pred = new PredicateBuilder()
        .property(UpgradeResourceProvider.UPGRADE_REQUEST_ID).equals(id.toString())
        .and()
        .property(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1")
        .toPredicate();

    Set<Resource> resources = urp.getResources(req, pred);
    assertEquals(1, resources.size());
    res = resources.iterator().next();

    Double value = (Double) res.getPropertyValue(UpgradeResourceProvider.REQUEST_PROGRESS_PERCENT_ID);

    assertEquals(37.5d, value, 0.1d);
  }
Test Downgrade from the partially completed upgrade
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java