private IdealState cloneIdealState(IdealState state, String newResourceName) {
    IdealState newState = new IdealState(newResourceName);
    newState.setStateModelDefRef(state.getStateModelDefRef());
    for (Map.Entry<String, List<String>> entry : state.getPreferenceLists().entrySet()) {
      String partitionName = entry.getKey();
      ArrayList<String> instances = new ArrayList<>(entry.getValue());
      Collections.shuffle(instances);
      newState.setPreferenceList(partitionName, instances);
    }
    newState.setNumPartitions(state.getPreferenceLists().size());
    newState.setReplicas(ResourceConfig.ResourceConfigConstants.ANY_LIVEINSTANCE.name());
    if (!newState.isValid()) {
      throw new IllegalStateException("IdealState could not be validated for new resource " + newResourceName);
    }
    return newState;
  }
Assert that the state of datanodes in the cluster manager's view are consistent with their actual states in the
cluster.
@param expectedDownInstances the expected down instances set in cluster manager.
@param expectedUpInstances the expected up instances set in cluster manager.
ambry-clustermap/src/test/java/com/github/ambry/clustermap/HelixClusterManagerTest.java