# Problem running example from Akka Geting Started Guide (iot example) Test

**URL:** <https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571>\
**Category:** Akka Libraries\
**Created:** [February 28, 2019, 12:54am UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571 "2019-02-28T00:54:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbp](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dbp](https://discuss.akka.io/u/dbp)\
**Post date:** [February 28, 2019, 12:54am UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/1 "2019-02-28T00:54:07Z")

</div>

The part of the test suite for “DeviceGroup” looks like:

```auto
  probe.watch(toShutDown)
   toShutDown ! PoisonPill
   probe.expectTerminated(toShutDown)
 
   // using awaitAssert to retry because it might take longer for the groupActor
   // to see the Terminated, that order is undefined
   probe.awaitAssert {
     groupActor.tell(DeviceGroup.RequestDeviceList(requestId = 1), probe.ref)
     probe.expectMsg(DeviceGroup.ReplyDeviceList(requestId = 1, Set("device2")))
   }

```

The def Receive for DeviceGroup inlucdes

```auto
    case Terminated(deviceActor) ⇒
       val deviceId = actorToDeviceId(deviceActor)
       log.info("Device actor for {} has been terminated", deviceId)
       actorToDeviceId -= deviceActor
       deviceIdToActor -= deviceId

```

What’s weird is that the `probe.expectTerminated(toShutdown)` is passing  
but:

1. I’m not seeing the log message “Device … has been terminated”
2. The last test that verifies that the Device has been removed from the DeviceGroup fails.

Has anyone else run into this? Suggestions on how to debug?

---

<div class="post-metadata">

**Author:** ![johanandren](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/johanandren/32/85_2.png) [@johanandren](https://discuss.akka.io/u/johanandren)\
**Post date:** [February 28, 2019, 2:51pm UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/2 "2019-02-28T14:51:42Z")

</div>

Hi David,

How are you running that spec, have you copied it to a project based on the `akka-quickstart-scala` or are you running it in some other way?

The log is at info level, have you set the `akka.loglevel` setting to `info` or `debug` and also made sure the logger used is not filtering INFO level logs out?

---

<div class="post-metadata">

**Author:** ![dbp](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dbp](https://discuss.akka.io/u/dbp)\
**Post date:** [February 28, 2019, 5:54pm UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/3 "2019-02-28T17:54:03Z")

</div>

Thanks for responding Johan.  
I’ve just copied the sources from the doc into an intellij project. Everything seems to be working fine except for this particular test (sending a PoisonPill to a DeviceActor and handling the Terminate message in the DeviceGroup.)

When I looked at the sources on Github I notice that the declaration of the test class extends “AkkaSpec”

> import akka.actor.PoisonPill  
> import akka.testkit.{AkkaSpec, TestProbe}
> 
> import scala.concurrent.duration.\_
> 
> class DeviceGroupSpec extends AkkaSpec {

I tried adding this to my DeviceGroupSpec but intellij can’t find AkkaSpec.  
I’m using build.sbt from AkkaQuickStart:

> version := “1.0”
> 
> scalaVersion := “2.12.6”
> 
> lazy val akkaVersion = “2.5.21”
> 
> libraryDependencies ++= Seq(  
> “com.typesafe.akka” %% “akka-actor” % akkaVersion,  
> “com.typesafe.akka” %% “akka-testkit” % akkaVersion,  
> “org.scalatest” %% “scalatest” % “3.0.5” % “test”  
> )

Could this be the problem and if where do I find AkkaSpec?

Thanks again for your help!

---

<div class="post-metadata">

**Author:** ![dbp](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dbp](https://discuss.akka.io/u/dbp)\
**Post date:** [February 28, 2019, 6:38pm UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/4 "2019-02-28T18:38:57Z")

</div>

I think I see the problem. I misinterpreted “expectTerminated” to mean that a “Terminate” message was received from the watched Actor. It just means that the Actor terminated. So somehow the DeviceGroup actor needs to be informed that the DeviceActor terminated via a Terminate message or some other mechanism that I don’t know about so that it can remove the Device Actor from its collection. Does this seem correct and if so how should I modify the Device or the DeviceGroup code?

Thanks again.

---

<div class="post-metadata">

**Author:** ![dbp](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dbp](https://discuss.akka.io/u/dbp)\
**Post date:** [February 28, 2019, 9:09pm UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/5 "2019-02-28T21:09:57Z")

</div>

Problem solved! I have the DeviceGroup Actor watch newly created Device Actors so that it will receive the Terminate message and remove the dead actor. (I think the example needs to be modified to do this.)

---

<div class="post-metadata">

**Author:** ![dbp](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dbp](https://discuss.akka.io/u/dbp)\
**Post date:** [February 28, 2019, 10:12pm UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/6 "2019-02-28T22:12:46Z")

</div>

There’s one other mystery in the test code having to do with “TestProbe” that’s bothering me. In the tests for DeviceGroupQuery we have the following:

```auto
val requester = TestProbe()

  val device1 = TestProbe()
  val device2 = TestProbe()

```

What is TestProbe() returning? requester is supposed to be a DeviceGroup actor and device 1 and 2 represent device actors but where how does the type of the actor get specified or am I completely missing something here. (This may be related to my previous question.)

---

<div class="post-metadata">

**Author:** ![dbp](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dbp](https://discuss.akka.io/u/dbp)\
**Post date:** [February 28, 2019, 10:46pm UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/7 "2019-02-28T22:46:41Z")

</div>

Sorry, I found documentation on TestProbe

---

<div class="post-metadata">

**Author:** ![johanandren](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/johanandren/32/85_2.png) [@johanandren](https://discuss.akka.io/u/johanandren)\
**Post date:** [March 1, 2019, 12:03pm UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/8 "2019-03-01T12:03:03Z")

</div>

As far as I can see the device group is watching of it’s children:

[https://doc.akka.io/docs/akka/current/guide/tutorial\_4.html#keeping-track-of-the-device-actors-in-the-group](https://doc.akka.io/docs/akka/current/guide/tutorial_4.html#keeping-track-of-the-device-actors-in-the-group)

Maybe you are looking at the section before that is introduced?

---

<div class="post-metadata">

**Author:** ![dbp](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dbp](https://discuss.akka.io/u/dbp)\
**Post date:** [March 1, 2019, 2:27pm UTC](https://discuss.akka.io/t/problem-running-example-from-akka-geting-started-guide-iot-example-test/3571/9 "2019-03-01T14:27:19Z")

</div>

You’re right! I missed that addition. Sorry!
