Skip to content

Commit

Permalink
chore: Remove more reflectiveCall. (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
He-Pin authored Jan 30, 2024
1 parent daf84d7 commit 5e00e6b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
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

0 comments on commit 5e00e6b

Please sign in to comment.