You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celeborn.apache.org by ch...@apache.org on 2023/07/06 11:34:43 UTC
[incubator-celeborn] branch main updated: [CELEBORN-747][FOLLOWUP] Fix nanoDurationToString and add UT
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new a556b02bc [CELEBORN-747][FOLLOWUP] Fix nanoDurationToString and add UT
a556b02bc is described below
commit a556b02bc1e898f09781bf562fd0a4896c8ed344
Author: Cheng Pan <ch...@apache.org>
AuthorDate: Thu Jul 6 19:34:35 2023 +0800
[CELEBORN-747][FOLLOWUP] Fix nanoDurationToString and add UT
### What changes were proposed in this pull request?
Sorry, the last added `nanoDurationToString` is not correct, this PR fixes it and adds UT to verify.
### Why are the changes needed?
Bug fix.
### Does this PR introduce _any_ user-facing change?
No, unreleased change.
### How was this patch tested?
UT.
Closes #1688 from pan3793/CELEBORN-747-followup2.
Authored-by: Cheng Pan <ch...@apache.org>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../scala/org/apache/celeborn/common/util/Utils.scala | 4 ++--
.../org/apache/celeborn/common/util/UtilsSuite.scala | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/common/src/main/scala/org/apache/celeborn/common/util/Utils.scala b/common/src/main/scala/org/apache/celeborn/common/util/Utils.scala
index 04ac4744d..c6a072ddf 100644
--- a/common/src/main/scala/org/apache/celeborn/common/util/Utils.scala
+++ b/common/src/main/scala/org/apache/celeborn/common/util/Utils.scala
@@ -146,7 +146,7 @@ object Utils extends Logging {
}
def nanoDurationToString(ns: Long): String = {
- val ms = 1000 * 1000
+ val ms = 1000 * 1000L
val second = 1000 * ms
val minute = 60 * second
val hour = 60 * minute
@@ -156,7 +156,7 @@ object Utils extends Logging {
case t if t < ms =>
"%d ns".formatLocal(locale, t)
case t if t < second =>
- "%d ms".formatLocal(locale, t)
+ "%.1f ms".formatLocal(locale, t.toFloat / ms)
case t if t < minute =>
"%.1f s".formatLocal(locale, t.toFloat / second)
case t if t < hour =>
diff --git a/common/src/test/scala/org/apache/celeborn/common/util/UtilsSuite.scala b/common/src/test/scala/org/apache/celeborn/common/util/UtilsSuite.scala
index e3e812a0d..ff9157448 100644
--- a/common/src/test/scala/org/apache/celeborn/common/util/UtilsSuite.scala
+++ b/common/src/test/scala/org/apache/celeborn/common/util/UtilsSuite.scala
@@ -60,6 +60,23 @@ class UtilsSuite extends CelebornFunSuite {
assert("16.0 GiB" == Utils.bytesToString(17179869184L))
}
+ test("msDurationToString") {
+ assert(Utils.msDurationToString(1) === "1 ms")
+ assert(Utils.msDurationToString(1234) === "1.2 s")
+ assert(Utils.msDurationToString(67890) === "1.1 m")
+ assert(Utils.msDurationToString(3678000) === "1.02 h")
+ }
+
+ test("nanoDurationToString") {
+ assert(Utils.nanoDurationToString(1) === "1 ns")
+ assert(Utils.nanoDurationToString(123456) === "123456 ns")
+ assert(Utils.nanoDurationToString(1234567) === "1.2 ms")
+ assert(Utils.nanoDurationToString(123456789L) === "123.5 ms")
+ assert(Utils.nanoDurationToString(1234567890L) === "1.2 s")
+ assert(Utils.nanoDurationToString(1234567890123L) === "20.6 m")
+ assert(Utils.nanoDurationToString(12345678901234L) === "3.43 h")
+ }
+
test("extractHostPortFromCelebornUrl") {
val target = ("abc", 123)
val result = Utils.extractHostPortFromCelebornUrl("celeborn://abc:123")