2016-05-27 16:45:48 +02:00
|
|
|
/**
|
2018-01-04 17:26:29 +00:00
|
|
|
* Copyright (C) 2016-2018 Lightbend Inc. <https://www.lightbend.com>
|
2016-05-27 16:45:48 +02:00
|
|
|
*/
|
2018-03-13 23:45:55 +09:00
|
|
|
|
2016-05-27 16:45:48 +02:00
|
|
|
package akka.remote.artery
|
|
|
|
|
|
2016-06-08 10:04:30 +02:00
|
|
|
import akka.actor.{ EmptyLocalActorRef, InternalActorRef }
|
2016-05-27 16:45:48 +02:00
|
|
|
import akka.remote.RemoteActorRef
|
2016-06-08 10:04:30 +02:00
|
|
|
import akka.testkit.{ EventFilter, TestActors }
|
2016-09-27 16:34:43 +02:00
|
|
|
import akka.actor.ExtendedActorSystem
|
|
|
|
|
import akka.actor.ActorRefScope
|
2016-05-27 16:45:48 +02:00
|
|
|
|
2016-06-08 10:04:30 +02:00
|
|
|
class RemoteActorRefProviderSpec extends ArteryMultiNodeSpec {
|
2016-05-27 16:45:48 +02:00
|
|
|
|
2016-06-08 10:04:30 +02:00
|
|
|
val addressA = address(localSystem)
|
2016-05-27 16:45:48 +02:00
|
|
|
system.actorOf(TestActors.echoActorProps, "echo")
|
|
|
|
|
|
2016-06-08 10:04:30 +02:00
|
|
|
val systemB = newRemoteSystem()
|
|
|
|
|
val addressB = address(systemB)
|
2016-05-27 16:45:48 +02:00
|
|
|
systemB.actorOf(TestActors.echoActorProps, "echo")
|
|
|
|
|
|
|
|
|
|
"RemoteActorRefProvider" must {
|
|
|
|
|
|
|
|
|
|
"resolve local actor selection" in {
|
2016-09-08 16:12:29 +02:00
|
|
|
val sel = system.actorSelection(s"akka://${system.name}@${addressA.host.get}:${addressA.port.get}/user/echo")
|
2016-05-27 16:45:48 +02:00
|
|
|
sel.anchor.asInstanceOf[InternalActorRef].isLocal should be(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"resolve remote actor selection" in {
|
2016-09-08 16:12:29 +02:00
|
|
|
val sel = system.actorSelection(s"akka://${systemB.name}@${addressB.host.get}:${addressB.port.get}/user/echo")
|
2016-05-27 16:45:48 +02:00
|
|
|
sel.anchor.getClass should ===(classOf[RemoteActorRef])
|
|
|
|
|
sel.anchor.asInstanceOf[InternalActorRef].isLocal should be(false)
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-27 16:34:43 +02:00
|
|
|
"cache resolveActorRef for local ref" in {
|
|
|
|
|
val provider = localSystem.asInstanceOf[ExtendedActorSystem].provider
|
|
|
|
|
val path = s"akka://${system.name}@${addressA.host.get}:${addressA.port.get}/user/echo"
|
|
|
|
|
val ref1 = provider.resolveActorRef(path)
|
|
|
|
|
ref1.getClass should !==(classOf[EmptyLocalActorRef])
|
|
|
|
|
ref1.asInstanceOf[ActorRefScope].isLocal should ===(true)
|
|
|
|
|
|
|
|
|
|
val ref2 = provider.resolveActorRef(path)
|
|
|
|
|
ref1 should be theSameInstanceAs (ref2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"not cache resolveActorRef for unresolved ref" in {
|
|
|
|
|
val provider = localSystem.asInstanceOf[ExtendedActorSystem].provider
|
|
|
|
|
val path = s"akka://${system.name}@${addressA.host.get}:${addressA.port.get}/user/doesNotExist"
|
|
|
|
|
val ref1 = provider.resolveActorRef(path)
|
|
|
|
|
ref1.getClass should ===(classOf[EmptyLocalActorRef])
|
|
|
|
|
|
|
|
|
|
val ref2 = provider.resolveActorRef(path)
|
|
|
|
|
ref1 should not be theSameInstanceAs(ref2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"cache resolveActorRef for remote ref" in {
|
|
|
|
|
val provider = localSystem.asInstanceOf[ExtendedActorSystem].provider
|
|
|
|
|
val path = s"akka://${systemB.name}@${addressB.host.get}:${addressB.port.get}/user/echo"
|
|
|
|
|
val ref1 = provider.resolveActorRef(path)
|
|
|
|
|
ref1.getClass should ===(classOf[RemoteActorRef])
|
|
|
|
|
|
|
|
|
|
val ref2 = provider.resolveActorRef(path)
|
|
|
|
|
ref1 should be theSameInstanceAs (ref2)
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-27 16:45:48 +02:00
|
|
|
"detect wrong protocol" in {
|
|
|
|
|
EventFilter[IllegalArgumentException](start = "No root guardian at", occurrences = 1).intercept {
|
|
|
|
|
val sel = system.actorSelection(s"akka.tcp://${systemB.name}@${addressB.host.get}:${addressB.port.get}/user/echo")
|
|
|
|
|
sel.anchor.getClass should ===(classOf[EmptyLocalActorRef])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|