83 lines
1.7 KiB
Scala
83 lines
1.7 KiB
Scala
|
|
package akka.remote
|
||
|
|
|
||
|
|
import akka.actor.Actor
|
||
|
|
import akka.remote._
|
||
|
|
|
||
|
|
object NewRemoteActorMultiJvmSpec {
|
||
|
|
val NrOfNodes = 2
|
||
|
|
|
||
|
|
class SomeActor extends Actor with Serializable {
|
||
|
|
def receive = {
|
||
|
|
case "identify" ⇒ sender ! system.nodename
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
import com.typesafe.config.ConfigFactory
|
||
|
|
val commonConfig = ConfigFactory.parseString("""
|
||
|
|
akka {
|
||
|
|
loglevel = "WARNING"
|
||
|
|
actor {
|
||
|
|
provider = "akka.remote.RemoteActorRefProvider"
|
||
|
|
deployment {
|
||
|
|
/app/service-hello.remote.nodes = ["localhost:9991"]
|
||
|
|
}
|
||
|
|
}
|
||
|
|
remote.server.hostname = "localhost"
|
||
|
|
}""")
|
||
|
|
|
||
|
|
val node1Config = ConfigFactory.parseString("""
|
||
|
|
akka {
|
||
|
|
remote.server.port = "9991"
|
||
|
|
cluster.nodename = "node1"
|
||
|
|
}""") withFallback commonConfig
|
||
|
|
|
||
|
|
val node2Config = ConfigFactory.parseString("""
|
||
|
|
akka {
|
||
|
|
remote.server.port = "9992"
|
||
|
|
cluster.nodename = "node2"
|
||
|
|
}""") withFallback commonConfig
|
||
|
|
}
|
||
|
|
|
||
|
|
class NewRemoteActorMultiJvmNode1 extends AkkaRemoteSpec(NewRemoteActorMultiJvmSpec.node1Config) {
|
||
|
|
|
||
|
|
import NewRemoteActorMultiJvmSpec._
|
||
|
|
|
||
|
|
val nodes = NrOfNodes
|
||
|
|
|
||
|
|
"___" must {
|
||
|
|
"___" in {
|
||
|
|
barrier("setup")
|
||
|
|
|
||
|
|
remote.start()
|
||
|
|
|
||
|
|
barrier("start")
|
||
|
|
|
||
|
|
barrier("done")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class NewRemoteActorMultiJvmNode2 extends AkkaRemoteSpec(NewRemoteActorMultiJvmSpec.node2Config) {
|
||
|
|
|
||
|
|
import NewRemoteActorMultiJvmSpec._
|
||
|
|
|
||
|
|
val nodes = NrOfNodes
|
||
|
|
|
||
|
|
"A new remote actor" must {
|
||
|
|
"be locally instantiated on a remote node and be able to communicate through its RemoteActorRef" in {
|
||
|
|
barrier("setup")
|
||
|
|
|
||
|
|
remote.start()
|
||
|
|
|
||
|
|
barrier("start")
|
||
|
|
|
||
|
|
val actor = system.actorOf[SomeActor]("service-hello")
|
||
|
|
val result = (actor ? "identify").get
|
||
|
|
result must equal("node1")
|
||
|
|
|
||
|
|
barrier("done")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|