K0K0V0K commented on code in PR #6432:
URL: https://github.com/apache/hadoop/pull/6432#discussion_r1448689111
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestWebServiceUtil.java:
##########
@@ -213,15 +207,74 @@ public static void assertJsonResponse(ClientResponse
response,
IOException {
assertJsonType(response);
JSONObject json = response.getEntity(JSONObject.class);
+ sortQueuesLexically(json);
String actual = prettyPrintJson(json.toString(2));
updateTestDataAutomatically(expectedResourceFilename, actual);
assertEquals(
prettyPrintJson(getResourceAsString(expectedResourceFilename)),
actual);
}
+ /**
+ * Sorts the "queue": [ {}, {}, {} ] parts recursively by the queuePath key.
+ *
+ * <p>
+ * There was a marshalling error described in YARN-4785 in
CapacitySchedulerInfo.getQueues().
+ * If that issue still present, we can't sort the queues there, but only
sort the leaf queues
+ * then the non-leaf queues which would make a consistent output, but hard
to document.
+ * Instead we make sure the test data is at least ordered by queue names.
+ * </p>
+ *
+ * @param object the json object to sort.
+ * @throws JSONException when
+ */
+ private static void sortQueuesLexically(JSONObject object) throws
JSONException {
+ Iterator<?> keys = object.keys();
+ while (keys.hasNext()) {
+ String key = (String) keys.next();
+ Object o = object.get(key);
+ if (key.equals("queue") && (o instanceof JSONArray)) {
+ JSONArray original = (JSONArray) o;
+
+ List<JSONObject> queues = new ArrayList<>(original.length());
+ for (int i = 0; i < original.length(); i++) {
+ if (original.get(i) instanceof JSONObject) {
+ queues.add((JSONObject) original.get(i));
+ }
+ }
+ queues.sort(new Comparator<JSONObject>() {
+ private static final String SORT_BY_KEY = "queuePath";
+
+ @Override
+ public int compare(JSONObject a, JSONObject b) {
+ String vA = "";
+ String vB = "";
+
+ try {
+ vA = (String) a.get(SORT_BY_KEY);
+ vB = (String) b.get(SORT_BY_KEY);
+ } catch (JSONException ignored) {
+ }
+
+ return vA.compareTo(vB);
+ }
+ });
+
+ JSONArray sortedArray = new JSONArray(queues.size());
+ for (JSONObject queue : queues) {
Review Comment:
Can we use the putAll method here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]