+sam #3689 Make activator template of the multi-node sample
This commit is contained in:
parent
276eb0881f
commit
1a3080b7a6
12 changed files with 177 additions and 107 deletions
|
|
@ -21,86 +21,9 @@ You can then add multi-JVM testing to ``project/Build.scala`` by including the `
|
|||
settings and config. Please note that MultiJvm test sources are located in ``src/multi-jvm/...``,
|
||||
and not in ``src/test/...``.
|
||||
|
||||
Here is an example Build.scala file for sbt 0.12 that uses the MultiJvm plugin:
|
||||
Here is an example Build.scala file for sbt 0.13 that uses the MultiJvm plugin:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
import sbt._
|
||||
import Keys._
|
||||
import com.typesafe.sbt.SbtMultiJvm
|
||||
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys.MultiJvm
|
||||
|
||||
object ExampleBuild extends Build {
|
||||
|
||||
lazy val buildSettings = Defaults.defaultSettings ++ multiJvmSettings ++ Seq(
|
||||
organization := "example",
|
||||
version := "1.0",
|
||||
scalaVersion := "@scalaVersion@",
|
||||
// make sure that the artifacts don't have the scala version in the name
|
||||
crossPaths := false
|
||||
)
|
||||
|
||||
lazy val example = Project(
|
||||
id = "example",
|
||||
base = file("."),
|
||||
settings = buildSettings ++
|
||||
Seq(libraryDependencies ++= Dependencies.example)
|
||||
) configs(MultiJvm)
|
||||
|
||||
lazy val multiJvmSettings = SbtMultiJvm.multiJvmSettings ++ Seq(
|
||||
// make sure that MultiJvm test are compiled by the default test compilation
|
||||
compile in MultiJvm <<= (compile in MultiJvm) triggeredBy (compile in Test),
|
||||
// disable parallel tests
|
||||
parallelExecution in Test := false,
|
||||
// make sure that MultiJvm tests are executed by the default test target
|
||||
executeTests in Test <<=
|
||||
((executeTests in Test), (executeTests in MultiJvm)) map {
|
||||
case ((_, testResults), (_, multiJvmResults)) =>
|
||||
val results = testResults ++ multiJvmResults
|
||||
(Tests.overall(results.values), results)
|
||||
}
|
||||
)
|
||||
|
||||
object Dependencies {
|
||||
val example = Seq(
|
||||
// ---- application dependencies ----
|
||||
"com.typesafe.akka" %% "akka-actor" % "@version@" @crossString@,
|
||||
"com.typesafe.akka" %% "akka-remote" % "@version@" @crossString@,
|
||||
|
||||
// ---- test dependencies ----
|
||||
"com.typesafe.akka" %% "akka-testkit" % "@version@" %
|
||||
"test" @crossString@,
|
||||
"com.typesafe.akka" %% "akka-multi-node-testkit" % "@version@" %
|
||||
"test" @crossString@,
|
||||
"org.scalatest" %% "scalatest" % "2.0" % "test",
|
||||
"junit" % "junit" % "4.10" % "test"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
If you are using sbt 0.13 the multiJvmSettings in the Build.scala file looks like this instead:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
lazy val multiJvmSettings = SbtMultiJvm.multiJvmSettings ++ Seq(
|
||||
// make sure that MultiJvm test are compiled by the default test compilation
|
||||
compile in MultiJvm <<= (compile in MultiJvm) triggeredBy (compile in Test),
|
||||
// disable parallel tests
|
||||
parallelExecution in Test := false,
|
||||
// make sure that MultiJvm tests are executed by the default test target
|
||||
executeTests in Test <<=
|
||||
((executeTests in Test), (executeTests in MultiJvm)) map {
|
||||
case ((testResults), (multiJvmResults)) =>
|
||||
val overall =
|
||||
if (testResults.overall.id < multiJvmResults.overall.id)
|
||||
multiJvmResults.overall
|
||||
else
|
||||
testResults.overall
|
||||
Tests.Output(overall,
|
||||
testResults.events ++ multiJvmResults.events,
|
||||
testResults.summaries ++ multiJvmResults.summaries)
|
||||
}
|
||||
)
|
||||
.. includecode:: ../../../akka-samples/akka-sample-multi-node-scala/project/Build.scala
|
||||
|
||||
You can specify JVM options for the forked JVMs::
|
||||
|
||||
|
|
|
|||
|
|
@ -185,20 +185,23 @@ A Multi Node Testing Example
|
|||
First we need some scaffolding to hook up the ``MultiNodeSpec`` with your favorite test framework. Lets define a trait
|
||||
``STMultiNodeSpec`` that uses ScalaTest to start and stop ``MultiNodeSpec``.
|
||||
|
||||
.. includecode:: ../../../akka-samples/akka-sample-multi-node/src/test/scala/sample/multinode/STMultiNodeSpec.scala#example
|
||||
.. includecode:: ../../../akka-samples/akka-sample-multi-node-scala/src/test/scala/sample/multinode/STMultiNodeSpec.scala#example
|
||||
|
||||
Then we need to define a configuration. Lets use two nodes ``"node1`` and ``"node2"`` and call it
|
||||
``MultiNodeSampleConfig``.
|
||||
|
||||
.. includecode:: ../../../akka-samples/akka-sample-multi-node/src/multi-jvm/scala/sample/multinode/MultiNodeSample.scala
|
||||
.. includecode:: ../../../akka-samples/akka-sample-multi-node-scala/src/multi-jvm/scala/sample/multinode/MultiNodeSample.scala
|
||||
:include: package,config
|
||||
|
||||
And then finally to the node test code. That starts the two nodes, and demonstrates a barrier, and a remote actor
|
||||
message send/receive.
|
||||
|
||||
.. includecode:: ../../../akka-samples/akka-sample-multi-node/src/multi-jvm/scala/sample/multinode/MultiNodeSample.scala
|
||||
.. includecode:: ../../../akka-samples/akka-sample-multi-node-scala/src/multi-jvm/scala/sample/multinode/MultiNodeSample.scala
|
||||
:include: package,spec
|
||||
|
||||
The easiest way to run this example yourself is to download `Typesafe Activator <http://typesafe.com/platform/getstarted>`_
|
||||
and open the tutorial named `Akka Multi-Node Testing Sample with Scala <http://typesafe.com/activator/template/akka-sample-multi-node-scala>`_.
|
||||
|
||||
Things to Keep in Mind
|
||||
======================
|
||||
|
||||
|
|
|
|||
13
akka-samples/akka-sample-multi-node-scala/LICENSE
Normal file
13
akka-samples/akka-sample-multi-node-scala/LICENSE
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Copyright 2013-2014 Typesafe, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
name=akka-sample-multi-node-scala
|
||||
title=Akka Multi-Node Testing Sample with Scala
|
||||
description=Sample containing sbt build settings and test classes for illustrating multi-node testing with Akka and Scala
|
||||
tags=akka,testing,scala,sample
|
||||
authorName=Akka Team
|
||||
authorLink=http://akka.io/
|
||||
sourceLink=https://github.com/akka/akka
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import sbt._
|
||||
import sbt.Keys._
|
||||
import com.typesafe.sbt.SbtMultiJvm
|
||||
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys.MultiJvm
|
||||
|
||||
object AkkaSampleMultiNodeBuild extends Build {
|
||||
|
||||
val akkaVersion = "2.3-SNAPSHOT"
|
||||
|
||||
lazy val akkaSampleMultiNode = Project(
|
||||
id = "akka-sample-multi-node-scala",
|
||||
base = file("."),
|
||||
settings = Project.defaultSettings ++ SbtMultiJvm.multiJvmSettings ++ Seq(
|
||||
name := "akka-sample-multi-node-scala",
|
||||
version := "1.0",
|
||||
scalaVersion := "2.10.3",
|
||||
libraryDependencies ++= Seq(
|
||||
"com.typesafe.akka" %% "akka-remote" % akkaVersion,
|
||||
"com.typesafe.akka" %% "akka-multi-node-testkit" % akkaVersion,
|
||||
"org.scalatest" %% "scalatest" % "2.0" % "test"),
|
||||
// make sure that MultiJvm test are compiled by the default test compilation
|
||||
compile in MultiJvm <<= (compile in MultiJvm) triggeredBy (compile in Test),
|
||||
// disable parallel tests
|
||||
parallelExecution in Test := false,
|
||||
// make sure that MultiJvm tests are executed by the default test target,
|
||||
// and combine the results from ordinary test and multi-jvm tests
|
||||
executeTests in Test <<= (executeTests in Test, executeTests in MultiJvm) map {
|
||||
case (testResults, multiNodeResults) =>
|
||||
val overall =
|
||||
if (testResults.overall.id < multiNodeResults.overall.id)
|
||||
multiNodeResults.overall
|
||||
else
|
||||
testResults.overall
|
||||
Tests.Output(overall,
|
||||
testResults.events ++ multiNodeResults.events,
|
||||
testResults.summaries ++ multiNodeResults.summaries)
|
||||
}
|
||||
)
|
||||
) configs (MultiJvm)
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
sbt.version=0.13.1
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
resolvers += Classpaths.typesafeResolver
|
||||
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.3.8")
|
||||
|
|
@ -22,10 +22,19 @@ import akka.actor.{ Props, Actor }
|
|||
class MultiNodeSampleSpecMultiJvmNode1 extends MultiNodeSample
|
||||
class MultiNodeSampleSpecMultiJvmNode2 extends MultiNodeSample
|
||||
|
||||
object MultiNodeSample {
|
||||
class Ponger extends Actor {
|
||||
def receive = {
|
||||
case "ping" => sender() ! "pong"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MultiNodeSample extends MultiNodeSpec(MultiNodeSampleConfig)
|
||||
with STMultiNodeSpec with ImplicitSender {
|
||||
|
||||
import MultiNodeSampleConfig._
|
||||
import MultiNodeSample._
|
||||
|
||||
def initialParticipants = roles.size
|
||||
|
||||
|
|
@ -38,17 +47,13 @@ class MultiNodeSample extends MultiNodeSpec(MultiNodeSampleConfig)
|
|||
"send to and receive from a remote node" in {
|
||||
runOn(node1) {
|
||||
enterBarrier("deployed")
|
||||
val ponger = system.actorFor(node(node2) / "user" / "ponger")
|
||||
val ponger = system.actorSelection(node(node2) / "user" / "ponger")
|
||||
ponger ! "ping"
|
||||
expectMsg("pong")
|
||||
}
|
||||
|
||||
runOn(node2) {
|
||||
system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "ping" => sender() ! "pong"
|
||||
}
|
||||
}), "ponger")
|
||||
system.actorOf(Props[Ponger], "ponger")
|
||||
enterBarrier("deployed")
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<!-- <html> -->
|
||||
<head>
|
||||
<title>Akka Multi-Node Testing Sample with Scala</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div>
|
||||
<p>
|
||||
This sample contains <a href="http://www.scala-sbt.org/" target="_blank">sbt</a> build settings
|
||||
and test classes for illustrating multi-node testing with Akka.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Please refer to the full documentation of
|
||||
<a href="http://doc.akka.io/docs/akka/2.3-SNAPSHOT/dev/multi-node-testing.html" target="_blank">multi-node testing</a>
|
||||
and the closely related
|
||||
<a href="http://doc.akka.io/docs/akka/2.3-SNAPSHOT/dev/multi-jvm-testing.html" target="_blank">multi-jvm testing</a>
|
||||
for details.
|
||||
There is also an section on
|
||||
<a href="http://doc.akka.io/docs/akka/2.3-SNAPSHOT/scala/cluster-usage.html#How_to_Test" target="_blank">cluster testing</a>.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>sbt setup</h2>
|
||||
|
||||
<p>
|
||||
Open <a href="#code/project/plugins.sbt" class="shortcut">project/plugins.sbt</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
It adds the <a href="http://github.com/typesafehub/sbt-multi-jvm" target="_blank">sbt-multi-jvm</a> plugin to the build.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Open <a href="#code/project/Build.scala" class="shortcut">project/Build.scala</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
It includes the MultiJvm settings that are needed to run multi-jvm tests.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Tests</h2>
|
||||
|
||||
<p>
|
||||
Open <a href="#code/src/multi-jvm/scala/sample/multinode/MultiNodeSample.scala" class="shortcut">MultiNodeSample.scala</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Note that MultiJvm test sources are located in <code>src/multi-jvm/...</code> and the
|
||||
test classes must end with <code>MultiJvm</code> followed by the node name, typically
|
||||
<code>Node1</code>, <code>Node2</code>, <code>Node3</code>...
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To hook up the MultiNodeSpec with with ScalaTest you need something like:
|
||||
<a href="#code/src/test/scala/sample/multinode/STMultiNodeSpec.scala" class="shortcut">STMultiNodeSpec.scala</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To see the test in action, open the <a href="#test" class="shortcut">Test</a> tab
|
||||
and click <b>Start</b> to run the <code>MultiNodeSample</code>. This corresponds to
|
||||
<code>sbt test</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
In case you have many tests in the project it can be convenient to run a single test from
|
||||
the sbt prompt:
|
||||
</p>
|
||||
|
||||
<pre><code>
|
||||
> multi-jvm:testOnly sample.multinode.MultiNodeSampleSpec
|
||||
</code></pre>
|
||||
|
||||
<p>
|
||||
The same test can be run on multiple machines as described in the
|
||||
<a href="http://doc.akka.io/docs/akka/2.3-SNAPSHOT/dev/multi-node-testing.html" target="_blank">multi-node testing documentation</a>.
|
||||
</p>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
Multi-Node Test Sample
|
||||
======================
|
||||
|
||||
This sample is meant to be used by studying the code; it does not perform any
|
||||
astounding functions when running it. If you want to run it, check out the akka
|
||||
sources on your local hard drive, follow the [instructions for setting up Akka
|
||||
with SBT](http://doc.akka.io/docs/akka/current/intro/getting-started.html).
|
||||
When you start SBT within the checked-out akka source directory, you can run
|
||||
this sample by typing
|
||||
|
||||
akka-sample-multi-node-experimental/multi-jvm:test-only sample.multinode.MultiNodeSampleSpec
|
||||
|
||||
(You might have to pass a system property containing `akka.test.tags.include=long-running`.)
|
||||
|
||||
You can read more in the [Akka docs](http://akka.io/docs).
|
||||
|
|
@ -370,7 +370,7 @@ object AkkaBuild extends Build {
|
|||
aggregate = Seq(camelSampleJava, camelSampleScala, mainSampleJava, mainSampleScala,
|
||||
remoteSampleJava, remoteSampleScala, clusterSampleJava, clusterSampleScala,
|
||||
fsmSampleScala, persistenceSample,
|
||||
multiNodeSample, helloKernelSample, osgiDiningHakkersSample)
|
||||
multiNodeSampleScala, helloKernelSample, osgiDiningHakkersSample)
|
||||
)
|
||||
|
||||
lazy val camelSampleJava = Project(
|
||||
|
|
@ -472,9 +472,9 @@ object AkkaBuild extends Build {
|
|||
)
|
||||
) configs (MultiJvm)
|
||||
|
||||
lazy val multiNodeSample = Project(
|
||||
id = "akka-sample-multi-node",
|
||||
base = file("akka-samples/akka-sample-multi-node"),
|
||||
lazy val multiNodeSampleScala = Project(
|
||||
id = "akka-sample-multi-node-scala",
|
||||
base = file("akka-samples/akka-sample-multi-node-scala"),
|
||||
dependencies = Seq(multiNodeTestkit % "test", testkit % "test"),
|
||||
settings = multiJvmSettings ++ sampleSettings ++ experimentalSettings ++ Seq(
|
||||
libraryDependencies ++= Dependencies.multiNodeSample,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue