Skip to content

Commit

Permalink
Remove akka typed actor system implementation
Browse files Browse the repository at this point in the history
The end goal for akka is to have a new runtime that can be optomoized
for typed actors. However to get the API production ready so it can
start getting adopted  it has been decided to only have adapted actor
systems initially.

Further discussion here: akka#24149
  • Loading branch information
chbatey committed Dec 18, 2017
1 parent f7b3b48 commit c394ee7
Show file tree
Hide file tree
Showing 44 changed files with 194 additions and 2,810 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import static junit.framework.TestCase.assertSame;
import static org.junit.Assert.assertTrue;

public class ExtensionsTest extends JUnitSuite {

class ExtensionsTest extends JUnitSuite {

public static class MyExtImpl implements Extension {
}
Expand Down Expand Up @@ -46,7 +45,7 @@ public void loadJavaExtensionsFromConfig() {
Behavior.empty(),
"loadJavaExtensionsFromConfig",
Optional.empty(),
Optional.of(ConfigFactory.parseString("akka.typed.extensions += \"akka.actor.typed.ExtensionsTest$MyExtension\"").resolve()),
Optional.of(ConfigFactory.parseString("akka.typed.extensions += \"akka.typed.ExtensionsTest$MyExtension\"").resolve()),
Optional.empty(),
Optional.empty()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ class ActorContextSpec extends TypedSpec(ConfigFactory.parseString(

implicit def system: ActorSystem[TypedSpec.Command]

private def mySuite: String =
if (system eq nativeSystem) suite + "Native"
else suite + "Adapted"
private def mySuite: String = suite + "Adapted"

def setup(name: String, wrapper: Option[Behavior[Command] Behavior[Command]] = None, ignorePostStop: Boolean = true)(
proc: (scaladsl.ActorContext[Event], StepWise.Steps[Event, ActorRef[Command]]) StepWise.Steps[Event, _]): Future[TypedSpec.Status] =
Expand Down Expand Up @@ -635,7 +633,6 @@ class ActorContextSpec extends TypedSpec(ConfigFactory.parseString(
override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] =
subject(ctx.self, ignorePostStop)
}
object `An ActorContext (native)` extends Normal with NativeSystem
object `An ActorContext (adapted)` extends Normal with AdaptedSystem

trait Widened extends Tests {
Expand All @@ -644,31 +641,26 @@ class ActorContextSpec extends TypedSpec(ConfigFactory.parseString(
override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] =
subject(ctx.self, ignorePostStop).widen { case x x }
}
object `An ActorContext with widened Behavior (native)` extends Widened with NativeSystem
object `An ActorContext with widened Behavior (adapted)` extends Widened with AdaptedSystem

trait Deferred extends Tests {
override def suite = "deferred"
override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] =
Actor.deferred(_ subject(ctx.self, ignorePostStop))
}
object `An ActorContext with deferred Behavior (native)` extends Deferred with NativeSystem
object `An ActorContext with deferred Behavior (adapted)` extends Deferred with AdaptedSystem

trait NestedDeferred extends Tests {
override def suite = "deferred"
override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] =
Actor.deferred(_ Actor.deferred(_ subject(ctx.self, ignorePostStop)))
}
object `An ActorContext with nested deferred Behavior (native)` extends NestedDeferred with NativeSystem
object `An ActorContext with nested deferred Behavior (adapted)` extends NestedDeferred with AdaptedSystem

trait Tap extends Tests {
override def suite = "tap"
override def behavior(ctx: scaladsl.ActorContext[Event], ignorePostStop: Boolean): Behavior[Command] =
Actor.tap((_, _) (), (_, _) (), subject(ctx.self, ignorePostStop))
}
object `An ActorContext with Tap (old-native)` extends Tap with NativeSystem
object `An ActorContext with Tap (old-adapted)` extends Tap with AdaptedSystem

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class AskSpec extends TypedSpec with ScalaFutures {
}
}

object `Ask pattern (native)` extends Common with NativeSystem

object `Ask pattern (adapted)` extends Common with AdaptedSystem {

import AskSpec._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ class BehaviorSpec extends TypedSpec {
trait FullBehavior extends Messages with BecomeWithLifecycle with Stoppable {
override def behavior(monitor: ActorRef[Event]): (Behavior[Command], Aux) = mkFull(monitor) null
}
object `A Full Behavior (native)` extends FullBehavior with NativeSystem
object `A Full Behavior (adapted)` extends FullBehavior with AdaptedSystem

trait ImmutableBehavior extends Messages with BecomeWithLifecycle with Stoppable {
Expand Down Expand Up @@ -320,7 +319,6 @@ class BehaviorSpec extends TypedSpec {
}
}
}
object `A immutable Behavior (native)` extends ImmutableBehavior with NativeSystem
object `A immutable Behavior (adapted)` extends ImmutableBehavior with AdaptedSystem

trait ImmutableWithSignalScalaBehavior extends Messages with BecomeWithLifecycle with Stoppable {
Expand Down Expand Up @@ -356,7 +354,6 @@ class BehaviorSpec extends TypedSpec {
SActor.same
}
}
object `A ImmutableWithSignal Behavior (scala,native)` extends ImmutableWithSignalScalaBehavior with NativeSystem
object `A ImmutableWithSignal Behavior (scala,adapted)` extends ImmutableWithSignalScalaBehavior with AdaptedSystem

trait ImmutableScalaBehavior extends Messages with Become with Stoppable {
Expand Down Expand Up @@ -387,7 +384,6 @@ class BehaviorSpec extends TypedSpec {
}
}
}
object `A immutable Behavior (scala,native)` extends ImmutableScalaBehavior with NativeSystem
object `A immutable Behavior (scala,adapted)` extends ImmutableScalaBehavior with AdaptedSystem

trait MutableScalaBehavior extends Messages with Become with Stoppable {
Expand Down Expand Up @@ -425,7 +421,6 @@ class BehaviorSpec extends TypedSpec {
}
}
}
object `A mutable Behavior (scala,native)` extends MutableScalaBehavior with NativeSystem
object `A mutable Behavior (scala,adapted)` extends MutableScalaBehavior with AdaptedSystem

trait WidenedScalaBehavior extends ImmutableWithSignalScalaBehavior with Reuse with Siphon {
Expand All @@ -436,7 +431,6 @@ class BehaviorSpec extends TypedSpec {
super.behavior(monitor)._1.widen[Command] { case c inbox.ref ! c; c } inbox
}
}
object `A widened Behavior (scala,native)` extends WidenedScalaBehavior with NativeSystem
object `A widened Behavior (scala,adapted)` extends WidenedScalaBehavior with AdaptedSystem

trait DeferredScalaBehavior extends ImmutableWithSignalScalaBehavior {
Expand All @@ -453,7 +447,6 @@ class BehaviorSpec extends TypedSpec {
override def checkAux(signal: Signal, aux: Aux): Unit =
aux.receiveAll() should ===(Done :: Nil)
}
object `A deferred Behavior (scala,native)` extends DeferredScalaBehavior with NativeSystem
object `A deferred Behavior (scala,adapted)` extends DeferredScalaBehavior with AdaptedSystem

trait TapScalaBehavior extends ImmutableWithSignalScalaBehavior with Reuse with SignalSiphon {
Expand All @@ -462,15 +455,13 @@ class BehaviorSpec extends TypedSpec {
(SActor.tap((_, msg) inbox.ref ! Right(msg), (_, sig) inbox.ref ! Left(sig), super.behavior(monitor)._1), inbox)
}
}
object `A tap Behavior (scala,native)` extends TapScalaBehavior with NativeSystem
object `A tap Behavior (scala,adapted)` extends TapScalaBehavior with AdaptedSystem

trait RestarterScalaBehavior extends ImmutableWithSignalScalaBehavior with Reuse {
override def behavior(monitor: ActorRef[Event]): (Behavior[Command], Aux) = {
SActor.supervise(super.behavior(monitor)._1).onFailure(SupervisorStrategy.restart) null
}
}
object `A restarter Behavior (scala,native)` extends RestarterScalaBehavior with NativeSystem
object `A restarter Behavior (scala,adapted)` extends RestarterScalaBehavior with AdaptedSystem

/*
Expand Down Expand Up @@ -536,7 +527,6 @@ class BehaviorSpec extends TypedSpec {
SActor.same
}))
}
object `A ImmutableWithSignal Behavior (java,native)` extends ImmutableWithSignalJavaBehavior with NativeSystem
object `A ImmutableWithSignal Behavior (java,adapted)` extends ImmutableWithSignalJavaBehavior with AdaptedSystem

trait ImmutableJavaBehavior extends Messages with Become with Stoppable {
Expand Down Expand Up @@ -568,7 +558,6 @@ class BehaviorSpec extends TypedSpec {
})
}
}
object `A immutable Behavior (java,native)` extends ImmutableJavaBehavior with NativeSystem
object `A immutable Behavior (java,adapted)` extends ImmutableJavaBehavior with AdaptedSystem

trait WidenedJavaBehavior extends ImmutableWithSignalJavaBehavior with Reuse with Siphon {
Expand All @@ -577,7 +566,6 @@ class BehaviorSpec extends TypedSpec {
JActor.widened(super.behavior(monitor)._1, pf(_.`match`(classOf[Command], fi(x { inbox.ref ! x; x })))) inbox
}
}
object `A widened Behavior (java,native)` extends WidenedJavaBehavior with NativeSystem
object `A widened Behavior (java,adapted)` extends WidenedJavaBehavior with AdaptedSystem

trait DeferredJavaBehavior extends ImmutableWithSignalJavaBehavior {
Expand All @@ -594,7 +582,6 @@ class BehaviorSpec extends TypedSpec {
override def checkAux(signal: Signal, aux: Aux): Unit =
aux.receiveAll() should ===(Done :: Nil)
}
object `A deferred Behavior (java,native)` extends DeferredJavaBehavior with NativeSystem
object `A deferred Behavior (java,adapted)` extends DeferredJavaBehavior with AdaptedSystem

trait TapJavaBehavior extends ImmutableWithSignalJavaBehavior with Reuse with SignalSiphon {
Expand All @@ -606,7 +593,6 @@ class BehaviorSpec extends TypedSpec {
super.behavior(monitor)._1), inbox)
}
}
object `A tap Behavior (java,native)` extends TapJavaBehavior with NativeSystem
object `A tap Behavior (java,adapted)` extends TapJavaBehavior with AdaptedSystem

trait RestarterJavaBehavior extends ImmutableWithSignalJavaBehavior with Reuse {
Expand All @@ -615,7 +601,6 @@ class BehaviorSpec extends TypedSpec {
.onFailure(classOf[Exception], SupervisorStrategy.restart) null
}
}
object `A restarter Behavior (java,native)` extends RestarterJavaBehavior with NativeSystem
object `A restarter Behavior (java,adapted)` extends RestarterJavaBehavior with AdaptedSystem

}
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ class DeferredSpec extends TypedSpec {

}

object `A DeferredBehavior (stubbed, native)` extends StubbedTests with NativeSystem
object `A DeferredBehavior (stubbed, adapted)` extends StubbedTests with AdaptedSystem

object `A DeferredBehavior (real, native)` extends RealTests with NativeSystem
object `A DeferredBehavior (real, adapted)` extends RealTests with AdaptedSystem

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class ExtensionsSpec extends TypedSpecSetup {
akka.typed.extensions = ["akka.actor.typed.FailingToLoadExtension$"]
""")))
}

intercept[RuntimeException] {
create()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PerformanceSpec extends TypedSpec(
}
}

val iterations = nativeSystem.settings.config.getInt("akka.actor.typed.PerformanceSpec.iterations")
val iterations = system.settings.config.getInt("akka.actor.typed.PerformanceSpec.iterations")

trait CommonTests {
implicit def system: ActorSystem[TypedSpec.Command]
Expand All @@ -78,8 +78,6 @@ class PerformanceSpec extends TypedSpec(
def `09 when using 8 pairs with 10 messages`(): Unit = sync(runTest("09")(behavior(8, 10, iterations, "dispatcher-8")))
}

object `must be fast with native ActorSystem` extends CommonTests with NativeSystem
object `must be fast with ActorSystemAdapter` extends CommonTests with AdaptedSystem
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,16 @@ package akka.actor.typed

class PropsSpec extends TypedSpecSetup {

val dispatcherFirst = DispatcherDefault(MailboxCapacity(666, DispatcherFromConfig("pool")))
val mailboxFirst = MailboxCapacity(999) withNext dispatcherFirst
val dispatcherFirst = DispatcherDefault(DispatcherFromConfig("pool"))

object `A Props` {

def `must get first dispatcher`(): Unit = {
dispatcherFirst.firstOrElse[DispatcherSelector](null) should ===(dispatcherFirst)
mailboxFirst.firstOrElse[DispatcherSelector](null) should ===(dispatcherFirst)
}

def `must get first mailbox`(): Unit = {
dispatcherFirst.firstOrElse[MailboxCapacity](null).capacity should ===(666)
mailboxFirst.firstOrElse[MailboxCapacity](null).capacity should ===(999)
}

def `must get default value`(): Unit = {
mailboxFirst.firstOrElse[DispatcherFromExecutor](null) should ===(null)
}

def `must filter out the right things`(): Unit = {
val filtered = mailboxFirst.filterNot[DispatcherSelector]
filtered.firstOrElse[MailboxCapacity](null).capacity should ===(999)
filtered.firstOrElse[DispatcherSelector](null) should ===(null)
}

def `must yield all configs of some type`(): Unit = {
dispatcherFirst.allOf[DispatcherSelector] should ===(DispatcherSelector.default() :: DispatcherSelector.fromConfig("pool") :: Nil)
mailboxFirst.allOf[MailboxCapacity] should ===(List(999, 666).map(MailboxCapacity(_)))
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,7 @@ class RestarterSpec extends TypedSpec {

}

object `A restarter (stubbed, native)` extends StubbedTests with NativeSystem
object `A restarter (stubbed, adapted)` extends StubbedTests with AdaptedSystem

object `A restarter (real, native)` extends RealTests with NativeSystem
object `A restarter (real, adapted)` extends RealTests with AdaptedSystem

}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,5 @@ class TimerSpec extends TypedSpec("""
}
}

object `A Restarter (real, native)` extends RealTests with NativeSystem
object `A Restarter (real, adapted)` extends RealTests with AdaptedSystem

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TypedSpecSetup extends RefSpec with Matchers with BeforeAndAfterAll with S
* Helper class for writing tests against both ActorSystemImpl and ActorSystemAdapter.
*/
abstract class TypedSpec(val config: Config) extends TypedSpecSetup {

import TypedSpec._
import AskPattern._

Expand All @@ -58,16 +59,8 @@ abstract class TypedSpec(val config: Config) extends TypedSpecSetup {
// extension point
def setTimeout: Timeout = Timeout(1.minute)

private var nativeSystemUsed = false
lazy val nativeSystem: ActorSystem[TypedSpec.Command] = {
val sys = ActorSystem(guardian(), AkkaSpec.getCallerName(classOf[TypedSpec]), config = Some(config withFallback AkkaSpec.testConf))
nativeSystemUsed = true
sys
}
private var adaptedSystemUsed = false
lazy val system: ActorSystem[TypedSpec.Command] = {
val sys = ActorSystem.adapter(AkkaSpec.getCallerName(classOf[TypedSpec]), guardian(), config = Some(config withFallback AkkaSpec.testConf))
adaptedSystemUsed = true
val sys = ActorSystem(guardian(), AkkaSpec.getCallerName(classOf[TypedSpec]), config = Some(config withFallback AkkaSpec.testConf))
sys
}

Expand All @@ -85,33 +78,27 @@ abstract class TypedSpec(val config: Config) extends TypedSpecSetup {
}
}

trait NativeSystem {
def system: ActorSystem[TypedSpec.Command] = nativeSystem
}

trait AdaptedSystem {
def system: ActorSystem[TypedSpec.Command] = TypedSpec.this.system
}

implicit val timeout = setTimeout
implicit def scheduler = nativeSystem.scheduler
implicit def scheduler = system.scheduler

lazy val blackhole = await(system ? Create(immutable[Any] { case _ same }, "blackhole"))

override def afterAll(): Unit = {
if (nativeSystemUsed)
Await.result(nativeSystem.terminate, timeout.duration)
if (adaptedSystemUsed)
Await.result(system.terminate, timeout.duration)
Await.result(system.terminate, timeout.duration)
}

// TODO remove after basing on ScalaTest 3 with async support
import akka.testkit._
def await[T](f: Future[T]): T = Await.result(f, timeout.duration * 1.1)

lazy val blackhole = await(nativeSystem ? Create(immutable[Any] { case _ same }, "blackhole"))
def await[T](f: Future[T]): T = Await.result(f, timeout.duration * 1.1)

/**
* Run an Actor-based test. The test procedure is most conveniently
* formulated using the [[StepWise$]] behavior type.
* formulated using the [[StepWise]] behavior type.
*/
def runTest[T: ClassTag](name: String)(behavior: Behavior[T])(implicit system: ActorSystem[Command]): Future[Status] =
system ? (RunTest(name, behavior, _, timeout.duration))
Expand Down Expand Up @@ -176,6 +163,7 @@ abstract class TypedSpec(val config: Config) extends TypedSpecSetup {
}

object TypedSpec {

import akka.{ typed t }

sealed abstract class Start
Expand Down Expand Up @@ -246,7 +234,6 @@ class TypedSpecSpec extends TypedSpec {
}
}

object `when using the native implementation` extends CommonTests with NativeSystem
object `when using the adapted implementation` extends CommonTests with AdaptedSystem
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ class WatchSpec extends TypedSpec {
}
}

object `Actor monitoring (native)` extends Tests with NativeSystem
object `Actor monitoring (adapted)` extends Tests with AdaptedSystem
}
Loading

0 comments on commit c394ee7

Please sign in to comment.