You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2017/05/09 09:39:48 UTC
svn commit: r1794516 - in /jackrabbit/oak/trunk/oak-commons/src:
main/java/org/apache/jackrabbit/oak/commons/IOUtils.java
test/java/org/apache/jackrabbit/oak/commons/IOUtilsTest.java
Author: mduerig
Date: Tue May 9 09:39:48 2017
New Revision: 1794516
URL: http://svn.apache.org/viewvc?rev=1794516&view=rev
Log:
OAK-6175: Add unit test coverage for IOUtils.humanReadableByteCount
Use ENGLISH local to encode the human readable byte count
Credits to Matt Ryan for the patch
Modified:
jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/IOUtils.java
jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/IOUtilsTest.java
Modified: jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/IOUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/IOUtils.java?rev=1794516&r1=1794515&r2=1794516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/IOUtils.java (original)
+++ jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/IOUtils.java Tue May 9 09:39:48 2017
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
+import java.util.Locale;
/**
* Input/output utility methods.
@@ -364,6 +365,6 @@ public final class IOUtils {
}
int exp = (int) (Math.log(bytes) / Math.log(unit));
char pre = "kMGTPE".charAt(exp - 1);
- return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
+ return String.format(Locale.ENGLISH, "%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
}
Modified: jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/IOUtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/IOUtilsTest.java?rev=1794516&r1=1794515&r2=1794516&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/IOUtilsTest.java (original)
+++ jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/IOUtilsTest.java Tue May 9 09:39:48 2017
@@ -286,31 +286,30 @@ public class IOUtilsTest extends TestCas
}
}
-// FIXME OAK-6175: test expectations fail to take the locale into account
-// public void testHumanReadableByteCount() {
-// assertEquals("0 B", IOUtils.humanReadableByteCount(0L));
-// assertEquals("1 B", IOUtils.humanReadableByteCount(1L));
-// assertEquals("999 B", IOUtils.humanReadableByteCount(999L));
-// assertEquals("1.0 kB", IOUtils.humanReadableByteCount(1000L));
-// assertEquals("1.0 kB", IOUtils.humanReadableByteCount(1001L));
-// assertEquals("1.1 kB", IOUtils.humanReadableByteCount(1100L));
-// assertEquals("2.0 kB", IOUtils.humanReadableByteCount(2000L));
-// assertEquals("1000.0 kB", IOUtils.humanReadableByteCount(999999L));
-// assertEquals("1.0 MB", IOUtils.humanReadableByteCount(1000000L));
-// assertEquals("1.0 MB", IOUtils.humanReadableByteCount(1010000L));
-// assertEquals("1.1 MB", IOUtils.humanReadableByteCount(1100000L));
-// assertEquals("2.0 MB", IOUtils.humanReadableByteCount(2000000L));
-// assertEquals("2.1 GB", IOUtils.humanReadableByteCount(Integer.MAX_VALUE));
-// assertEquals("54.3 GB", IOUtils.humanReadableByteCount(54320000000L));
-// assertEquals("20.6 TB", IOUtils.humanReadableByteCount(20560000000000L));
-// assertEquals("377.5 PB", IOUtils.humanReadableByteCount(377500000000000000L));
-// assertEquals("1.0 EB", IOUtils.humanReadableByteCount(1000000000000000000L));
-// assertEquals("9.2 EB", IOUtils.humanReadableByteCount(Long.MAX_VALUE));
-// assertEquals("0 B", IOUtils.humanReadableByteCount(-0L));
-// assertEquals("0", IOUtils.humanReadableByteCount(-1L));
-// assertEquals("0", IOUtils.humanReadableByteCount(Integer.MIN_VALUE));
-// assertEquals("0", IOUtils.humanReadableByteCount(Long.MIN_VALUE));
-// }
+ public void testHumanReadableByteCount() {
+ assertEquals("0 B", IOUtils.humanReadableByteCount(0L));
+ assertEquals("1 B", IOUtils.humanReadableByteCount(1L));
+ assertEquals("999 B", IOUtils.humanReadableByteCount(999L));
+ assertEquals("1.0 kB", IOUtils.humanReadableByteCount(1000L));
+ assertEquals("1.0 kB", IOUtils.humanReadableByteCount(1001L));
+ assertEquals("1.1 kB", IOUtils.humanReadableByteCount(1100L));
+ assertEquals("2.0 kB", IOUtils.humanReadableByteCount(2000L));
+ assertEquals("1000.0 kB", IOUtils.humanReadableByteCount(999999L));
+ assertEquals("1.0 MB", IOUtils.humanReadableByteCount(1000000L));
+ assertEquals("1.0 MB", IOUtils.humanReadableByteCount(1010000L));
+ assertEquals("1.1 MB", IOUtils.humanReadableByteCount(1100000L));
+ assertEquals("2.0 MB", IOUtils.humanReadableByteCount(2000000L));
+ assertEquals("2.1 GB", IOUtils.humanReadableByteCount(Integer.MAX_VALUE));
+ assertEquals("54.3 GB", IOUtils.humanReadableByteCount(54320000000L));
+ assertEquals("20.6 TB", IOUtils.humanReadableByteCount(20560000000000L));
+ assertEquals("377.5 PB", IOUtils.humanReadableByteCount(377500000000000000L));
+ assertEquals("1.0 EB", IOUtils.humanReadableByteCount(1000000000000000000L));
+ assertEquals("9.2 EB", IOUtils.humanReadableByteCount(Long.MAX_VALUE));
+ assertEquals("0 B", IOUtils.humanReadableByteCount(-0L));
+ assertEquals("0", IOUtils.humanReadableByteCount(-1L));
+ assertEquals("0", IOUtils.humanReadableByteCount(Integer.MIN_VALUE));
+ assertEquals("0", IOUtils.humanReadableByteCount(Long.MIN_VALUE));
+ }
private static void testVarInt(int x, int expectedLen) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();