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

@ -0,0 +1 @@
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.actor.testkit.typed.scaladsl.LoggingTestKit.expect")

View file

@ -54,7 +54,7 @@ import org.slf4j.event.Level
mdc.forall { case (key, value) => event.mdc.contains(key) && event.mdc(key) == value } && mdc.forall { case (key, value) => event.mdc.contains(key) && event.mdc(key) == value } &&
custom.forall(f => f(event)) custom.forall(f => f(event))
// loggerName is handled when installing the filter, in `intercept` // loggerName is handled when installing the filter, in `expect`
} }
private def messageOrEmpty(event: LoggingEvent): String = private def messageOrEmpty(event: LoggingEvent): String =
@ -82,7 +82,7 @@ import org.slf4j.event.Level
todo > 0 todo > 0
} }
override def intercept[T](code: => T)(implicit system: ActorSystem[_]): T = { override def expect[T](code: => T)(implicit system: ActorSystem[_]): T = {
val effectiveLoggerName = loggerName.getOrElse("") val effectiveLoggerName = loggerName.getOrElse("")
checkLogback(system) checkLogback(system)
TestAppender.setupTestAppender(effectiveLoggerName) TestAppender.setupTestAppender(effectiveLoggerName)
@ -107,6 +107,13 @@ import org.slf4j.event.Level
} }
} }
override def expect[T](system: ActorSystem[_], code: Supplier[T]): T =
expect(code.get())(system)
// deprecated (renamed to expect)
override def intercept[T](code: => T)(implicit system: ActorSystem[_]): T =
expect(code)(system)
private def checkLogback(system: ActorSystem[_]): Unit = { private def checkLogback(system: ActorSystem[_]): Unit = {
if (!system.dynamicAccess.classIsOnClasspath("ch.qos.logback.classic.spi.ILoggingEvent")) { if (!system.dynamicAccess.classIsOnClasspath("ch.qos.logback.classic.spi.ILoggingEvent")) {
throw new IllegalStateException("LoggingEventFilter requires logback-classic dependency in classpath.") throw new IllegalStateException("LoggingEventFilter requires logback-classic dependency in classpath.")
@ -150,7 +157,4 @@ import org.slf4j.event.Level
override def withCause(newCause: Class[_ <: Throwable]): javadsl.LoggingTestKit = override def withCause(newCause: Class[_ <: Throwable]): javadsl.LoggingTestKit =
copy(cause = Option(newCause)) copy(cause = Option(newCause))
override def expect[T](system: ActorSystem[_], code: Supplier[T]): T =
intercept(code.get())(system)
} }

View file

@ -87,7 +87,7 @@ import org.slf4j.event.Level
def matches(event: LoggingEvent): Boolean def matches(event: LoggingEvent): Boolean
/** /**
* Run the given code block and assert that this filter has * Run the given code block and assert that the criteria of this `LoggingTestKit` has
* matched within the configured `akka.actor.testkit.typed.filter-leeway` * matched within the configured `akka.actor.testkit.typed.filter-leeway`
* as often as requested by its `occurrences` parameter specifies. * as often as requested by its `occurrences` parameter specifies.
* *

View file

@ -27,7 +27,7 @@ import org.slf4j.event.Level
* Number of events the testkit is supposed to match. By default 1. * Number of events the testkit is supposed to match. By default 1.
* *
* When occurrences > 0 it will not look for excess messages that are logged asynchronously * When occurrences > 0 it will not look for excess messages that are logged asynchronously
* outside (after) the `intercept` thunk and it has already found expected number. * outside (after) the `expect` thunk and it has already found expected number.
* *
* When occurrences is 0 it will look for unexpected matching events, and then it will * When occurrences is 0 it will look for unexpected matching events, and then it will
* also look for excess messages during the configured `akka.actor.testkit.typed.expect-no-message-default` * also look for excess messages during the configured `akka.actor.testkit.typed.expect-no-message-default`
@ -86,12 +86,22 @@ import org.slf4j.event.Level
def matches(event: LoggingEvent): Boolean def matches(event: LoggingEvent): Boolean
/** /**
* Apply this filter while executing the given code block. * Run the given code block and assert that the criteria of this `LoggingTestKit` has
* Assert that this filter has matched as often as requested by its * matched within the configured `akka.actor.testkit.typed.filter-leeway`
* `occurrences` parameter specifies. * as often as requested by its `occurrences` parameter specifies.
* *
* Care is taken to remove the filter when the block is finished or aborted. * Care is taken to remove the testkit when the block is finished or aborted.
*/ */
def expect[T](code: => T)(implicit system: ActorSystem[_]): T
/**
* Run the given code block and assert that the criteria of this `LoggingTestKit` has
* matched within the configured `akka.actor.testkit.typed.filter-leeway`
* as often as requested by its `occurrences` parameter specifies.
*
* Care is taken to remove the testkit when the block is finished or aborted.
*/
@deprecated("Use except instead.", "2.6.0")
def intercept[T](code: => T)(implicit system: ActorSystem[_]): T def intercept[T](code: => T)(implicit system: ActorSystem[_]): T
} }

View file

