diff --git a/src/main/java/com/baidu/hugegraph/util/TimeUtil.java b/src/main/java/com/baidu/hugegraph/util/TimeUtil.java index 76c3751df..35696f0de 100644 --- a/src/main/java/com/baidu/hugegraph/util/TimeUtil.java +++ b/src/main/java/com/baidu/hugegraph/util/TimeUtil.java @@ -48,6 +48,10 @@ public static long tillNextMillis(long lastTimestamp) { } public static String readableTime(long time) { + if (time > 60 * 1000) { + // Remove the milliseconds part + time = time / 1000 * 1000; + } Duration duration = Duration.ofMillis(time); return duration.toString() .substring(2) diff --git a/src/test/java/com/baidu/hugegraph/unit/util/StringUtilTest.java b/src/test/java/com/baidu/hugegraph/unit/util/StringUtilTest.java index 5a090c516..2c9fd4fc4 100644 --- a/src/test/java/com/baidu/hugegraph/unit/util/StringUtilTest.java +++ b/src/test/java/com/baidu/hugegraph/unit/util/StringUtilTest.java @@ -33,23 +33,23 @@ public class StringUtilTest { @Test public void testSplit() { Assert.assertEquals(guavaSplit("123", " "), - toList(StringUtil.split("123", " "))); + toStringList(StringUtil.split("123", " "))); Assert.assertEquals(guavaSplit("1 2 3", " "), - toList(StringUtil.split("1 2 3", " "))); + toStringList(StringUtil.split("1 2 3", " "))); Assert.assertEquals(guavaSplit("1:2:3", ":"), - toList(StringUtil.split("1:2:3", ":"))); + toStringList(StringUtil.split("1:2:3", ":"))); Assert.assertEquals(guavaSplit("1::2:3", ":"), - toList(StringUtil.split("1::2:3", ":"))); + toStringList(StringUtil.split("1::2:3", ":"))); Assert.assertEquals(guavaSplit("1::2::3", ":"), - toList(StringUtil.split("1::2::3", ":"))); + toStringList(StringUtil.split("1::2::3", ":"))); Assert.assertEquals(guavaSplit("1::2::3", "::"), - toList(StringUtil.split("1::2::3", "::"))); + toStringList(StringUtil.split("1::2::3", "::"))); Assert.assertEquals(guavaSplit("1:|2|:3", "|"), - toList(StringUtil.split("1:|2|:3", "|"))); + toStringList(StringUtil.split("1:|2|:3", "|"))); Assert.assertEquals(guavaSplit("1\t2\t3", "\t"), - toList(StringUtil.split("1\t2\t3", "\t"))); + toStringList(StringUtil.split("1\t2\t3", "\t"))); Assert.assertEquals(guavaSplit("111", "1"), - toList(StringUtil.split("111", "1"))); + toStringList(StringUtil.split("111", "1"))); Assert.assertThrows(IllegalArgumentException.class, () -> { StringUtil.split("123", ""); @@ -60,7 +60,7 @@ private static List guavaSplit(String line, String delimiter) { return Splitter.on(delimiter).splitToList(line); } - private static List toList(List chars) { + private static List toStringList(List chars) { List results = new ArrayList<>(chars.size()); for (CharSequence seq : chars) { results.add(seq.toString()); diff --git a/src/test/java/com/baidu/hugegraph/unit/util/TimeUtilTest.java b/src/test/java/com/baidu/hugegraph/unit/util/TimeUtilTest.java index 9db52554c..13f831af5 100644 --- a/src/test/java/com/baidu/hugegraph/unit/util/TimeUtilTest.java +++ b/src/test/java/com/baidu/hugegraph/unit/util/TimeUtilTest.java @@ -70,10 +70,14 @@ public void testReadableTime() { Assert.assertEquals("15s", TimeUtil.readableTime(15 * 1000)); Assert.assertEquals("59.99s", TimeUtil.readableTime(59990)); Assert.assertEquals("1m", TimeUtil.readableTime(60000)); - Assert.assertEquals("1m 0.1s", TimeUtil.readableTime(60000 + 100)); + // Ignore milliseconds part + Assert.assertEquals("1m", TimeUtil.readableTime(60000 + 100)); Assert.assertEquals("1m 1s", TimeUtil.readableTime(60000 + 1000)); + Assert.assertEquals("1m 1s", TimeUtil.readableTime(60000 + 1200)); Assert.assertEquals("59m", TimeUtil.readableTime(59 * 60 * 1000)); Assert.assertEquals("1h", TimeUtil.readableTime(60 * 60 * 1000)); + Assert.assertEquals("1h 1m", TimeUtil.readableTime(60 * 60 * 1000 + + 60 * 1000)); Assert.assertEquals("23h 59m 59s", TimeUtil.readableTime( 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + @@ -82,6 +86,6 @@ public void testReadableTime() { Assert.assertEquals("25h 1m 1s", TimeUtil.readableTime( 25 * 60 * 60 * 1000 + 1 * 60 * 1000 + - 1 * 1000)); + 1 * 1200)); } }