Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/20516#discussion_r166350354
--- Diff:
core/src/test/scala/org/apache/spark/network/netty/NettyBlockTransferServiceSuite.scala
---
@@ -77,16 +79,68 @@ class NettyBlockTransferServiceSuite
verifyServicePort(expectedPort = service0.port + 1, actualPort =
service1.port)
}
+ test("can bind to max specific ports is true") {
+ service0 = createService(port = 65535)
+ verifyServicePort(expectedPort = 65535, actualPort = service0.port)
+ }
+
+ test("can bind to two max specific ports") {
+ service0 = createService(port = 65535)
+ service1 = createService(port = 65535)
+ verifyServicePort(expectedPort = 65535, actualPort = service0.port)
+ // see `Utils.userPort` the user port to try when trying to bind a
service,
+ // the max privileged port is 1024.
+ verifyServicePort(expectedPort = 1024, actualPort = service1.port)
+ }
+
+ test("can't bind to a privileged port") {
+ val excMsg = intercept[IllegalArgumentException] {
+ service0 = createService(port = 23)
+ }.getMessage
+
+ assert(excMsg.contains("startPort should be between 1024 and 65535
(inclusive), " +
+ "or 0 for a random free port."))
+ }
+
+ test("can't to bind same port") {
+ val port = 17634 + Random.nextInt(10000)
+ logInfo("random port for test: " + port)
+ service0 = createService(port)
+ verifyServicePort(expectedPort = port, actualPort = service0.port)
+
+ service1 = createService(service0.port)
+ // `service0.port` is occupied, so `service1.port` should not be
`service0.port`
+ verifyServicePort(expectedPort = service0.port + 1, actualPort =
service1.port)
+
+ // bind already in use `service0.port`
+ val excMsg = intercept[BindException] {
+ val conf = new SparkConf()
+ .set("spark.app.id", s"test-${getClass.getName}")
+ .set("spark.testing", "true")
+ .set("spark.port.maxRetries", "1")
+
+ val securityManager = new SecurityManager(conf)
+ val blockDataManager = mock(classOf[BlockDataManager])
+ val service = new NettyBlockTransferService(conf, securityManager,
"localhost", "localhost",
+ service0.port, 1)
+ service.init(blockDataManager)
+ }.getMessage
+
+ assert(excMsg.contains("Address already in use: bind"))
--- End diff --
Hm, is this verifying that the port actually bound? that's much easier to
test directly.
Is this verifying `BindException` is thrown? not sure that's a behavior
that we need to guarantee, even if it's almost certainly what the
implementation will do.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]