@ -27,20 +27,20 @@ class TestAppenderSpec
"TestAppender and LoggingEventFilter" must { "TestAppender and LoggingEventFilter" must {
"filter errors without cause" in { "filter errors without cause" in {
LoggingTestKit.error("an error").withOccurrences(2).intercept { LoggingTestKit.error("an error").withOccurrences(2).expect {
log.error("an error") log.error("an error")
log.error("an error") log.error("an error")
} }
} }
"filter errors with cause" in { "filter errors with cause" in {
LoggingTestKit.error("err").withCause[TestException].intercept { LoggingTestKit.error("err").withCause[TestException].expect {
log.error("err", TestException("an error")) log.error("err", TestException("an error"))
} }
} }
"filter warnings" in { "filter warnings" in {
LoggingTestKit.warn("a warning").withOccurrences(2).intercept { LoggingTestKit.warn("a warning").withOccurrences(2).expect {
log.error("an error") log.error("an error")
log.warn("a warning") log.warn("a warning")
log.error("an error") log.error("an error")
@ -50,7 +50,7 @@ class TestAppenderSpec
"find excess messages" in { "find excess messages" in {
intercept[AssertionError] { intercept[AssertionError] {
LoggingTestKit.warn("a warning").withOccurrences(2).intercept { LoggingTestKit.warn("a warning").withOccurrences(2).expect {
log.error("an error") log.error("an error")
log.warn("a warning") log.warn("a warning")
log.warn("a warning") log.warn("a warning")
@ -73,7 +73,7 @@ class TestAppenderSpec
}) })
.withOccurrences(2) .withOccurrences(2)
.withLoggerName(classOf[AnotherLoggerClass].getName) .withLoggerName(classOf[AnotherLoggerClass].getName)
.intercept { .expect {
LoggerFactory.getLogger(classOf[AnotherLoggerClass]).info("Hello from right logger") LoggerFactory.getLogger(classOf[AnotherLoggerClass]).info("Hello from right logger")
log.info("Hello wrong logger") log.info("Hello wrong logger")
LoggerFactory.getLogger(classOf[AnotherLoggerClass]).info("Hello from right logger") LoggerFactory.getLogger(classOf[AnotherLoggerClass]).info("Hello from right logger")
@ -82,13 +82,13 @@ class TestAppenderSpec
} }
"find unexpected events withOccurrences(0)" in { "find unexpected events withOccurrences(0)" in {
LoggingTestKit.warn("a warning").withOccurrences(0).intercept { LoggingTestKit.warn("a warning").withOccurrences(0).expect {
log.error("an error") log.error("an error")
log.warn("another warning") log.warn("another warning")
} }
intercept[AssertionError] { intercept[AssertionError] {
LoggingTestKit.warn("a warning").withOccurrences(0).intercept { LoggingTestKit.warn("a warning").withOccurrences(0).expect {
log.error("an error") log.error("an error")
log.warn("a warning") log.warn("a warning")
log.warn("another warning") log.warn("another warning")
@ -96,7 +96,7 @@ class TestAppenderSpec
}.getMessage should include("Received 1 excess messages") }.getMessage should include("Received 1 excess messages")
intercept[AssertionError] { intercept[AssertionError] {
LoggingTestKit.warn("a warning").withOccurrences(0).intercept { LoggingTestKit.warn("a warning").withOccurrences(0).expect {
log.warn("a warning") log.warn("a warning")
log.warn("a warning") log.warn("a warning")
} }
@ -107,7 +107,7 @@ class TestAppenderSpec
"find unexpected async events withOccurrences(0)" in { "find unexpected async events withOccurrences(0)" in {
// expect-no-message-default = 1000 ms // expect-no-message-default = 1000 ms
intercept[AssertionError] { intercept[AssertionError] {
LoggingTestKit.warn("a warning").withOccurrences(0).intercept { LoggingTestKit.warn("a warning").withOccurrences(0).expect {
Future { Future {
Thread.sleep(20) Thread.sleep(20)
log.warn("a warning") log.warn("a warning")

View file

@ -139,7 +139,7 @@ abstract class ActorContextSpec extends ScalaTestWithActorTestKit with WordSpecL
val behavior = Behaviors.supervise(internal).onFailure(SupervisorStrategy.restart) val behavior = Behaviors.supervise(internal).onFailure(SupervisorStrategy.restart)
val actor = spawn(behavior) val actor = spawn(behavior)
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
actor ! Fail actor ! Fail
} }
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
@ -203,7 +203,7 @@ abstract class ActorContextSpec extends ScalaTestWithActorTestKit with WordSpecL
val parentRef = spawn(parent) val parentRef = spawn(parent)
val childRef = probe.expectMessageType[ChildMade].ref val childRef = probe.expectMessageType[ChildMade].ref
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
childRef ! Fail childRef ! Fail
} }
probe.expectMessage(GotChildSignal(PreRestart)) probe.expectMessage(GotChildSignal(PreRestart))
@ -260,7 +260,7 @@ abstract class ActorContextSpec extends ScalaTestWithActorTestKit with WordSpecL
val actor = spawn(behavior) val actor = spawn(behavior)
actor ! Ping actor ! Ping
probe.expectMessage(1) probe.expectMessage(1)
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
actor ! Fail actor ! Fail
} }
actor ! Ping actor ! Ping
@ -286,7 +286,7 @@ abstract class ActorContextSpec extends ScalaTestWithActorTestKit with WordSpecL
val actor = spawn(behavior) val actor = spawn(behavior)
actor ! Ping actor ! Ping
probe.expectMessage(1) probe.expectMessage(1)
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
actor ! Fail actor ! Fail
} }
actor ! Ping actor ! Ping
@ -328,7 +328,7 @@ abstract class ActorContextSpec extends ScalaTestWithActorTestKit with WordSpecL
probe.expectMessage(Pong) probe.expectMessage(Pong)
watcher ! Ping watcher ! Ping
probe.expectMessage(Pong) probe.expectMessage(Pong)
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
actorToWatch ! Fail actorToWatch ! Fail
} }
probe.expectMessage(ReceivedSignal(PostStop)) probe.expectMessage(ReceivedSignal(PostStop))
@ -513,7 +513,7 @@ abstract class ActorContextSpec extends ScalaTestWithActorTestKit with WordSpecL
val childRef = probe.expectMessageType[ChildMade].ref val childRef = probe.expectMessageType[ChildMade].ref
actor ! Inert actor ! Inert
probe.expectMessage(InertEvent) probe.expectMessage(InertEvent)
LoggingTestKit.error[DeathPactException].intercept { LoggingTestKit.error[DeathPactException].expect {
childRef ! Stop childRef ! Stop
probe.expectMessage(GotChildSignal(PostStop)) probe.expectMessage(GotChildSignal(PostStop))
probe.expectMessage(ReceivedSignal(PostStop)) probe.expectMessage(ReceivedSignal(PostStop))

View file

@ -175,7 +175,7 @@ class AskSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCaptur
LoggingTestKit LoggingTestKit
.error("Exception thrown out of adapter. Stopping myself.") .error("Exception thrown out of adapter. Stopping myself.")
.intercept { .expect {
replyRef2 ! 42L replyRef2 ! 42L
}(system) }(system)

View file

@ -62,7 +62,7 @@ class DeferredSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogC
Behaviors.stopped Behaviors.stopped
} }
} }
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
spawn(behv) spawn(behv)
probe.expectMessage(Started) probe.expectMessage(Started)
probe.expectMessage(Pong) probe.expectMessage(Pong)
@ -138,7 +138,7 @@ class DeferredSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogC
Behaviors.same Behaviors.same
} }
} }
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
val ref = spawn(behv) val ref = spawn(behv)
probe.expectTerminated(ref, probe.remainingOrDefault) probe.expectTerminated(ref, probe.remainingOrDefault)
} }

View file

@ -282,7 +282,7 @@ class InterceptSpec extends ScalaTestWithActorTestKit with WordSpecLike with Log
val probe = TestProbe[String]() val probe = TestProbe[String]()
val interceptor = snitchingInterceptor(probe.ref) val interceptor = snitchingInterceptor(probe.ref)
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
val ref = spawn(Behaviors.intercept(() => interceptor)(Behaviors.setup[String] { _ => val ref = spawn(Behaviors.intercept(() => interceptor)(Behaviors.setup[String] { _ =>
Behaviors.same[String] Behaviors.same[String]
})) }))

View file

@ -26,11 +26,11 @@ class LogMessagesSpec extends ScalaTestWithActorTestKit("""
val ref: ActorRef[String] = spawn(behavior) val ref: ActorRef[String] = spawn(behavior)
LoggingTestKit.debug(s"actor [${ref.path.toString}] received message: Hello").intercept { LoggingTestKit.debug(s"actor [${ref.path.toString}] received message: Hello").expect {
ref ! "Hello" ref ! "Hello"
} }
LoggingTestKit.debug(s"actor [${ref.path}] received signal: PostStop").intercept { LoggingTestKit.debug(s"actor [${ref.path}] received signal: PostStop").expect {
testKit.stop(ref) testKit.stop(ref)
} }
} }
@ -41,11 +41,11 @@ class LogMessagesSpec extends ScalaTestWithActorTestKit("""
val ref: ActorRef[String] = spawn(behavior) val ref: ActorRef[String] = spawn(behavior)
LoggingTestKit.info(s"actor [${ref.path}] received message: Hello").intercept { LoggingTestKit.info(s"actor [${ref.path}] received message: Hello").expect {
ref ! "Hello" ref ! "Hello"
} }
LoggingTestKit.info(s"actor [${ref.path}] received signal: PostStop").intercept { LoggingTestKit.info(s"actor [${ref.path}] received signal: PostStop").expect {
testKit.stop(ref) testKit.stop(ref)
} }
} }
@ -57,11 +57,11 @@ class LogMessagesSpec extends ScalaTestWithActorTestKit("""
val ref: ActorRef[String] = spawn(behavior) val ref: ActorRef[String] = spawn(behavior)
LoggingTestKit.debug(s"actor [${ref.path}] received message: Hello").intercept { LoggingTestKit.debug(s"actor [${ref.path}] received message: Hello").expect {
ref ! "Hello" ref ! "Hello"
} }
LoggingTestKit.debug(s"actor [${ref.path}] received signal: PostStop").intercept { LoggingTestKit.debug(s"actor [${ref.path}] received signal: PostStop").expect {
testKit.stop(ref) testKit.stop(ref)
} }
} }
@ -72,11 +72,11 @@ class LogMessagesSpec extends ScalaTestWithActorTestKit("""
val ref: ActorRef[String] = spawn(behavior) val ref: ActorRef[String] = spawn(behavior)
LoggingTestKit.debug(s"actor [${ref.path}] received message: Hello").withOccurrences(0).intercept { LoggingTestKit.debug(s"actor [${ref.path}] received message: Hello").withOccurrences(0).expect {
ref ! "Hello" ref ! "Hello"
} }
LoggingTestKit.debug(s"actor [${ref.path}] received signal: PostStop").withOccurrences(0).intercept { LoggingTestKit.debug(s"actor [${ref.path}] received signal: PostStop").withOccurrences(0).expect {
testKit.stop(ref) testKit.stop(ref)
} }
} }
@ -88,11 +88,11 @@ class LogMessagesSpec extends ScalaTestWithActorTestKit("""
val ref = spawn(behavior) val ref = spawn(behavior)
LoggingTestKit.debug(s"actor [${ref.path}] received message: Hello").withMdc(mdc).intercept { LoggingTestKit.debug(s"actor [${ref.path}] received message: Hello").withMdc(mdc).expect {
ref ! "Hello" ref ! "Hello"
} }
LoggingTestKit.debug(s"actor [${ref.path}] received signal: PostStop").withMdc(mdc).intercept { LoggingTestKit.debug(s"actor [${ref.path}] received signal: PostStop").withMdc(mdc).expect {
testKit.stop(ref) testKit.stop(ref)
} }
} }
@ -106,21 +106,21 @@ class LogMessagesSpec extends ScalaTestWithActorTestKit("""
val ref2 = spawn(behavior2) val ref2 = spawn(behavior2)
LoggingTestKit.debug(s"actor [${ref2.path}] received message: Hello").withMdc(mdc2).intercept { LoggingTestKit.debug(s"actor [${ref2.path}] received message: Hello").withMdc(mdc2).expect {
ref2 ! "Hello" ref2 ! "Hello"
} }
val ref1 = spawn(behavior1) val ref1 = spawn(behavior1)
LoggingTestKit.debug(s"actor [${ref1.path}] received message: Hello").withMdc(mdc1).intercept { LoggingTestKit.debug(s"actor [${ref1.path}] received message: Hello").withMdc(mdc1).expect {
ref1 ! "Hello" ref1 ! "Hello"
} }
LoggingTestKit.debug(s"actor [${ref2.path}] received signal: PostStop").withMdc(mdc2).intercept { LoggingTestKit.debug(s"actor [${ref2.path}] received signal: PostStop").withMdc(mdc2).expect {
testKit.stop(ref2) testKit.stop(ref2)
} }
LoggingTestKit.debug(s"actor [${ref1.path}] received signal: PostStop").withMdc(mdc1).intercept { LoggingTestKit.debug(s"actor [${ref1.path}] received signal: PostStop").withMdc(mdc1).expect {
testKit.stop(ref1) testKit.stop(ref1)
} }
} }
@ -130,7 +130,7 @@ class LogMessagesSpec extends ScalaTestWithActorTestKit("""
val ref = spawn(behavior) val ref = spawn(behavior)
LoggingTestKit.debug(s"actor [${ref.path}] received message: 13").intercept { LoggingTestKit.debug(s"actor [${ref.path}] received message: 13").expect {
ref.unsafeUpcast[Any] ! 13 ref.unsafeUpcast[Any] ! 13
} }
} }

View file

@ -71,7 +71,7 @@ class MailboxSelectorSpec extends ScalaTestWithActorTestKit("""
}, MailboxSelector.bounded(2)) }, MailboxSelector.bounded(2))
actor ! "one" // actor will block here actor ! "one" // actor will block here
actor ! "two" actor ! "two"
LoggingTestKit.deadLetters().intercept { LoggingTestKit.deadLetters().expect {
// one or both of these doesn't fit in mailbox // one or both of these doesn't fit in mailbox
// depending on race with how fast actor consumes // depending on race with how fast actor consumes
actor ! "three" actor ! "three"

View file

@ -316,7 +316,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val probe = TestProbe[Event]("evt") val probe = TestProbe[Event]("evt")
val behv = targetBehavior(probe.ref) val behv = targetBehavior(probe.ref)
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc3].intercept { LoggingTestKit.error[Exc3].expect {
ref ! Throw(new Exc3) ref ! Throw(new Exc3)
probe.expectMessage(ReceivedSignal(PostStop)) probe.expectMessage(ReceivedSignal(PostStop))
probe.expectTerminated(ref) probe.expectTerminated(ref)
@ -326,7 +326,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val probe = TestProbe[Event]("evt") val probe = TestProbe[Event]("evt")
val behv = Behaviors.supervise(targetBehavior(probe.ref)).onFailure[Throwable](SupervisorStrategy.stop) val behv = Behaviors.supervise(targetBehavior(probe.ref)).onFailure[Throwable](SupervisorStrategy.stop)
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc3].intercept { LoggingTestKit.error[Exc3].expect {
ref ! Throw(new Exc3) ref ! Throw(new Exc3)
probe.expectMessage(ReceivedSignal(PostStop)) probe.expectMessage(ReceivedSignal(PostStop))
probe.expectTerminated(ref) probe.expectTerminated(ref)
@ -340,7 +340,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
targetBehavior(probe.ref) targetBehavior(probe.ref)
}) })
val behv = Behaviors.supervise(failedSetup).onFailure[Throwable](SupervisorStrategy.stop) val behv = Behaviors.supervise(failedSetup).onFailure[Throwable](SupervisorStrategy.stop)
LoggingTestKit.error[Exc3].intercept { LoggingTestKit.error[Exc3].expect {
spawn(behv) spawn(behv)
} }
} }
@ -353,12 +353,12 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[IOException].intercept { LoggingTestKit.error[IOException].expect {
ref ! Throw(new IOException()) ref ! Throw(new IOException())
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
LoggingTestKit.error[IllegalArgumentException].intercept { LoggingTestKit.error[IllegalArgumentException].expect {
ref ! Throw(new IllegalArgumentException("cat")) ref ! Throw(new IllegalArgumentException("cat"))
probe.expectMessage(ReceivedSignal(PostStop)) probe.expectMessage(ReceivedSignal(PostStop))
} }
@ -374,7 +374,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exception].intercept { LoggingTestKit.error[Exception].expect {
ref ! Throw(new IOException()) ref ! Throw(new IOException())
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
@ -382,7 +382,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! Ping(1) ref ! Ping(1)
probe.expectMessage(Pong(1)) probe.expectMessage(Pong(1))
LoggingTestKit.error[IllegalArgumentException].intercept { LoggingTestKit.error[IllegalArgumentException].expect {
ref ! Throw(new IllegalArgumentException("cat")) ref ! Throw(new IllegalArgumentException("cat"))
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
@ -400,7 +400,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exception].intercept { LoggingTestKit.error[Exception].expect {
ref ! Throw(new IOException()) ref ! Throw(new IOException())
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
@ -408,7 +408,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! Ping(1) ref ! Ping(1)
probe.expectMessage(Pong(1)) probe.expectMessage(Pong(1))
LoggingTestKit.error[IllegalArgumentException].intercept { LoggingTestKit.error[IllegalArgumentException].expect {
ref ! Throw(new IllegalArgumentException("cat")) ref ! Throw(new IllegalArgumentException("cat"))
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
@ -422,7 +422,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val probe = TestProbe[Event]("evt") val probe = TestProbe[Event]("evt")
val behv = targetBehavior(probe.ref) val behv = targetBehavior(probe.ref)
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc3].intercept { LoggingTestKit.error[Exc3].expect {
ref ! Throw(new Exc3) ref ! Throw(new Exc3)
probe.expectMessage(ReceivedSignal(PostStop)) probe.expectMessage(ReceivedSignal(PostStop))
} }
@ -432,7 +432,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val probe = TestProbe[Event]("evt") val probe = TestProbe[Event]("evt")
val behv = Behaviors.supervise(targetBehavior(probe.ref)).onFailure[Exc1](SupervisorStrategy.restart) val behv = Behaviors.supervise(targetBehavior(probe.ref)).onFailure[Exc1](SupervisorStrategy.restart)
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc3].intercept { LoggingTestKit.error[Exc3].expect {
ref ! Throw(new Exc3) ref ! Throw(new Exc3)
probe.expectMessage(ReceivedSignal(PostStop)) probe.expectMessage(ReceivedSignal(PostStop))
} }
@ -446,7 +446,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! GetState ref ! GetState
probe.expectMessage(State(1, Map.empty)) probe.expectMessage(State(1, Map.empty))
LoggingTestKit.error[Exc2].intercept { LoggingTestKit.error[Exc2].expect {
ref ! Throw(new Exc2) ref ! Throw(new Exc2)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
@ -465,7 +465,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! GetState ref ! GetState
probe.expectMessage(State(1, Map.empty)) probe.expectMessage(State(1, Map.empty))
LoggingTestKit.error[Exc2].withOccurrences(3).intercept { LoggingTestKit.error[Exc2].withOccurrences(3).expect {
ref ! Throw(new Exc2) ref ! Throw(new Exc2)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
ref ! Throw(new Exc2) ref ! Throw(new Exc2)
@ -488,7 +488,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! GetState ref ! GetState
probe.expectMessage(State(1, Map.empty)) probe.expectMessage(State(1, Map.empty))
LoggingTestKit.error[Exc2].withOccurrences(3).intercept { LoggingTestKit.error[Exc2].withOccurrences(3).expect {
ref ! Throw(new Exc2) ref ! Throw(new Exc2)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
ref ! Throw(new Exc2) ref ! Throw(new Exc2)
@ -528,7 +528,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! GetState ref ! GetState
parentProbe.expectMessageType[State].children.keySet should ===(Set(child1Name, child2Name)) parentProbe.expectMessageType[State].children.keySet should ===(Set(child1Name, child2Name))
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
parentProbe.expectMessage(ReceivedSignal(PreRestart)) parentProbe.expectMessage(ReceivedSignal(PreRestart))
ref ! GetState ref ! GetState
@ -566,7 +566,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! GetState ref ! GetState
parentProbe.expectMessageType[State].children.keySet should contain(childName) parentProbe.expectMessageType[State].children.keySet should contain(childName)
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
parentProbe.expectMessage(ReceivedSignal(PreRestart)) parentProbe.expectMessage(ReceivedSignal(PreRestart))
ref ! GetState ref ! GetState
@ -597,7 +597,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val child2Name = nextName() val child2Name = nextName()
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
parentProbe.expectMessage(ReceivedSignal(PreRestart)) parentProbe.expectMessage(ReceivedSignal(PreRestart))
ref ! GetState ref ! GetState
@ -606,7 +606,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
} }
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
slowStop.countDown() slowStop.countDown()
childProbe.expectMessage(ReceivedSignal(PostStop)) // child1 childProbe.expectMessage(ReceivedSignal(PostStop)) // child1
parentProbe.expectMessageType[State].children.keySet should ===(Set.empty) parentProbe.expectMessageType[State].children.keySet should ===(Set.empty)
@ -651,7 +651,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
} }
.onFailure[RuntimeException](strategy) .onFailure[RuntimeException](strategy)
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
val ref = spawn(behv) val ref = spawn(behv)
slowStop1.countDown() slowStop1.countDown()
child1Probe.expectMessage(ReceivedSignal(PostStop)) child1Probe.expectMessage(ReceivedSignal(PostStop))
@ -702,12 +702,12 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
throwFromSetup.set(true) throwFromSetup.set(true)
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
parentProbe.expectMessage(ReceivedSignal(PreRestart)) parentProbe.expectMessage(ReceivedSignal(PreRestart))
} }
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
slowStop1.countDown() slowStop1.countDown()
child1Probe.expectMessage(ReceivedSignal(PostStop)) child1Probe.expectMessage(ReceivedSignal(PostStop))
child1Probe.expectMessage(ReceivedSignal(PostStop)) child1Probe.expectMessage(ReceivedSignal(PostStop))
@ -728,7 +728,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! GetState ref ! GetState
probe.expectMessage(State(1, Map.empty)) probe.expectMessage(State(1, Map.empty))
LoggingTestKit.error[Exc2].intercept { LoggingTestKit.error[Exc2].expect {
ref ! Throw(new Exc2) ref ! Throw(new Exc2)
ref ! GetState ref ! GetState
probe.expectMessage(State(1, Map.empty)) probe.expectMessage(State(1, Map.empty))
@ -746,7 +746,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
probe.expectMessage(State(1, Map.empty)) probe.expectMessage(State(1, Map.empty))
// resume // resume
LoggingTestKit.error[Exc2].intercept { LoggingTestKit.error[Exc2].expect {
ref ! Throw(new Exc2) ref ! Throw(new Exc2)
probe.expectNoMessage() probe.expectNoMessage()
ref ! GetState ref ! GetState
@ -754,7 +754,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
} }
// restart // restart
LoggingTestKit.error[Exc3].intercept { LoggingTestKit.error[Exc3].expect {
ref ! Throw(new Exc3) ref ! Throw(new Exc3)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
ref ! GetState ref ! GetState
@ -762,7 +762,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
} }
// stop // stop
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
probe.expectMessage(ReceivedSignal(PostStop)) probe.expectMessage(ReceivedSignal(PostStop))
} }
@ -784,7 +784,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
.onFailure[Exception](strategy) .onFailure[Exception](strategy)
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
startedProbe.expectMessage(Started) startedProbe.expectMessage(Started)
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
@ -819,7 +819,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
.onFailure[Exception](strategy) .onFailure[Exception](strategy)
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
startedProbe.expectMessage(Started) startedProbe.expectMessage(Started)
ref ! IncrementState ref ! IncrementState
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
@ -835,7 +835,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
probe.expectMessage(State(0, Map.empty)) probe.expectMessage(State(0, Map.empty))
// one more time // one more time
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
ref ! IncrementState ref ! IncrementState
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
@ -873,8 +873,8 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
.onFailure[Exception](strategy) .onFailure[Exception](strategy)
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
LoggingTestKit.error[TestException].withOccurrences(2).intercept { LoggingTestKit.error[TestException].withOccurrences(2).expect {
startedProbe.expectMessage(Started) startedProbe.expectMessage(Started)
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
probe.expectTerminated(ref, 3.seconds) probe.expectTerminated(ref, 3.seconds)
@ -895,7 +895,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val behv = supervise(targetBehavior(probe.ref)).onFailure[Exc1](strategy) val behv = supervise(targetBehavior(probe.ref)).onFailure[Exc1](strategy)
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
ref ! IncrementState ref ! IncrementState
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
@ -908,7 +908,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
probe.expectMessage(State(0, Map.empty)) probe.expectMessage(State(0, Map.empty))
// one more time after the reset timeout // one more time after the reset timeout
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
probe.expectNoMessage(strategy.resetBackoffAfter + 100.millis.dilated) probe.expectNoMessage(strategy.resetBackoffAfter + 100.millis.dilated)
ref ! IncrementState ref ! IncrementState
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
@ -939,7 +939,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
failCount = 1, failCount = 1,
strategy = SupervisorStrategy.restart) { strategy = SupervisorStrategy.restart) {
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
spawn(behv) spawn(behv)
} }
} }
@ -947,7 +947,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
"fail to restart when deferred factory throws unhandled" in new FailingUnhandledTestSetup( "fail to restart when deferred factory throws unhandled" in new FailingUnhandledTestSetup(
strategy = SupervisorStrategy.restart) { strategy = SupervisorStrategy.restart) {
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
spawn(behv) spawn(behv)
} }
} }
@ -955,8 +955,8 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
"fail to resume when deferred factory throws" in new FailingDeferredTestSetup( "fail to resume when deferred factory throws" in new FailingDeferredTestSetup(
failCount = 1, failCount = 1,
strategy = SupervisorStrategy.resume) { strategy = SupervisorStrategy.resume) {
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
spawn(behv) spawn(behv)
} }
} }
@ -966,7 +966,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
failCount = 1, failCount = 1,
strategy = SupervisorStrategy.restartWithBackoff(minBackoff = 100.millis.dilated, maxBackoff = 1.second, 0)) { strategy = SupervisorStrategy.restartWithBackoff(minBackoff = 100.millis.dilated, maxBackoff = 1.second, 0)) {
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
spawn(behv) spawn(behv)
probe.expectMessage(StartFailed) probe.expectMessage(StartFailed)
@ -979,7 +979,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
"fail instead of restart with exponential backoff when deferred factory throws unhandled" in new FailingUnhandledTestSetup( "fail instead of restart with exponential backoff when deferred factory throws unhandled" in new FailingUnhandledTestSetup(
strategy = SupervisorStrategy.restartWithBackoff(minBackoff = 100.millis.dilated, maxBackoff = 1.second, 0)) { strategy = SupervisorStrategy.restartWithBackoff(minBackoff = 100.millis.dilated, maxBackoff = 1.second, 0)) {
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
spawn(behv) spawn(behv)
probe.expectMessage(StartFailed) probe.expectMessage(StartFailed)
} }
@ -989,7 +989,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
failCount = 1, failCount = 1,
strategy = SupervisorStrategy.restart.withLimit(3, 1.second)) { strategy = SupervisorStrategy.restart.withLimit(3, 1.second)) {
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
spawn(behv) spawn(behv)
probe.expectMessage(StartFailed) probe.expectMessage(StartFailed)
@ -1001,8 +1001,8 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
failCount = 20, failCount = 20,
strategy = SupervisorStrategy.restart.withLimit(2, 1.second)) { strategy = SupervisorStrategy.restart.withLimit(2, 1.second)) {
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
LoggingTestKit.error[TestException].withOccurrences(2).intercept { LoggingTestKit.error[TestException].withOccurrences(2).expect {
spawn(behv) spawn(behv)
// first one from initial setup // first one from initial setup
@ -1018,7 +1018,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
"fail instead of restart with limit when deferred factory throws unhandled" in new FailingUnhandledTestSetup( "fail instead of restart with limit when deferred factory throws unhandled" in new FailingUnhandledTestSetup(
strategy = SupervisorStrategy.restart.withLimit(3, 1.second)) { strategy = SupervisorStrategy.restart.withLimit(3, 1.second)) {
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
spawn(behv) spawn(behv)
probe.expectMessage(StartFailed) probe.expectMessage(StartFailed)
} }
@ -1029,7 +1029,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
val behv = supervise(setup[Command](ctx => new FailingConstructor(ctx, probe.ref))) val behv = supervise(setup[Command](ctx => new FailingConstructor(ctx, probe.ref)))
.onFailure[Exception](SupervisorStrategy.restart) .onFailure[Exception](SupervisorStrategy.restart)
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
spawn(behv) spawn(behv)
probe.expectMessage(Started) // first one before failure probe.expectMessage(Started) // first one before failure
} }
@ -1074,7 +1074,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
actor ! "ping" actor ! "ping"
probe.expectMessage("pong") probe.expectMessage("pong")
LoggingTestKit.error[RuntimeException].intercept { LoggingTestKit.error[RuntimeException].expect {
// Should be supervised as resume // Should be supervised as resume
actor ! "boom" actor ! "boom"
} }
@ -1122,7 +1122,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
actor ! "ping" actor ! "ping"
probe.expectMessage("pong") probe.expectMessage("pong")
LoggingTestKit.error[RuntimeException].intercept { LoggingTestKit.error[RuntimeException].expect {
// Should be supervised as resume // Should be supervised as resume
actor ! "boom" actor ! "boom"
} }
@ -1166,7 +1166,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
probe.expectMessage("started 1") probe.expectMessage("started 1")
ref ! "ping" ref ! "ping"
probe.expectMessage("pong 1") probe.expectMessage("pong 1")
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
ref ! "boom" ref ! "boom"
probe.expectMessage("crashing 1") probe.expectMessage("crashing 1")
ref ! "ping" ref ! "ping"
@ -1178,7 +1178,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
probe.expectMessage("pong 2") probe.expectMessage("pong 2")
LoggingTestKit LoggingTestKit
.error[TestException] .error[TestException]
.intercept { .expect {
ref ! "boom" // now we should have replaced supervision with the resuming one ref ! "boom" // now we should have replaced supervision with the resuming one
probe.expectMessage("crashing 2") probe.expectMessage("crashing 2")
}(system) }(system)
@ -1211,7 +1211,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
}) })
.onFailure[DeathPactException](SupervisorStrategy.restart)) .onFailure[DeathPactException](SupervisorStrategy.restart))
LoggingTestKit.error[DeathPactException].intercept { LoggingTestKit.error[DeathPactException].expect {
actor ! "boom" actor ! "boom"
val child = probe.expectMessageType[ActorRef[_]] val child = probe.expectMessageType[ActorRef[_]]
probe.expectTerminated(child, 3.seconds) probe.expectTerminated(child, 3.seconds)
@ -1226,7 +1226,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
.supervise(targetBehavior(probe.ref)) .supervise(targetBehavior(probe.ref))
.onFailure[Exc1](SupervisorStrategy.restart.withLoggingEnabled(true).withLogLevel(Level.INFO)) .onFailure[Exc1](SupervisorStrategy.restart.withLoggingEnabled(true).withLogLevel(Level.INFO))
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.info("exc-1").intercept { LoggingTestKit.info("exc-1").expect {
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
@ -1238,7 +1238,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
.supervise(targetBehavior(probe.ref)) .supervise(targetBehavior(probe.ref))
.onFailure[Exc1](SupervisorStrategy.restart.withLoggingEnabled(true).withLogLevel(Level.DEBUG)) .onFailure[Exc1](SupervisorStrategy.restart.withLoggingEnabled(true).withLogLevel(Level.DEBUG))
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.info("exc-1").withSource(ref.path.toString).withOccurrences(0).intercept { LoggingTestKit.info("exc-1").withSource(ref.path.toString).withOccurrences(0).expect {
ref ! Throw(new Exc1) ref ! Throw(new Exc1)
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
@ -1266,7 +1266,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
ref ! Ping(1) ref ! Ping(1)
probe.expectMessage(Pong(1)) probe.expectMessage(Pong(1))
LoggingTestKit.error[Exc1].intercept { LoggingTestKit.error[Exc1].expect {
ref.unsafeUpcast ! "boom" ref.unsafeUpcast ! "boom"
probe.expectMessage(ReceivedSignal(PreRestart)) probe.expectMessage(ReceivedSignal(PreRestart))
} }
@ -1317,7 +1317,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
.error[IllegalStateException] .error[IllegalStateException]
.withMessageContains("created with wrong ActorContext") .withMessageContains("created with wrong ActorContext")
.withOccurrences(2) // twice because also logged for PostStop signal .withOccurrences(2) // twice because also logged for PostStop signal
.intercept { .expect {
wrong ! "boom" wrong ! "boom"
} }
probe.expectTerminated(wrong) probe.expectTerminated(wrong)
@ -1363,7 +1363,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
}) })
.onFailure[TestException](strategy)) .onFailure[TestException](strategy))
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
actor ! "boom" actor ! "boom"
} }
createTestProbe().expectTerminated(actor, 3.second) createTestProbe().expectTerminated(actor, 3.second)

