This commit is contained in:
parent
776191c31d
commit
4a2b6b23e5
3 changed files with 11 additions and 17 deletions
|
|
@ -3,9 +3,7 @@
|
|||
*/
|
||||
package akka.pattern
|
||||
|
||||
import java.time.Instant
|
||||
|
||||
import scala.concurrent.duration.{ Deadline, Duration, FiniteDuration }
|
||||
import scala.concurrent.duration.{ Duration, FiniteDuration }
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
import java.util.Optional
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ package akka.stream.javadsl
|
|||
import akka.NotUsed
|
||||
import akka.japi.function.Creator
|
||||
import akka.stream.KillSwitch
|
||||
import akka.stream.scaladsl.{ Sink, Source }
|
||||
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ package akka.testkit
|
|||
import scala.collection.immutable
|
||||
import scala.util.Random
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.SocketAddress
|
||||
import java.nio.channels.DatagramChannel
|
||||
import java.nio.channels.ServerSocketChannel
|
||||
import java.net.NetworkInterface
|
||||
|
|
@ -19,13 +18,6 @@ object SocketUtil {
|
|||
|
||||
import scala.language.reflectiveCalls
|
||||
|
||||
// Structural type needed since DatagramSocket and ServerSocket has no common ancestor apart from Object
|
||||
private type GeneralSocket = {
|
||||
def bind(sa: SocketAddress): Unit
|
||||
def close(): Unit
|
||||
def getLocalPort(): Int
|
||||
}
|
||||
|
||||
val RANDOM_LOOPBACK_ADDRESS = "RANDOM_LOOPBACK_ADDRESS"
|
||||
|
||||
private val canBindOnAlternativeLoopbackAddresses = {
|
||||
|
|
@ -51,9 +43,6 @@ object SocketUtil {
|
|||
|
||||
def temporaryServerAddresses(numberOfAddresses: Int, hostname: String = RANDOM_LOOPBACK_ADDRESS, udp: Boolean = false): immutable.IndexedSeq[InetSocketAddress] = {
|
||||
Vector.fill(numberOfAddresses) {
|
||||
val serverSocket: GeneralSocket =
|
||||
if (udp) DatagramChannel.open().socket()
|
||||
else ServerSocketChannel.open().socket()
|
||||
|
||||
val address = hostname match {
|
||||
case RANDOM_LOOPBACK_ADDRESS ⇒
|
||||
|
|
@ -63,8 +52,16 @@ object SocketUtil {
|
|||
other
|
||||
}
|
||||
|
||||
serverSocket.bind(new InetSocketAddress(address, 0))
|
||||
(serverSocket, new InetSocketAddress(address, serverSocket.getLocalPort))
|
||||
if (udp) {
|
||||
val ds = DatagramChannel.open().socket()
|
||||
ds.bind(new InetSocketAddress(address, 0))
|
||||
(ds, new InetSocketAddress(address, ds.getLocalPort))
|
||||
} else {
|
||||
val ss = ServerSocketChannel.open().socket()
|
||||
ss.bind(new InetSocketAddress(address, 0))
|
||||
(ss, new InetSocketAddress(address, ss.getLocalPort))
|
||||
}
|
||||
|
||||
} collect { case (socket, address) ⇒ socket.close(); address }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue