Skip to content

Commit d1b8533

Browse files
committed
🚨test: TestKit still work after passivation
1 parent 6e9abc5 commit d1b8533

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

src/test/scala/lerna/akka/entityreplication/typed/testkit/ReplicatedEntityBehaviorTestKitSpec.scala

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ class ReplicatedEntityBehaviorTestKitSpec extends FlatSpec with Matchers with Be
7272

7373
behavior of "ReplicatedEntityBehaviorTestKit"
7474

75+
it should "still work after passivation which is triggered by handling message with 'tell' pattern" in {
76+
// check no exception raised
77+
replicatedEntityTestKit.runCommand(TellAndPassivate())
78+
replicatedEntityTestKit.runCommand(TellAndReplicateAEventAndPassivate(inc = 10))
79+
replicatedEntityTestKit.runCommand(TellAndReplicateAEvent(inc = 10))
80+
}
81+
it should "still work after passivation which is triggered by handling message with 'ask' pattern" in {
82+
// check no exception raised
83+
replicatedEntityTestKit.runCommand(AskAndReplicateAEventAndPassivate(inc = 10, _))
84+
replicatedEntityTestKit.runCommand(AskAndReplicateAEvent(inc = 10, _))
85+
}
7586
it should "report the command that could not be serialized" in {
7687
val ex = intercept[AssertionError] {
7788
replicatedEntityTestKit.runCommand(FailCommandSerialization())
@@ -237,14 +248,19 @@ object ReplicatedEntityBehaviorTestKitSpec {
237248

238249
sealed trait Command
239250
final case class AskAndReplicateAEvent(inc: Int, replyTo: ActorRef[Reply]) extends Command with KryoSerializable
240-
final case class AskAndNoReply(replyTo: ActorRef[Reply]) extends Command with KryoSerializable
241-
final case class AskAndNoEvents(replyTo: ActorRef[Reply]) extends Command with KryoSerializable
242-
final case class TellAndNoEvents() extends Command with KryoSerializable
243-
final case class TellAndReplicateAEvent(inc: Int) extends Command with KryoSerializable
244-
final case class FailCommandSerialization() extends Command
245-
final case class FailReplySerialization(replyTo: ActorRef[Reply]) extends Command with KryoSerializable
246-
final case class FailStateSerialization() extends Command with KryoSerializable
247-
final case class FailEventSerialization() extends Command with KryoSerializable
251+
final case class AskAndReplicateAEventAndPassivate(inc: Int, replyTo: ActorRef[Reply])
252+
extends Command
253+
with KryoSerializable
254+
final case class AskAndNoReply(replyTo: ActorRef[Reply]) extends Command with KryoSerializable
255+
final case class AskAndNoEvents(replyTo: ActorRef[Reply]) extends Command with KryoSerializable
256+
final case class TellAndNoEvents() extends Command with KryoSerializable
257+
final case class TellAndPassivate() extends Command with KryoSerializable
258+
final case class TellAndReplicateAEvent(inc: Int) extends Command with KryoSerializable
259+
final case class TellAndReplicateAEventAndPassivate(inc: Int) extends Command with KryoSerializable
260+
final case class FailCommandSerialization() extends Command
261+
final case class FailReplySerialization(replyTo: ActorRef[Reply]) extends Command with KryoSerializable
262+
final case class FailStateSerialization() extends Command with KryoSerializable
263+
final case class FailEventSerialization() extends Command with KryoSerializable
248264

249265
trait Reply
250266
final case class SerializableReply(inc: Int, total: Int) extends Reply with KryoSerializable
@@ -277,6 +293,15 @@ object ReplicatedEntityBehaviorTestKitSpec {
277293
}
278294
.thenReply(replyTo)(state => SerializableReply(inc, state.total))
279295

296+
case AskAndReplicateAEventAndPassivate(inc, replyTo) =>
297+
Effect
298+
.replicate(SerializableEvent(inc))
299+
.thenRun { _: State =>
300+
context.log.info("complete depositing")
301+
}
302+
.thenPassivate()
303+
.thenReply(replyTo)(state => SerializableReply(inc, state.total))
304+
280305
case AskAndNoReply(_) =>
281306
Effect.noReply
282307

@@ -289,9 +314,15 @@ object ReplicatedEntityBehaviorTestKitSpec {
289314
context.log.info("receive a command")
290315
}.thenNoReply()
291316

317+
case TellAndPassivate() =>
318+
Effect.passivate().thenNoReply()
319+
292320
case TellAndReplicateAEvent(inc: Int) =>
293321
Effect.replicate(SerializableEvent(inc)).thenNoReply()
294322

323+
case TellAndReplicateAEventAndPassivate(inc: Int) =>
324+
Effect.replicate(SerializableEvent(inc)).thenPassivate().thenNoReply()
325+
295326
case FailCommandSerialization() =>
296327
Effect.noReply
297328

0 commit comments

Comments
 (0)