View file

@ -175,7 +175,7 @@ class TimerSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
probe.expectMessage(Tock(1)) probe.expectMessage(Tock(1))
val latch = new CountDownLatch(1) val latch = new CountDownLatch(1)
LoggingTestKit.error[Exc].intercept { LoggingTestKit.error[Exc].expect {
// next Tock(1) is enqueued in mailbox, but should be discarded by new incarnation // next Tock(1) is enqueued in mailbox, but should be discarded by new incarnation
ref ! SlowThenThrow(latch, new Exc) ref ! SlowThenThrow(latch, new Exc)
@ -205,7 +205,7 @@ class TimerSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
probe.expectMessage(Tock(2)) probe.expectMessage(Tock(2))
LoggingTestKit.error[Exc].intercept { LoggingTestKit.error[Exc].expect {
val latch = new CountDownLatch(1) val latch = new CountDownLatch(1)
// next Tock(2) is enqueued in mailbox, but should be discarded by new incarnation // next Tock(2) is enqueued in mailbox, but should be discarded by new incarnation
ref ! SlowThenThrow(latch, new Exc) ref ! SlowThenThrow(latch, new Exc)
@ -226,7 +226,7 @@ class TimerSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
target(probe.ref, timer, 1) target(probe.ref, timer, 1)
} }
val ref = spawn(behv) val ref = spawn(behv)
LoggingTestKit.error[Exc].intercept { LoggingTestKit.error[Exc].expect {
ref ! Throw(new Exc) ref ! Throw(new Exc)
probe.expectMessage(GotPostStop(false)) probe.expectMessage(GotPostStop(false))
} }
@ -305,7 +305,7 @@ class TimerSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
} }
} }
}) })
LoggingTestKit.info("stopping").intercept { LoggingTestKit.info("stopping").expect {
ref ! "stop" ref ! "stop"
} }
probe.expectTerminated(ref) probe.expectTerminated(ref)
@ -344,7 +344,7 @@ class TimerSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
Behaviors.unhandled Behaviors.unhandled
} }
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
val ref = spawn(Behaviors.supervise(behv).onFailure[TestException](SupervisorStrategy.restart)) val ref = spawn(Behaviors.supervise(behv).onFailure[TestException](SupervisorStrategy.restart))
ref ! Tick(-1) ref ! Tick(-1)
probe.expectMessage(Tock(-1)) probe.expectMessage(Tock(-1))
@ -379,7 +379,7 @@ class TimerSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
Behaviors.unhandled Behaviors.unhandled
} }
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
val ref = spawn(Behaviors.supervise(behv).onFailure[TestException](SupervisorStrategy.restart)) val ref = spawn(Behaviors.supervise(behv).onFailure[TestException](SupervisorStrategy.restart))
ref ! Tick(-1) ref ! Tick(-1)
probe.expectMessage(Tock(-1)) probe.expectMessage(Tock(-1))

