Make it compile on 2.13-M5

This commit is contained in:
Johan Andrén 2019-02-28 16:51:51 +01:00
parent be7790c7b9
commit dc882ee077
3 changed files with 24 additions and 10 deletions

View file

@ -18,6 +18,8 @@ import scala.util.Success
import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit
import org.scalatest.WordSpecLike
import scala.concurrent.Future
object AskSpec {
sealed trait Msg
final case class Foo(s: String, replyTo: ActorRef[String]) extends Msg
@ -51,10 +53,12 @@ class AskSpec extends ScalaTestWithActorTestKit("""
"Ask pattern" must {
"fail the future if the actor is already terminated" in {
val ref = spawn(behavior)
(ref.ask(Stop)).futureValue
val stopResult: Future[Unit] = ref.ask(Stop)
stopResult.futureValue
val probe = createTestProbe()
probe.expectTerminated(ref, probe.remainingOrDefault)
val answer =
val answer: Future[String] =
EventFilter.warning(pattern = ".*received dead letter.*", occurrences = 1).intercept {
ref.ask(Foo("bar", _))
}
@ -65,13 +69,13 @@ class AskSpec extends ScalaTestWithActorTestKit("""
"succeed when the actor is alive" in {
val ref = spawn(behavior)
val response = ref.ask(Foo("bar", _))
val response: Future[String] = ref.ask(Foo("bar", _))
response.futureValue should ===("foo")
}
"provide a symbolic alias that works the same" in {
val ref = spawn(behavior)
val response = ref ? (Foo("bar", _))
val response: Future[String] = ref ? (Foo("bar", _))
response.futureValue should ===("foo")
}
@ -79,7 +83,7 @@ class AskSpec extends ScalaTestWithActorTestKit("""
val actor = spawn(Behaviors.empty[Foo])
implicit val timeout: Timeout = 10.millis
EventFilter.warning(pattern = ".*unhandled message.*", occurrences = 1).intercept {
val answer = actor.ask(Foo("bar", _))
val answer: Future[String] = actor.ask(Foo("bar", _))
val result = answer.failed.futureValue
result shouldBe a[TimeoutException]
result.getMessage should startWith("Ask timed out on")
@ -96,7 +100,7 @@ class AskSpec extends ScalaTestWithActorTestKit("""
fail("this test must only run in an adapted actor system")
}
val answer =
val answer: Future[String] =
EventFilter.warning(pattern = ".*received dead letter.*", occurrences = 1).intercept {
noSuchActor.ask(Foo("bar", _))
}

View file

@ -54,6 +54,9 @@ object AskPattern {
* val target: ActorRef[Request] = ...
* val f: Future[Reply] = target ? (replyTo => (Request("hello", replyTo)))
* }}}
*
* Note: it is preferrable to use the non-symbolic ask method as it easier allows for wildcards for
* the `ActorRef`.
*/
def ?[U](replyTo: ActorRef[U] T)(implicit timeout: Timeout, @unused scheduler: Scheduler): Future[U] = {
ask(replyTo)(timeout, scheduler)
@ -80,7 +83,11 @@ object AskPattern {
* implicit val scheduler = system.scheduler
* implicit val timeout = Timeout(3.seconds)
* val target: ActorRef[Request] = ...
* val f: Future[Reply] = target ? replyTo => (Request("hello", replyTo))
* val f: Future[Reply] = target.ask(replyTo => (Request("hello", replyTo)))
* // alternatively
* val f2: Future[Reply] = target.ask(Request("hello", _))
* // note that the explicit type on f2 is important for the compiler
* // to understand the type of the wildcard
* }}}
*/
def ask[U](replyTo: ActorRef[U] T)(implicit timeout: Timeout, @unused scheduler: Scheduler): Future[U] = {

View file

@ -6,13 +6,14 @@ package akka.persistence.typed.scaladsl
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import akka.actor.typed.{ ActorRef, Behavior }
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.scaladsl.TimerScheduler
import akka.persistence.typed.PersistenceId
import akka.persistence.typed.SideEffect
import scala.concurrent.Future
object PersistentActorCompileOnlyTest {
import akka.persistence.typed.scaladsl.EventSourcedBehavior._
@ -67,8 +68,10 @@ object PersistentActorCompileOnlyTest {
implicit val scheduler: akka.actor.Scheduler = ???
implicit val ec: ExecutionContext = ???
sideEffectProcessor.ask(Request(correlationId, data, _))
.map(response AcknowledgeSideEffect(response.correlationId))
val response: Future[RecoveryComplete.Response] =
sideEffectProcessor.ask(Request(correlationId, data, _))
response.map(response AcknowledgeSideEffect(response.correlationId))
.foreach(sender ! _)
}