Skip to content

Commit 69dd299

Browse files
Niklas WilckeAndrew Or
authored andcommitted
[SPARK-4169] [Core] Accommodate non-English Locales in unit tests
For me the core tests failed because there are two locale dependent parts in the code. Look at the Jira ticket for details. Why is it necessary to check the exception message in isBindCollision in https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/util/Utils.scala#L1686 ? Author: Niklas Wilcke <[email protected]> Closes #3036 from numbnut/core-test-fix and squashes the following commits: 1fb0d04 [Niklas Wilcke] Fixing locale dependend code and tests (cherry picked from commit ed8bf1e) Signed-off-by: Andrew Or <[email protected]>
1 parent 9b781c8 commit 69dd299

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ private[spark] object Utils extends Logging {
17001700
def isBindCollision(exception: Throwable): Boolean = {
17011701
exception match {
17021702
case e: BindException =>
1703-
if (e.getMessage != null && e.getMessage.contains("Address already in use")) {
1703+
if (e.getMessage != null) {
17041704
return true
17051705
}
17061706
isBindCollision(e.getCause)

core/src/test/scala/org/apache/spark/util/UtilsSuite.scala

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import scala.util.Random
2222
import java.io.{File, ByteArrayOutputStream, ByteArrayInputStream, FileOutputStream}
2323
import java.net.{BindException, ServerSocket, URI}
2424
import java.nio.{ByteBuffer, ByteOrder}
25+
import java.text.DecimalFormatSymbols
26+
import java.util.Locale
2527

2628
import com.google.common.base.Charsets.UTF_8
2729
import com.google.common.io.Files
@@ -103,14 +105,16 @@ class UtilsSuite extends FunSuite {
103105
val hour = minute * 60
104106
def str = Utils.msDurationToString(_)
105107

108+
val sep = new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator()
109+
106110
assert(str(123) === "123 ms")
107-
assert(str(second) === "1.0 s")
108-
assert(str(second + 462) === "1.5 s")
109-
assert(str(hour) === "1.00 h")
110-
assert(str(minute) === "1.0 m")
111-
assert(str(minute + 4 * second + 34) === "1.1 m")
112-
assert(str(10 * hour + minute + 4 * second) === "10.02 h")
113-
assert(str(10 * hour + 59 * minute + 59 * second + 999) === "11.00 h")
111+
assert(str(second) === "1" + sep + "0 s")
112+
assert(str(second + 462) === "1" + sep + "5 s")
113+
assert(str(hour) === "1" + sep + "00 h")
114+
assert(str(minute) === "1" + sep + "0 m")
115+
assert(str(minute + 4 * second + 34) === "1" + sep + "1 m")
116+
assert(str(10 * hour + minute + 4 * second) === "10" + sep + "02 h")
117+
assert(str(10 * hour + 59 * minute + 59 * second + 999) === "11" + sep + "00 h")
114118
}
115119

116120
test("reading offset bytes of a file") {
@@ -300,12 +304,11 @@ class UtilsSuite extends FunSuite {
300304
assert(!Utils.isBindCollision(new Exception))
301305
assert(!Utils.isBindCollision(new Exception(new Exception)))
302306
assert(!Utils.isBindCollision(new Exception(new BindException)))
303-
assert(!Utils.isBindCollision(new Exception(new BindException("Random message"))))
304307

305308
// Positives
306-
val be = new BindException("Address already in use")
307-
val be1 = new Exception(new BindException("Address already in use"))
308-
val be2 = new Exception(new Exception(new BindException("Address already in use")))
309+
val be = new BindException("Random Message")
310+
val be1 = new Exception(new BindException("Random Message"))
311+
val be2 = new Exception(new Exception(new BindException("Random Message")))
309312
assert(Utils.isBindCollision(be))
310313
assert(Utils.isBindCollision(be1))
311314
assert(Utils.isBindCollision(be2))

0 commit comments

Comments
 (0)