From ce1407858c6df1518703f42cfe4e8d0a74aa7c4e Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Wed, 29 Jun 2011 13:33:41 +0300 Subject: [PATCH] - initial example on the clustered test to get me up and running.. will be refactored to a more useful testin the very near future. --- .../PeterExampleMultiJvmNode1.conf | 4 + .../PeterExampleMultiJvmNode1.opts | 1 + .../PeterExampleMultiJvmNode2.conf | 4 + .../PeterExampleMultiJvmNode2.opts | 1 + .../PeterExampleMultiJvmSpec.scala | 91 +++++++++++++++++++ .../testing-design-improvements.txt | 54 +++++++++++ 6 files changed, 155 insertions(+) create mode 100644 akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode1.conf create mode 100644 akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode1.opts create mode 100644 akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode2.conf create mode 100644 akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode2.opts create mode 100644 akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmSpec.scala create mode 100644 akka-cluster/src/test/scala/akka/cluster/routing/peterexample/testing-design-improvements.txt diff --git a/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode1.conf b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode1.conf new file mode 100644 index 0000000000..f3a3da248a --- /dev/null +++ b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode1.conf @@ -0,0 +1,4 @@ +akka.event-handler-level = "DEBUG" +akka.actor.deployment.service-hello.router = "round-robin" +akka.actor.deployment.service-hello.clustered.home = "node:node1" +akka.actor.deployment.service-hello.clustered.replicas = 2 \ No newline at end of file diff --git a/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode1.opts b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode1.opts new file mode 100644 index 0000000000..a88c260d8c --- /dev/null +++ b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode1.opts @@ -0,0 +1 @@ +-Dakka.cluster.nodename=node1 -Dakka.cluster.port=9991 diff --git a/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode2.conf b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode2.conf new file mode 100644 index 0000000000..746f608425 --- /dev/null +++ b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode2.conf @@ -0,0 +1,4 @@ +akka.event-handler-level = "DEBUG" +akka.actor.deployment.service-hello.router = "round-robin" +akka.actor.deployment.service-hello.clustered.home = "node:node2" +akka.actor.deployment.service-hello.clustered.replicas = 2 \ No newline at end of file diff --git a/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode2.opts b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode2.opts new file mode 100644 index 0000000000..f1e01f253d --- /dev/null +++ b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmNode2.opts @@ -0,0 +1 @@ +-Dakka.cluster.nodename=node2 -Dakka.cluster.port=9992 diff --git a/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmSpec.scala b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmSpec.scala new file mode 100644 index 0000000000..bc703d7d8b --- /dev/null +++ b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/PeterExampleMultiJvmSpec.scala @@ -0,0 +1,91 @@ +package akka.cluster.routing.peterexample + +import org.scalatest.matchers.MustMatchers +import akka.config.Config +import org.scalatest.{ BeforeAndAfterAll, WordSpec } +import akka.cluster.Cluster +import akka.actor.{ ActorRef, Actor } + +object PeterExampleMultiJvmSpec { + + val NrOfNodes = 2 + + class HelloWorld extends Actor with Serializable { + println("---------------------------------------------------------------------------") + println("HelloWorldActor has been created on node [" + Config.nodename + "]") + println("---------------------------------------------------------------------------") + + def receive = { + case x: String ⇒ { + println("Hello message was received") + } + } + } +} + +class TestNode extends WordSpec with MustMatchers with BeforeAndAfterAll { + + override def beforeAll() { + Cluster.startLocalCluster() + // LocalBookKeeperEnsemble.start() + } + + override def afterAll() { + Cluster.shutdownLocalCluster() + // TransactionLog.shutdown() + // LocalBookKeeperEnsemble.shutdown() + } +} + +class PeterExampleMultiJvmNode1 extends TestNode { + + import PeterExampleMultiJvmSpec._ + + "foo" must { + "bla" in { + /* + println("Node 1 has started") + + Cluster.barrier("start-node1", NrOfNodes) { + Cluster.node.start() + } + + Cluster.barrier("start-node2", NrOfNodes) {} + + println("Getting reference to service-hello actor") + var hello: ActorRef = null + Cluster.barrier("get-ref-to-actor-on-node2", NrOfNodes) { + hello = Actor.actorOf[HelloWorld]("service-hello") + } + + println("Successfully acquired reference") + + println("Saying hello to actor") + hello ! "say hello" + Cluster.node.shutdown() */ + } + } +} + +class PeterExampleMultiJvmNode2 extends WordSpec with MustMatchers with BeforeAndAfterAll { + + import PeterExampleMultiJvmSpec._ + + "foo" must { + "bla" in { + /* + println("Waiting for Node 1 to start") + Cluster.barrier("start-node1", NrOfNodes) {} + + println("Waiting for himself to start???") + Cluster.barrier("start-node2", NrOfNodes) { + Cluster.node.start() + } + + Cluster.barrier("get-ref-to-actor-on-node2", NrOfNodes) {} + + println("Shutting down JVM Node 2") + Cluster.node.shutdown() / + } + } +} diff --git a/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/testing-design-improvements.txt b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/testing-design-improvements.txt new file mode 100644 index 0000000000..142a0674dd --- /dev/null +++ b/akka-cluster/src/test/scala/akka/cluster/routing/peterexample/testing-design-improvements.txt @@ -0,0 +1,54 @@ +- It would be nice if the .conf files somehow could be integrated in the scala file + +object SomeNode extends ClusterNodeWithConf{ + def config() = " + akka.event-handler-level = "DEBUG" + akka.actor.deployment.service-hello.router = "round-robin" + akka.actor.deployment.service-hello.clustered.home = "node:node1" + akka.actor.deployment.service-hello.clustered.replicas = 1" + } +} + +- It would be nice if the .opts file somehow could be integrated in the scala file. + +object SomeNode extends ClusterNodeWithOpts{ + def opts() = -Dakka.cluster.nodename=node1 -Dakka.cluster.port=9991 +} + +- It should be transparent which node starts/stops the cluster. Perhaps some kind of 'before the world starts' and +'after the world ended' logic could be added. The consequence is that there are mixed responsibilities in a node. + +- A node has the mixed responsibity of being part of the grid and doing checks. It would be nice if one could create +cluster nodes very easily (just spawn a jvm and everything will be copied on them) and if one could create 'client nodes' +that communicate with the grid and do their validations. + +- Each node has been expressed in code, so it is very hard to either use a large number of nodes (lots of code) of to change +the number of nodes without changes all the code. It would be nice if one could say: I want 100 jvm instances with this +specification. + +- There is a lot of waiting for each other, but it would be nice if each node could say this: + waitForGo. + +so you get something like: + +object God{ + def beforeBegin(){ + ZooKeeper.start() + } + + def afterEnd{ + ZooKeeper.stop() + } +} + +class SomeNode extends ClusterTestNode{ + "foo" must { + "bla" in { + waitForGo() + + ..now do testing logic. + } + } +} + +