2011-12-05 11:16:29 +01:00
|
|
|
package akka.remote
|
2011-10-05 18:45:26 +02:00
|
|
|
|
|
|
|
|
import akka.remote._
|
|
|
|
|
import akka.routing._
|
2011-12-13 16:59:43 +01:00
|
|
|
import akka.actor.{ Actor, Props }
|
2011-10-13 17:42:26 +02:00
|
|
|
import akka.testkit._
|
2011-12-14 17:26:18 +01:00
|
|
|
import akka.dispatch.Await
|
2011-10-05 18:45:26 +02:00
|
|
|
|
|
|
|
|
object DirectRoutedRemoteActorMultiJvmSpec {
|
|
|
|
|
val NrOfNodes = 2
|
|
|
|
|
|
|
|
|
|
class SomeActor extends Actor with Serializable {
|
|
|
|
|
def receive = {
|
2011-12-05 20:01:42 +01:00
|
|
|
case "identify" ⇒ sender ! context.system.nodename
|
2011-10-05 18:45:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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"
|
|
|
|
|
}""")
|
2011-10-05 18:45:26 +02:00
|
|
|
|
2011-12-05 11:16:29 +01:00
|
|
|
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
|
|
|
|
|
}
|
2011-10-05 18:45:26 +02:00
|
|
|
|
2011-12-05 11:16:29 +01:00
|
|
|
class DirectRoutedRemoteActorMultiJvmNode1 extends AkkaRemoteSpec(DirectRoutedRemoteActorMultiJvmSpec.node1Config) {
|
2011-10-05 18:45:26 +02:00
|
|
|
import DirectRoutedRemoteActorMultiJvmSpec._
|
|
|
|
|
val nodes = NrOfNodes
|
|
|
|
|
|
|
|
|
|
"___" must {
|
|
|
|
|
"___" in {
|
|
|
|
|
barrier("start")
|
|
|
|
|
barrier("done")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-15 11:43:26 +01:00
|
|
|
class DirectRoutedRemoteActorMultiJvmNode2 extends AkkaRemoteSpec(DirectRoutedRemoteActorMultiJvmSpec.node2Config) with DefaultTimeout {
|
2011-10-05 18:45:26 +02:00
|
|
|
|
|
|
|
|
import DirectRoutedRemoteActorMultiJvmSpec._
|
|
|
|
|
val nodes = NrOfNodes
|
|
|
|
|
|
|
|
|
|
"A new remote actor configured with a Direct router" must {
|
|
|
|
|
"be locally instantiated on a remote node and be able to communicate through its RemoteActorRef" in {
|
|
|
|
|
barrier("start")
|
|
|
|
|
|
2011-12-13 16:59:43 +01:00
|
|
|
val actor = system.actorOf(Props[SomeActor], "service-hello")
|
2011-12-09 20:58:59 +01:00
|
|
|
actor.isInstanceOf[RemoteActorRef] must be(true)
|
2011-10-05 18:45:26 +02:00
|
|
|
|
2011-12-14 17:26:18 +01:00
|
|
|
Await.result(actor ? "identify", timeout.duration) must equal("node1")
|
2011-10-05 18:45:26 +02:00
|
|
|
|
|
|
|
|
barrier("done")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|