rename scaladsl.LoggingTestKit.intercept to expect, #28194 (#28199)

* deprecate intercept
This commit is contained in:
Patrik Nordwall 2019-11-19 17:25:43 +01:00 committed by Arnout Engelen
parent 905694be1c
commit f17bdbe233
30 changed files with 221 additions and 215 deletions

View file

@ -189,7 +189,7 @@ class RecoveryPermitterSpec extends ScalaTestWithActorTestKit(s"""
val stopProbe = createTestProbe[ActorRef[Command]]()
val parent =
LoggingTestKit.error("Exception during recovery.").intercept {
LoggingTestKit.error("Exception during recovery.").expect {
spawn(Behaviors.setup[Command](ctx => {
val persistentActor =
ctx.spawnAnonymous(persistentBehavior("p3", p3, p3, throwOnRecovery = true))

View file

@ -121,7 +121,7 @@ class EventSourcedBehaviorFailureSpec
"A typed persistent actor (failures)" must {
"signal RecoveryFailure when replay fails" in {
LoggingTestKit.error[JournalFailureException].intercept {
LoggingTestKit.error[JournalFailureException].expect {
val probe = TestProbe[String]()
val excProbe = TestProbe[Throwable]()
spawn(failingPersistentActor(PersistenceId.ofUniqueId("fail-recovery"), probe.ref, {
@ -159,7 +159,7 @@ class EventSourcedBehaviorFailureSpec
probe.expectMessage("malicious")
probe.expectMessage("persisted")
LoggingTestKit.error[JournalFailureException].intercept {
LoggingTestKit.error[JournalFailureException].expect {
// start again and then the event handler will throw
spawn(failingPersistentActor(pid, probe.ref, {
case (_, RecoveryFailed(t)) =>
@ -173,7 +173,7 @@ class EventSourcedBehaviorFailureSpec
"fail recovery if exception from RecoveryCompleted signal handler" in {
val probe = TestProbe[String]()
LoggingTestKit.error[JournalFailureException].intercept {
LoggingTestKit.error[JournalFailureException].expect {
spawn(
Behaviors
.supervise(failingPersistentActor(
@ -252,7 +252,7 @@ class EventSourcedBehaviorFailureSpec
}
"stop (default supervisor strategy) if command handler throws" in {
LoggingTestKit.error[TestException].intercept {
LoggingTestKit.error[TestException].expect {
val probe = TestProbe[String]()
val behav = failingPersistentActor(PersistenceId.ofUniqueId("wrong-command-1"), probe.ref)
val c = spawn(behav)
@ -263,7 +263,7 @@ class EventSourcedBehaviorFailureSpec
}
"restart supervisor strategy if command handler throws" in {
LoggingTestKit.error[TestException].intercept {
LoggingTestKit.error[TestException].expect {
val probe = TestProbe[String]()
val behav = Behaviors
.supervise(failingPersistentActor(PersistenceId.ofUniqueId("wrong-command-2"), probe.ref))
@ -276,7 +276,7 @@ class EventSourcedBehaviorFailureSpec
}
"stop (default supervisor strategy) if side effect callback throws" in {
LoggingTestKit.error[TestException].intercept {
LoggingTestKit.error[TestException].expect {
val probe = TestProbe[String]()
val behav = failingPersistentActor(PersistenceId.ofUniqueId("wrong-command-3"), probe.ref)
val c = spawn(behav)
@ -291,7 +291,7 @@ class EventSourcedBehaviorFailureSpec
"stop (default supervisor strategy) if signal handler throws" in {
case object SomeSignal extends Signal
LoggingTestKit.error[TestException].intercept {
LoggingTestKit.error[TestException].expect {
val probe = TestProbe[String]()
val behav = failingPersistentActor(PersistenceId.ofUniqueId("wrong-signal-handler"), probe.ref, {
case (_, SomeSignal) => throw TestException("from signal")
@ -304,7 +304,7 @@ class EventSourcedBehaviorFailureSpec
}
"not accept wrong event, before persisting it" in {
LoggingTestKit.error[TestException].intercept {
LoggingTestKit.error[TestException].expect {
val probe = TestProbe[String]()
val behav = failingPersistentActor(PersistenceId.ofUniqueId("wrong-event-2"), probe.ref)
val c = spawn(behav)

View file

@ -88,7 +88,7 @@ class EventSourcedBehaviorRecoveryTimeoutSpec
LoggingTestKit
.error[JournalFailureException]
.withMessageRegex("Exception during recovery.*Replay timed out")
.intercept {
.expect {
val replaying = spawn(testBehavior(pid, probe.ref))
// initial read highest

View file

@ -496,7 +496,7 @@ class EventSourcedBehaviorSpec
}
"fail after recovery timeout" in {
LoggingTestKit.error("Exception during recovery from snapshot").intercept {
LoggingTestKit.error("Exception during recovery from snapshot").expect {
val c = spawn(
Behaviors.setup[Command](ctx =>
counter(ctx, nextPid)
@ -522,7 +522,7 @@ class EventSourcedBehaviorSpec
c ! StopIt
probe.expectTerminated(c)
LoggingTestKit.error[TestException].intercept {
LoggingTestKit.error[TestException].expect {
val c2 = spawn(Behaviors.setup[Command](counter(_, pid)))
c2 ! Fail
probe.expectTerminated(c2) // should fail
@ -534,20 +534,14 @@ class EventSourcedBehaviorSpec
PersistenceId.ofUniqueId(null)
}
val probe = TestProbe[AnyRef]
LoggingTestKit
.error[ActorInitializationException]
.withMessageContains("persistenceId must not be null")
.intercept {
val ref = spawn(Behaviors.setup[Command](counter(_, persistenceId = PersistenceId.ofUniqueId(null))))
probe.expectTerminated(ref)
}
LoggingTestKit
.error[ActorInitializationException]
.withMessageContains("persistenceId must not be null")
.intercept {
val ref = spawn(Behaviors.setup[Command](counter(_, persistenceId = null)))
probe.expectTerminated(ref)
}
LoggingTestKit.error[ActorInitializationException].withMessageContains("persistenceId must not be null").expect {
val ref = spawn(Behaviors.setup[Command](counter(_, persistenceId = PersistenceId.ofUniqueId(null))))
probe.expectTerminated(ref)
}
LoggingTestKit.error[ActorInitializationException].withMessageContains("persistenceId must not be null").expect {
val ref = spawn(Behaviors.setup[Command](counter(_, persistenceId = null)))
probe.expectTerminated(ref)
}
}
"fail fast if persistenceId is empty" in {
@ -555,13 +549,10 @@ class EventSourcedBehaviorSpec
PersistenceId.ofUniqueId("")
}
val probe = TestProbe[AnyRef]
LoggingTestKit
.error[ActorInitializationException]
.withMessageContains("persistenceId must not be empty")
.intercept {
val ref = spawn(Behaviors.setup[Command](counter(_, persistenceId = PersistenceId.ofUniqueId(""))))
probe.expectTerminated(ref)
}
LoggingTestKit.error[ActorInitializationException].withMessageContains("persistenceId must not be empty").expect {
val ref = spawn(Behaviors.setup[Command](counter(_, persistenceId = PersistenceId.ofUniqueId(""))))
probe.expectTerminated(ref)
}
}
"fail fast if default journal plugin is not defined" in {
@ -571,7 +562,7 @@ class EventSourcedBehaviorSpec
LoggingTestKit
.error[ActorInitializationException]
.withMessageContains("Default journal plugin is not configured")
.intercept {
.expect {
val ref = testkit2.spawn(Behaviors.setup[Command](counter(_, nextPid())))
val probe = testkit2.createTestProbe()
probe.expectTerminated(ref)
@ -588,7 +579,7 @@ class EventSourcedBehaviorSpec
LoggingTestKit
.error[ActorInitializationException]
.withMessageContains("Journal plugin [missing] configuration doesn't exist")
.intercept {
.expect {
val ref = testkit2.spawn(Behaviors.setup[Command](counter(_, nextPid()).withJournalPluginId("missing")))
val probe = testkit2.createTestProbe()
probe.expectTerminated(ref)
@ -609,7 +600,7 @@ class EventSourcedBehaviorSpec
try {
LoggingTestKit
.warn("No default snapshot store configured")
.intercept {
.expect {
val ref = testkit2.spawn(Behaviors.setup[Command](counter(_, nextPid())))
val probe = testkit2.createTestProbe[State]()
// verify that it's not terminated
@ -633,7 +624,7 @@ class EventSourcedBehaviorSpec
LoggingTestKit
.error[ActorInitializationException]
.withMessageContains("Snapshot store plugin [missing] configuration doesn't exist")
.intercept {
.expect {
val ref = testkit2.spawn(Behaviors.setup[Command](counter(_, nextPid()).withSnapshotPluginId("missing")))
val probe = testkit2.createTestProbe()
probe.expectTerminated(ref)

View file

@ -542,7 +542,7 @@ class EventSourcedBehaviorStashSpec
c ! "start-stashing"
val limit = system.settings.config.getInt("akka.persistence.typed.stash-capacity")
LoggingTestKit.warn("Stash buffer is full, dropping message").intercept {
LoggingTestKit.warn("Stash buffer is full, dropping message").expect {
(0 to limit).foreach { n =>
c ! s"cmd-$n" // limit triggers overflow
}
@ -590,7 +590,7 @@ class EventSourcedBehaviorStashSpec
LoggingTestKit
.error[StashOverflowException]
.intercept {
.expect {
val limit = system.settings.config.getInt("akka.persistence.typed.stash-capacity")
(0 to limit).foreach { n =>
c ! s"cmd-$n" // limit triggers overflow

View file

@ -48,8 +48,8 @@ class LoggerSourceSpec
// one test case leaks to another, the actual log class is what is tested in each individual case
"log from setup" in {
LoggingTestKit.info("recovery-completed").intercept {
eventFilterFor("setting-up-behavior").intercept {
LoggingTestKit.info("recovery-completed").expect {
eventFilterFor("setting-up-behavior").expect {
spawn(behavior)
}
}
@ -57,8 +57,8 @@ class LoggerSourceSpec
}
"log from recovery completed" in {
LoggingTestKit.info("setting-up-behavior").intercept {
eventFilterFor("recovery-completed").intercept {
LoggingTestKit.info("setting-up-behavior").expect {
eventFilterFor("recovery-completed").expect {
spawn(behavior)
}
}
@ -69,8 +69,8 @@ class LoggerSourceSpec
.withLogLevel(Level.INFO)
.withMessageRegex("(setting-up-behavior|recovery-completed|event-received)")
.withOccurrences(3)
.intercept {
eventFilterFor("command-received").intercept {
.expect {
eventFilterFor("command-received").expect {
spawn(behavior) ! "cmd"
}
}
@ -81,8 +81,8 @@ class LoggerSourceSpec
.withLogLevel(Level.INFO)
.withMessageRegex("(setting-up-behavior|recovery-completed|command-received)")
.withOccurrences(3)
.intercept {
eventFilterFor("event-received").intercept {
.expect {
eventFilterFor("event-received").expect {
spawn(behavior) ! "cmd"
}
}

View file

@ -54,7 +54,7 @@ class OptionalSnapshotStoreSpec extends ScalaTestWithActorTestKit(s"""
"Persistence extension" must {
"initialize properly even in absence of configured snapshot store" in {
LoggingTestKit.warn("No default snapshot store configured").intercept {
LoggingTestKit.warn("No default snapshot store configured").expect {
val stateProbe = TestProbe[State]()
spawn(persistentBehavior(stateProbe))
stateProbe.expectNoMessage()
@ -62,8 +62,8 @@ class OptionalSnapshotStoreSpec extends ScalaTestWithActorTestKit(s"""
}
"fail if PersistentActor tries to saveSnapshot without snapshot-store available" in {
LoggingTestKit.error("No snapshot store configured").intercept {
LoggingTestKit.warn("Failed to save snapshot").intercept {
LoggingTestKit.error("No snapshot store configured").expect {
LoggingTestKit.warn("Failed to save snapshot").expect {
val stateProbe = TestProbe[State]()
val persistentActor = spawn(persistentBehavior(stateProbe))
persistentActor ! AnyCommand