DataNode replaceDataNodeWithNewOne(DataNode dataNode) throws JSONException {
      this.version += 1;
      // replace the data node, so the number of data node is not changed
      for (int i = 0; i < datacenterCount; i++) {
        JSONArray dataNodes = datanodeJSONArrays.get(i);
        for (int j = 0; j < dataNodes.length(); j++) {
          JSONObject dataNodeFromJson = dataNodes.getJSONObject(j);
          if (dataNodeFromJson.getString("hostname").equals(dataNode.getHostname())
              && dataNodeFromJson.getInt("port") == dataNode.getPort()) {
            // Create a new one and replace it.
            JSONArray disksArray = getDisks();
            JSONObject newDataNodeInJson;
            int curBasePort = basePort;
            int sslPort = curBasePort + 10000;
            int http2Port = sslPort + 10000;
            if (rackAware) {
              newDataNodeInJson =
                  getJsonDataNode(getLocalHost(), curBasePort, sslPort, http2Port, dataNodeFromJson.getLong("rackId"),
                      DEFAULT_XID, disksArray, HardwareState.AVAILABLE);
            } else {
              newDataNodeInJson =
                  getJsonDataNode(getLocalHost(), curBasePort, sslPort, http2Port, HardwareState.AVAILABLE, disksArray);
            }
            dataNodes.put(j, newDataNodeInJson);
            basePort += 1;
            this.hardwareLayout = new HardwareLayout(
                getJsonHardwareLayout(clusterName, TestUtils.getJsonArrayDatacenters(names, datanodeJSONArrays)),
                new ClusterMapConfig(new VerifiableProperties(properties)));
            return this.hardwareLayout.findDataNode(getLocalHost(), curBasePort);
          }
        }
      }
      throw new IllegalStateException(
          "DataNode " + dataNode.getHostname() + ":" + dataNode.getPort() + " can't be found");
    }
@param rangeStart start of the range of partitions.
@param count the number of partitions in the range.
@param expectedClass the expected class of all of the partitions
@param expectedState the expected state of all of the partitions
ambry-clustermap/src/test/java/com/github/ambry/clustermap/TestUtils.java