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 17:46:28 UTC

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

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



##########
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:
       @rhtyd these tests already exist in NumbersUtilTest.java

##########
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:
       I have added a check and a test for null which prevents an NPE.

##########
File path: utils/src/test/java/com/cloud/utils/HumanReadableJsonTest.java
##########
@@ -50,4 +51,14 @@ public void parseMatchJsonTest() {
         assertEquals("[{\"size\":\"(0 bytes) 0\"}]", getHumanReadableBytesJson("[{\"size\": \"0\"}]"));
         assertEquals("[{\"size\":\"(0 bytes) 0\",\"bytesSent\":\"(0 bytes) 0\"}]", getHumanReadableBytesJson("[{\"size\": \"0\", \"bytesSent\": \"0\"}]"));
     }
+
+    @Test
+    public void localeTest() {
+        Locale.setDefault(Locale.UK); // UK test

Review comment:
       @rhtyd From Java Docs:
   "The Java Virtual Machine sets the default locale during startup based on the host environment. It is used by many locale-sensitive methods if no locale is explicitly specified. It can be changed using the setDefault method."




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