- initial example on the clustered test to get me up and running.. will be refactored to a more useful testin the very near future.

This commit is contained in:
Peter Veentjer 2011-06-29 13:33:41 +03:00
parent ce3586221c
commit ce1407858c
6 changed files with 155 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1 @@
-Dakka.cluster.nodename=node1 -Dakka.cluster.port=9991

View file

@ -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

View file

@ -0,0 +1 @@
-Dakka.cluster.nodename=node2 -Dakka.cluster.port=9992

View file

@ -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() /
}
}
}

View file

@ -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.
}
}
}