akka/akka-core

Only EventSourcedBehavior, or nested EventSourcedBehavior allowed. exception thrown in EventSourcedBehaviorTestKit

Open

#30.747 geöffnet am 5. Okt. 2021

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Scala (3.547 Forks)batch import
1 - triagedhelp wantedt:persistencet:testing

Repository-Metriken

Stars
 (13.277 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 17h 35m) (11 gemergte PRs in 30 T)

Beschreibung

There is an issue when running EventSourcedBehaviorTestKit and receiveSignal() handler defined on actor's EventSourcedBehavior. Initially found it on one of akka examples - https://developer.lightbend.com/docs/akka-platform-guide/microservices-tutorial/dev-env.html STR:

  1. Add receiveSignal handler to EventSourcedBehavior e.g.
EventSourcedBehavior
      .withEnforcedReplies[Command, Event, State](
        persistenceId = PersistenceId(EntityKey.name, cartId),
        emptyState = State.empty,
        commandHandler =
          (state, command) => handleCommand(cartId, state, command),
        eventHandler = (state, event) => handleEvent(state, event))
      .receiveSignal {
        case (_, signal) =>
          //react to the persistent events e.g. RecoveryCompleted/ SnapshotFailed etc
            println("Received signal: "+ signal)
      }
  1. Initialize EventSourcedBehaviorTestKit:
private val cartId = "testCart"
private val eventSourcedTestKit =
    EventSourcedBehaviorTestKit[
      ShoppingCart.Command,
      ShoppingCart.Event,
      ShoppingCart.State](system, ShoppingCart(cartId, "carts-0"))

Expected result: test run succesfully Actual result: an exception is thrown:

An exception or error caused a run to abort: Only EventSourcedBehavior, or nested EventSourcedBehavior allowed. 
java.lang.IllegalArgumentException: Only EventSourcedBehavior, or nested EventSourcedBehavior allowed.
	at akka.persistence.testkit.internal.EventSourcedBehaviorTestKitImpl.liftedTree1$1(EventSourcedBehaviorTestKitImpl.scala:111)
	at akka.persistence.testkit.internal.EventSourcedBehaviorTestKitImpl.<init>(EventSourcedBehaviorTestKitImpl.scala:107)
	at akka.persistence.testkit.scaladsl.EventSourcedBehaviorTestKit$.apply(EventSourcedBehaviorTestKit.scala:113)
	at akka.persistence.testkit.scaladsl.EventSourcedBehaviorTestKit$.apply(EventSourcedBehaviorTestKit.scala:101)
	at shopping.cart.ShoppingCartSpec.<init>(ShoppingCartSpec.scala:32)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

Contributor Guide