@VisibleForTesting
  RebalanceResult executeRebalanceOnDS(ManagementService managementService,
      InternalCache cache, String simulate,
      List<String> excludeRegionsList, FunctionExecutor functionExecutor) {
    RebalanceResultImpl rebalanceResult = new RebalanceResultImpl();
    rebalanceResult.setSuccess(false);
    List<String> errors = new ArrayList<>();

    List<MemberPRInfo> listMemberRegion =
        getMemberRegionList(managementService, cache, excludeRegionsList);

    if (listMemberRegion.isEmpty()) {
      rebalanceResult.setStatusMessage(CliStrings.REBALANCE__MSG__NO_REBALANCING_REGIONS_ON_DS);
      rebalanceResult.setSuccess(true);
      return rebalanceResult;
    }

    Iterator<MemberPRInfo> iterator = listMemberRegion.iterator();
    boolean flagToContinueWithRebalance = false;

    // check if list has some members that can be rebalanced
    while (iterator.hasNext()) {
      if (iterator.next().dsMemberList.size() > 1) {
        flagToContinueWithRebalance = true;
        break;
      }
    }

    if (!flagToContinueWithRebalance) {
      rebalanceResult.setStatusMessage(CliStrings.REBALANCE__MSG__NO_REBALANCING_REGIONS_ON_DS);
      rebalanceResult.setSuccess(true);
      return rebalanceResult;
    }

    List<RebalanceRegionResult> rebalanceRegionResults = new ArrayList<>();
    for (MemberPRInfo memberPR : listMemberRegion) {
      try {
        // check if there are more than one members associated with region for rebalancing
        if (memberPR.dsMemberList.size() > 1) {
          for (int i = 0; i < memberPR.dsMemberList.size(); i++) {
            DistributedMember dsMember = memberPR.dsMemberList.get(i);
            Function rebalanceFunction = getRebalanceFunction(
                (InternalDistributedMember) dsMember);
            Object[] functionArgs = new Object[3];
            functionArgs[0] = simulate;
            Set<String> regionSet = new HashSet<>();

            regionSet.add(memberPR.region);
            functionArgs[1] = regionSet;

            Set<String> excludeRegionSet = new HashSet<>();
            functionArgs[2] = excludeRegionSet;

            List<Object> resultList = new ArrayList<>();

            try {
              if (checkMemberPresence(cache, dsMember)) {
                resultList = functionExecutor.execute(rebalanceFunction, functionArgs, dsMember);
                if (checkResultList(errors, resultList, dsMember)) {
                  continue;
                }

                List<String> rstList = Arrays.asList(((String) resultList.get(0)).split(","));
                rebalanceRegionResults.add(toRebalanceRegionResult(rstList));
                rebalanceResult.setSuccess(true);

                // Rebalancing for region is done so break and continue with other region
                break;
              } else {
                if (i == memberPR.dsMemberList.size() - 1) {
                  // The last member hosting this region departed so no need to rebalance it.
                  // So act as if we never tried to rebalance this region.
                  // Break to get out of this inner loop and try the next region (if any).
                  break;
                } else {
                  continue;
                }
              }
            } catch (Exception ex) {
              if (i == memberPR.dsMemberList.size() - 1) {
                errors.add(
                    MessageFormat.format(
                        CliStrings.REBALANCE__MSG__NO_EXECUTION_FOR_REGION_0_ON_MEMBERS_1,
                        memberPR.region, listOfAllMembers(memberPR.dsMemberList)) + ", " +
                        CliStrings.REBALANCE__MSG__REASON + ex.getMessage());
              } else {
                continue;
              }
            }

            if (checkResultList(errors, resultList, dsMember)) {
              continue;
            }

            List<String> rstList = Arrays.asList(((String) resultList.get(0)).split(","));
            rebalanceRegionResults.add(toRebalanceRegionResult(rstList));
            rebalanceResult.setSuccess(true);
          }
        }
      } catch (NoMembersException e) {
        rebalanceResult.setStatusMessage(e.getMessage());
        rebalanceResult.setRebalanceSummary(rebalanceRegionResults);
        return rebalanceResult;
      }
    }
    rebalanceResult.setRebalanceSummary(rebalanceRegionResults);
    if (rebalanceRegionResults.isEmpty()) {
      rebalanceResult.setSuccess(false);
    }
    return rebalanceResult;
  }
This class was introduced so that it can be mocked
to all executeRebalanceOnDS to be unit tested
geode-core/src/main/java/org/apache/geode/management/internal/operation/RebalanceOperationPerformer.java