View file

@ -134,7 +134,7 @@ class TransformMessagesSpec extends ScalaTestWithActorTestKit with WordSpecLike
case s => s.toLowerCase case s => s.toLowerCase
} }
LoggingTestKit.error[ActorInitializationException].intercept { LoggingTestKit.error[ActorInitializationException].expect {
val ref = spawn(transform(transform(Behaviors.receiveMessage[String] { _ => val ref = spawn(transform(transform(Behaviors.receiveMessage[String] { _ =>
Behaviors.same Behaviors.same
}))) })))

View file

@ -109,7 +109,7 @@ class WatchSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
}, },
"supervised-child-parent") "supervised-child-parent")
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
parent ! "boom" parent ! "boom"
} }
probe.expectMessageType[ChildHasFailed].t.cause shouldEqual ex probe.expectMessageType[ChildHasFailed].t.cause shouldEqual ex
@ -144,7 +144,7 @@ class WatchSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
} }
val parent = spawn(behavior, "parent") val parent = spawn(behavior, "parent")
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
parent ! "boom" parent ! "boom"
} }
probe.expectMessageType[ChildHasFailed].t.cause shouldEqual ex probe.expectMessageType[ChildHasFailed].t.cause shouldEqual ex
@ -183,8 +183,8 @@ class WatchSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
}, },
"grosso-bosso") "grosso-bosso")
LoggingTestKit.error[TestException].intercept { LoggingTestKit.error[TestException].expect {
LoggingTestKit.error[DeathPactException].intercept { LoggingTestKit.error[DeathPactException].expect {
grossoBosso ! "boom" grossoBosso ! "boom"
} }
} }
@ -327,7 +327,7 @@ class WatchSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
LoggingTestKit LoggingTestKit
.error[IllegalStateException] .error[IllegalStateException]
.withMessageContains("termination message was not overwritten") .withMessageContains("termination message was not overwritten")
.intercept { .expect {
watcher ! StartWatching(terminator) watcher ! StartWatching(terminator)
} }
// supervisor should have stopped the actor // supervisor should have stopped the actor
@ -340,7 +340,7 @@ class WatchSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
LoggingTestKit LoggingTestKit
.error[IllegalStateException] .error[IllegalStateException]
.withMessageContains("termination message was not overwritten") .withMessageContains("termination message was not overwritten")
.intercept { .expect {
watcher ! StartWatchingWith(terminator, CustomTerminationMessage2) watcher ! StartWatchingWith(terminator, CustomTerminationMessage2)
} }
// supervisor should have stopped the actor // supervisor should have stopped the actor
@ -352,7 +352,7 @@ class WatchSpec extends ScalaTestWithActorTestKit with WordSpecLike with LogCapt
LoggingTestKit LoggingTestKit
.error[IllegalStateException] .error[IllegalStateException]
.withMessageContains("termination message was not overwritten") .withMessageContains("termination message was not overwritten")
.intercept { .expect {
watcher ! StartWatchingWith(terminator, CustomTerminationMessage) watcher ! StartWatchingWith(terminator, CustomTerminationMessage)
} }
// supervisor should have stopped the actor // supervisor should have stopped the actor

