Permalink
Browse files

Merge pull request #992 from akka/wip-2843-port-zero-∂π

ticket 2843: make all ports dynamic in remoting tests
  • Loading branch information...
2 parents f2aa947 + 6c31d53 commit cca5e5a4f1b94c1e550528fb0ed15f3658c3aa53 @rkuhn rkuhn committed Jan 3, 2013
@@ -100,7 +100,7 @@ abstract class LargeClusterSpec
*/
override def cluster: Cluster = Cluster(system)
- override def atTermination(): Unit = {
+ override def afterTermination(): Unit = {
systems foreach { _.shutdown }
val shutdownTimeout = 20.seconds
val deadline = Deadline.now + shutdownTimeout
@@ -127,7 +127,7 @@ class MyMailboxSpec extends DurableMailboxSpec("MyStorage", MyMailboxSpec.config
override def atStartup() {
}
- override def atTermination() {
+ override def afterTermination() {
}
"MyMailbox" must {
@@ -28,7 +28,7 @@ class RemoteDeploymentDocSpec extends AkkaSpec("""
val other = ActorSystem("remote", system.settings.config)
val address = other.asInstanceOf[ExtendedActorSystem].provider.getExternalAddressFor(Address("tcp.akka", "s", "host", 1)).get
- override def atTermination() { other.shutdown() }
+ override def afterTermination() { other.shutdown() }
"demonstrate programmatic deployment" in {
//#deploy
@@ -45,8 +45,8 @@ class FileBasedMailboxSpec extends DurableMailboxSpec("File", FileBasedMailboxSp
super.atStartup()
}
- override def atTermination() {
+ override def afterTermination() {
clean()
- super.atTermination()
+ super.afterTermination()
}
}
@@ -84,14 +84,14 @@ abstract class DurableMailboxSpec(system: ActorSystem, val backendName: String)
try system.awaitTermination(5 seconds) catch {
case _: TimeoutException system.log.warning("Failed to stop [{}] within 5 seconds", system.name)
}
- atTermination()
+ afterTermination()
}
/**
* May be implemented in concrete subclass to do additional things once after all
* test cases have been run.
*/
- def atTermination() {}
+ def afterTermination() {}
protected def streamMustContain(in: InputStream, words: String): Unit = {
val output = new Array[Byte](8192)
@@ -272,7 +272,7 @@ abstract class MultiNodeSpec(val myself: RoleName, _system: ActorSystem, _roles:
if (verifySystemShutdown) throw new RuntimeException(msg)
else system.log.warning(msg)
}
- atTermination()
+ afterTermination()
}
/**
@@ -293,7 +293,7 @@ abstract class MultiNodeSpec(val myself: RoleName, _system: ActorSystem, _roles:
/**
* Override this method to do something when the whole test is terminating.
*/
- protected def atTermination(): Unit = {}
+ protected def afterTermination(): Unit = {}
/**
* All registered roles
@@ -41,30 +41,41 @@ akka {
remote.transport = "akka.remote.netty.NettyRemoteTransport"
remote.netty {
hostname = localhost
- port = 12345
- }
- actor.deployment {
- /blub.remote = "akka://remote-sys@localhost:12346"
- /looker/child.remote = "akka://remote-sys@localhost:12346"
- /looker/child/grandchild.remote = "akka://RemoteCommunicationSpec@localhost:12345"
+ port = 0
}
}
""") with ImplicitSender with DefaultTimeout {
import RemoteCommunicationSpec._
- val conf = ConfigFactory.parseString("akka.remote.netty.port=12346").withFallback(system.settings.config)
- val other = ActorSystem("remote-sys", conf)
+ val other = ActorSystem("remote-sys", system.settings.config)
+
+ val localAddr = system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
+ val remoteAddr = other.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
+
+ val deploys = Seq(
+ Deploy("/blub", scope = RemoteScope(remoteAddr)),
+ Deploy("/looker/child", scope = RemoteScope(remoteAddr)),
+ Deploy("/looker/child/grandchild", scope = RemoteScope(localAddr)))
+
+ def deploy(sys: ActorSystem, d: Deploy) {
+ sys.asInstanceOf[ExtendedActorSystem].provider.asInstanceOf[RemoteActorRefProvider].deployer.deploy(d)
+ }
+
+ for (d deploys) {
+ deploy(system, d)
+ deploy(other, d)
+ }
val remote = other.actorOf(Props(new Actor {
def receive = {
case "ping" sender ! (("pong", sender))
}
}), "echo")
- val here = system.actorFor("akka://remote-sys@localhost:12346/user/echo")
+ val here = system.actorFor(RootActorPath(remoteAddr) / "user" / "echo")
- override def atTermination() {
+ override def afterTermination() {
other.shutdown()
}
@@ -81,7 +92,7 @@ akka {
val old = other.eventStream.logLevel
other.eventStream.setLogLevel(Logging.DebugLevel)
EventFilter.debug(start = "dropping", occurrences = 1).intercept {
- system.actorFor("akka://remotesys@localhost:12346/user/echo") ! "ping"
+ system.actorFor(RootActorPath(remoteAddr.copy(system = "remotesys")) / "user" / "echo") ! "ping"
}(other)
other.eventStream.setLogLevel(old)
}
@@ -95,13 +106,13 @@ akka {
"send dead letters on remote if actor does not exist" in {
EventFilter.warning(pattern = "dead.*buh", occurrences = 1).intercept {
- system.actorFor("akka://remote-sys@localhost:12346/does/not/exist") ! "buh"
+ system.actorFor(RootActorPath(remoteAddr) / "does" / "not" / "exist") ! "buh"
}(other)
}
"create and supervise children on remote node" in {
val r = system.actorOf(Props[Echo], "blub")
- r.path.toString must be === "akka://remote-sys@localhost:12346/remote/akka/RemoteCommunicationSpec@localhost:12345/user/blub"
+ r.path.toString must be === s"akka://remote-sys@localhost:${remoteAddr.port.get}/remote/akka/RemoteCommunicationSpec@localhost:${localAddr.port.get}/user/blub"
r ! 42
expectMsg(42)
EventFilter[Exception]("crash", occurrences = 1).intercept {
@@ -26,7 +26,12 @@ akka {
val other = ActorSystem("other", ConfigFactory.parseString("akka.remoting.transports.tcp.port=2666")
.withFallback(system.settings.config))
- override def atTermination() {
+ override def beforeTermination() {
+ system.eventStream.publish(TestEvent.Mute(
+ EventFilter.warning(pattern = "received dead letter.*Disassociate")))
+ }
+
+ override def afterTermination() {
other.shutdown()
}
@@ -70,7 +70,7 @@ akka.actor.deployment {
}""").withFallback(system.settings.config)
val otherSystem = ActorSystem("remote-sys", conf)
- override def atTermination() {
+ override def afterTermination() {
otherSystem.shutdown()
}
@@ -219,4 +219,9 @@ akka.actor.deployment {
}
+ override def beforeTermination() {
+ system.eventStream.publish(TestEvent.Mute(
+ EventFilter.warning(pattern = "received dead letter.*Disassociate")))
+ }
+
}
@@ -53,9 +53,9 @@ object RemotingSpec {
remoting.log-remote-lifecycle-events = on
remoting.enabled-transports = [test, tcp, udp, ssl]
- remoting.transports.tcp.port = 12345
- remoting.transports.udp.port = 12345
- remoting.transports.ssl.port = 23456
+ remoting.transports.tcp.port = 0
+ remoting.transports.udp.port = 0
+ remoting.transports.ssl.port = 0
remoting.transports.ssl.ssl = ${common-ssl-settings}
remoting.transports.test {
@@ -69,9 +69,6 @@ object RemotingSpec {
actor.deployment {
/blub.remote = "test.akka://remote-sys@localhost:12346"
- /gonk.remote = "tcp.akka://remote-sys@localhost:12346"
- /zagzag.remote = "udp.akka://remote-sys@localhost:12346"
- /roghtaar.remote = "tcp.ssl.akka://remote-sys@localhost:23457"
/looker/child.remote = "test.akka://remote-sys@localhost:12346"
/looker/child/grandchild.remote = "test.akka://RemotingSpec@localhost:12345"
}
@@ -90,14 +87,25 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
val conf = ConfigFactory.parseString(
"""
akka.remoting.transports {
- tcp.port = 12346
- udp.port = 12346
- ssl.port = 23457
test.local-address = "test://remote-sys@localhost:12346"
}
""").withFallback(system.settings.config).resolve()
val other = ActorSystem("remote-sys", conf)
+ for (
+ (name, proto) Seq(
+ "/gonk" -> "tcp",
+ "/zagzag" -> "udp",
+ "/roghtaar" -> "tcp.ssl")
+ ) deploy(system, Deploy(name, scope = RemoteScope(addr(other, proto))))
+
+ def addr(sys: ActorSystem, proto: String) =
+ sys.asInstanceOf[ExtendedActorSystem].provider.getExternalAddressFor(Address(s"$proto.akka", "", "", 0)).get
+ def port(sys: ActorSystem, proto: String) = addr(sys, proto).port.get
+ def deploy(sys: ActorSystem, d: Deploy) {
+ sys.asInstanceOf[ExtendedActorSystem].provider.asInstanceOf[RemoteActorRefProvider].deployer.deploy(d)
+ }
+
val remote = other.actorOf(Props(new Actor {
def receive = {
case "ping" sender ! (("pong", sender))
@@ -106,7 +114,7 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
val here = system.actorFor("test.akka://remote-sys@localhost:12346/user/echo")
- override def atTermination() {
+ override def afterTermination() {
other.shutdown()
AssociationRegistry.clear()
}
@@ -119,7 +127,7 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
}
"send error message for wrong address" in {
- EventFilter.error(start = "AssociationError").intercept {
+ filterEvents(EventFilter[EndpointException](occurrences = 6), EventFilter.error(start = "Association", occurrences = 6)) {
system.actorFor("test.akka://nonexistingsystem@localhost:12346/user/echo") ! "ping"
}
}
@@ -183,7 +191,8 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
"be able to use multiple transports and use the appropriate one (TCP)" in {
val r = system.actorOf(Props[Echo], "gonk")
- r.path.toString must be === "tcp.akka://remote-sys@localhost:12346/remote/tcp.akka/RemotingSpec@localhost:12345/user/gonk"
+ r.path.toString must be ===
+ s"tcp.akka://remote-sys@localhost:${port(other, "tcp")}/remote/tcp.akka/RemotingSpec@localhost:${port(system, "tcp")}/user/gonk"
r ! 42
expectMsg(42)
EventFilter[Exception]("crash", occurrences = 1).intercept {
@@ -198,9 +207,10 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
"be able to use multiple transports and use the appropriate one (UDP)" in {
val r = system.actorOf(Props[Echo], "zagzag")
- r.path.toString must be === "udp.akka://remote-sys@localhost:12346/remote/udp.akka/RemotingSpec@localhost:12345/user/zagzag"
+ r.path.toString must be ===
+ s"udp.akka://remote-sys@localhost:${port(other, "udp")}/remote/udp.akka/RemotingSpec@localhost:${port(system, "udp")}/user/zagzag"
r ! 42
- expectMsg(10 seconds, 42)
+ expectMsg(10.seconds, 42)
EventFilter[Exception]("crash", occurrences = 1).intercept {
r ! new Exception("crash")
}(other)
@@ -213,9 +223,10 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
"be able to use multiple transports and use the appropriate one (SSL)" in {
val r = system.actorOf(Props[Echo], "roghtaar")
- r.path.toString must be === "tcp.ssl.akka://remote-sys@localhost:23457/remote/tcp.ssl.akka/RemotingSpec@localhost:23456/user/roghtaar"
+ r.path.toString must be ===
+ s"tcp.ssl.akka://remote-sys@localhost:${port(other, "tcp.ssl")}/remote/tcp.ssl.akka/RemotingSpec@localhost:${port(system, "tcp.ssl")}/user/roghtaar"
r ! 42
- expectMsg(10 seconds, 42)
+ expectMsg(10.seconds, 42)
EventFilter[Exception]("crash", occurrences = 1).intercept {
r ! new Exception("crash")
}(other)
@@ -228,4 +239,13 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
}
+ override def beforeTermination() {
+ system.eventStream.publish(TestEvent.Mute(
+ EventFilter.warning(pattern = "received dead letter.*(InboundPayload|Disassociate)")))
+ other.eventStream.publish(TestEvent.Mute(
+ EventFilter[EndpointException](),
+ EventFilter.error(start = "AssociationError"),
+ EventFilter.warning(pattern = "received dead letter.*(InboundPayload|Disassociate|HandleListener)")))
+ }
+
}
@@ -125,7 +125,7 @@ abstract class Ticket1978CommunicationSpec(val cipherConfig: CipherConfig) exten
"remote-sys",
ConfigFactory.parseString("akka.remote.netty.port=" + cipherConfig.remotePort).withFallback(system.settings.config))
- override def atTermination() {
+ override def afterTermination() {
if (cipherConfig.runTest) {
other.shutdown()
other.awaitTermination()
@@ -37,7 +37,7 @@ akka.loglevel = DEBUG
val target1 = other.actorFor(RootActorPath(addr) / "remote")
val target2 = other.actorFor(RootActorPath(addr) / testActor.path.elements)
- override def atTermination() {
+ override def afterTermination() {
other.shutdown()
}
@@ -202,7 +202,7 @@ class AkkaProtocolSpec extends AkkaSpec("""akka.actor.provider = "akka.remote.Re
codec,
failureDetector)))
- Await.result(statusPromise.future, 3 seconds) match {
+ Await.result(statusPromise.future, 3.seconds) match {
case h: AssociationHandle
h.remoteAddress must be === remoteAkkaAddress
h.localAddress must be === localAkkaAddress
@@ -241,7 +241,7 @@ class AkkaProtocolSpec extends AkkaSpec("""akka.actor.provider = "akka.remote.Re
// finish connection by sending back a payload
reader ! testPayload
- Await.result(statusPromise.future, 3 seconds) match {
+ Await.result(statusPromise.future, 3.seconds) match {
case h: AssociationHandle
h.remoteAddress must be === remoteAkkaAddress
h.localAddress must be === localAkkaAddress
@@ -315,7 +315,7 @@ class AkkaProtocolSpec extends AkkaSpec("""akka.actor.provider = "akka.remote.Re
codec,
failureDetector)))
- Await.result(statusPromise.future, 3 seconds) match {
+ Await.result(statusPromise.future, 3.seconds) match {
case h: AssociationHandle
h.remoteAddress must be === remoteAkkaAddress
h.localAddress must be === localAkkaAddress
@@ -341,7 +341,7 @@ class AkkaProtocolSpec extends AkkaSpec("""akka.actor.provider = "akka.remote.Re
codec,
failureDetector)))
- val wrappedHandle = Await.result(statusPromise.future, 3 seconds) match {
+ val wrappedHandle = Await.result(statusPromise.future, 3.seconds) match {
case h: AssociationHandle
h.remoteAddress must be === remoteAkkaAddress
h.localAddress must be === localAkkaAddress
@@ -379,7 +379,7 @@ class AkkaProtocolSpec extends AkkaSpec("""akka.actor.provider = "akka.remote.Re
// Finish association with a heartbeat -- pushes state out of WaitActivity
reader ! testHeartbeat
- val wrappedHandle = Await.result(statusPromise.future, 3 seconds) match {
+ val wrappedHandle = Await.result(statusPromise.future, 3.seconds) match {
case h: AssociationHandle
h.remoteAddress must be === remoteAkkaAddress
h.localAddress must be === localAkkaAddress
@@ -412,7 +412,7 @@ class AkkaProtocolSpec extends AkkaSpec("""akka.actor.provider = "akka.remote.Re
codec,
failureDetector)))
- val wrappedHandle = Await.result(statusPromise.future, 3 seconds) match {
+ val wrappedHandle = Await.result(statusPromise.future, 3.seconds) match {
case h: AssociationHandle
h.remoteAddress must be === remoteAkkaAddress
h.localAddress must be === localAkkaAddress
@@ -448,7 +448,7 @@ class AkkaProtocolSpec extends AkkaSpec("""akka.actor.provider = "akka.remote.Re
codec,
failureDetector)))
- val wrappedHandle = Await.result(statusPromise.future, 3 seconds) match {
+ val wrappedHandle = Await.result(statusPromise.future, 3.seconds) match {
case h: AssociationHandle
h.remoteAddress must be === remoteAkkaAddress
h.localAddress must be === localAkkaAddress
Oops, something went wrong.

0 comments on commit cca5e5a

Please sign in to comment.