You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "mario-renau-alstom (via GitHub)" <gi...@apache.org> on 2023/08/15 14:10:09 UTC

[GitHub] [incubator-pekko-samples] mario-renau-alstom commented on a diff in pull request #66: Tests for worker and work executor

mario-renau-alstom commented on code in PR #66:
URL: https://github.com/apache/incubator-pekko-samples/pull/66#discussion_r1294647949


##########
pekko-sample-distributed-workers-scala/src/test/scala/worker/WorkerSpec.scala:
##########
@@ -0,0 +1,39 @@
+package worker
+
+import org.apache.pekko
+import org.apache.pekko.actor.typed.delivery.ConsumerController
+import org.apache.pekko.actor.typed.scaladsl.Behaviors
+import pekko.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit
+import org.scalatest.wordspec.AnyWordSpecLike
+
+class WorkerSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike{
+
+  "A Worker" must {
+
+    "start work when in idle state" in {
+      val workExecutorProbe = createTestProbe[WorkExecutor.ExecuteWork]()
+      val worker = spawn(Worker(workExecutorFactory = () => Behaviors.monitor(workExecutorProbe.ref, WorkExecutor())))
+      val work = WorkManager.DoWork(Work("TestWork", 1000))
+      val deliveryProbe = createTestProbe[ConsumerController.Confirmed]()
+      val deliveredMessage = Worker.DeliveredMessage(deliveryProbe.ref, work, 1)
+
+      worker ! deliveredMessage
+
+      workExecutorProbe.expectMessageType[WorkExecutor.ExecuteWork]
+    }
+
+    "confirm the work when work is complete" in {
+      val workExecutorProbe = createTestProbe[WorkExecutor.ExecuteWork]()
+      val worker = spawn(Worker(workExecutorFactory = () => Behaviors.monitor(workExecutorProbe.ref, WorkExecutor())))
+      val work = WorkManager.DoWork(Work("TestWork", 1000))
+
+      val deliveryProbe = createTestProbe[ConsumerController.Confirmed]()
+      val deliveredMessage = Worker.DeliveredMessage(deliveryProbe.ref, work, 1)
+
+      worker ! deliveredMessage
+      worker ! Worker.WorkComplete("Successful result")
+
+      deliveryProbe.expectMessageType[ConsumerController.Confirmed]
+    }
+  }
+}

Review Comment:
   Fixed



##########
pekko-sample-distributed-workers-scala/src/test/scala/worker/WorkerSpec.scala:
##########
@@ -0,0 +1,39 @@
+package worker
+
+import org.apache.pekko
+import org.apache.pekko.actor.typed.delivery.ConsumerController

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org