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

chore: Remove more reflectiveCall. #1084

Merged
merged 1 commit into from
Jan 30, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ class ByteStringInitializationSpec extends AnyWordSpec with Matchers {
}
}

import scala.language.reflectiveCalls
type WithRun = { def run(): Unit }
cleanCl
.loadClass("org.apache.pekko.util.ByteStringInitTest")
.getDeclaredConstructor()
.newInstance()
.asInstanceOf[WithRun]
.asInstanceOf[Runnable]
.run()
}
}
}

class ByteStringInitTest {
class ByteStringInitTest extends Runnable {
def run(): Unit = {
require(CompactByteString.empty ne null)
require(ByteString.empty ne null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ object DummyData3 {

class InteractionPatterns3Spec extends ScalaTestWithActorTestKit with AnyWordSpecLike with LogCapturing {
import DummyData3._
private class DummyContext[T](val self: ActorRef[T])

"The interaction patterns docs" must {

Expand Down Expand Up @@ -101,10 +102,7 @@ class InteractionPatterns3Spec extends ScalaTestWithActorTestKit with AnyWordSpe
val cookieFabric: ActorRef[CookieFabric.Request] = spawn(CookieFabric())
val probe = createTestProbe[CookieFabric.Response]()
// shhh, don't tell anyone
import scala.language.reflectiveCalls
val context: { def self: ActorRef[CookieFabric.Response] } = new {
def self = probe.ref
}
val context = new DummyContext(probe.ref)

// #request-response-send
cookieFabric ! CookieFabric.Request("give me cookies", context.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case class Wallet()
// #per-session-child

class InteractionPatternsSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike with LogCapturing {

private class DummyContext[T](val self: ActorRef[T])
"The interaction patterns docs" must {

"contain a sample for fire and forget" in {
Expand Down Expand Up @@ -97,10 +97,7 @@ class InteractionPatternsSpec extends ScalaTestWithActorTestKit with AnyWordSpec
val cookieFabric: ActorRef[CookieFabric.Request] = spawn(CookieFabric())
val probe = createTestProbe[CookieFabric.Response]()
// shhh, don't tell anyone
import scala.language.reflectiveCalls
val context: { def self: ActorRef[CookieFabric.Response] } = new {
def self = probe.ref
}
val context = new DummyContext[CookieFabric.Response](probe.ref)

// #request-response-send
cookieFabric ! CookieFabric.Request("give me cookies", context.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package org.apache.pekko.stream.impl.fusing
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.Promise
import scala.language.reflectiveCalls

import org.apache.pekko
import pekko.Done
Expand All @@ -40,6 +39,11 @@ class AsyncCallbackSpec extends PekkoSpec("""
case class Elem(n: Int)
case object Stopped

private class GraphStageLogicWithAsyncCallback(shape: Shape) extends GraphStageLogic(shape) {
def callback: AsyncCallback[AnyRef] = null
def callbacks: Set[AsyncCallback[AnyRef]] = Set.empty
}

class AsyncCallbackGraphStage(probe: ActorRef, early: Option[AsyncCallback[AnyRef] => Unit] = None)
extends GraphStageWithMaterializedValue[FlowShape[Int, Int], AsyncCallback[AnyRef]] {

Expand All @@ -48,14 +52,13 @@ class AsyncCallbackSpec extends PekkoSpec("""
val shape = FlowShape(in, out)

def createLogicAndMaterializedValue(inheritedAttributes: Attributes): (GraphStageLogic, AsyncCallback[AnyRef]) = {
val logic: GraphStageLogic { val callback: AsyncCallback[AnyRef] } = new GraphStageLogic(shape) {
val callback = getAsyncCallback((whatever: AnyRef) => {
whatever match {
case t: Throwable => throw t
case "fail-the-stage" => failStage(new RuntimeException("failing the stage"))
case anythingElse => probe ! anythingElse
}
})
val logic = new GraphStageLogicWithAsyncCallback(shape) {
override val callback = getAsyncCallback {
case t: Throwable => throw t
case "fail-the-stage" => failStage(new RuntimeException("failing the stage"))
case anythingElse => probe ! anythingElse
}

early.foreach(cb => cb(callback))

override def preStart(): Unit = {
Expand Down Expand Up @@ -256,8 +259,8 @@ class AsyncCallbackSpec extends PekkoSpec("""
val out = Outlet[String]("out")
val shape = SourceShape(out)
def createLogicAndMaterializedValue(inheritedAttributes: Attributes) = {
val logic: GraphStageLogic { val callbacks: Set[AsyncCallback[AnyRef]] } = new GraphStageLogic(shape) {
val callbacks = (0 to 10).map(_ => getAsyncCallback[AnyRef](probe ! _)).toSet
val logic = new GraphStageLogicWithAsyncCallback(shape) {
override val callbacks = (0 to 10).map(_ => getAsyncCallback[AnyRef](probe ! _)).toSet
setHandler(out,
new OutHandler {
def onPull(): Unit = ()
Expand Down
Loading