2011-12-05 11:16:29 +01:00
|
|
|
package akka.remote
|
|
|
|
|
|
2011-12-15 11:43:26 +01:00
|
|
|
import akka.actor.{ Actor, Props }
|
2011-12-05 11:16:29 +01:00
|
|
|
import akka.remote._
|
2011-12-15 11:43:26 +01:00
|
|
|
import akka.routing._
|
|
|
|
|
import akka.testkit._
|
|
|
|
|
import akka.util.duration._
|
|
|
|
|
import akka.dispatch.Await
|
2011-12-05 11:16:29 +01:00
|
|
|
|
|
|
|
|
object NewRemoteActorMultiJvmSpec {
|
|
|
|
|
val NrOfNodes = 2
|
|
|
|
|
|
|
|
|
|
class SomeActor extends Actor with Serializable {
|
|
|
|
|
def receive = {
|
2011-12-15 11:43:26 +01:00
|
|
|
case "identify" ⇒ sender ! context.system.nodename
|
2011-12-05 11:16:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
val commonConfig = ConfigFactory.parseString("""
|
|
|
|
|
akka {
|
|
|
|
|
loglevel = "WARNING"
|
|
|
|
|
actor {
|
|
|
|
|
provider = "akka.remote.RemoteActorRefProvider"
|
|
|
|
|
deployment {
|
2011-12-15 11:43:26 +01:00
|
|
|
/service-hello.remote = "akka://AkkaRemoteSpec@localhost:9991"
|
2011-12-05 11:16:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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("start")
|
|
|
|
|
|
|
|
|
|
barrier("done")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-15 11:43:26 +01:00
|
|
|
class NewRemoteActorMultiJvmNode2 extends AkkaRemoteSpec(NewRemoteActorMultiJvmSpec.node2Config) with DefaultTimeout {
|
2011-12-05 11:16:29 +01:00
|
|
|
|
|
|
|
|
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("start")
|
|
|
|
|
|
2011-12-15 11:43:26 +01:00
|
|
|
val actor = system.actorOf(Props[SomeActor], "service-hello")
|
|
|
|
|
Await.result(actor ? "identify", timeout.duration) must equal("node1")
|
2011-12-05 11:16:29 +01:00
|
|
|
|
|
|
|
|
barrier("done")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|