diff --git a/akka-cluster/src/test/scala/akka/cluster/ClusteredFunctions.scala b/akka-cluster/src/test/scala/akka/cluster/ClusteredFunctions.scala index 4cd0bac6fb..031b6aea4f 100644 --- a/akka-cluster/src/test/scala/akka/cluster/ClusteredFunctions.scala +++ b/akka-cluster/src/test/scala/akka/cluster/ClusteredFunctions.scala @@ -10,7 +10,7 @@ import akka.dispatch.Futures /** * @author Jonas Bonér */ -object ClusteredFunctions { +object ComputeGridSample { //sample.cluster.ClusteredFunctions.fun2 // FIXME rewrite as multi-jvm test diff --git a/akka-cluster/src/test/scala/akka/cluster/ComputeGridSample.scala b/akka-cluster/src/test/scala/akka/cluster/ComputeGridSample.scala new file mode 100644 index 0000000000..4cd0bac6fb --- /dev/null +++ b/akka-cluster/src/test/scala/akka/cluster/ComputeGridSample.scala @@ -0,0 +1,94 @@ +/** + * Copyright (C) 2009-2011 Scalable Solutions AB + */ + +package sample.cluster + +import akka.cluster._ +import akka.dispatch.Futures + +/** + * @author Jonas Bonér + */ +object ClusteredFunctions { + //sample.cluster.ClusteredFunctions.fun2 + + // FIXME rewrite as multi-jvm test + + /* + // run all + def run { + fun1 + fun2 + fun3 + fun4 + } + + // Send Function0[Unit] + def fun1 = { + Cluster.startLocalCluster() + val node = Cluster newNode (NodeAddress("test", "local", port = 9991)) start + val remote1 = Cluster newNode (NodeAddress("test", "remote1", port = 9992)) start + + Thread.sleep(100) + val fun = () ⇒ println("=============>>> AKKA ROCKS <<<=============") + node send (fun, 2) // send and invoke function on to two cluster nodes + + node.stop + remote1.stop + Cluster.shutdownLocalCluster() + } + + // Send Function0[Any] + def fun2 = { + Cluster.startLocalCluster() + val local = Cluster newNode (NodeAddress("test", "local", port = 9991)) start + val remote1 = Cluster newNode (NodeAddress("test", "remote1", port = 9992)) start + + Thread.sleep(100) + val fun = () ⇒ "AKKA ROCKS" + val futures = local send (fun, 2) // send and invoke function on to two cluster nodes and get result + + val result = Futures.fold("")(futures)(_ + " - " + _).await.resultOrException + println("===================>>> Cluster says [" + result + "]") + + local.stop + remote1.stop + Cluster.shutdownLocalCluster() + } + + // Send Function1[Any, Unit] + def fun3 = { + Cluster.startLocalCluster() + val local = Cluster newNode (NodeAddress("test", "local", port = 9991)) start + val remote1 = Cluster newNode (NodeAddress("test", "remote1", port = 9992)) start + + val fun = ((s: String) ⇒ println("=============>>> " + s + " <<<=============")).asInstanceOf[Function1[Any, Unit]] + local send (fun, "AKKA ROCKS", 2) // send and invoke function on to two cluster nodes + + local.stop + remote1.stop + Cluster.shutdownLocalCluster() + } + + // Send Function1[Any, Any] + def fun4 = { + Cluster.startLocalCluster() + val local = Cluster newNode (NodeAddress("test", "local", port = 9991)) start + val remote1 = Cluster newNode (NodeAddress("test", "remote1", port = 9992)) start + + val fun = ((i: Int) ⇒ i * i).asInstanceOf[Function1[Any, Any]] + + val future1 = local send (fun, 2, 1) head // send and invoke function on one cluster node and get result + val future2 = local send (fun, 2, 1) head // send and invoke function on one cluster node and get result + + // grab the result from the first one that returns + val result = Futures.firstCompletedOf(List(future1, future2)).await.resultOrException + println("===================>>> Cluster says [" + result.get + "]") + + local.stop + remote1.stop + Cluster.shutdownLocalCluster() + } + */ +}