From 40483a25061759db3b1ca531b7e7748f55cc4be5 Mon Sep 17 00:00:00 2001 From: Oliver Burkhalter Date: Thu, 15 Nov 2018 12:55:29 +0100 Subject: [PATCH] Improve Getting Started Guide Part 3 for writing a first Actor test #25193 --- akka-docs/src/main/paradox/guide/tutorial_1.md | 2 +- akka-docs/src/main/paradox/guide/tutorial_2.md | 2 +- akka-docs/src/main/paradox/guide/tutorial_3.md | 7 +++++-- .../java/jdocs/tutorial_1/ActorHierarchyExperiments.java | 2 +- akka-docs/src/test/java/jdocs/tutorial_2/IotMain.java | 2 +- .../src/test/java/jdocs/tutorial_2/IotSupervisor.java | 2 +- .../test/scala/tutorial_1/ActorHierarchyExperiments.scala | 2 +- akka-docs/src/test/scala/tutorial_2/IotApp.scala | 2 +- akka-docs/src/test/scala/tutorial_2/IotSupervisor.scala | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/akka-docs/src/main/paradox/guide/tutorial_1.md b/akka-docs/src/main/paradox/guide/tutorial_1.md index 8412d8e98c..f296dfc41f 100644 --- a/akka-docs/src/main/paradox/guide/tutorial_1.md +++ b/akka-docs/src/main/paradox/guide/tutorial_1.md @@ -37,7 +37,7 @@ We create child, or non-top-level, actors by invoking `context.actorOf()` from a The easiest way to see the actor hierarchy in action is to print `ActorRef` instances. In this small experiment, we create an actor, print its reference, create a child of this actor, and print the child's reference. We start with the Hello World project, if you have not downloaded it, download the Quickstart project from the @scala[[Lightbend Tech Hub](http://developer.lightbend.com/start/?group=akka&project=akka-quickstart-scala)]@java[[Lightbend Tech Hub](http://developer.lightbend.com/start/?group=akka&project=akka-quickstart-java)]. -In your Hello World project, navigate to the `com.lightbend.akka.sample` package and create a new @scala[Scala file called `ActorHierarchyExperiments.scala`]@java[Java file called `ActorHierarchyExperiments.java`] here. Copy and paste the code from the snippet below to this new source file. Save your file and run `sbt "runMain com.lightbend.akka.sample.ActorHierarchyExperiments"` to observe the output. +In your Hello World project, navigate to the `com.example` package and create a new @scala[Scala file called `ActorHierarchyExperiments.scala`]@java[Java file called `ActorHierarchyExperiments.java`] here. Copy and paste the code from the snippet below to this new source file. Save your file and run `sbt "runMain com.example.ActorHierarchyExperiments"` to observe the output. Scala : @@snip [ActorHierarchyExperiments.scala](/akka-docs/src/test/scala/tutorial_1/ActorHierarchyExperiments.scala) { #print-refs } diff --git a/akka-docs/src/main/paradox/guide/tutorial_2.md b/akka-docs/src/main/paradox/guide/tutorial_2.md index 88b27a0292..a7e9e9c3bb 100644 --- a/akka-docs/src/main/paradox/guide/tutorial_2.md +++ b/akka-docs/src/main/paradox/guide/tutorial_2.md @@ -20,7 +20,7 @@ represent devices and dashboards at the top level. Instead, we recommend creatin We can define the first actor, the IotSupervisor, with a few simple lines of code. To start your tutorial application: -1. Create a new `IotSupervisor` source file in the `com.lightbend.akka.sample` package. +1. Create a new `IotSupervisor` source file in your appropriate package, e.g. in the `com.example` package 1. Paste the following code into the new file to define the IotSupervisor. Scala diff --git a/akka-docs/src/main/paradox/guide/tutorial_3.md b/akka-docs/src/main/paradox/guide/tutorial_3.md index 5884e54dab..9072165c13 100644 --- a/akka-docs/src/main/paradox/guide/tutorial_3.md +++ b/akka-docs/src/main/paradox/guide/tutorial_3.md @@ -146,8 +146,11 @@ Note in the code that: ## Testing the actor -Based on the simple actor above, we could write a simple test. In the `com.lightbend.akka.sample` package in the test tree of your project, add the following code to a @scala[`DeviceSpec.scala`]@java[`DeviceTest.java`] file. -@scala[(We use ScalaTest but any other test framework can be used with the Akka Testkit)]. +Based on the simple actor above, we could write a simple test. You can check a full example of an Actor test in the Quickstart guide here @scala[[Quickstart Guide Testing example](https://developer.lightbend.com/guides/akka-quickstart-scala/testing-actors.html)] @java[[Quickstart Guide Testing example](https://developer.lightbend.com/guides/akka-quickstart-java/testing-actors.html)]. +You'll find there an example on how you can fully setup an Actor test, so that you can run it properly. + +In the test tree of your project, add the following code to a @scala[`DeviceSpec.scala`]@java[`DeviceTest.java`] file. +@scala[(We use [ScalaTest](http://www.scalatest.org) but any other testing framework can be used with the Akka Testkit)]. You can run this test @java[by running `mvn test` or] by running `test` at the sbt prompt. diff --git a/akka-docs/src/test/java/jdocs/tutorial_1/ActorHierarchyExperiments.java b/akka-docs/src/test/java/jdocs/tutorial_1/ActorHierarchyExperiments.java index 93082f832d..b1a50bcf9d 100644 --- a/akka-docs/src/test/java/jdocs/tutorial_1/ActorHierarchyExperiments.java +++ b/akka-docs/src/test/java/jdocs/tutorial_1/ActorHierarchyExperiments.java @@ -3,7 +3,7 @@ */ //#print-refs -package com.lightbend.akka.sample; +package com.example; //#print-refs diff --git a/akka-docs/src/test/java/jdocs/tutorial_2/IotMain.java b/akka-docs/src/test/java/jdocs/tutorial_2/IotMain.java index 4bfdf1bd4f..39fa368a60 100644 --- a/akka-docs/src/test/java/jdocs/tutorial_2/IotMain.java +++ b/akka-docs/src/test/java/jdocs/tutorial_2/IotMain.java @@ -3,7 +3,7 @@ */ //#iot-app -package com.lightbend.akka.sample; +package com.example; import java.io.IOException; diff --git a/akka-docs/src/test/java/jdocs/tutorial_2/IotSupervisor.java b/akka-docs/src/test/java/jdocs/tutorial_2/IotSupervisor.java index 4ced35aca2..ea9eef6fe6 100644 --- a/akka-docs/src/test/java/jdocs/tutorial_2/IotSupervisor.java +++ b/akka-docs/src/test/java/jdocs/tutorial_2/IotSupervisor.java @@ -3,7 +3,7 @@ */ //#iot-supervisor -package com.lightbend.akka.sample; +package com.example; import akka.actor.AbstractActor; import akka.actor.ActorLogging; diff --git a/akka-docs/src/test/scala/tutorial_1/ActorHierarchyExperiments.scala b/akka-docs/src/test/scala/tutorial_1/ActorHierarchyExperiments.scala index ba340a0ec4..86222a0a84 100644 --- a/akka-docs/src/test/scala/tutorial_1/ActorHierarchyExperiments.scala +++ b/akka-docs/src/test/scala/tutorial_1/ActorHierarchyExperiments.scala @@ -6,7 +6,7 @@ package docs.tutorial_1 //#print-refs -package com.lightbend.akka.sample +package com.example import akka.actor.{ Actor, Props, ActorSystem } import scala.io.StdIn diff --git a/akka-docs/src/test/scala/tutorial_2/IotApp.scala b/akka-docs/src/test/scala/tutorial_2/IotApp.scala index e914f90831..b7f36a3efb 100644 --- a/akka-docs/src/test/scala/tutorial_2/IotApp.scala +++ b/akka-docs/src/test/scala/tutorial_2/IotApp.scala @@ -5,7 +5,7 @@ package tutorial_2 //#iot-app -package com.lightbend.akka.sample +package com.example import akka.actor.ActorSystem import scala.io.StdIn diff --git a/akka-docs/src/test/scala/tutorial_2/IotSupervisor.scala b/akka-docs/src/test/scala/tutorial_2/IotSupervisor.scala index 3e95bfa04a..b94214f840 100644 --- a/akka-docs/src/test/scala/tutorial_2/IotSupervisor.scala +++ b/akka-docs/src/test/scala/tutorial_2/IotSupervisor.scala @@ -5,7 +5,7 @@ package tutorial_2 //#iot-supervisor -package com.lightbend.akka.sample +package com.example import akka.actor.{ Actor, ActorLogging, Props }