@Test
  public void testResumeUpgrade() 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);

    // !!! make sure we can.  actual abort is tested elsewhere
    Request req = PropertyHelper.getUpdateRequest(requestProps, null);
    urp.updateResources(req, null);

    ActionManager am = injector.getInstance(ActionManager.class);

    List<HostRoleCommand> commands = am.getRequestTasks(id);

    boolean foundOne = false;
    for (HostRoleCommand hrc : commands) {
      if (hrc.getRole().equals(Role.AMBARI_SERVER_ACTION)) {
        assertEquals(-1L, hrc.getHostId());
        assertNull(hrc.getHostName());
        foundOne = true;
      }
    }

    assertTrue("Expected at least one server-side action", foundOne);

    // make sure we have enough commands to properly test this
    assertTrue(commands.size() > 5);

    // now, set some status of the commands to reflect an actual aborted upgrade
    // (some completed, some faiures, some timeouts)
    HostRoleCommandDAO dao = injector.getInstance(HostRoleCommandDAO.class);
    for (int i = 0; i < commands.size(); i++) {
      HostRoleCommand command = commands.get(i);
      HostRoleCommandEntity entity = dao.findByPK(command.getTaskId());

      // make sure to interweave failures/timeouts with completed
      final HostRoleStatus newStatus;
      switch (i) {
        case 0:
        case 1:
          newStatus = HostRoleStatus.COMPLETED;
          break;
        case 2:
          newStatus = HostRoleStatus.TIMEDOUT;
          break;
        case 3:
          newStatus = HostRoleStatus.COMPLETED;
          break;
        case 4:
          newStatus = HostRoleStatus.FAILED;
          break;
        default:
          newStatus = HostRoleStatus.ABORTED;
          break;
      }

      entity.setStatus(newStatus);
      dao.merge(entity);
    }


    // resume the upgrade
    requestProps = new HashMap<>();
    requestProps.put(UpgradeResourceProvider.UPGRADE_REQUEST_ID, id.toString());
    requestProps.put(UpgradeResourceProvider.UPGRADE_REQUEST_STATUS, "PENDING");
    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
    requestProps.put(UpgradeResourceProvider.UPGRADE_SUSPENDED, "false");

    // !!! make sure we can.  actual reset is tested elsewhere
    req = PropertyHelper.getUpdateRequest(requestProps, null);
    urp.updateResources(req, null);

    // test that prior completions (both timedout and failure) did not go back
    // to PENDING
    commands = am.getRequestTasks(id);
    for (int i = 0; i < commands.size(); i++) {
      HostRoleCommand command = commands.get(i);
      if (i < 5) {
        assertTrue(command.getStatus() != HostRoleStatus.PENDING);
      } else {
        assertTrue(command.getStatus() == HostRoleStatus.PENDING);
      }
    }
  }
Test Downgrade from the partially completed upgrade
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java