[ https://issues.apache.org/jira/browse/YARN-11645?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17805524#comment-17805524 ]
ASF GitHub Bot commented on YARN-11645: --------------------------------------- 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? > Fix flaky json assert tests in TestRMWebServices > ------------------------------------------------ > > Key: YARN-11645 > URL: https://issues.apache.org/jira/browse/YARN-11645 > Project: Hadoop YARN > Issue Type: Bug > Components: capacityscheduler > Affects Versions: 3.4.0 > Reporter: Tamas Domok > Assignee: Tamas Domok > Priority: Major > Labels: pull-request-available > > TestRMWebServicesCapacitySchedDynamicConfig and > TestRMWebServicesCapacitySchedulerMixedMode are flaky due to changes in the > queue order. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: yarn-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: yarn-issues-h...@hadoop.apache.org