Uploaded image for project: 'Hadoop YARN'
  1. Hadoop YARN
  2. YARN-11052

Improve code quality in TestRMWebServicesNodeLabels

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 3.4.0
    • test
    • Reviewed

    Description

      Possible code improvements I've identified in this class:

      1. In TestRMWebServicesNodeLabels#testNodeLabels: Missing HTTP response status code checks for successful operations
      2. Some methods are throwing too many types of Exceptions, e.g. "throws JSONException, Exception" can be simplified to "throws Exception"
      3. Repeated code fragments can be replaced. E.g.:

      assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
          response.getType().toString());
      

      4. Some variable names are confusing, e.g. "NodeLabelsInfo nlsifo"
      5. There are many node label related endpoint calls, all copy-pasted, for example:

      response =
          r.path("ws").path("v1").path("cluster")
              .path("add-node-labels").queryParam("user.name", userName)
              .accept(MediaType.APPLICATION_JSON)
              .entity(toJson(nodeLabelsInfo, NodeLabelsInfo.class),
                  MediaType.APPLICATION_JSON)
              .post(ClientResponse.class);
      

      This is just an example, there are many many endpoint calls duplicated like this, they could be extracted to methods.

      6. Duplicated validation code of all REST endpoints can be simplified
      7. There are weird, repeated log strings that could be removed, like:

      LOG.info("posted node nodelabel")
      

      8. Constants could be added for labels, node ids, etc.

      Attachments

        Issue Links

          Activity

            People

              snemeth Szilard Nemeth
              snemeth Szilard Nemeth
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 4h 50m
                  4h 50m