You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/10/06 08:12:43 UTC

[GitHub] [ozone] ayushtkn commented on a change in pull request #2713: HDDS-5824. `ozone sh volume list` should print valid JSON array

ayushtkn commented on a change in pull request #2713:
URL: https://github.com/apache/ozone/pull/2713#discussion_r722963383



##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
##########
@@ -22,10 +22,14 @@
 import java.io.FileNotFoundException;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
 import java.util.UUID;
 
+import com.google.gson.Gson;
+import com.google.gson.internal.LinkedTreeMap;

Review comment:
       The import order is wrong should be in the below block with ```import com.google.common.base.Strings```

##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
##########
@@ -855,4 +861,36 @@ public void testShQuota() throws Exception {
     objectStore.getVolume("vol4").deleteBucket("buck4");
     objectStore.deleteVolume("vol4");
   }
+
+  @Test
+  public void testListVolumeShouldPrintValidJson()
+      throws UnsupportedEncodingException {
+
+    final List<String> volumesForThisTest =
+        Arrays.asList("random-vol1", "random-vol2", "random-vol3");
+
+    // Create test volumes
+    volumesForThisTest.forEach(vol ->
+        execute(ozoneShell, new String[] {"volume", "create", vol}));
+    out.reset();
+
+    execute(ozoneShell, new String[] {"volume", "list"});
+
+    // Expect proper JSON output
+    final ArrayList<LinkedTreeMap<String, String>> outArray =
+        new Gson().fromJson(out.toString(DEFAULT_ENCODING), ArrayList.class);

Review comment:
       Out of curiosity why ``toString(DEFAULT_ENCODING)`` isn't it already set to UTF_8 in the before?

##########
File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
##########
@@ -855,4 +861,36 @@ public void testShQuota() throws Exception {
     objectStore.getVolume("vol4").deleteBucket("buck4");
     objectStore.deleteVolume("vol4");
   }
+
+  @Test
+  public void testListVolumeShouldPrintValidJson()
+      throws UnsupportedEncodingException {
+
+    final List<String> volumesForThisTest =
+        Arrays.asList("random-vol1", "random-vol2", "random-vol3");
+
+    // Create test volumes
+    volumesForThisTest.forEach(vol ->
+        execute(ozoneShell, new String[] {"volume", "create", vol}));
+    out.reset();
+
+    execute(ozoneShell, new String[] {"volume", "list"});
+
+    // Expect proper JSON output
+    final ArrayList<LinkedTreeMap<String, String>> outArray =
+        new Gson().fromJson(out.toString(DEFAULT_ENCODING), ArrayList.class);
+    // Might have s3v and volumes from other test cases that aren't clean up.
+    Assert.assertTrue(outArray.size() >= 3);
+    final HashSet<String> volumesSet = new HashSet<>(volumesForThisTest);
+    outArray.forEach(treeMap -> volumesSet.remove(treeMap.get("name")));
+
+    // Should have found all 3 volumes we created for this test
+    Assert.assertEquals(0, volumesSet.size());
+
+    // Clean up
+    volumesForThisTest.forEach(vol ->
+        execute(ozoneShell, new String[] {"volume", "delete", vol}));
+    out.reset();
+    err.reset();

Review comment:
       This seems redundant? The After block does this reset?

##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ListVolumeHandler.java
##########
@@ -85,11 +85,18 @@ protected void execute(OzoneClient client, OzoneAddress address)
     }
 
     int counter = 0;
+    final StringBuilder res = new StringBuilder("[ ");  // Mark JSON array start

Review comment:
       Quick Question:
   Why you can't use the `out` itself? Why you are moving to `StringBuilder`? Earlier the flow was we are just producing json and pushing it to the out stream, now If I catch correct we will be storing it till the end and then push, Any reasons for doing so? Does this approach not increase the memory pressure, storing the entire list till end? Or did I interpret it wrong?




-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org