Skip to content

Commit

Permalink
Add test for isBindCollision
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewor14 committed Aug 6, 2014
1 parent b97b02a commit 523c30e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.spark.util
import scala.util.Random

import java.io.{File, ByteArrayOutputStream, ByteArrayInputStream, FileOutputStream}
import java.net.URI
import java.net.{BindException, ServerSocket, URI}
import java.nio.{ByteBuffer, ByteOrder}

import com.google.common.base.Charsets
Expand Down Expand Up @@ -265,4 +265,36 @@ class UtilsSuite extends FunSuite {
Array("hdfs:/a.jar", "s3:/another.jar"))
}

test("isBindCollision") {
// Negatives
assert(!Utils.isBindCollision(null))
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")))
assert(Utils.isBindCollision(be))
assert(Utils.isBindCollision(be1))
assert(Utils.isBindCollision(be2))

// Actual bind exception
var server1: ServerSocket = null
var server2: ServerSocket = null
try {
server1 = new java.net.ServerSocket(0)
server2 = new java.net.ServerSocket(server1.getLocalPort)
} catch {
case e: Exception =>
assert(e.isInstanceOf[java.net.BindException])
assert(Utils.isBindCollision(e))
} finally {
Option(server1).foreach(_.close())
Option(server2).foreach(_.close())
}
}

}

0 comments on commit 523c30e

Please sign in to comment.