Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-4169] [Core] Accommodate non-English Locales in unit tests #3036

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ private[spark] object Utils extends Logging {
def isBindCollision(exception: Throwable): Boolean = {
exception match {
case e: BindException =>
if (e.getMessage != null && e.getMessage.contains("Address already in use")) {
if (e.getMessage != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's hacky to depend on the exact message. I suppose this will now trigger on any BindException with a message, which could include things like invalid port or other failure. But maybe that's fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably not a whole lot of harm in a false-positive here, since I think we limit the number of retries and will eventually fail.

return true
}
isBindCollision(e.getCause)
Expand Down
25 changes: 14 additions & 11 deletions core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import scala.util.Random
import java.io.{File, ByteArrayOutputStream, ByteArrayInputStream, FileOutputStream}
import java.net.{BindException, ServerSocket, URI}
import java.nio.{ByteBuffer, ByteOrder}
import java.text.DecimalFormatSymbols
import java.util.Locale

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

val sep = new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good fix; just hard-coding Locale.ENGLISH is also a fix. On the one hand that's less friendly to the non-English-speaking world, but might avoid some unexpected complications of this form. I expect they will be cosmetic only. I'm indifferent; wonder if anyone else has a though.

BTW you should put the SPARK-XXXX in the title and maybe a more action-oriented title like "Accommodate non-English Locales in unit tests"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the title. Thanks for the hint.


assert(str(123) === "123 ms")
assert(str(second) === "1.0 s")
assert(str(second + 462) === "1.5 s")
assert(str(hour) === "1.00 h")
assert(str(minute) === "1.0 m")
assert(str(minute + 4 * second + 34) === "1.1 m")
assert(str(10 * hour + minute + 4 * second) === "10.02 h")
assert(str(10 * hour + 59 * minute + 59 * second + 999) === "11.00 h")
assert(str(second) === "1" + sep + "0 s")
assert(str(second + 462) === "1" + sep + "5 s")
assert(str(hour) === "1" + sep + "00 h")
assert(str(minute) === "1" + sep + "0 m")
assert(str(minute + 4 * second + 34) === "1" + sep + "1 m")
assert(str(10 * hour + minute + 4 * second) === "10" + sep + "02 h")
assert(str(10 * hour + 59 * minute + 59 * second + 999) === "11" + sep + "00 h")
}

test("reading offset bytes of a file") {
Expand Down Expand Up @@ -284,12 +288,11 @@ class UtilsSuite extends FunSuite {
assert(!Utils.isBindCollision(new Exception))
assert(!Utils.isBindCollision(new Exception(new Exception)))
assert(!Utils.isBindCollision(new Exception(new BindException)))
assert(!Utils.isBindCollision(new Exception(new BindException("Random message"))))

// Positives
val be = new BindException("Address already in use")
val be1 = new Exception(new BindException("Address already in use"))
val be2 = new Exception(new Exception(new BindException("Address already in use")))
val be = new BindException("Random Message")
val be1 = new Exception(new BindException("Random Message"))
val be2 = new Exception(new Exception(new BindException("Random Message")))
assert(Utils.isBindCollision(be))
assert(Utils.isBindCollision(be1))
assert(Utils.isBindCollision(be2))
Expand Down