Run tests for actors and typed actors on Scala 3 (#30283)

Co-authored-by: Renato Cavalcanti <renato@cavalcanti.be>
This commit is contained in:
Lukas Rytz 2021-07-23 12:31:45 +02:00 committed by GitHub
parent 186ace214b
commit 9db28c68a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 40 additions and 41 deletions

View file

@ -38,7 +38,7 @@ jobs:
- stage: scala3
name: scala3
# separate job since only a few modules compile with Scala 3 yet
script: jabba install adopt@1.11-0 && jabba use adopt@1.11-0 && sbt -Dakka.build.scalaVersion=3.0 "akka-actor-tests/test:compile" akka-actor-testkit-typed/compile akka-actor-typed/compile akka-discovery/test akka-pki/test:compile akka-protobuf/test:compile akka-protobuf-v3/test:compile akka-slf4j/test:compile akka-stream/compile akka-stream-tests-tck/test akka-coordination/test akka-serialization-jackson/test:compile akka-testkit/test akka-stream-testkit/test akka-remote/compile
script: jabba install adopt@1.11-0 && jabba use adopt@1.11-0 && sbt -jvm-opts .jvmopts-travis -Dakka.build.scalaVersion=3.0 "akka-actor-tests/test:compile" akka-actor-testkit-typed/compile akka-actor-typed/compile akka-actor-typed-tests/test akka-discovery/test akka-pki/test:compile akka-protobuf/test:compile akka-protobuf-v3/test:compile akka-slf4j/test:compile akka-stream/compile akka-stream-tests-tck/test akka-coordination/test akka-serialization-jackson/test:compile akka-testkit/test akka-stream-testkit/test akka-remote/compile
stages:
- name: whitesource

View file

@ -13,6 +13,8 @@ import org.scalatestplus.junit.JUnitSuite;
public class AbstractFSMActorTest extends JUnitSuite {
// javac produces an `unchecked` warning about `akka$actor$FSM$$transitionEvent`
// https://github.com/lampepfl/dotty/issues/6350
public static class MyFSM extends AbstractFSM<String, String> {
private final ActorRef probe;

View file

@ -147,15 +147,6 @@ public interface IntroTest {
// #hello-world-main
interface CustomDispatchersExample {
public static class SayHello {
public final String name;
public SayHello(String name) {
this.name = name;
}
}
// #hello-world-main-with-dispatchers
public class HelloWorldMain extends AbstractBehavior<HelloWorldMain.SayHello> {

View file

@ -647,7 +647,8 @@ abstract class ActorContextSpec extends ScalaTestWithActorTestKit with AnyWordSp
}
"not allow null messages" in {
val actor = spawn(Behaviors.empty[Null].decorate)
// Scala 3 doesn't generate an implicit `ClassTag[Null]` (https://github.com/lampepfl/dotty/issues/9586)
val actor = spawn(decoration(ClassTag.Null)(Behaviors.empty[Null]))
intercept[InvalidMessageException] {
actor ! null
}

View file

@ -44,7 +44,7 @@ class ActorRefIgnoreSpec extends ScalaTestWithActorTestKit() with AnyWordSpecLik
implicit val timeout: Timeout = 1.second
// send a message to interactWithRef
context.ask(askMeRef, Request) {
context.ask(askMeRef, Request.apply) {
case Success(res) => res
case Failure(ex) => throw ex
}

View file

@ -50,7 +50,7 @@ class AskSpec extends ScalaTestWithActorTestKit("""
"Ask pattern" must {
"fail the future if the actor is already terminated" in {
val ref = spawn(behavior)
val stopResult: Future[Unit] = ref.ask(Stop)
val stopResult: Future[Unit] = ref.ask(Stop.apply)
stopResult.futureValue
val probe = createTestProbe()
@ -131,7 +131,7 @@ class AskSpec extends ScalaTestWithActorTestKit("""
import akka.actor.typed.scaladsl.adapter._
implicit val timeout: Timeout = 3.seconds
val typedLegacy: ActorRef[AnyRef] = legacyActor
(typedLegacy.ask(Ping)).failed.futureValue should ===(ex)
typedLegacy.ask(Ping.apply).failed.futureValue should ===(ex)
} finally {
akka.testkit.TestKit.shutdownActorSystem(classicSystem)
}

View file

@ -448,7 +448,7 @@ class MutableScalaBehaviorSpec extends Messages with Become with Stoppable {
override def onMessage(message: Command): Behavior[Command] = {
message match {
case GetSelf =>
monitor ! Self(context.self)
monitor ! Self(this.context.self)
this
case Miss =>
monitor ! Missed

View file

@ -263,7 +263,9 @@ class ExtensionsSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike with
}
val sys = setup match {
case None => ActorSystem[Any](Behaviors.empty[Any], name, bootstrap)
case Some(s) => ActorSystem[Any](Behaviors.empty[Any], name, s.and(bootstrap))
case Some(s) =>
// explicit Props.empty: https://github.com/lampepfl/dotty/issues/12679
ActorSystem[Any](Behaviors.empty[Any], name, s.and(bootstrap), Props.empty)
}
try f(sys)

View file

@ -51,13 +51,13 @@ class MailboxSelectorSpec extends ScalaTestWithActorTestKit("""
"The Mailbox selectors" must {
"default to unbounded" in {
val actor = spawn(behavior)
val mailbox = actor.ask(WhatsYourMailbox).futureValue
val mailbox = actor.ask(WhatsYourMailbox.apply).futureValue
mailbox shouldBe a[UnboundedMessageQueueSemantics]
}
"select a bounded mailbox" in {
val actor = spawn(behavior, MailboxSelector.bounded(3))
val mailbox = actor.ask(WhatsYourMailbox).futureValue
val mailbox = actor.ask(WhatsYourMailbox.apply).futureValue
mailbox shouldBe a[BoundedMessageQueueSemantics]
// capacity is private so only way to test is to fill mailbox
}
@ -85,7 +85,7 @@ class MailboxSelectorSpec extends ScalaTestWithActorTestKit("""
"select an arbitrary mailbox from config" in {
val actor = spawn(behavior, MailboxSelector.fromConfig("specific-mailbox"))
val mailbox = actor.ask(WhatsYourMailbox).futureValue
val mailbox = actor.ask(WhatsYourMailbox.apply).futureValue
mailbox shouldBe a[BoundedMessageQueueSemantics]
mailbox.asInstanceOf[BoundedNodeMessageQueue].capacity should ===(4)

View file

@ -53,7 +53,7 @@ class ActorContextAskSpec
val snitch = Behaviors.setup[Pong] { context =>
// Timeout comes from TypedAkkaSpec
context.ask(pingPong, Ping) {
context.ask(pingPong, Ping.apply) {
case Success(_) => Pong(context.self.path.name + "1", Thread.currentThread().getName)
case Failure(ex) => throw ex
}
@ -86,7 +86,7 @@ class ActorContextAskSpec
})
val snitch = Behaviors.setup[AnyRef] { context =>
context.ask(pingPong, Ping) {
context.ask(pingPong, Ping.apply) {
case Success(message) => throw new NotImplementedError(message.toString)
case Failure(x) => x
}
@ -194,7 +194,7 @@ class ActorContextAskSpec
val probe = createTestProbe[Any]()
spawn(Behaviors.setup[Pong.type] { ctx =>
ctx.askWithStatus(probe.ref, Ping) {
ctx.askWithStatus(probe.ref, Ping.apply) {
case Success(Pong) => Pong
case Failure(ex) => throw ex
}
@ -217,7 +217,7 @@ class ActorContextAskSpec
val probe = createTestProbe[Any]()
spawn(Behaviors.setup[Throwable] { ctx =>
ctx.askWithStatus(probe.ref, Ping) {
ctx.askWithStatus(probe.ref, Ping.apply) {
case Failure(ex) => ex
case wat => throw new IllegalArgumentException(s"Unexpected response $wat")
}
@ -241,7 +241,7 @@ class ActorContextAskSpec
val probe = createTestProbe[Any]()
case class Message(any: Any)
spawn(Behaviors.setup[Throwable] { ctx =>
ctx.askWithStatus(probe.ref, Ping) {
ctx.askWithStatus(probe.ref, Ping.apply) {
case Failure(ex) => ex
case wat => throw new IllegalArgumentException(s"Unexpected response $wat")
}

View file

@ -281,7 +281,7 @@ class MessageAdapterSpec
val deadLetterProbe = testKit.createDeadLetterProbe()
val snitch = Behaviors.setup[PingReply] { context =>
val replyTo = context.messageAdapter[Pong](PingReply)
val replyTo = context.messageAdapter[Pong](PingReply.apply)
pingProbe.ref ! Ping(replyTo)
Behaviors.stopped
}

View file

@ -76,7 +76,7 @@ object AbstractStashSpec {
context.self ! Unstash // continue unstashing until buffer is empty
val numberOfMessages = 2
context.log.debug(s"Unstash $numberOfMessages of ${buffer.size}, starting with ${buffer.head}")
buffer.unstash(unstashing(processed), numberOfMessages, Unstashed)
buffer.unstash(unstashing(processed), numberOfMessages, Unstashed.apply)
}
case Stash =>
Behaviors.unhandled
@ -113,7 +113,7 @@ object AbstractStashSpec {
context.self ! Unstash // continue unstashing until buffer is empty
val numberOfMessages = 2
context.log.debug(s"Unstash $numberOfMessages of ${buffer.size}, starting with ${buffer.head}")
buffer.unstash(unstashing(processed), numberOfMessages, Unstashed)
buffer.unstash(unstashing(processed), numberOfMessages, Unstashed.apply)
}
case GetStashSize(replyTo) =>
replyTo ! buffer.size
@ -166,7 +166,7 @@ object AbstractStashSpec {
context.self ! Unstash // continue unstashing until buffer is empty
val numberOfMessages = 2
context.log.debug(s"Unstash $numberOfMessages of ${buffer.size}, starting with ${buffer.head}")
buffer.unstash(this, numberOfMessages, Unstashed)
buffer.unstash(this, numberOfMessages, Unstashed.apply)
}
case Unstashed(message: Msg) =>
context.log.debug(s"unstashed $message")

View file

@ -80,7 +80,7 @@ class InteractionPatternsSpec extends ScalaTestWithActorTestKit with AnyWordSpec
val probe = createTestProbe[CookieFabric.Response]()
// shhh, don't tell anyone
import scala.language.reflectiveCalls
val context = new {
val context: { def self: ActorRef[CookieFabric.Response] } = new {
def self = probe.ref
}
@ -259,7 +259,7 @@ class InteractionPatternsSpec extends ScalaTestWithActorTestKit with AnyWordSpec
// as OpenThePodBayDoorsPlease is a case class it has a factory apply method
// that is what we are passing as the second parameter here it could also be written
// as `ref => OpenThePodBayDoorsPlease(ref)`
context.ask(hal, Hal.OpenThePodBayDoorsPlease) {
context.ask(hal, Hal.OpenThePodBayDoorsPlease.apply) {
case Success(Hal.Response(message)) => AdaptedResponse(message)
case Failure(_) => AdaptedResponse("Request failed")
}
@ -269,7 +269,7 @@ class InteractionPatternsSpec extends ScalaTestWithActorTestKit with AnyWordSpec
// changed at the time the response arrives and the transformation is done, best is to
// use immutable state we have closed over like here.
val requestId = 1
context.ask(hal, Hal.OpenThePodBayDoorsPlease) {
context.ask(hal, Hal.OpenThePodBayDoorsPlease.apply) {
case Success(Hal.Response(message)) => AdaptedResponse(s"$requestId: $message")
case Failure(_) => AdaptedResponse(s"$requestId: Request failed")
}
@ -324,7 +324,7 @@ class InteractionPatternsSpec extends ScalaTestWithActorTestKit with AnyWordSpec
// A StatusReply.Success(m) ends up as a Success(m) here, while a
// StatusReply.Error(text) becomes a Failure(ErrorMessage(text))
context.askWithStatus(hal, Hal.OpenThePodBayDoorsPlease) {
context.askWithStatus(hal, Hal.OpenThePodBayDoorsPlease.apply) {
case Success(message) => AdaptedResponse(message)
case Failure(StatusReply.ErrorMessage(text)) => AdaptedResponse(s"Request denied: $text")
case Failure(_) => AdaptedResponse("Request failed")

View file

@ -69,7 +69,7 @@ object OOIntroSpec {
}
}
object SessionBehavior {
private object SessionBehavior {
def apply(
room: ActorRef[PublishSessionMessage],
screenName: String,

View file

@ -485,14 +485,16 @@ object StyleGuideDocExamples {
@nowarn
private def counter(remaining: Int): Behavior[Command] = {
//#pattern-match-without-guard
Behaviors.receiveMessage {
case Down =>
if (remaining == 1) {
notifyWhenZero.tell(Done)
zero
} else
counter(remaining - 1)
}
// `@unchecked` for Scala 3, which doesn't support @nowarn
Behaviors.receiveMessage(x =>
(x: @unchecked) match {
case Down =>
if (remaining == 1) {
notifyWhenZero.tell(Done)
zero
} else
counter(remaining - 1)
})
//#pattern-match-without-guard
}

View file

@ -167,6 +167,7 @@ object BehaviorBuilder {
/**
* @return new empty immutable behavior builder.
*/
// Empty param list to work around https://github.com/lampepfl/dotty/issues/10347
def create[T]: BehaviorBuilder[T] = _empty.asInstanceOf[BehaviorBuilder[T]]
}