From 935ab0d82ee6d2643723f705014ce7d2a2ce651c Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Wed, 18 May 2016 09:22:22 +0200 Subject: [PATCH] make use of auto port selection in tests --- .../PiercingShouldKeepQuarantineSpec.scala | 18 ------------------ .../artery/RemoteQuarantinePiercingSpec.scala | 18 ------------------ .../RemoteRestartedQuarantinedSpec.scala | 18 ------------------ .../akka/remote/artery/ArteryTransport.scala | 2 ++ .../remote/artery/HandshakeFailureSpec.scala | 6 +++--- .../remote/artery/HandshakeRetrySpec.scala | 5 +++-- .../artery/RemoteSendConsistencySpec.scala | 15 ++++----------- .../artery/SystemMessageDeliverySpec.scala | 13 ++++--------- 8 files changed, 16 insertions(+), 79 deletions(-) diff --git a/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/PiercingShouldKeepQuarantineSpec.scala b/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/PiercingShouldKeepQuarantineSpec.scala index fd292f172f..cb17da59d2 100644 --- a/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/PiercingShouldKeepQuarantineSpec.scala +++ b/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/PiercingShouldKeepQuarantineSpec.scala @@ -25,24 +25,6 @@ object PiercingShouldKeepQuarantineSpec extends MultiNodeConfig { akka.remote.artery.enabled = on """))) - def aeronPort(roleName: RoleName): Int = - roleName match { - case `first` ⇒ 20561 // TODO yeah, we should have support for dynamic port assignment - case `second` ⇒ 20562 - } - - nodeConfig(first) { - ConfigFactory.parseString(s""" - akka.remote.artery.port = ${aeronPort(first)} - """) - } - - nodeConfig(second) { - ConfigFactory.parseString(s""" - akka.remote.artery.port = ${aeronPort(second)} - """) - } - class Subject extends Actor { def receive = { case "getuid" ⇒ sender() ! AddressUidExtension(context.system).addressUid diff --git a/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/RemoteQuarantinePiercingSpec.scala b/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/RemoteQuarantinePiercingSpec.scala index e546a293e6..299857cfc5 100644 --- a/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/RemoteQuarantinePiercingSpec.scala +++ b/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/RemoteQuarantinePiercingSpec.scala @@ -31,24 +31,6 @@ object RemoteQuarantinePiercingSpec extends MultiNodeConfig { akka.remote.artery.enabled = on """))) - def aeronPort(roleName: RoleName): Int = - roleName match { - case `first` ⇒ 20551 // TODO yeah, we should have support for dynamic port assignment - case `second` ⇒ 20552 - } - - nodeConfig(first) { - ConfigFactory.parseString(s""" - akka.remote.artery.port = ${aeronPort(first)} - """) - } - - nodeConfig(second) { - ConfigFactory.parseString(s""" - akka.remote.artery.port = ${aeronPort(second)} - """) - } - class Subject extends Actor { def receive = { case "shutdown" ⇒ context.system.terminate() diff --git a/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/RemoteRestartedQuarantinedSpec.scala b/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/RemoteRestartedQuarantinedSpec.scala index 24402358bd..b22d35c0fb 100644 --- a/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/RemoteRestartedQuarantinedSpec.scala +++ b/akka-remote-tests/src/multi-jvm/scala/akka/remote/artery/RemoteRestartedQuarantinedSpec.scala @@ -45,24 +45,6 @@ object RemoteRestartedQuarantinedSpec extends MultiNodeConfig { akka.remote.artery.enabled = on """))) - def aeronPort(roleName: RoleName): Int = - roleName match { - case `first` ⇒ 20541 // TODO yeah, we should have support for dynamic port assignment - case `second` ⇒ 20542 - } - - nodeConfig(first) { - ConfigFactory.parseString(s""" - akka.remote.artery.port = ${aeronPort(first)} - """) - } - - nodeConfig(second) { - ConfigFactory.parseString(s""" - akka.remote.artery.port = ${aeronPort(second)} - """) - } - class Subject extends Actor { def receive = { case "shutdown" ⇒ context.system.terminate() diff --git a/akka-remote/src/main/scala/akka/remote/artery/ArteryTransport.scala b/akka-remote/src/main/scala/akka/remote/artery/ArteryTransport.scala index a9473a9d9f..0ef73d7d47 100644 --- a/akka-remote/src/main/scala/akka/remote/artery/ArteryTransport.scala +++ b/akka-remote/src/main/scala/akka/remote/artery/ArteryTransport.scala @@ -265,6 +265,8 @@ private[remote] class ArteryTransport(_system: ExtendedActorSystem, _provider: R messageDispatcher = new MessageDispatcher(system, provider) runInboundStreams() + + log.info("Remoting started; listening on address: {}", defaultAddress) } private def startMediaDriver(): Unit = { diff --git a/akka-remote/src/test/scala/akka/remote/artery/HandshakeFailureSpec.scala b/akka-remote/src/test/scala/akka/remote/artery/HandshakeFailureSpec.scala index 08475939fd..d350151041 100644 --- a/akka-remote/src/test/scala/akka/remote/artery/HandshakeFailureSpec.scala +++ b/akka-remote/src/test/scala/akka/remote/artery/HandshakeFailureSpec.scala @@ -13,14 +13,15 @@ import com.typesafe.config.ConfigFactory object HandshakeFailureSpec { - val Seq(portA, portB) = SocketUtil.temporaryServerAddresses(2, "localhost", udp = true).map(_.getPort) + // need the port before systemB is started + val portB = SocketUtil.temporaryServerAddress("localhost", udp = true).getPort val commonConfig = ConfigFactory.parseString(s""" akka { actor.provider = "akka.remote.RemoteActorRefProvider" remote.artery.enabled = on remote.artery.hostname = localhost - remote.artery.port = $portA + remote.artery.port = 0 remote.handshake-timeout = 2s } """) @@ -47,7 +48,6 @@ class HandshakeFailureSpec extends AkkaSpec(HandshakeFailureSpec.commonConfig) w within(10.seconds) { awaitAssert { - println(s"# identify $sel") // FIXME sel ! "hello2" expectMsg(1.second, "hello2") } diff --git a/akka-remote/src/test/scala/akka/remote/artery/HandshakeRetrySpec.scala b/akka-remote/src/test/scala/akka/remote/artery/HandshakeRetrySpec.scala index df22b2cb84..a334efa642 100644 --- a/akka-remote/src/test/scala/akka/remote/artery/HandshakeRetrySpec.scala +++ b/akka-remote/src/test/scala/akka/remote/artery/HandshakeRetrySpec.scala @@ -13,14 +13,15 @@ import com.typesafe.config.ConfigFactory object HandshakeRetrySpec { - val Seq(portA, portB) = SocketUtil.temporaryServerAddresses(2, "localhost", udp = true).map(_.getPort) + // need the port before systemB is started + val portB = SocketUtil.temporaryServerAddress("localhost", udp = true).getPort val commonConfig = ConfigFactory.parseString(s""" akka { actor.provider = "akka.remote.RemoteActorRefProvider" remote.artery.enabled = on remote.artery.hostname = localhost - remote.artery.port = $portA + remote.artery.port = 0 remote.handshake-timeout = 10s } """) diff --git a/akka-remote/src/test/scala/akka/remote/artery/RemoteSendConsistencySpec.scala b/akka-remote/src/test/scala/akka/remote/artery/RemoteSendConsistencySpec.scala index c94e21ad64..a7256705a8 100644 --- a/akka-remote/src/test/scala/akka/remote/artery/RemoteSendConsistencySpec.scala +++ b/akka-remote/src/test/scala/akka/remote/artery/RemoteSendConsistencySpec.scala @@ -7,31 +7,24 @@ import scala.concurrent.duration._ import akka.actor.{ Actor, ActorIdentity, ActorSystem, Deploy, ExtendedActorSystem, Identify, Props, RootActorPath } import akka.testkit.{ AkkaSpec, ImplicitSender } import com.typesafe.config.ConfigFactory -import RemoteSendConsistencySpec._ import akka.actor.Actor.Receive -import akka.testkit.SocketUtil object RemoteSendConsistencySpec { - val Seq(portA, portB) = SocketUtil.temporaryServerAddresses(2, "localhost", udp = true).map(_.getPort) - - val commonConfig = ConfigFactory.parseString(s""" + val config = ConfigFactory.parseString(s""" akka { actor.provider = "akka.remote.RemoteActorRefProvider" remote.artery.enabled = on remote.artery.hostname = localhost - remote.artery.port = $portA + remote.artery.port = 0 } """) - val configB = ConfigFactory.parseString(s"akka.remote.artery.port = $portB") - .withFallback(commonConfig) - } -class RemoteSendConsistencySpec extends AkkaSpec(commonConfig) with ImplicitSender { +class RemoteSendConsistencySpec extends AkkaSpec(RemoteSendConsistencySpec.config) with ImplicitSender { - val systemB = ActorSystem("systemB", RemoteSendConsistencySpec.configB) + val systemB = ActorSystem("systemB", system.settings.config) val addressB = systemB.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress println(addressB) val rootB = RootActorPath(addressB) diff --git a/akka-remote/src/test/scala/akka/remote/artery/SystemMessageDeliverySpec.scala b/akka-remote/src/test/scala/akka/remote/artery/SystemMessageDeliverySpec.scala index 280f04455b..55fe0b941f 100644 --- a/akka-remote/src/test/scala/akka/remote/artery/SystemMessageDeliverySpec.scala +++ b/akka-remote/src/test/scala/akka/remote/artery/SystemMessageDeliverySpec.scala @@ -30,37 +30,32 @@ import akka.stream.scaladsl.Source import akka.stream.testkit.scaladsl.TestSink import akka.testkit.AkkaSpec import akka.testkit.ImplicitSender -import akka.testkit.SocketUtil import akka.testkit.TestActors import akka.testkit.TestProbe import com.typesafe.config.ConfigFactory object SystemMessageDeliverySpec { - val Seq(portA, portB) = SocketUtil.temporaryServerAddresses(2, "localhost", udp = true).map(_.getPort) - - val commonConfig = ConfigFactory.parseString(s""" + val config = ConfigFactory.parseString(s""" akka { actor.provider = "akka.remote.RemoteActorRefProvider" remote.artery.enabled = on remote.artery.hostname = localhost - remote.artery.port = $portA + remote.artery.port = 0 } akka.actor.serialize-creators = off akka.actor.serialize-messages = off """) - val configB = ConfigFactory.parseString(s"akka.remote.artery.port = $portB") - .withFallback(commonConfig) } -class SystemMessageDeliverySpec extends AkkaSpec(SystemMessageDeliverySpec.commonConfig) with ImplicitSender { +class SystemMessageDeliverySpec extends AkkaSpec(SystemMessageDeliverySpec.config) with ImplicitSender { import SystemMessageDeliverySpec._ val addressA = UniqueAddress( system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress, AddressUidExtension(system).addressUid) - val systemB = ActorSystem("systemB", configB) + val systemB = ActorSystem("systemB", system.settings.config) val addressB = UniqueAddress( systemB.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress, AddressUidExtension(systemB).addressUid)