diff --git a/akka-docs/src/test/java/jdocs/tutorial_3/DeviceGroupTest.java b/akka-docs/src/test/java/jdocs/tutorial_3/DeviceGroupTest.java index 9bdc05d500..4c502b5f5d 100644 --- a/akka-docs/src/test/java/jdocs/tutorial_3/DeviceGroupTest.java +++ b/akka-docs/src/test/java/jdocs/tutorial_3/DeviceGroupTest.java @@ -122,10 +122,16 @@ public class DeviceGroupTest extends JUnitSuite { toShutDown.tell(PoisonPill.getInstance(), ActorRef.noSender()); probe.expectTerminated(toShutDown); - groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef()); - reply = probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class); - assertEquals(1L, reply.requestId); - assertEquals(Stream.of("device2").collect(Collectors.toSet()), reply.ids); + // using awaitAssert to retry because it might take longer for the groupActor + // to see the Terminated, that order is undefined + probe.awaitAssert(() -> { + groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef()); + DeviceGroup.ReplyDeviceList r = + probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class); + assertEquals(1L, r.requestId); + assertEquals(Stream.of("device2").collect(Collectors.toSet()), r.ids); + return null; + }); } //#device-group-list-terminate-test } diff --git a/akka-docs/src/test/java/jdocs/tutorial_4/DeviceGroupTest.java b/akka-docs/src/test/java/jdocs/tutorial_4/DeviceGroupTest.java index 7c3139ba9c..a51cf88a29 100644 --- a/akka-docs/src/test/java/jdocs/tutorial_4/DeviceGroupTest.java +++ b/akka-docs/src/test/java/jdocs/tutorial_4/DeviceGroupTest.java @@ -121,10 +121,16 @@ public class DeviceGroupTest extends JUnitSuite { toShutDown.tell(PoisonPill.getInstance(), ActorRef.noSender()); probe.expectTerminated(toShutDown); - groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef()); - reply = probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class); - assertEquals(1L, reply.requestId); - assertEquals(Stream.of("device2").collect(Collectors.toSet()), reply.ids); + // using awaitAssert to retry because it might take longer for the groupActor + // to see the Terminated, that order is undefined + probe.awaitAssert(() -> { + groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef()); + DeviceGroup.ReplyDeviceList r = + probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class); + assertEquals(1L, r.requestId); + assertEquals(Stream.of("device2").collect(Collectors.toSet()), r.ids); + return null; + }); } //#group-query-integration-test diff --git a/akka-docs/src/test/java/jdocs/tutorial_5/DeviceGroupTest.java b/akka-docs/src/test/java/jdocs/tutorial_5/DeviceGroupTest.java index 932f46d50c..fdfb97a6c0 100644 --- a/akka-docs/src/test/java/jdocs/tutorial_5/DeviceGroupTest.java +++ b/akka-docs/src/test/java/jdocs/tutorial_5/DeviceGroupTest.java @@ -120,10 +120,16 @@ public class DeviceGroupTest extends JUnitSuite { toShutDown.tell(PoisonPill.getInstance(), ActorRef.noSender()); probe.expectTerminated(toShutDown); - groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef()); - reply = probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class); - assertEquals(1L, reply.requestId); - assertEquals(Stream.of("device2").collect(Collectors.toSet()), reply.ids); + // using awaitAssert to retry because it might take longer for the groupActor + // to see the Terminated, that order is undefined + probe.awaitAssert(() -> { + groupActor.tell(new DeviceGroup.RequestDeviceList(1L), probe.getRef()); + DeviceGroup.ReplyDeviceList r = + probe.expectMsgClass(DeviceGroup.ReplyDeviceList.class); + assertEquals(1L, r.requestId); + assertEquals(Stream.of("device2").collect(Collectors.toSet()), r.ids); + return null; + }); } @Test diff --git a/akka-docs/src/test/scala/tutorial_3/DeviceGroupSpec.scala b/akka-docs/src/test/scala/tutorial_3/DeviceGroupSpec.scala index 35f1cc1f72..e40295b40c 100644 --- a/akka-docs/src/test/scala/tutorial_3/DeviceGroupSpec.scala +++ b/akka-docs/src/test/scala/tutorial_3/DeviceGroupSpec.scala @@ -93,8 +93,12 @@ class DeviceGroupSpec extends AkkaSpec { toShutDown ! PoisonPill probe.expectTerminated(toShutDown) - groupActor.tell(DeviceGroup.RequestDeviceList(requestId = 1), probe.ref) - probe.expectMsg(DeviceGroup.ReplyDeviceList(requestId = 1, Set("device2"))) + // 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"))) + } } //#device-group-list-terminate-test diff --git a/akka-docs/src/test/scala/tutorial_4/DeviceGroupSpec.scala b/akka-docs/src/test/scala/tutorial_4/DeviceGroupSpec.scala index 316e372433..24a069e0cd 100644 --- a/akka-docs/src/test/scala/tutorial_4/DeviceGroupSpec.scala +++ b/akka-docs/src/test/scala/tutorial_4/DeviceGroupSpec.scala @@ -88,8 +88,12 @@ class DeviceGroupSpec extends AkkaSpec { toShutDown ! PoisonPill probe.expectTerminated(toShutDown) - groupActor.tell(DeviceGroup.RequestDeviceList(requestId = 1), probe.ref) - probe.expectMsg(DeviceGroup.ReplyDeviceList(requestId = 1, Set("device2"))) + // 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"))) + } } //#group-query-integration-test @@ -123,10 +127,7 @@ class DeviceGroupSpec extends AkkaSpec { temperatures = Map( "device1" -> DeviceGroup.Temperature(1.0), "device2" -> DeviceGroup.Temperature(2.0), - "device3" -> DeviceGroup.TemperatureNotAvailable - ) - ) - ) + "device3" -> DeviceGroup.TemperatureNotAvailable))) } //#group-query-integration-test diff --git a/akka-docs/src/test/scala/tutorial_5/DeviceGroupSpec.scala b/akka-docs/src/test/scala/tutorial_5/DeviceGroupSpec.scala index e33f2fb01a..3faab1fdd5 100644 --- a/akka-docs/src/test/scala/tutorial_5/DeviceGroupSpec.scala +++ b/akka-docs/src/test/scala/tutorial_5/DeviceGroupSpec.scala @@ -88,8 +88,12 @@ class DeviceGroupSpec extends AkkaSpec { toShutDown ! PoisonPill probe.expectTerminated(toShutDown) - groupActor.tell(DeviceGroup.RequestDeviceList(requestId = 1), probe.ref) - probe.expectMsg(DeviceGroup.ReplyDeviceList(requestId = 1, Set("device2"))) + // 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"))) + } } "be able to collect temperatures from all active devices" in { @@ -122,10 +126,7 @@ class DeviceGroupSpec extends AkkaSpec { temperatures = Map( "device1" -> DeviceGroup.Temperature(1.0), "device2" -> DeviceGroup.Temperature(2.0), - "device3" -> DeviceGroup.TemperatureNotAvailable - ) - ) - ) + "device3" -> DeviceGroup.TemperatureNotAvailable))) } }