devmadhuu commented on code in PR #6651:
URL: https://github.com/apache/ozone/pull/6651#discussion_r1596476788
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/heatmap/TestHeatMapInfo.java:
##########
@@ -745,35 +744,43 @@ public void setUp() throws Exception {
public void testHeatMapGeneratedInfo() throws IOException {
// Setup
// Run the test
- JsonElement jsonElement = JsonParser.parseString(auditRespStr);
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- JsonElement facets = jsonObject.get("facets");
- JsonObject facetsBucketsObject =
- facets.getAsJsonObject().get("resources")
- .getAsJsonObject();
- ObjectMapper objectMapper = new ObjectMapper();
+ // Parse the JSON string to JsonNode
+ JsonNode rootNode = JsonUtils.readTree(auditRespStr);
- HeatMapProviderDataResource auditLogFacetsResources =
- objectMapper.readValue(
- facetsBucketsObject.toString(), HeatMapProviderDataResource.class);
- EntityMetaData[] entities = auditLogFacetsResources.getMetaDataList();
- List<EntityMetaData> entityMetaDataList =
- Arrays.stream(entities).collect(Collectors.toList());
- EntityReadAccessHeatMapResponse entityReadAccessHeatMapResponse =
- heatMapUtil.generateHeatMap(entityMetaDataList);
-
assertThat(entityReadAccessHeatMapResponse.getChildren().size()).isGreaterThan(0);
- assertEquals(12, entityReadAccessHeatMapResponse.getChildren().size());
- assertEquals(25600, entityReadAccessHeatMapResponse.getSize());
- assertEquals(2924, entityReadAccessHeatMapResponse.getMinAccessCount());
- assertEquals(155074, entityReadAccessHeatMapResponse.getMaxAccessCount());
- assertEquals("root", entityReadAccessHeatMapResponse.getLabel());
- assertEquals(0.0,
entityReadAccessHeatMapResponse.getChildren().get(0).getColor());
- assertEquals(0.442,
- entityReadAccessHeatMapResponse.getChildren().get(0).getChildren()
- .get(0).getChildren().get(1).getColor());
- assertEquals(0.058,
- entityReadAccessHeatMapResponse.getChildren().get(0).getChildren()
- .get(1).getChildren().get(3).getColor());
+ JsonNode facetsNode = rootNode.path("facets");
+ JsonNode resourcesNode = facetsNode.path("resources");
+
+ // Deserialize the resources node directly if it's not missing
+ HeatMapProviderDataResource auditLogFacetsResources = null;
+
+// assumeThat(resourcesNode.isMissingNode()).isFalse();
+
+ auditLogFacetsResources = JsonTestUtils.treeToValue(resourcesNode,
Review Comment:
```suggestion
HeatMapProviderDataResource auditLogFacetsResources =
auditLogFacetsResources = JsonTestUtils.treeToValue(resourcesNode,
```
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java:
##########
@@ -409,12 +408,12 @@ private int getNumOfBuckets(String bucketPrefix)
}
/**
- * Parse output into ArrayList with Gson.
+ * Parse output into ArrayList with Jackson.
* @return ArrayList
*/
- private ArrayList<LinkedTreeMap<String, String>> parseOutputIntoArrayList()
- throws UnsupportedEncodingException {
- return new Gson().fromJson(out.toString(DEFAULT_ENCODING),
ArrayList.class);
+ private List<Map<String, Object>> parseOutputIntoArrayList() throws
IOException {
+ String jsonInput = out.toString(DEFAULT_ENCODING);
+ return JsonTestUtils.readTreeAsListOfMaps(jsonInput);
Review Comment:
```suggestion
return
JsonTestUtils.readTreeAsListOfMaps(out.toString(DEFAULT_ENCODING));
```
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/heatmap/TestHeatMapInfo.java:
##########
@@ -745,35 +744,43 @@ public void setUp() throws Exception {
public void testHeatMapGeneratedInfo() throws IOException {
// Setup
// Run the test
- JsonElement jsonElement = JsonParser.parseString(auditRespStr);
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- JsonElement facets = jsonObject.get("facets");
- JsonObject facetsBucketsObject =
- facets.getAsJsonObject().get("resources")
- .getAsJsonObject();
- ObjectMapper objectMapper = new ObjectMapper();
+ // Parse the JSON string to JsonNode
+ JsonNode rootNode = JsonUtils.readTree(auditRespStr);
- HeatMapProviderDataResource auditLogFacetsResources =
- objectMapper.readValue(
- facetsBucketsObject.toString(), HeatMapProviderDataResource.class);
- EntityMetaData[] entities = auditLogFacetsResources.getMetaDataList();
- List<EntityMetaData> entityMetaDataList =
- Arrays.stream(entities).collect(Collectors.toList());
- EntityReadAccessHeatMapResponse entityReadAccessHeatMapResponse =
- heatMapUtil.generateHeatMap(entityMetaDataList);
-
assertThat(entityReadAccessHeatMapResponse.getChildren().size()).isGreaterThan(0);
- assertEquals(12, entityReadAccessHeatMapResponse.getChildren().size());
- assertEquals(25600, entityReadAccessHeatMapResponse.getSize());
- assertEquals(2924, entityReadAccessHeatMapResponse.getMinAccessCount());
- assertEquals(155074, entityReadAccessHeatMapResponse.getMaxAccessCount());
- assertEquals("root", entityReadAccessHeatMapResponse.getLabel());
- assertEquals(0.0,
entityReadAccessHeatMapResponse.getChildren().get(0).getColor());
- assertEquals(0.442,
- entityReadAccessHeatMapResponse.getChildren().get(0).getChildren()
- .get(0).getChildren().get(1).getColor());
- assertEquals(0.058,
- entityReadAccessHeatMapResponse.getChildren().get(0).getChildren()
- .get(1).getChildren().get(3).getColor());
+ JsonNode facetsNode = rootNode.path("facets");
+ JsonNode resourcesNode = facetsNode.path("resources");
+
+ // Deserialize the resources node directly if it's not missing
+ HeatMapProviderDataResource auditLogFacetsResources = null;
+
+// assumeThat(resourcesNode.isMissingNode()).isFalse();
Review Comment:
Remove this commented code. Pls check other places also.
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/heatmap/TestHeatMapInfo.java:
##########
@@ -965,150 +972,149 @@ public void
testHeatMapInfoResponseWithEntityTypeBucket() throws IOException {
" }\n" +
" }\n" +
"}";
- JsonElement jsonElement =
- JsonParser.parseString(auditRespStrWithPathAndBucketEntityType);
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- JsonElement facets = jsonObject.get("facets");
- JsonElement resources = facets.getAsJsonObject().get("resources");
- JsonObject facetsBucketsObject = new JsonObject();
- if (null != resources) {
- facetsBucketsObject = resources.getAsJsonObject();
- }
- ObjectMapper objectMapper = new ObjectMapper();
- HeatMapProviderDataResource auditLogFacetsResources =
- objectMapper.readValue(
- facetsBucketsObject.toString(), HeatMapProviderDataResource.class);
- EntityMetaData[] entities = auditLogFacetsResources.getMetaDataList();
- if (null != entities && entities.length > 0) {
- List<EntityMetaData> entityMetaDataList =
- Arrays.stream(entities).collect(Collectors.toList());
- // Below heatmap response would be of format like:
- //{
- // "label": "root",
- // "path": "/",
- // "children": [
- // {
- // "label": "testnewvol2",
- // "path": "testnewvol2",
- // "children": [
- // {
- // "label": "fsobuck11",
- // "path": "/testnewvol2/fsobuck11",
- // "children": [
- // {
- // "label": "",
- // "path": "/testnewvol2/fsobuck11/",
- // "size": 100,
- // "accessCount": 701,
- // "color": 1.0
- // }
- // ],
- // "size": 100,
- // "minAccessCount": 701,
- // "maxAccessCount": 701
- // },
- // {
- // "label": "fsobuck12",
- // "path": "/testnewvol2/fsobuck12",
- // "children": [
- // {
- // "label": "",
- // "path": "/testnewvol2/fsobuck12/",
- // "size": 100,
- // "accessCount": 701,
- // "color": 1.0
- // }
- // ],
- // "size": 100,
- // "minAccessCount": 701,
- // "maxAccessCount": 701
- // },
- // {
- // "label": "fsobuck13",
- // "path": "/testnewvol2/fsobuck13",
- // "children": [
- // {
- // "label": "",
- // "path": "/testnewvol2/fsobuck13/",
- // "size": 100,
- // "accessCount": 701,
- // "color": 1.0
- // }
- // ],
- // "size": 100,
- // "minAccessCount": 701,
- // "maxAccessCount": 701
- // },
- // {
- // "label": "obsbuck11",
- // "path": "/testnewvol2/obsbuck11",
- // "children": [
- // {
- // "label": "",
- // "path": "/testnewvol2/obsbuck11/",
- // "size": 107,
- // "accessCount": 263,
- // "color": 1.0
- // }
- // ],
- // "size": 107,
- // "minAccessCount": 263,
- // "maxAccessCount": 263
- // },
- // {
- // "label": "obsbuck12",
- // "path": "/testnewvol2/obsbuck12",
- // "children": [
- // {
- // "label": "",
- // "path": "/testnewvol2/obsbuck12/",
- // "size": 100,
- // "accessCount": 200,
- // "color": 1.0
- // }
- // ],
- // "size": 100,
- // "minAccessCount": 200,
- // "maxAccessCount": 200
- // },
- // {
- // "label": "obsbuck13",
- // "path": "/testnewvol2/obsbuck13",
- // "children": [
- // {
- // "label": "",
- // "path": "/testnewvol2/obsbuck13/",
- // "size": 100,
- // "accessCount": 200,
- // "color": 1.0
- // }
- // ],
- // "size": 100,
- // "minAccessCount": 200,
- // "maxAccessCount": 200
- // }
- // ],
- // "size": 607
- // }
- // ],
- // "size": 607,
- // "minAccessCount": 200,
- // "maxAccessCount": 701
- //}
- EntityReadAccessHeatMapResponse entityReadAccessHeatMapResponse =
- heatMapUtil.generateHeatMap(entityMetaDataList);
-
assertThat(entityReadAccessHeatMapResponse.getChildren().size()).isGreaterThan(0);
- assertEquals(2,
- entityReadAccessHeatMapResponse.getChildren().size());
- assertEquals(0.0,
- entityReadAccessHeatMapResponse.getChildren().get(0).getColor());
- String path =
- entityReadAccessHeatMapResponse.getChildren().get(1).getChildren()
- .get(0).getPath();
- assertEquals("/testnewvol2/fsobuck11", path);
- } else {
- assertNull(entities);
+ JsonNode rootNode =
JsonUtils.readTree(auditRespStrWithPathAndBucketEntityType);
+ // Navigate to the nested JSON objects
+ JsonNode facetsNode = rootNode.path("facets");
+ JsonNode resourcesNode = facetsNode.path("resources");
+ // Deserialize the resources node directly if it's not missing
+ HeatMapProviderDataResource auditLogFacetsResources = null;
+// assumeThat(resourcesNode.isMissingNode()).isFalse();
Review Comment:
Remove this commented code. Pls check other places also.
--
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]