=sam #16905 multiple fixes for java-lambda doc samples

* use a free port instead of a hardcoded one
* do not use null for stream elements
* use defined java8 home key
This commit is contained in:
Martynas Mickevičius 2015-03-26 20:56:49 +02:00
parent 354b52f62f
commit 7616b40e29
2 changed files with 53 additions and 19 deletions

View file

@ -0,0 +1,24 @@
/**
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
*/
package docs.utils
import java.net.InetSocketAddress
import java.nio.channels.ServerSocketChannel
object TestUtils {
def temporaryServerAddress(interface: String = "127.0.0.1"): InetSocketAddress = {
val serverSocket = ServerSocketChannel.open()
try {
serverSocket.socket.bind(new InetSocketAddress(interface, 0))
val port = serverSocket.socket.getLocalPort
new InetSocketAddress(interface, port)
} finally serverSocket.close()
}
def temporaryServerHostnameAndPort(interface: String = "127.0.0.1"): (String, Int) = {
val socketAddress = temporaryServerAddress(interface)
socketAddress.getHostName -> socketAddress.getPort
}
}