You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:39:01 UTC

[GitHub] [cloudstack] rhtyd commented on a change in pull request #4207: Human readable sizes in logs

rhtyd commented on a change in pull request #4207:
URL: https://github.com/apache/cloudstack/pull/4207#discussion_r462080672



##########
File path: utils/src/test/java/com/cloud/utils/HumanReadableJsonTest.java
##########
@@ -0,0 +1,53 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+package com.cloud.utils;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static com.cloud.utils.HumanReadableJson.getHumanReadableBytesJson;
+
+public class HumanReadableJsonTest {
+
+    @Test
+    public void parseJsonObjectTest() {
+        assertEquals("{}", getHumanReadableBytesJson("{}"));
+    }
+    @Test
+    public void parseJsonArrayTest() {
+        assertEquals("[]", getHumanReadableBytesJson("[]"));
+        assertEquals("[{},{}]", getHumanReadableBytesJson("[{},{}]"));
+    }
+    @Test
+    public void parseSimpleJsonTest() {
+        assertEquals("[{\"object\":{}}]", getHumanReadableBytesJson("[{\"object\":{}}]"));
+    }
+    @Test
+    public void parseComplexJsonTest() {
+        assertEquals("[{\"object\":[]}]", getHumanReadableBytesJson("[{\"object\":[]}]"));
+        assertEquals("[{\"object\":[{},{}]}]", getHumanReadableBytesJson("[{\"object\":[{},{}]}]"));
+        assertEquals("[{\"object\":[]},{\"object\":[]}]", getHumanReadableBytesJson("[{\"object\":[]},{\"object\":[]}]"));
+        assertEquals("[{\"object\":[{\"object\":[]}]},{\"object\":[]}]", getHumanReadableBytesJson("[{\"object\":[{\"object\":[]}]},{\"object\":[]}]"));
+    }
+    @Test
+    public void parseMatchJsonTest() {

Review comment:
       @Spaceman1984 can you add tests for non zero values, and see if the expected results match? (for kbs, mbs, gbs)

##########
File path: utils/src/main/java/com/cloud/utils/NumbersUtil.java
##########
@@ -93,6 +95,13 @@ public static String toReadableSize(long bytes) {
         return builder.toString();
     }
 
+    public static String toHumanReadableSize(long size) {

Review comment:
       @Spaceman1984 can you add unit test for this method, giving some values such as zero and non-zero (to test KB, MB, GB, TB). Have you verified that all consumes would pass `long` to it and not `Long` which may potentially cause a NPE?




----------------------------------------------------------------
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.

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