Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package wow.doge.mygame
  2. import akka.actor.typed.scaladsl.Behaviors
  3. import akka.actor.typed.scaladsl.ActorContext
  4. import org.scalatest.funsuite.AnyFunSuite
  5. import org.scalatest.BeforeAndAfterAll
  6. import akka.actor.typed.ActorSystem
  7. import scala.concurrent.duration._
  8. import akka.actor.typed.ActorRef
  9. import akka.actor.typed.scaladsl.AskPattern._
  10. import akka.util.Timeout
  11. import scala.concurrent.Await
  12. class ActorTimeoutTest extends AnyFunSuite with BeforeAndAfterAll {
  13. import ActorTimeoutTest._
  14. implicit val as = ActorSystem(new MyActor.Props().create, "system")
  15. implicit val timeout = Timeout(1.millis)
  16. test("timeoutTest") {
  17. val fut = as.ask(MyActor.GetInt)
  18. val res = Await.result(fut, 1.second)
  19. assert(res == 1)
  20. }
  21. override protected def afterAll(): Unit =
  22. as.terminate()
  23. }
  24. object ActorTimeoutTest {
  25. object MyActor {
  26. sealed trait Command
  27. case class GetInt(replyTo: ActorRef[Int]) extends Command
  28. class Props() {
  29. def create =
  30. Behaviors.setup[Command] { ctx =>
  31. new MyActor(ctx, this).receive
  32. }
  33. }
  34. }
  35. class MyActor(
  36. ctx: ActorContext[MyActor.Command],
  37. props: MyActor.Props
  38. ) {
  39. import MyActor._
  40. def receive =
  41. Behaviors.receiveMessage[Command] {
  42. case GetInt(replyTo) =>
  43. // Thread.sleep(1000)
  44. replyTo ! 1
  45. Behaviors.same
  46. }
  47. }
  48. }