Skip to content

Commit

Permalink
customise test for race between GetState and persistAsync handler #22052
Browse files Browse the repository at this point in the history


(cherry picked from commit 5ee25d9)
  • Loading branch information
ortigali authored and patriknw committed Feb 21, 2017
1 parent 196a6a3 commit b224c34
Showing 1 changed file with 30 additions and 1 deletion.
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/

package akka.persistence
Expand Down Expand Up @@ -646,6 +646,23 @@ object PersistentActorSpec {
}
}

class PersistInRecovery(name: String) extends ExamplePersistentActor(name) {
override def receiveRecover = {
case Evt("invalid")
persist(Evt("invalid-recovery"))(updateState)
case e: Evt updateState(e)
case RecoveryCompleted
persistAsync(Evt("rc-1"))(updateState)
persist(Evt("rc-2"))(updateState)
persistAsync(Evt("rc-3"))(updateState)
}

override def onRecoveryFailure(cause: scala.Throwable, event: Option[Any]): Unit = ()

def receiveCommand = commonBehavior orElse {
case Cmd(d) persist(Evt(d))(updateState)
}
}
}

abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(config) with ImplicitSender {
Expand Down Expand Up @@ -1133,6 +1150,18 @@ abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(confi
persistentActor ! "Boom"
expectMsg("failed with TestException while processing Boom")
}

"be able to persist events that happen during recovery" in {
val persistentActor = namedPersistentActor[PersistInRecovery]
persistentActor ! GetState
expectMsgAnyOf(List("a-1", "a-2", "rc-1", "rc-2"), List("a-1", "a-2", "rc-1", "rc-2", "rc-3"))
persistentActor ! Cmd("invalid")
persistentActor ! GetState
expectMsg(List("a-1", "a-2", "rc-1", "rc-2", "rc-3", "invalid"))
watch(persistentActor)
persistentActor ! "boom"
expectTerminated(persistentActor)
}
}

}
Expand Down

0 comments on commit b224c34

Please sign in to comment.