import akka.remote.testkit.{MultiNodeConfig, MultiNodeSpec}
import akka.testkit.ImplicitSender
import org.scalatest.{BeforeAndAfterAll, MustMatchers, WordSpecLike}
object SimpleClusterListenerSpecConfig extends MultiNodeConfig {
val cluster = role("cluster")
}
class SimpleClusterListenerSpec extends MultiNodeSpec(SimpleClusterListenerSpecConfig)
with WordSpecLike
with MustMatchers
with BeforeAndAfterAll
with ImplicitSender {
import SimpleClusterListenerSpecConfig._
override def initialParticipants: Int = roles.size
"A SimpleClusterListener" must {
"wait for all nodes to enter a barrier" in {
enterBarrier("startup")
}
runOn(cluster) {
enterBarrier("deployed")
val clusterSelection = system.actorSelection(node(cluster) / "user" / "clusterListener")
clusterSelection ! Hello
expectMsg("hello")
}
}
override def beforeAll() = multiNodeSpecBeforeAll()
override def afterAll() = multiNodeSpecAfterAll()
}
$ sbt clean compile test
[info] Loading project definition from /Users/harit/IdeaProjects/libs/akka-cluster-investigation/project
[info] Set current project to akka-cluster-investigation (in build file:/Users/harit/IdeaProjects/libs/akka-cluster-investigation/)
[success] Total time: 0 s, completed Oct 18, 2015 9:43:50 PM
[info] Updating {file:/Users/harit/IdeaProjects/libs/akka-cluster-investigation/}cluster_simple...
[info] Updating {file:/Users/harit/IdeaProjects/libs/akka-cluster-investigation/}akka-cluster-investigation...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 2 Scala sources to /Users/harit/IdeaProjects/libs/akka-cluster-investigation/cluster_simple/target/scala-2.11/classes...
[success] Total time: 6 s, completed Oct 18, 2015 9:43:56 PM
[info] Compiling 1 Scala source to /Users/harit/IdeaProjects/libs/akka-cluster-investigation/cluster_simple/target/scala-2.11/multi-jvm-classes...
[info] * SimpleClusterListenerSpec
[JVM-1] Run starting. Expected test count is: 2
[JVM-1] SimpleClusterListenerSpecMultiJvmNode1:
[JVM-1] - Illustrate how to start-up a cluster
[JVM-1] - show that SimpleClusterListener receives message
[JVM-1] [WARN] [10/18/2015 21:44:01.571] [SimpleClusterListenerSpec-akka.actor.default-dispatcher-16] [akka://SimpleClusterListenerSpec/user/controller/127.0.0.1:53775-server1] received dead letter from Actor[akka://SimpleClusterListenerSpec/deadLetters]: ClientDisconnected
[JVM-1] Run completed in 1 second, 889 milliseconds.
[JVM-1] Total number of tests run: 2
[JVM-1] Suites: completed 1, aborted 0
[JVM-1] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[JVM-1] All tests passed.
[info] Run completed in 37 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[success] Total time: 5 s, completed Oct 18, 2015 9:44:01 PM