Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of the toClassic adapters for typed #27650

Merged
merged 2 commits into from Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -60,15 +60,15 @@ static Behavior<String> create(akka.actor.ActorRef ref, akka.actor.ActorRef prob

Behavior<String> onMessage(ActorContext<String> context, String message) {
if (message.equals("send")) {
akka.actor.ActorRef replyTo = Adapter.toUntyped(context.getSelf());
akka.actor.ActorRef replyTo = Adapter.toClassic(context.getSelf());
ref.tell("ping", replyTo);
return same();
} else if (message.equals("pong")) {
probe.tell("ok", akka.actor.ActorRef.noSender());
return same();
} else if (message.equals("actorOf")) {
akka.actor.ActorRef child = Adapter.actorOf(context, untyped1());
child.tell("ping", Adapter.toUntyped(context.getSelf()));
child.tell("ping", Adapter.toClassic(context.getSelf()));
return same();
} else if (message.equals("watch")) {
Adapter.watch(context, ref);
Expand All @@ -77,8 +77,8 @@ Behavior<String> onMessage(ActorContext<String> context, String message) {
// restart is the default, otherwise an intermediate is required
akka.actor.ActorRef child = Adapter.actorOf(context, untyped1());
Adapter.watch(context, child);
child.tell(new ThrowIt3(), Adapter.toUntyped(context.getSelf()));
child.tell("ping", Adapter.toUntyped(context.getSelf()));
child.tell(new ThrowIt3(), Adapter.toClassic(context.getSelf()));
child.tell("ping", Adapter.toClassic(context.getSelf()));
return same();
} else if (message.equals("stop-child")) {
akka.actor.ActorRef child = Adapter.actorOf(context, untyped1());
Expand Down Expand Up @@ -246,7 +246,7 @@ static akka.actor.Props typed2Props() {
private final ActorSystem system = actorSystemResource.getSystem();

@Test
public void shouldSendMessageFromTypedToUntyped() {
public void shouldSendMessageFromTypedtoClassic() {
TestKit probe = new TestKit(system);
akka.actor.ActorRef untypedRef = system.actorOf(untyped1());
ActorRef<String> typedRef =
Expand Down
Expand Up @@ -26,7 +26,7 @@ public void testBubblingSample() throws Exception {
"akka.loggers = [ akka.testkit.TestEventListener ]\n" + "akka.loglevel=warning"));

// actual exception and then the deathpacts
new EventFilter(Exception.class, ActorSystemAdapter.toUntyped(system))
new EventFilter(Exception.class, ActorSystemAdapter.toClassic(system))
.occurrences(4)
.intercept(
() -> {
Expand Down
Expand Up @@ -45,7 +45,7 @@ public static Behavior<Command> behavior() {
Adapter.watch(context, second);

second.tell(
new Typed.Ping(context.getSelf().narrow()), Adapter.toUntyped(context.getSelf()));
new Typed.Ping(context.getSelf().narrow()), Adapter.toClassic(context.getSelf()));

return akka.actor.typed.javadsl.Behaviors.receive(Typed.Command.class)
.onMessage(
Expand Down Expand Up @@ -87,8 +87,8 @@ public void testItWorks() {
ActorRef<Typed.Command> typed = Adapter.spawn(as, Typed.behavior(), "Typed");
// #create
TestProbe probe = new TestProbe(as);
probe.watch(Adapter.toUntyped(typed));
probe.expectTerminated(Adapter.toUntyped(typed), Duration.create(1, "second"));
probe.watch(Adapter.toClassic(typed));
probe.expectTerminated(Adapter.toClassic(typed), Duration.create(1, "second"));
TestKit.shutdownActorSystem(as);
}
}
Expand Up @@ -69,7 +69,7 @@ abstract class ActorContextSpec extends ScalaTestWithActorTestKit("""

// FIXME #24348: eventfilter support in typed testkit
import scaladsl.adapter._
implicit val untypedSystem = system.toUntyped
implicit val untypedSystem = system.toClassic

import ActorSpecMessages._

Expand Down
Expand Up @@ -36,7 +36,7 @@ class AskSpec extends ScalaTestWithActorTestKit("""

// FIXME #24348: eventfilter support in typed testkit
import scaladsl.adapter._
implicit val untypedSystem = system.toUntyped
implicit val untypedSystem = system.toClassic

implicit def executor: ExecutionContext =
system.executionContext
Expand Down Expand Up @@ -175,7 +175,7 @@ class AskSpec extends ScalaTestWithActorTestKit("""
EventFilter[RuntimeException](message = "Exception thrown out of adapter. Stopping myself.", occurrences = 1)
.intercept {
replyRef2 ! 42L
}(system.toUntyped)
}(system.toClassic)

probe.expectTerminated(ref, probe.remainingOrDefault)
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ class DeferredSpec extends ScalaTestWithActorTestKit("""

// FIXME #24348: eventfilter support in typed testkit
import scaladsl.adapter._
implicit val untypedSystem = system.toUntyped
implicit val untypedSystem = system.toClassic

"Deferred behavior" must {
"must create underlying" in {
Expand Down
Expand Up @@ -48,7 +48,7 @@ class InterceptSpec extends ScalaTestWithActorTestKit("""

// FIXME #24348: eventfilter support in typed testkit
import scaladsl.adapter._
implicit val untypedSystem = system.toUntyped
implicit val untypedSystem = system.toClassic

private def snitchingInterceptor(probe: ActorRef[String]) = new BehaviorInterceptor[String, String] {
override def aroundReceive(
Expand Down
Expand Up @@ -17,7 +17,7 @@ class LogMessagesSpec extends ScalaTestWithActorTestKit("""
akka.loggers = ["akka.testkit.TestEventListener"]
""") with WordSpecLike {

implicit val untyped: actor.ActorSystem = system.toUntyped
implicit val untyped: actor.ActorSystem = system.toClassic

"The log messages behavior" should {

Expand Down
Expand Up @@ -88,7 +88,7 @@ class OrElseSpec extends ScalaTestWithActorTestKit("""

import OrElseStubbedSpec._

implicit val untyped: actor.ActorSystem = system.toUntyped
implicit val untyped: actor.ActorSystem = system.toClassic

"Behavior.orElse" must {
"work for deferred behavior on the left" in {
Expand Down
Expand Up @@ -258,7 +258,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
// FIXME #24348: eventfilter support in typed testkit
import akka.actor.typed.scaladsl.adapter._

implicit val untypedSystem = system.toUntyped
implicit val untypedSystem = system.toClassic

class FailingConstructorTestSetup(failCount: Int) {
val failCounter = new AtomicInteger(0)
Expand Down Expand Up @@ -779,7 +779,7 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
.onFailure[Exception](strategy)

val droppedMessagesProbe = TestProbe[Dropped]()
system.toUntyped.eventStream.subscribe(droppedMessagesProbe.ref.toUntyped, classOf[Dropped])
system.toClassic.eventStream.subscribe(droppedMessagesProbe.ref.toClassic, classOf[Dropped])
val ref = spawn(behv)
EventFilter[Exc1](occurrences = 1).intercept {
startedProbe.expectMessage(Started)
Expand Down
Expand Up @@ -25,7 +25,7 @@ class TimerSpec extends ScalaTestWithActorTestKit("""

// FIXME #24348: eventfilter support in typed testkit
import scaladsl.adapter._
implicit val untypedSystem = system.toUntyped
implicit val untypedSystem = system.toClassic

sealed trait Command
case class Tick(n: Int) extends Command
Expand Down Expand Up @@ -313,7 +313,7 @@ class TimerSpec extends ScalaTestWithActorTestKit("""
ref ! "stop"
}
probe.expectTerminated(ref)
system.toUntyped.eventStream.subscribe(probe.ref.toUntyped, classOf[DeadLetter])
system.toClassic.eventStream.subscribe(probe.ref.toClassic, classOf[DeadLetter])
probe.expectNoMessage(1.second)
}
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ object WatchSpec {

class WatchSpec extends ScalaTestWithActorTestKit(WatchSpec.config) with WordSpecLike {

implicit def untypedSystem = system.toUntyped
implicit def untypedSystem = system.toClassic

import WatchSpec._

Expand Down
Expand Up @@ -20,7 +20,7 @@ class WidenSpec extends ScalaTestWithActorTestKit("""
akka.loggers = [akka.testkit.TestEventListener]
""") with WordSpecLike {

implicit val untypedSystem = system.toUntyped
implicit val untypedSystem = system.toClassic

def intToString(probe: ActorRef[String]): Behavior[Int] = {
Behaviors
Expand Down
Expand Up @@ -59,28 +59,28 @@ class UntypedSupervisingTypedSpec extends AkkaSpec with ImplicitSender {
"default to stop for supervision" in {
val probe = TestProbe()
val underTest = system.spawn(ProbedBehavior.behavior(probe.ref), "a1")
watch(underTest.toUntyped)
watch(underTest.toClassic)
underTest ! "throw"
probe.expectMsg(PostStop)
probe.expectNoMessage(smallDuration)
expectTerminated(underTest.toUntyped)
expectTerminated(underTest.toClassic)
}

"default to stop for supervision for spawn anonymous" in {
val probe = TestProbe()
val underTest = system.spawnAnonymous(ProbedBehavior.behavior(probe.ref))
watch(underTest.toUntyped)
watch(underTest.toClassic)
underTest ! "throw"
probe.expectMsg(PostStop)
probe.expectNoMessage(smallDuration)
expectTerminated(underTest.toUntyped)
expectTerminated(underTest.toClassic)
}

"allows overriding the default" in {
val probe = TestProbe()
val value = Behaviors.supervise(ProbedBehavior.behavior(probe.ref)).onFailure(SupervisorStrategy.restart)
val underTest = system.spawn(value, "a2")
watch(underTest.toUntyped)
watch(underTest.toClassic)
underTest ! "throw"
probe.expectMsg(PreRestart)
probe.expectNoMessage(smallDuration)
Expand All @@ -92,11 +92,11 @@ class UntypedSupervisingTypedSpec extends AkkaSpec with ImplicitSender {
val probe = TestProbe()
untyped ! SpawnFromUntyped(ProbedBehavior.behavior(probe.ref), "a3")
val underTest = expectMsgType[TypedSpawnedFromUntypedConext].actorRef
watch(underTest.toUntyped)
watch(underTest.toClassic)
underTest ! "throw"
probe.expectMsg(PostStop)
probe.expectNoMessage(smallDuration)
expectTerminated(underTest.toUntyped)
expectTerminated(underTest.toClassic)
}

"allow overriding the default (from context)" in {
Expand All @@ -105,7 +105,7 @@ class UntypedSupervisingTypedSpec extends AkkaSpec with ImplicitSender {
val behavior = Behaviors.supervise(ProbedBehavior.behavior(probe.ref)).onFailure(SupervisorStrategy.restart)
untyped ! SpawnFromUntyped(behavior, "a4")
val underTest = expectMsgType[TypedSpawnedFromUntypedConext].actorRef
watch(underTest.toUntyped)
watch(underTest.toClassic)
underTest ! "throw"
probe.expectMsg(PreRestart)
probe.expectNoMessage(smallDuration)
Expand All @@ -117,11 +117,11 @@ class UntypedSupervisingTypedSpec extends AkkaSpec with ImplicitSender {
val probe = TestProbe()
untyped ! SpawnAnonFromUntyped(ProbedBehavior.behavior(probe.ref))
val underTest = expectMsgType[TypedSpawnedFromUntypedConext].actorRef
watch(underTest.toUntyped)
watch(underTest.toClassic)
underTest ! "throw"
probe.expectMsg(PostStop)
probe.expectNoMessage(smallDuration)
expectTerminated(underTest.toUntyped)
expectTerminated(underTest.toClassic)
}

}
Expand Down
Expand Up @@ -27,7 +27,7 @@ object ActorRefSerializationSpec {

class ActorRefSerializationSpec extends ScalaTestWithActorTestKit(ActorRefSerializationSpec.config) with WordSpecLike {

val serialization = SerializationExtension(system.toUntyped)
val serialization = SerializationExtension(system.toClassic)

"ActorRef[T]" must {
"be serialized and deserialized by MiscMessageSerializer" in {
Expand Down
Expand Up @@ -15,7 +15,7 @@ class ServiceKeySerializationSpec
extends ScalaTestWithActorTestKit(ActorRefSerializationSpec.config)
with WordSpecLike {

val serialization = SerializationExtension(system.toUntyped)
val serialization = SerializationExtension(system.toClassic)

"ServiceKey[T]" must {
"be serialized and deserialized by ServiceKeySerializer" in {
Expand Down
Expand Up @@ -33,7 +33,7 @@ object ActorContextAskSpec {

class ActorContextAskSpec extends ScalaTestWithActorTestKit(ActorContextAskSpec.config) with WordSpecLike {

implicit val untyped = system.toUntyped // FIXME #24348: eventfilter support in typed testkit
implicit val untyped = system.toClassic // FIXME #24348: eventfilter support in typed testkit

"The Scala DSL ActorContext" must {

Expand Down
Expand Up @@ -48,7 +48,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit("""
val marker = LogMarker("marker")
val cause = new TestException("böö")

implicit val untyped = system.toUntyped
implicit val untyped = system.toClassic

"Logging in a typed actor" must {

Expand Down
Expand Up @@ -33,7 +33,7 @@ object MessageAdapterSpec {

class MessageAdapterSpec extends ScalaTestWithActorTestKit(MessageAdapterSpec.config) with WordSpecLike {

implicit val untyped = system.toUntyped // FIXME #24348: eventfilter support in typed testkit
implicit val untyped = system.toClassic // FIXME #24348: eventfilter support in typed testkit

"Message adapters" must {

Expand Down
Expand Up @@ -22,7 +22,7 @@ class RoutersSpec extends ScalaTestWithActorTestKit("""
""") with WordSpecLike with Matchers {

// needed for the event filter
implicit val untypedSystem = system.toUntyped
implicit val untypedSystem = system.toClassic

def compileOnlyApiCoverage(): Unit = {
Routers.group(ServiceKey[String]("key")).withRandomRouting().withRoundRobinRouting()
Expand Down Expand Up @@ -151,7 +151,7 @@ class RoutersSpec extends ScalaTestWithActorTestKit("""
val serviceKey = ServiceKey[String]("group-routing-2")
val group = spawn(Routers.group(serviceKey), "group-router-2")
val probe = TestProbe[DeadLetter]()
system.toUntyped.eventStream.subscribe(probe.ref.toUntyped, classOf[DeadLetter])
system.toClassic.eventStream.subscribe(probe.ref.toClassic, classOf[DeadLetter])

(0 to 3).foreach { n =>
val msg = s"message-$n"
Expand Down
Expand Up @@ -257,7 +257,7 @@ class UnstashingSpec extends ScalaTestWithActorTestKit("""
// needed for EventFilter
private implicit val untypedSys: akka.actor.ActorSystem = {
import akka.actor.typed.scaladsl.adapter._
system.toUntyped
system.toClassic
}

private def slowStoppingChild(latch: CountDownLatch): Behavior[String] =
Expand Down Expand Up @@ -638,7 +638,7 @@ class UnstashingSpec extends ScalaTestWithActorTestKit("""
"deal with stop" in {
val probe = TestProbe[Any]
import akka.actor.typed.scaladsl.adapter._
untypedSys.eventStream.subscribe(probe.ref.toUntyped, classOf[DeadLetter])
untypedSys.eventStream.subscribe(probe.ref.toClassic, classOf[DeadLetter])
val ref = spawn(Behaviors.setup[String] { ctx =>
val stash = StashBuffer[String](10)
stash.stash("one")
Expand Down
Expand Up @@ -42,15 +42,15 @@ object AdapterSpec {
.receive[String] { (context, message) =>
message match {
case "send" =>
val replyTo = context.self.toUntyped
val replyTo = context.self.toClassic
ref.tell("ping", replyTo)
Behaviors.same
case "pong" =>
probe ! "ok"
Behaviors.same
case "actorOf" =>
val child = context.actorOf(untyped1)
child.tell("ping", context.self.toUntyped)
child.tell("ping", context.self.toClassic)
Behaviors.same
case "watch" =>
context.watch(ref)
Expand All @@ -60,7 +60,7 @@ object AdapterSpec {
val child = context.actorOf(untyped1)
context.watch(child)
child ! ThrowIt3
child.tell("ping", context.self.toUntyped)
child.tell("ping", context.self.toClassic)
Behaviors.same
case "stop-child" =>
val child = context.actorOf(untyped1)
Expand Down Expand Up @@ -182,7 +182,7 @@ class AdapterSpec extends AkkaSpec("""
system = ActorSystem.create(
Behaviors.setup[NotUsed](_ => Behavior.stopped[NotUsed]),
"AdapterSpec-stopping-guardian")
} finally if (system != null) shutdown(system.toUntyped)
} finally if (system != null) shutdown(system.toClassic)
}
}

Expand All @@ -198,7 +198,7 @@ class AdapterSpec extends AkkaSpec("""

}, "AdapterSpec-stopping-guardian-2")

} finally if (system != null) shutdown(system.toUntyped)
} finally if (system != null) shutdown(system.toClassic)
}
}
}
Expand Down
Expand Up @@ -43,7 +43,7 @@ class GuardianStartupSpec extends WordSpec with Matchers with ScalaFutures {
var system: ActorSystem[String] = null
val initialized = new CountDownLatch(1)
val guardianBehavior = Behaviors.setup[String] { ctx =>
ctx.system.toUntyped.asInstanceOf[ActorSystemImpl].assertInitialized()
ctx.system.toClassic.asInstanceOf[ActorSystemImpl].assertInitialized()
initialized.countDown()
Behaviors.empty
}
Expand Down