From 3b4ce564bec605a2dbe868db9e5b6e60ad0393da Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Thu, 23 Sep 2021 15:25:50 +0200 Subject: [PATCH] build akka-cluster-typed on scala 3 (#30703) * build akka-cluster-typed on scala 3 Refs #30243 * mima exclude * scalafmt --- .github/workflows/scala3-build.yml | 2 +- .../receptionist.excludes | 3 +++ .../ClusterReceptionistProtocol.scala | 17 +++++++++++++++ .../ClusterReceptionistProtocol.scala | 17 +++++++++++++++ .../ClusterReceptionistProtocol.scala | 21 +++++++++++++++++++ .../typed/internal/ReplicatorBehavior.scala | 6 +++--- .../receptionist/ClusterReceptionist.scala | 6 +++--- .../typed/BasicClusterExampleTest.java | 2 +- .../scaladsl/ReplicatorCompileOnlyTest.scala | 2 +- .../cluster/typed/RemoteContextAskSpec.scala | 2 +- .../ClusterReceptionistStateSpec.scala | 2 +- .../typed/BasicClusterExampleSpec.scala | 17 ++++++++------- .../cluster/typed/ReceptionistExample.scala | 2 +- 13 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 akka-cluster-typed/src/main/mima-filters/2.6.16.backwards.excludes/receptionist.excludes create mode 100644 akka-cluster-typed/src/main/scala-2.12/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala create mode 100644 akka-cluster-typed/src/main/scala-2.13/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala create mode 100644 akka-cluster-typed/src/main/scala-3/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala diff --git a/.github/workflows/scala3-build.yml b/.github/workflows/scala3-build.yml index df09a39bed..213e0a01b1 100644 --- a/.github/workflows/scala3-build.yml +++ b/.github/workflows/scala3-build.yml @@ -22,7 +22,7 @@ jobs: - akka-testkit/test akka-actor-tests/test - akka-actor-testkit-typed/test akka-actor-typed-tests/test - akka-bench-jmh/test - - akka-cluster/Test/compile akka-cluster-tools/test akka-distributed-data/test akka-cluster-metrics/Test/compile + - akka-cluster/Test/compile akka-cluster-tools/test akka-cluster-typed/test akka-distributed-data/test akka-cluster-metrics/Test/compile - akka-coordination/test - akka-discovery/test - akka-persistence/test akka-persistence-shared/test akka-persistence-query/test diff --git a/akka-cluster-typed/src/main/mima-filters/2.6.16.backwards.excludes/receptionist.excludes b/akka-cluster-typed/src/main/mima-filters/2.6.16.backwards.excludes/receptionist.excludes new file mode 100644 index 0000000000..a9d477d3f8 --- /dev/null +++ b/akka-cluster-typed/src/main/mima-filters/2.6.16.backwards.excludes/receptionist.excludes @@ -0,0 +1,3 @@ +# Generics changed, but not runtime behaviour +# (and is in 'internal' anyway) +ProblemFilters.exclude[IncompatibleSignatureProblem]("akka.cluster.typed.internal.receptionist.ClusterReceptionist#State.removeSubscriber") diff --git a/akka-cluster-typed/src/main/scala-2.12/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala b/akka-cluster-typed/src/main/scala-2.12/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala new file mode 100644 index 0000000000..40ff74dc8f --- /dev/null +++ b/akka-cluster-typed/src/main/scala-2.12/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2021 Lightbend Inc. + */ + +package akka.cluster.typed.internal.receptionist + +import akka.actor.typed.ActorRef +import akka.actor.typed.internal.receptionist.{ AbstractServiceKey, ReceptionistMessages } +import akka.annotation.InternalApi + +/** + * INTERNAL API + */ +@InternalApi +private[receptionist] object ClusterReceptionistProtocol { + type SubscriptionsKV[K <: AbstractServiceKey] = ActorRef[ReceptionistMessages.Listing[K#Protocol]] +} diff --git a/akka-cluster-typed/src/main/scala-2.13/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala b/akka-cluster-typed/src/main/scala-2.13/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala new file mode 100644 index 0000000000..40ff74dc8f --- /dev/null +++ b/akka-cluster-typed/src/main/scala-2.13/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2021 Lightbend Inc. + */ + +package akka.cluster.typed.internal.receptionist + +import akka.actor.typed.ActorRef +import akka.actor.typed.internal.receptionist.{ AbstractServiceKey, ReceptionistMessages } +import akka.annotation.InternalApi + +/** + * INTERNAL API + */ +@InternalApi +private[receptionist] object ClusterReceptionistProtocol { + type SubscriptionsKV[K <: AbstractServiceKey] = ActorRef[ReceptionistMessages.Listing[K#Protocol]] +} diff --git a/akka-cluster-typed/src/main/scala-3/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala b/akka-cluster-typed/src/main/scala-3/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala new file mode 100644 index 0000000000..c89f434bd8 --- /dev/null +++ b/akka-cluster-typed/src/main/scala-3/akka/cluster/typed/internal/receptionist/ClusterReceptionistProtocol.scala @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2021 Lightbend Inc. + */ + +package akka.cluster.typed.internal.receptionist + +import akka.actor.typed.ActorRef +import akka.actor.typed.internal.receptionist.{ AbstractServiceKey, ReceptionistMessages } +import akka.annotation.InternalApi + +/** + * INTERNAL API + */ +@InternalApi +private[receptionist] object ClusterReceptionistProtocol { + type Aux[P] = AbstractServiceKey { type Protocol = P } + + type SubscriptionsKV[K <: Aux[_]] = K match { + case Aux[t] => ActorRef[ReceptionistMessages.Listing[t]] + } +} diff --git a/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/internal/ReplicatorBehavior.scala b/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/internal/ReplicatorBehavior.scala index f4a48a280a..3e457b5394 100644 --- a/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/internal/ReplicatorBehavior.scala +++ b/akka-cluster-typed/src/main/scala/akka/cluster/ddata/typed/internal/ReplicatorBehavior.scala @@ -71,7 +71,7 @@ import akka.util.Timeout Behaviors.same case cmd: JReplicator.Get[d] => - implicit val timeout = Timeout(cmd.consistency.timeout match { + implicit val timeout: Timeout = Timeout(cmd.consistency.timeout match { case java.time.Duration.ZERO => localAskTimeout case t => t.asScala + additionalAskTimeout }) @@ -99,7 +99,7 @@ import akka.util.Timeout Behaviors.same case cmd: JReplicator.Update[d] => - implicit val timeout = Timeout(cmd.writeConsistency.timeout match { + implicit val timeout: Timeout = Timeout(cmd.writeConsistency.timeout match { case java.time.Duration.ZERO => localAskTimeout case t => t.asScala + additionalAskTimeout }) @@ -166,7 +166,7 @@ import akka.util.Timeout Behaviors.same case cmd: JReplicator.Delete[d] => - implicit val timeout = Timeout(cmd.consistency.timeout match { + implicit val timeout: Timeout = Timeout(cmd.consistency.timeout match { case java.time.Duration.ZERO => localAskTimeout case t => t.asScala + additionalAskTimeout }) diff --git a/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionist.scala b/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionist.scala index 207c210270..1cf87d40cf 100644 --- a/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionist.scala +++ b/akka-cluster-typed/src/main/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionist.scala @@ -38,7 +38,7 @@ private[typed] final class ClusterReceptionist @InternalApi private[typed] object ClusterReceptionist extends ReceptionistBehaviorProvider { - type SubscriptionsKV[K <: AbstractServiceKey] = ActorRef[ReceptionistMessages.Listing[K#Protocol]] + import ClusterReceptionistProtocol.SubscriptionsKV type SubscriptionRegistry = TypedMultiMap[AbstractServiceKey, SubscriptionsKV] type DDataKey = ORMultiMapKey[ServiceKey[_], Entry] @@ -167,7 +167,7 @@ private[typed] object ClusterReceptionist extends ReceptionistBehaviorProvider { addTombstone(serviceInstance, key, tombstoneDeadline).copy(servicesPerActor = newServicesForActor) } - def removeSubscriber(subscriber: ActorRef[ReceptionistMessages.Listing[Any]]): ClusterReceptionist.State = + def removeSubscriber[T](subscriber: ActorRef[ReceptionistMessages.Listing[T]]): ClusterReceptionist.State = copy(subscriptions = subscriptions.valueRemoved(subscriber)) } @@ -591,7 +591,7 @@ private[typed] object ClusterReceptionist extends ReceptionistBehaviorProvider { // support two heterogeneous types of messages without union types case cmd: InternalCommand => onInternalCommand(cmd) case cmd: Command => onCommand(cmd) - case _ => Behaviors.unhandled + case null => Behaviors.unhandled } } } diff --git a/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/BasicClusterExampleTest.java b/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/BasicClusterExampleTest.java index d036fa5098..1b2ea998a6 100644 --- a/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/BasicClusterExampleTest.java +++ b/akka-cluster-typed/src/test/java/jdocs/akka/cluster/typed/BasicClusterExampleTest.java @@ -69,7 +69,7 @@ public class BasicClusterExampleTest { // extends JUnitSuite { // #prepare PrepareForFullClusterShutdown msg = - PrepareForFullClusterShutdown.prepareForFullClusterShutdown(); + PrepareForFullClusterShutdown$.MODULE$.prepareForFullClusterShutdown(); cluster2.manager().tell(msg); // #prepare diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/ddata/typed/scaladsl/ReplicatorCompileOnlyTest.scala b/akka-cluster-typed/src/test/scala/akka/cluster/ddata/typed/scaladsl/ReplicatorCompileOnlyTest.scala index 28efc66fe1..e82107626a 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/ddata/typed/scaladsl/ReplicatorCompileOnlyTest.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/ddata/typed/scaladsl/ReplicatorCompileOnlyTest.scala @@ -26,7 +26,7 @@ object ReplicatorCompileOnlyTest { import akka.actor.typed.scaladsl.AskPattern._ val replicator: ActorRef[Replicator.Command] = ??? - implicit val timeout = Timeout(3.seconds) + implicit val timeout: Timeout = Timeout(3.seconds) implicit val scheduler: Scheduler = ??? implicit val cluster: SelfUniqueAddress = ??? val key = GCounterKey("counter") diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteContextAskSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteContextAskSpec.scala index b9f4141e83..02573a66d9 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteContextAskSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/RemoteContextAskSpec.scala @@ -85,7 +85,7 @@ class RemoteContextAskSpec spawn(Behaviors.setup[AnyRef] { ctx => implicit val timeout: Timeout = 3.seconds - ctx.ask(remoteRef, Ping) { + ctx.ask(remoteRef, Ping.apply) { case Success(pong) => pong case Failure(ex) => ex } diff --git a/akka-cluster-typed/src/test/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionistStateSpec.scala b/akka-cluster-typed/src/test/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionistStateSpec.scala index a858abe070..97440efb81 100644 --- a/akka-cluster-typed/src/test/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionistStateSpec.scala +++ b/akka-cluster-typed/src/test/scala/akka/cluster/typed/internal/receptionist/ClusterReceptionistStateSpec.scala @@ -15,7 +15,7 @@ import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit import akka.actor.typed.internal.receptionist.AbstractServiceKey import akka.actor.typed.receptionist.ServiceKey import akka.cluster.UniqueAddress -import akka.cluster.typed.internal.receptionist.ClusterReceptionist.SubscriptionsKV +import akka.cluster.typed.internal.receptionist.ClusterReceptionistProtocol.SubscriptionsKV import akka.util.TypedMultiMap class ClusterReceptionistStateSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike with Matchers { diff --git a/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/BasicClusterExampleSpec.scala b/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/BasicClusterExampleSpec.scala index 20b565e9b2..0e7aa1e8ef 100644 --- a/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/BasicClusterExampleSpec.scala +++ b/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/BasicClusterExampleSpec.scala @@ -125,8 +125,10 @@ class BasicClusterConfigSpec extends AnyWordSpec with ScalaFutures with Eventual akka.cluster.seed-nodes = [ "akka://ClusterSystem@127.0.0.1:$sys1Port", "akka://ClusterSystem@127.0.0.1:$sys2Port" ] """) - val system1 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", config(sys1Port).withFallback(configSystem1)) - val system2 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", config(sys2Port).withFallback(configSystem2)) + val system1 = + ActorSystem[Nothing](Behaviors.empty[Nothing], "ClusterSystem", config(sys1Port).withFallback(configSystem1)) + val system2 = + ActorSystem[Nothing](Behaviors.empty[Nothing], "ClusterSystem", config(sys2Port).withFallback(configSystem2)) try { Cluster(system1) Cluster(system2) @@ -173,8 +175,8 @@ class BasicClusterManualSpec extends AnyWordSpec with ScalaFutures with Eventual "Cluster API" must { "init cluster" in { - val system = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) - val system2 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) + val system = ActorSystem[Nothing](Behaviors.empty[Nothing], "ClusterSystem", noPort.withFallback(clusterConfig)) + val system2 = ActorSystem[Nothing](Behaviors.empty[Nothing], "ClusterSystem", noPort.withFallback(clusterConfig)) try { //#cluster-create @@ -207,9 +209,10 @@ class BasicClusterManualSpec extends AnyWordSpec with ScalaFutures with Eventual } "subscribe to cluster events" in { - implicit val system1 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) - val system2 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) - val system3 = ActorSystem[Nothing](Behaviors.empty, "ClusterSystem", noPort.withFallback(clusterConfig)) + implicit val system1 = + ActorSystem[Nothing](Behaviors.empty[Nothing], "ClusterSystem", noPort.withFallback(clusterConfig)) + val system2 = ActorSystem[Nothing](Behaviors.empty[Nothing], "ClusterSystem", noPort.withFallback(clusterConfig)) + val system3 = ActorSystem[Nothing](Behaviors.empty[Nothing], "ClusterSystem", noPort.withFallback(clusterConfig)) try { val cluster1 = Cluster(system1) diff --git a/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/ReceptionistExample.scala b/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/ReceptionistExample.scala index f78a1c128d..cb54653927 100644 --- a/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/ReceptionistExample.scala +++ b/akka-cluster-typed/src/test/scala/docs/akka/cluster/typed/ReceptionistExample.scala @@ -77,7 +77,7 @@ object PingPongExample { def apply(): Behavior[Command] = { Behaviors.setup[Command] { context => - val listingResponseAdapter = context.messageAdapter[Receptionist.Listing](ListingResponse) + val listingResponseAdapter = context.messageAdapter[Receptionist.Listing](ListingResponse.apply) context.spawnAnonymous(PingService())