View file

@ -104,7 +104,7 @@ class ActorContextAskSpec
} }
} }
LoggingTestKit.error[NotImplementedError].withMessageContains("Pong").intercept { LoggingTestKit.error[NotImplementedError].withMessageContains("Pong").expect {
spawn(snitch) spawn(snitch)
} }

View file

@ -71,9 +71,9 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
} }
} }
val actor = LoggingTestKit.info("Started").intercept(spawn(behavior, "the-actor")) val actor = LoggingTestKit.info("Started").expect(spawn(behavior, "the-actor"))
LoggingTestKit.info("got message Hello").intercept(actor ! "Hello") LoggingTestKit.info("got message Hello").expect(actor ! "Hello")
} }
@ -89,7 +89,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
} }
val actor = val actor =
LoggingTestKit.info("Started").withLoggerName(classOf[AnotherLoggerClass].getName).intercept { LoggingTestKit.info("Started").withLoggerName(classOf[AnotherLoggerClass].getName).expect {
spawn(behavior, "the-other-actor") spawn(behavior, "the-other-actor")
} }
@ -104,7 +104,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
} }
.withLoggerName(classOf[AnotherLoggerClass].getName) .withLoggerName(classOf[AnotherLoggerClass].getName)
.withOccurrences(2) .withOccurrences(2)
.intercept { .expect {
actor ! "Hello" actor ! "Hello"
LoggerFactory.getLogger(classOf[ActorLoggingSpec]).debug("Hello from other logger") LoggerFactory.getLogger(classOf[ActorLoggingSpec]).debug("Hello from other logger")
actor ! "Hello" actor ! "Hello"
@ -122,7 +122,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
false false
}) })
eventFilter.intercept(spawn(Behaviors.setup[String] { context => eventFilter.expect(spawn(Behaviors.setup[String] { context =>
context.log.info("Started") context.log.info("Started")
Behaviors.receive { (context, message) => Behaviors.receive { (context, message) =>
@ -141,7 +141,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
false false
}) })
eventFilter.intercept(spawn(WhereTheBehaviorIsDefined.behavior, "the-actor-with-object")) eventFilter.expect(spawn(WhereTheBehaviorIsDefined.behavior, "the-actor-with-object"))
} }
"contain the abstract behavior class name where the first log was called" in { "contain the abstract behavior class name where the first log was called" in {
@ -152,7 +152,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
false false
}) })
eventFilter.intercept { eventFilter.expect {
spawn(Behaviors.setup[String](context => new BehaviorWhereTheLoggerIsUsed(context)), "the-actor-with-behavior") spawn(Behaviors.setup[String](context => new BehaviorWhereTheLoggerIsUsed(context)), "the-actor-with-behavior")
} }
} }
@ -163,7 +163,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
event.marker.map(_.getName) == Option(marker.getName) event.marker.map(_.getName) == Option(marker.getName)
} }
.withOccurrences(5) .withOccurrences(5)
.intercept(spawn(Behaviors.setup[Any] { context => .expect(spawn(Behaviors.setup[Any] { context =>
context.log.debug(marker, "whatever") context.log.debug(marker, "whatever")
context.log.info(marker, "whatever") context.log.info(marker, "whatever")
context.log.warn(marker, "whatever") context.log.warn(marker, "whatever")
@ -179,7 +179,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
event.throwable == Option(cause) event.throwable == Option(cause)
} }
.withOccurrences(2) .withOccurrences(2)
.intercept(spawn(Behaviors.setup[Any] { context => .expect(spawn(Behaviors.setup[Any] { context =>
context.log.warn("whatever", cause) context.log.warn("whatever", cause)
context.log.warn(marker, "whatever", cause) context.log.warn(marker, "whatever", cause)
Behaviors.stopped Behaviors.stopped
@ -195,7 +195,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
true // any is fine, we're just after the right count of statements reaching the listener true // any is fine, we're just after the right count of statements reaching the listener
} }
.withOccurrences(36) .withOccurrences(36)
.intercept({ .expect({
spawn(Behaviors.setup[String] { spawn(Behaviors.setup[String] {
context => context =>
context.log.debug("message") context.log.debug("message")
@ -246,7 +246,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
} }
"use Slf4jLogger from akka-slf4j automatically" in { "use Slf4jLogger from akka-slf4j automatically" in {
LoggingTestKit.info("via Slf4jLogger").intercept { LoggingTestKit.info("via Slf4jLogger").expect {
// this will log via classic eventStream // this will log via classic eventStream
system.toClassic.log.info("via Slf4jLogger") system.toClassic.log.info("via Slf4jLogger")
} }
@ -263,11 +263,11 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
} }
} }
val actor = val actor =
LoggingTestKit.info("Starting up").withMdc(Map(ActorMdc.TagsKey -> "tag1,tag2")).intercept { LoggingTestKit.info("Starting up").withMdc(Map(ActorMdc.TagsKey -> "tag1,tag2")).expect {
spawn(behavior, ActorTags("tag1", "tag2")) spawn(behavior, ActorTags("tag1", "tag2"))
} }
LoggingTestKit.info("Got message").withMdc(Map(ActorMdc.TagsKey -> "tag1,tag2")).intercept { LoggingTestKit.info("Got message").withMdc(Map(ActorMdc.TagsKey -> "tag1,tag2")).expect {
actor ! "ping" actor ! "ping"
} }
} }
@ -343,12 +343,12 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
.info("Starting") .info("Starting")
// not counting for example "akkaSource", but it shouldn't have any other entries // not counting for example "akkaSource", but it shouldn't have any other entries
.withCustom(logEvent => logEvent.mdc.keysIterator.forall(_.startsWith("akka"))) .withCustom(logEvent => logEvent.mdc.keysIterator.forall(_.startsWith("akka")))
.intercept { .expect {
spawn(behaviors) spawn(behaviors)
} }
// mdc on message // mdc on message
LoggingTestKit.info("Got message!").withMdc(Map("static" -> "1", "txId" -> "1", "first" -> "true")).intercept { LoggingTestKit.info("Got message!").withMdc(Map("static" -> "1", "txId" -> "1", "first" -> "true")).expect {
ref ! Message(1, "first") ref ! Message(1, "first")
} }
@ -357,7 +357,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
.info("Got message!") .info("Got message!")
.withMdc(Map("static" -> "1", "txId" -> "2")) .withMdc(Map("static" -> "1", "txId" -> "2"))
.withCustom(event => !event.mdc.contains("first")) .withCustom(event => !event.mdc.contains("first"))
.intercept { .expect {
ref ! Message(2, "second") ref ! Message(2, "second")
} }
} }
@ -379,7 +379,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
.info("message") .info("message")
.withMdc(Map("outermost" -> "true")) .withMdc(Map("outermost" -> "true"))
.withCustom(event => !event.mdc.contains("innermost")) .withCustom(event => !event.mdc.contains("innermost"))
.intercept { .expect {
ref ! "message" ref ! "message"
} }
} }
@ -397,7 +397,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
} }
val ref = spawn(Behaviors.withMdc(Map("hasMdc" -> "true"))(behavior)) val ref = spawn(Behaviors.withMdc(Map("hasMdc" -> "true"))(behavior))
LoggingTestKit.info("message").withMdc(Map("hasMdc" -> "true")).intercept { LoggingTestKit.info("message").withMdc(Map("hasMdc" -> "true")).expect {
ref ! "message" ref ! "message"
} }
@ -406,7 +406,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
LoggingTestKit LoggingTestKit
.info("message") .info("message")
.withMdc(Map("hasMdc" -> "true")) // original mdc should stay .withMdc(Map("hasMdc" -> "true")) // original mdc should stay
.intercept { .expect {
ref ! "message" ref ! "message"
} }
@ -429,14 +429,14 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
} }
val ref = spawn(behavior) val ref = spawn(behavior)
LoggingTestKit.info("message").withMdc(Map("mdc-version" -> "1")).intercept { LoggingTestKit.info("message").withMdc(Map("mdc-version" -> "1")).expect {
ref ! "message" ref ! "message"
} }
ref ! "new-mdc" ref ! "new-mdc"
LoggingTestKit LoggingTestKit
.info("message") .info("message")
.withMdc(Map("mdc-version" -> "2")) // mdc should have been replaced .withMdc(Map("mdc-version" -> "2")) // mdc should have been replaced
.intercept { .expect {
ref ! "message" ref ! "message"
} }
@ -454,8 +454,8 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
// mdc on message // mdc on message
val ref = spawn(behavior) val ref = spawn(behavior)
LoggingTestKit.info("first").withMdc(Map("mdc" -> "outer")).intercept { LoggingTestKit.info("first").withMdc(Map("mdc" -> "outer")).expect {
LoggingTestKit.info("second").withMdc(Map("mdc" -> "inner-outer")).intercept { LoggingTestKit.info("second").withMdc(Map("mdc" -> "inner-outer")).expect {
ref ! Message(1, "first") ref ! Message(1, "first")
} }
} }
@ -479,12 +479,12 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
// log from setup // log from setup
// can't use LoggingEventFilter.withMdc here because the actorPathStr isn't know yet // can't use LoggingEventFilter.withMdc here because the actorPathStr isn't know yet
val ref = val ref =
LoggingTestKit.info("Starting").withCustom(event => event.mdc("akkaSource") == actorPathStr.get).intercept { LoggingTestKit.info("Starting").withCustom(event => event.mdc("akkaSource") == actorPathStr.get).expect {
spawn(behavior) spawn(behavior)
} }
// on message // on message
LoggingTestKit.info("Got message!").withMdc(Map("akkaSource" -> actorPathStr.get)).withOccurrences(10).intercept { LoggingTestKit.info("Got message!").withMdc(Map("akkaSource" -> actorPathStr.get)).withOccurrences(10).expect {
(1 to 10).foreach { n => (1 to 10).foreach { n =>
ref ! Message(n, s"msg-$n") ref ! Message(n, s"msg-$n")
} }

View file

@ -24,52 +24,52 @@ class LoggerOpsSpec extends ScalaTestWithActorTestKit with WordSpecLike with Log
"LoggerOps" must { "LoggerOps" must {
"provide extension method for 2 arguments" in { "provide extension method for 2 arguments" in {
LoggingTestKit.info("[template a b]").intercept { LoggingTestKit.info("[template a b]").expect {
log.info2("[template {} {}]", "a", "b") log.info2("[template {} {}]", "a", "b")
} }
LoggingTestKit.info("[template a 2]").intercept { LoggingTestKit.info("[template a 2]").expect {
log.info2("[template {} {}]", "a", 2) log.info2("[template {} {}]", "a", 2)
} }
LoggingTestKit.info("[template 1 2]").intercept { LoggingTestKit.info("[template 1 2]").expect {
log.info2("[template {} {}]", 1, 2) log.info2("[template {} {}]", 1, 2)
} }
LoggingTestKit.info("[template 1 b]").intercept { LoggingTestKit.info("[template 1 b]").expect {
log.info2("[template {} {}]", 1, "b") log.info2("[template {} {}]", 1, "b")
} }
LoggingTestKit.info("[template a Value2(2)]").intercept { LoggingTestKit.info("[template a Value2(2)]").expect {
log.info2("[template {} {}]", "a", Value2(2)) log.info2("[template {} {}]", "a", Value2(2))
} }
LoggingTestKit.info("[template Value1(1) Value1(1)]").intercept { LoggingTestKit.info("[template Value1(1) Value1(1)]").expect {
log.info2("[template {} {}]", Value1(1), Value1(1)) log.info2("[template {} {}]", Value1(1), Value1(1))
} }
LoggingTestKit.info("[template Value1(1) Value2(2)]").intercept { LoggingTestKit.info("[template Value1(1) Value2(2)]").expect {
log.info2("[template {} {}]", Value1(1), Value2(2)) log.info2("[template {} {}]", Value1(1), Value2(2))
} }
} }
"provide extension method for vararg arguments" in { "provide extension method for vararg arguments" in {
LoggingTestKit.info("[template a b c]").intercept { LoggingTestKit.info("[template a b c]").expect {
log.infoN("[template {} {} {}]", "a", "b", "c") log.infoN("[template {} {} {}]", "a", "b", "c")
} }
LoggingTestKit.info("[template a b 3]").intercept { LoggingTestKit.info("[template a b 3]").expect {
log.infoN("[template {} {} {}]", "a", "b", 3) log.infoN("[template {} {} {}]", "a", "b", 3)
} }
LoggingTestKit.info("[template a 2 c]").intercept { LoggingTestKit.info("[template a 2 c]").expect {
log.infoN("[template {} {} {}]", "a", 2, "c") log.infoN("[template {} {} {}]", "a", 2, "c")
} }
LoggingTestKit.info("[template 1 2 3]").intercept { LoggingTestKit.info("[template 1 2 3]").expect {
log.infoN("[template {} {} {}]", 1, 2, 3) log.infoN("[template {} {} {}]", 1, 2, 3)
} }
LoggingTestKit.info("[template 1 b c]").intercept { LoggingTestKit.info("[template 1 b c]").expect {
log.infoN("[template {} {} {}]", 1, "b", "c") log.infoN("[template {} {} {}]", 1, "b", "c")
} }
LoggingTestKit.info("[template a Value2(2) Value3(3)]").intercept { LoggingTestKit.info("[template a Value2(2) Value3(3)]").expect {
log.infoN("[template {} {} {}]", "a", Value2(2), Value3(3)) log.infoN("[template {} {} {}]", "a", Value2(2), Value3(3))
} }
LoggingTestKit.info("[template Value1(1) Value1(1) Value1(1)]").intercept { LoggingTestKit.info("[template Value1(1) Value1(1) Value1(1)]").expect {
log.infoN("[template {} {} {}]", Value1(1), Value1(1), Value1(1)) log.infoN("[template {} {} {}]", Value1(1), Value1(1), Value1(1))
} }
LoggingTestKit.info("[template Value1(1) Value2(2) Value3(3)]").intercept { LoggingTestKit.info("[template Value1(1) Value2(2) Value3(3)]").expect {
log.infoN("[template {} {} {}]", Value1(1), Value2(2), Value3(3)) log.infoN("[template {} {} {}]", Value1(1), Value2(2), Value3(3))
} }
} }

View file

@ -259,7 +259,7 @@ class MessageAdapterSpec
} }
// Not expecting "Exception thrown out of adapter. Stopping myself" // Not expecting "Exception thrown out of adapter. Stopping myself"
LoggingTestKit.error[TestException].withMessageContains("boom").intercept { LoggingTestKit.error[TestException].withMessageContains("boom").expect {
spawn(snitch) spawn(snitch)
} }

View file

@ -83,7 +83,7 @@ class RoutersSpec extends ScalaTestWithActorTestKit("""
Behaviors.same Behaviors.same
})) }))
LoggingTestKit.debug("Pool child stopped").withOccurrences(2).intercept { LoggingTestKit.debug("Pool child stopped").withOccurrences(2).expect {
pool ! "stop" pool ! "stop"
pool ! "stop" pool ! "stop"
} }
@ -107,7 +107,7 @@ class RoutersSpec extends ScalaTestWithActorTestKit("""
Behaviors.stopped Behaviors.stopped
})) }))
LoggingTestKit.info("Last pool child stopped, stopping pool").intercept { LoggingTestKit.info("Last pool child stopped, stopping pool").expect {
(0 to 3).foreach { _ => (0 to 3).foreach { _ =>
pool ! "stop" pool ! "stop"
} }

View file

@ -422,7 +422,7 @@ class UnstashingSpec extends ScalaTestWithActorTestKit with WordSpecLike with Lo
LoggingTestKit LoggingTestKit
.error[TestException] .error[TestException]
.withMessageContains("unstash-fail") .withMessageContains("unstash-fail")
.intercept { .expect {
ref ! "unstash" ref ! "unstash"
probe.expectMessage("unstashing-0") probe.expectMessage("unstashing-0")
probe.expectMessage("unstashing-1") probe.expectMessage("unstashing-1")
@ -452,7 +452,7 @@ class UnstashingSpec extends ScalaTestWithActorTestKit with WordSpecLike with Lo
LoggingTestKit LoggingTestKit
.error[TestException] .error[TestException]
.withMessageContains("Supervisor RestartSupervisor saw failure: unstash-fail") .withMessageContains("Supervisor RestartSupervisor saw failure: unstash-fail")
.intercept { .expect {
ref ! "unstash" ref ! "unstash"
// when childLatch is defined this be stashed in the internal stash of the RestartSupervisor // when childLatch is defined this be stashed in the internal stash of the RestartSupervisor
// because it's waiting for child to stop // because it's waiting for child to stop
@ -535,7 +535,7 @@ class UnstashingSpec extends ScalaTestWithActorTestKit with WordSpecLike with Lo
LoggingTestKit LoggingTestKit
.error[TestException] .error[TestException]
.withMessageContains("Supervisor ResumeSupervisor saw failure: unstash-fail") .withMessageContains("Supervisor ResumeSupervisor saw failure: unstash-fail")
.intercept { .expect {
ref ! "unstash" ref ! "unstash"
ref ! "get-current" ref ! "get-current"

View file

@ -304,7 +304,7 @@ class AdapterSpec extends WordSpec with Matchers with BeforeAndAfterAll with Log
// only stop supervisorStrategy // only stop supervisorStrategy
LoggingTestKit LoggingTestKit
.error[AdapterSpec.ThrowIt3.type] .error[AdapterSpec.ThrowIt3.type]
.intercept { .expect {
typedRef ! "supervise-restart" typedRef ! "supervise-restart"
probe.expectMsg("ok") probe.expectMsg("ok")
}(system.toTyped) }(system.toTyped)
@ -317,7 +317,7 @@ class AdapterSpec extends WordSpec with Matchers with BeforeAndAfterAll with Log
LoggingTestKit LoggingTestKit
.error[ActorInitializationException] .error[ActorInitializationException]
.intercept { .expect {
typedRef ! "supervise-start-fail" typedRef ! "supervise-start-fail"
probe.expectMsg("terminated") probe.expectMsg("terminated")
}(system.toTyped) }(system.toTyped)
@ -343,7 +343,7 @@ class AdapterSpec extends WordSpec with Matchers with BeforeAndAfterAll with Log
val throwMsg = "sad panda" val throwMsg = "sad panda"
LoggingTestKit LoggingTestKit
.error("sad panda") .error("sad panda")
.intercept { .expect {
system.spawnAnonymous(unhappyTyped(throwMsg)) system.spawnAnonymous(unhappyTyped(throwMsg))
Thread.sleep(1000) Thread.sleep(1000)
}(system.toTyped) }(system.toTyped)

View file

@ -118,7 +118,7 @@ object LoggingDocExamples {
// implicit ActorSystem is needed, but that is given by ScalaTestWithActorTestKit // implicit ActorSystem is needed, but that is given by ScalaTestWithActorTestKit
//implicit val system: ActorSystem[_] //implicit val system: ActorSystem[_]
LoggingTestKit.info("Received message").intercept { LoggingTestKit.info("Received message").expect {
ref ! Message("hello") ref ! Message("hello")
} }
//#test-logging //#test-logging
@ -134,7 +134,7 @@ object LoggingDocExamples {
} }
} }
.withOccurrences(2) .withOccurrences(2)
.intercept { .expect {
ref ! Message("hellö") ref ! Message("hellö")
ref ! Message("hejdå") ref ! Message("hejdå")
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -542,7 +542,7 @@ class EventSourcedBehaviorStashSpec
c ! "start-stashing" c ! "start-stashing"
val limit = system.settings.config.getInt("akka.persistence.typed.stash-capacity") 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 => (0 to limit).foreach { n =>
c ! s"cmd-$n" // limit triggers overflow c ! s"cmd-$n" // limit triggers overflow
} }
@ -590,7 +590,7 @@ class EventSourcedBehaviorStashSpec
LoggingTestKit LoggingTestKit
.error[StashOverflowException] .error[StashOverflowException]
.intercept { .expect {
val limit = system.settings.config.getInt("akka.persistence.typed.stash-capacity") val limit = system.settings.config.getInt("akka.persistence.typed.stash-capacity")
(0 to limit).foreach { n => (0 to limit).foreach { n =>
c ! s"cmd-$n" // limit triggers overflow 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 // one test case leaks to another, the actual log class is what is tested in each individual case
"log from setup" in { "log from setup" in {
LoggingTestKit.info("recovery-completed").intercept { LoggingTestKit.info("recovery-completed").expect {
eventFilterFor("setting-up-behavior").intercept { eventFilterFor("setting-up-behavior").expect {
spawn(behavior) spawn(behavior)
} }
} }
@ -57,8 +57,8 @@ class LoggerSourceSpec
} }
"log from recovery completed" in { "log from recovery completed" in {
LoggingTestKit.info("setting-up-behavior").intercept { LoggingTestKit.info("setting-up-behavior").expect {
eventFilterFor("recovery-completed").intercept { eventFilterFor("recovery-completed").expect {
spawn(behavior) spawn(behavior)
} }
} }
@ -69,8 +69,8 @@ class LoggerSourceSpec
.withLogLevel(Level.INFO) .withLogLevel(Level.INFO)
.withMessageRegex("(setting-up-behavior|recovery-completed|event-received)") .withMessageRegex("(setting-up-behavior|recovery-completed|event-received)")
.withOccurrences(3) .withOccurrences(3)
.intercept { .expect {
eventFilterFor("command-received").intercept { eventFilterFor("command-received").expect {
spawn(behavior) ! "cmd" spawn(behavior) ! "cmd"
} }
} }
@ -81,8 +81,8 @@ class LoggerSourceSpec
.withLogLevel(Level.INFO) .withLogLevel(Level.INFO)
.withMessageRegex("(setting-up-behavior|recovery-completed|command-received)") .withMessageRegex("(setting-up-behavior|recovery-completed|command-received)")
.withOccurrences(3) .withOccurrences(3)
.intercept { .expect {
eventFilterFor("event-received").intercept { eventFilterFor("event-received").expect {
spawn(behavior) ! "cmd" spawn(behavior) ! "cmd"
} }
} }

View file

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