From fe0447d267197ad7e1d9277c43fb5856ee75b2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=CC=80i=20Vie=CC=A3=CC=82t=20Tha=CC=80nh?= Date: Mon, 6 Apr 2020 15:01:10 +0700 Subject: [PATCH] ExplicitResultTypes manually for implicit local val / def ExplicitResultTypes scalafix rule can't fix those cases --- .../scala/akka/actor/ActorSelectionSpec.scala | 2 +- .../scala/akka/actor/ActorSystemSpec.scala | 2 +- .../actor/LocalActorRefProviderSpec.scala | 2 +- .../test/scala/akka/actor/SchedulerSpec.scala | 10 +++--- .../scala/akka/dataflow/Future2Actor.scala | 3 +- .../src/test/scala/akka/pattern/AskSpec.scala | 34 +++++++++---------- .../pattern/extended/ExplicitAskSpec.scala | 4 +-- .../akka/actor/typed/SpawnProtocolSpec.scala | 2 +- .../akka/typed/StyleGuideDocExamples.scala | 2 +- .../src/main/scala/akka/event/Logging.scala | 3 +- project/AkkaBuild.scala | 2 +- 11 files changed, 34 insertions(+), 32 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorSelectionSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorSelectionSpec.scala index 76cb66b242..1bc0777780 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorSelectionSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorSelectionSpec.scala @@ -355,7 +355,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout { "identify actors with wildcard selection correctly" in { val creator = TestProbe() - implicit def self = creator.ref + implicit def self: ActorRef = creator.ref val top = system.actorOf(p, "a") val b1 = Await.result((top ? Create("b1")).mapTo[ActorRef], timeout.duration) val b2 = Await.result((top ? Create("b2")).mapTo[ActorRef], timeout.duration) diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorSystemSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorSystemSpec.scala index 9d7fb67878..4c72b51ea5 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorSystemSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorSystemSpec.scala @@ -263,7 +263,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend "reliably create waves of actors" in { import system.dispatcher - implicit val timeout = Timeout((20 seconds).dilated) + implicit val timeout: Timeout = Timeout((20 seconds).dilated) val waves = for (_ <- 1 to 3) yield system.actorOf(Props[ActorSystemSpec.Waves]) ? 50000 Await.result(Future.sequence(waves), timeout.duration + 5.seconds) should ===(Vector("done", "done", "done")) } diff --git a/akka-actor-tests/src/test/scala/akka/actor/LocalActorRefProviderSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/LocalActorRefProviderSpec.scala index 821583ae1d..9b7e287fd5 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/LocalActorRefProviderSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/LocalActorRefProviderSpec.scala @@ -130,7 +130,7 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi for (i <- 0 until 100) { val address = "new-actor" + i - implicit val timeout = Timeout(5 seconds) + implicit val timeout: Timeout = Timeout(5 seconds) val actors = for (_ <- 1 to 4) yield Future(system.actorOf(Props(new Actor { def receive = { case _ => } }), address)) diff --git a/akka-actor-tests/src/test/scala/akka/actor/SchedulerSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/SchedulerSpec.scala index b02939341f..0d52807f66 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/SchedulerSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/SchedulerSpec.scala @@ -496,7 +496,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev "execute multiple jobs at once when expiring multiple buckets" taggedAs TimingTest in { withScheduler() { (sched, driver) => - implicit def ec = localEC + implicit def ec: ExecutionContext = localEC import driver._ val start = step / 2 (0 to 3).foreach(i => sched.scheduleOnce(start + step * i, testActor, "hello")) @@ -511,7 +511,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev "properly defer jobs even when the timer thread oversleeps" taggedAs TimingTest in { withScheduler() { (sched, driver) => - implicit def ec = localEC + implicit def ec: ExecutionContext = localEC import driver._ sched.scheduleOnce(step * 3, probe.ref, "hello") wakeUp(step * 5) @@ -526,7 +526,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev "correctly wrap around wheel rounds" taggedAs TimingTest in { withScheduler(config = ConfigFactory.parseString("akka.scheduler.ticks-per-wheel=2")) { (sched, driver) => - implicit def ec = localEC + implicit def ec: ExecutionContext = localEC import driver._ val start = step / 2 (0 to 3).foreach(i => sched.scheduleOnce(start + step * i, probe.ref, "hello")) @@ -553,7 +553,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev "correctly execute jobs when clock wraps around" taggedAs TimingTest in { withScheduler(Long.MaxValue - 200000000L) { (sched, driver) => - implicit def ec = localEC + implicit def ec: ExecutionContext = localEC import driver._ val start = step / 2 (0 to 3).foreach(i => sched.scheduleOnce(start + step * i, testActor, "hello")) @@ -583,7 +583,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev val targetTicks = Int.MaxValue - numEvents + 20 withScheduler(_startTick = Int.MaxValue - 100) { (sched, driver) => - implicit def ec = localEC + implicit def ec: ExecutionContext = localEC import driver._ val start = step / 2 diff --git a/akka-actor-tests/src/test/scala/akka/dataflow/Future2Actor.scala b/akka-actor-tests/src/test/scala/akka/dataflow/Future2Actor.scala index 5f5cb53ea4..6143fa4ef6 100644 --- a/akka-actor-tests/src/test/scala/akka/dataflow/Future2Actor.scala +++ b/akka-actor-tests/src/test/scala/akka/dataflow/Future2Actor.scala @@ -7,6 +7,7 @@ package akka.dataflow import language.postfixOps import akka.actor.{ Actor, Props } +import akka.actor.ActorRef import scala.concurrent.Future import scala.concurrent.Await import scala.concurrent.duration._ @@ -25,7 +26,7 @@ class Future2ActorSpec extends AkkaSpec with DefaultTimeout { } "support convenient sending to multiple destinations with implicit sender" in { - implicit val someActor = system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior })) + implicit val someActor: ActorRef = system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior })) Future(42).pipeTo(testActor).pipeTo(testActor) expectMsgAllOf(1 second, 42, 42) lastSender should ===(someActor) diff --git a/akka-actor-tests/src/test/scala/akka/pattern/AskSpec.scala b/akka-actor-tests/src/test/scala/akka/pattern/AskSpec.scala index 797c31ba94..17e248bc2d 100644 --- a/akka-actor-tests/src/test/scala/akka/pattern/AskSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/pattern/AskSpec.scala @@ -19,7 +19,7 @@ class AskSpec extends AkkaSpec { "The “ask” pattern" must { "send request to actor and wrap the answer in Future" in { - implicit val timeout = Timeout(5.seconds) + implicit val timeout: Timeout = Timeout(5.seconds) val echo = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } })) val f = echo ? "ping" f.futureValue should ===("ping") @@ -35,7 +35,7 @@ class AskSpec extends AkkaSpec { } "return broken promises on EmptyLocalActorRefs" in { - implicit val timeout = Timeout(5 seconds) + implicit val timeout: Timeout = Timeout(5 seconds) val empty = system.asInstanceOf[ExtendedActorSystem].provider.resolveActorRef("/user/unknown") val f = empty ? 3.14 f.isCompleted should ===(true) @@ -46,7 +46,7 @@ class AskSpec extends AkkaSpec { } "return broken promises on unsupported ActorRefs" in { - implicit val timeout = Timeout(5 seconds) + implicit val timeout: Timeout = Timeout(5 seconds) val f = ask(null: ActorRef, 3.14) f.isCompleted should ===(true) @@ -57,7 +57,7 @@ class AskSpec extends AkkaSpec { } "return broken promises on 0 timeout" in { - implicit val timeout = Timeout(0 seconds) + implicit val timeout: Timeout = Timeout(0 seconds) val echo = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } })) val f = echo ? "foo" val expectedMsg = @@ -68,7 +68,7 @@ class AskSpec extends AkkaSpec { } "return broken promises on < 0 timeout" in { - implicit val timeout = Timeout(-1000 seconds) + implicit val timeout: Timeout = Timeout(-1000 seconds) val echo = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } })) val f = echo ? "foo" val expectedMsg = @@ -79,7 +79,7 @@ class AskSpec extends AkkaSpec { } "include target information in AskTimeout" in { - implicit val timeout = Timeout(0.5 seconds) + implicit val timeout: Timeout = Timeout(0.5 seconds) val silentOne = system.actorOf(Props.empty, "silent") val f = silentOne ? "noreply" intercept[AskTimeoutException] { @@ -88,7 +88,7 @@ class AskSpec extends AkkaSpec { } "include timeout information in AskTimeout" in { - implicit val timeout = Timeout(0.5 seconds) + implicit val timeout: Timeout = Timeout(0.5 seconds) val f = system.actorOf(Props.empty) ? "noreply" intercept[AskTimeoutException] { Await.result(f, 1 second) @@ -96,8 +96,8 @@ class AskSpec extends AkkaSpec { } "include sender information in AskTimeout" in { - implicit val timeout = Timeout(0.5 seconds) - implicit val sender = system.actorOf(Props.empty) + implicit val timeout: Timeout = Timeout(0.5 seconds) + implicit val sender: ActorRef = system.actorOf(Props.empty) val f = system.actorOf(Props.empty) ? "noreply" intercept[AskTimeoutException] { Await.result(f, 1 second) @@ -105,7 +105,7 @@ class AskSpec extends AkkaSpec { } "include message class information in AskTimeout" in { - implicit val timeout = Timeout(0.5 seconds) + implicit val timeout: Timeout = Timeout(0.5 seconds) val f = system.actorOf(Props.empty) ? Integer.valueOf(17) intercept[AskTimeoutException] { Await.result(f, 1 second) @@ -113,7 +113,7 @@ class AskSpec extends AkkaSpec { } "work for ActorSelection" in { - implicit val timeout = Timeout(5 seconds) + implicit val timeout: Timeout = Timeout(5 seconds) import system.dispatcher val echo = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } }), "select-echo") val identityFuture = @@ -123,7 +123,7 @@ class AskSpec extends AkkaSpec { } "work when reply uses actor selection" in { - implicit val timeout = Timeout(5 seconds) + implicit val timeout: Timeout = Timeout(5 seconds) val deadListener = TestProbe() system.eventStream.subscribe(deadListener.ref, classOf[DeadLetter]) @@ -138,7 +138,7 @@ class AskSpec extends AkkaSpec { } "throw AskTimeoutException on using *" in { - implicit val timeout = Timeout(0.5 seconds) + implicit val timeout: Timeout = Timeout(0.5 seconds) val deadListener = TestProbe() system.eventStream.subscribe(deadListener.ref, classOf[DeadLetter]) @@ -154,7 +154,7 @@ class AskSpec extends AkkaSpec { } "throw AskTimeoutException on using .." in { - implicit val timeout = Timeout(0.5 seconds) + implicit val timeout: Timeout = Timeout(0.5 seconds) val deadListener = TestProbe() system.eventStream.subscribe(deadListener.ref, classOf[DeadLetter]) @@ -175,7 +175,7 @@ class AskSpec extends AkkaSpec { } "send to DeadLetter when child does not exist" in { - implicit val timeout = Timeout(0.5 seconds) + implicit val timeout: Timeout = Timeout(0.5 seconds) val deadListener = TestProbe() system.eventStream.subscribe(deadListener.ref, classOf[DeadLetter]) @@ -194,7 +194,7 @@ class AskSpec extends AkkaSpec { } "send DeadLetter when answering to grandchild" in { - implicit val timeout = Timeout(0.5 seconds) + implicit val timeout: Timeout = Timeout(0.5 seconds) val deadListener = TestProbe() system.eventStream.subscribe(deadListener.ref, classOf[DeadLetter]) @@ -212,7 +212,7 @@ class AskSpec extends AkkaSpec { } "allow watching the promiseActor and send Terminated() when completes" in { - implicit val timeout = Timeout(300 millis) + implicit val timeout: Timeout = Timeout(300 millis) val p = TestProbe() val act = system.actorOf(Props(new Actor { diff --git a/akka-actor-tests/src/test/scala/akka/pattern/extended/ExplicitAskSpec.scala b/akka-actor-tests/src/test/scala/akka/pattern/extended/ExplicitAskSpec.scala index 8e79c690be..55c16b7621 100644 --- a/akka-actor-tests/src/test/scala/akka/pattern/extended/ExplicitAskSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/pattern/extended/ExplicitAskSpec.scala @@ -19,7 +19,7 @@ class ExplicitAskSpec extends AkkaSpec { "The “ask” pattern with explicit sender" must { "allow to access an explicit reference to actor to respond to" in { - implicit val timeout = Timeout(5.seconds) + implicit val timeout: Timeout = Timeout(5.seconds) val target = system.actorOf(Props(new Actor { def receive = { @@ -32,7 +32,7 @@ class ExplicitAskSpec extends AkkaSpec { } "work for ActorSelection" in { - implicit val timeout = Timeout(5.seconds) + implicit val timeout: Timeout = Timeout(5.seconds) val target = system.actorOf(Props(new Actor { def receive = { diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/SpawnProtocolSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/SpawnProtocolSpec.scala index 41b966d5df..af7f1ebb3b 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/SpawnProtocolSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/SpawnProtocolSpec.scala @@ -48,7 +48,7 @@ class SpawnProtocolSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike w "have nice API for ask" in { val parent = spawn(SpawnProtocol(), "parent2") import akka.actor.typed.scaladsl.AskPattern._ - implicit val timeout = Timeout(5.seconds) + implicit val timeout: Timeout = Timeout(5.seconds) val parentReply: Future[ActorRef[Ping]] = parent.ask(SpawnProtocol.Spawn(target, "child", Props.empty, _)) val child = parentReply.futureValue diff --git a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StyleGuideDocExamples.scala b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StyleGuideDocExamples.scala index 3ceb783724..591155a15f 100644 --- a/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StyleGuideDocExamples.scala +++ b/akka-actor-typed-tests/src/test/scala/docs/akka/typed/StyleGuideDocExamples.scala @@ -428,7 +428,7 @@ object StyleGuideDocExamples { import akka.actor.typed.scaladsl.AskPattern._ import akka.util.Timeout - implicit val timeout = Timeout(3.seconds) + implicit val timeout: Timeout = Timeout(3.seconds) val counter: ActorRef[Command] = ??? val result: Future[OperationResult] = counter.ask(replyTo => Increment(delta = 2, replyTo)) diff --git a/akka-actor/src/main/scala/akka/event/Logging.scala b/akka-actor/src/main/scala/akka/event/Logging.scala index 5cd62aab21..4e669d2ac4 100644 --- a/akka-actor/src/main/scala/akka/event/Logging.scala +++ b/akka-actor/src/main/scala/akka/event/Logging.scala @@ -22,6 +22,7 @@ import scala.collection.immutable import scala.concurrent.Await import scala.language.existentials import scala.util.control.{ NoStackTrace, NonFatal } +import akka.util.Timeout /** * This trait brings log level handling to the EventStream: it reads the log @@ -198,7 +199,7 @@ trait LoggingBus extends ActorEventBus { logName: String): ActorRef = { val name = "log" + LogExt(system).id() + "-" + simpleName(clazz) val actor = system.systemActorOf(Props(clazz).withDispatcher(system.settings.LoggersDispatcher), name) - implicit def timeout = system.settings.LoggerStartTimeout + implicit def timeout: Timeout = system.settings.LoggerStartTimeout import akka.pattern.ask val response = try Await.result(actor ? InitializeLogger(this), timeout.duration) catch { diff --git a/project/AkkaBuild.scala b/project/AkkaBuild.scala index ee9fd93d24..9a6dd92100 100644 --- a/project/AkkaBuild.scala +++ b/project/AkkaBuild.scala @@ -142,7 +142,7 @@ object AkkaBuild { |implicit def _system = system |def startSystem(remoting: Boolean = false) { system = ActorSystem("repl", if(remoting) remoteConfig else config); println("don’t forget to system.terminate()!") } |implicit def ec = system.dispatcher - |implicit val timeout = Timeout(5 seconds) + |implicit val timeout: Timeout = Timeout(5 seconds) |""".stripMargin, /**