scala3: remove runtime trait ordering check (#30904)

This commit is contained in:
Arnout Engelen 2021-11-18 14:44:43 +01:00 committed by GitHub
parent a8c67fc2e6
commit 9b174a31a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 11 deletions

View file

@ -21,7 +21,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 akka-cluster-tools/test akka-cluster-typed/test akka-distributed-data/test akka-cluster-metrics/test akka-cluster-sharding/Test/compile akka-cluster-sharding-typed/test
- akka-cluster/test akka-cluster-tools/test akka-cluster-typed/test akka-distributed-data/test akka-cluster-metrics/test akka-cluster-sharding/test akka-cluster-sharding-typed/test
- akka-discovery/test akka-coordination/test
- akka-persistence/test akka-persistence-shared/test akka-persistence-query/test akka-persistence-typed/test akka-persistence-testkit/test
- akka-pki/test akka-slf4j/test

View file

@ -0,0 +1,24 @@
/*
* Copyright (C) 2021 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.persistence
import akka.annotation.InternalApi
/**
* INTERNAL API
*/
@InternalApi
private[persistence] object TraitOrder {
val canBeChecked = true
def checkBefore(clazz: Class[_], one: Class[_], other: Class[_]): Unit = {
val interfaces = clazz.getInterfaces
val i = interfaces.indexOf(other)
val j = interfaces.indexOf(one)
if (i != -1 && j != -1 && i < j)
throw new IllegalStateException(
s"For ${clazz.getName}, use ${one.getName} with ${other.getName}, instead of ${other.getName} with ${one.getName}")
}
}

View file

@ -0,0 +1,19 @@
/*
* Copyright (C) 2021 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.persistence
import akka.annotation.InternalApi
/**
* INTERNAL API
*/
@InternalApi
private[persistence] object TraitOrder {
val canBeChecked = false
// No-op on Scala 3
def checkBefore(clazz: Class[_], one: Class[_], other: Class[_]): Unit =
()
}

View file

@ -58,13 +58,7 @@ private[persistence] trait Eventsourced
import JournalProtocol._
import SnapshotProtocol.{ LoadSnapshotFailed, LoadSnapshotResult }
{
val interfaces = getClass.getInterfaces
val i = interfaces.indexOf(classOf[PersistentActor])
val j = interfaces.indexOf(classOf[akka.actor.Timers])
if (i != -1 && j != -1 && i < j)
throw new IllegalStateException("use Timers with PersistentActor, instead of PersistentActor with Timers")
}
TraitOrder.checkBefore(getClass, classOf[akka.actor.Timers], classOf[PersistentActor])
private val extension = Persistence(context.system)

View file

@ -101,9 +101,11 @@ class TimerPersistentActorSpec extends PersistenceSpec(ConfigFactory.parseString
}
"reject wrong order of traits, PersistentActor with Timer" in {
val pa = system.actorOf(Props[WrongOrder]())
watch(pa)
expectTerminated(pa)
if (TraitOrder.canBeChecked) {
val pa = system.actorOf(Props[WrongOrder]())
watch(pa)
expectTerminated(pa)
}
}
"handle AutoReceivedMessage's automatically" in {