Skip to content

Commit

Permalink
format source with scalafmt, #1408
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew de Detrich <[email protected]>

# Conflicts:
#	actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/SupervisionSpec.scala
#	cluster-sharding/src/main/scala/org/apache/pekko/cluster/sharding/ClusterSharding.scala
#	stream/src/main/scala/org/apache/pekko/stream/javadsl/SourceWithContext.scala
  • Loading branch information
Auto Format authored and mdedetrich committed Sep 16, 2024
1 parent a8e0958 commit 68e2102
Show file tree
Hide file tree
Showing 1,210 changed files with 5,031 additions and 8,524 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ object CapturedLogEvent {
case _ => None
}

def apply(level: Level, message: String): CapturedLogEvent = {
def apply(level: Level, message: String): CapturedLogEvent =
CapturedLogEvent(level, message, None, None)
}

/**
* Auxiliary constructor that receives Pekko's internal [[OptionVal]] as parameters and converts them to Scala's [[Option]].
Expand All @@ -93,7 +92,6 @@ object CapturedLogEvent {
level: Level,
message: String,
errorCause: OptionVal[Throwable],
logMarker: OptionVal[Marker]): CapturedLogEvent = {
logMarker: OptionVal[Marker]): CapturedLogEvent =
new CapturedLogEvent(level, message, toOption(errorCause), toOption(logMarker))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ import pekko.util.FutureConverters._

override def printTree: String = "no tree for ActorSystemStub"

override def systemActorOf[U](behavior: Behavior[U], name: String, props: Props): ActorRef[U] = {
override def systemActorOf[U](behavior: Behavior[U], name: String, props: Props): ActorRef[U] =
throw new UnsupportedOperationException("ActorSystemStub cannot create system actors")
}

override def registerExtension[T <: Extension](ext: ExtensionId[T]): T =
throw new UnsupportedOperationException("ActorSystemStub cannot register extensions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ private[pekko] final class BehaviorTestKitImpl[T](
private[pekko] def as[U]: BehaviorTestKitImpl[U] = this.asInstanceOf[BehaviorTestKitImpl[U]]

private var currentUncanonical = _initialBehavior
private var current = {
private var current =
try {
context.setCurrentActorThread()
Behavior.validateAsInitial(Behavior.start(_initialBehavior, context))
} finally {
} finally
context.clearCurrentActorThread()
}
}

// execute any future tasks scheduled in Actor's constructor
runAllTasks()
Expand Down Expand Up @@ -92,24 +90,22 @@ private[pekko] final class BehaviorTestKitImpl[T](

def getAllEffects(): util.List[Effect] = retrieveAllEffects().asJava

override def expectEffect(expectedEffect: Effect): Unit = {
override def expectEffect(expectedEffect: Effect): Unit =
context.effectQueue.poll() match {
case null => assert(expectedEffect == NoEffects, s"expected: $expectedEffect but no effects were recorded")
case effect => assert(expectedEffect == effect, s"expected: $expectedEffect but found $effect")
}
}

def expectEffectClass[E <: Effect](effectClass: Class[E]): E = {
def expectEffectClass[E <: Effect](effectClass: Class[E]): E =
context.effectQueue.poll() match {
case null if effectClass.isAssignableFrom(NoEffects.getClass) => effectClass.cast(NoEffects)
case null =>
throw new AssertionError(s"expected: effect type ${effectClass.getName} but no effects were recorded")
case effect if effectClass.isAssignableFrom(effect.getClass) => effect.asInstanceOf[E]
case other => throw new AssertionError(s"expected: effect class ${effectClass.getName} but found $other")
}
}

def expectEffectPF[R](f: PartialFunction[Effect, R]): R = {
def expectEffectPF[R](f: PartialFunction[Effect, R]): R =
context.effectQueue.poll() match {
case null if f.isDefinedAt(NoEffects) =>
f.apply(NoEffects)
Expand All @@ -118,7 +114,6 @@ private[pekko] final class BehaviorTestKitImpl[T](
case other =>
throw new AssertionError(s"expected matching effect but got: $other")
}
}

def expectEffectType[E <: Effect](implicit classTag: ClassTag[E]): E =
expectEffectClass(classTag.runtimeClass.asInstanceOf[Class[E]])
Expand All @@ -136,14 +131,13 @@ private[pekko] final class BehaviorTestKitImpl[T](
throw e
}

private def runAllTasks(): Unit = {
private def runAllTasks(): Unit =
context.executionContext match {
case controlled: ControlledExecutor => controlled.runAll()
case _ =>
}
}

override def run(message: T): Unit = {
override def run(message: T): Unit =
try {
context.setCurrentActorThread()
try {
Expand All @@ -153,25 +147,21 @@ private[pekko] final class BehaviorTestKitImpl[T](
// notice we pass current and not intercepted, this way Behaviors.same will be resolved to current which will be intercepted again on the next message
// otherwise we would have risked intercepting an already intercepted behavior (or would have had to explicitly check if the current behavior is already intercepted by us)
current = Behavior.canonicalize(currentUncanonical, current, context)
} finally {
} finally
context.clearCurrentActorThread()
}
runAllTasks()
} catch handleException
}

override def runOne(): Unit = run(selfInbox().receiveMessage())

override def signal(signal: Signal): Unit = {
override def signal(signal: Signal): Unit =
try {
context.setCurrentActorThread()
currentUncanonical = Behavior.interpretSignal(current, context, signal)
current = Behavior.canonicalize(currentUncanonical, current, context)
} catch handleException
finally {
finally
context.clearCurrentActorThread()
}
}

override def hasEffects(): Boolean = !context.effectQueue.isEmpty

Expand All @@ -191,7 +181,7 @@ private[pekko] object BehaviorTestKitImpl {
override def aroundReceive(
ctx: TypedActorContext[Any],
msg: Any,
target: BehaviorInterceptor.ReceiveTarget[Any]): Behavior[Any] = {
target: BehaviorInterceptor.ReceiveTarget[Any]): Behavior[Any] =
msg match {
case AdaptWithRegisteredMessageAdapter(msgToAdapt) =>
val fn = ctx
Expand All @@ -206,7 +196,6 @@ private[pekko] object BehaviorTestKitImpl {
target.apply(ctx, adaptedMsg)
case t => target.apply(ctx, t)
}
}

def inteceptBehaviour[T](behavior: Behavior[T], ctx: TypedActorContext[T]): Behavior[T] =
Behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ import pekko.annotation.InternalApi
import pekko.util.ccompat.JavaConverters._
val logbackLogger = getLogbackLogger(classOf[CapturingAppender].getName + "Delegate")
val appenders = logbackLogger.iteratorForAppenders().asScala.filterNot(_ == this).toList
for (event <- buffer; appender <- appenders) {
for (event <- buffer; appender <- appenders)
appender.doAppend(event)
}
clear()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ private[pekko] final class ControlledExecutor extends ExecutionContextExecutor {

def runAll(): Unit = while (!tasks.isEmpty()) runOne()

def execute(task: Runnable): Unit = {
def execute(task: Runnable): Unit =
tasks.add(task)
}

def reportFailure(cause: Throwable): Unit = {
def reportFailure(cause: Throwable): Unit =
cause.printStackTrace()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ import scala.reflect.ClassTag

override def cancelAll(): Unit = activeTimers.foreach(cancel)

private def sendAction(key: Any): () => Unit = () => {
private def sendAction(key: Any): () => Unit = () =>
activeTimers.get(key).foreach {
case Effect.TimerScheduled(_, msg, _, mode, _) =>
mode match {
Expand All @@ -138,8 +138,6 @@ import scala.reflect.ClassTag
self ! msg
}

}

def startTimer(key: Any, msg: T, delay: FiniteDuration, mode: Effect.TimerScheduled.TimerMode) = {
val effect = Effect.TimerScheduled(key, msg, delay, mode, activeTimers.keySet(key))(sendAction(key))
activeTimers += (key -> effect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import scala.annotation.tailrec
getLogbackLoggerInternal(loggerName, 50)

@tailrec
private def getLogbackLoggerInternal(loggerName: String, count: Int): ch.qos.logback.classic.Logger = {
private def getLogbackLoggerInternal(loggerName: String, count: Int): ch.qos.logback.classic.Logger =
LoggerFactory.getLogger(loggerNameOrRoot(loggerName)) match {
case logger: ch.qos.logback.classic.Logger => logger
case _: org.slf4j.helpers.SubstituteLogger if count > 0 =>
Expand All @@ -43,9 +43,8 @@ import scala.annotation.tailrec
throw new IllegalArgumentException(
s"Requires Logback logger for [$loggerName], it was a [${other.getClass.getName}]")
}
}

def convertLevel(level: ch.qos.logback.classic.Level): Level = {
def convertLevel(level: ch.qos.logback.classic.Level): Level =
level.levelInt match {
case ch.qos.logback.classic.Level.TRACE_INT => Level.TRACE
case ch.qos.logback.classic.Level.DEBUG_INT => Level.DEBUG
Expand All @@ -55,5 +54,4 @@ import scala.annotation.tailrec
case _ =>
throw new IllegalArgumentException("Level " + level.levelStr + ", " + level.levelInt + " is unknown.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import pekko.testkit.TestKit
@volatile // JMM does not guarantee visibility for non-final fields
private var todo = occurrences

def matches(event: LoggingEvent): Boolean = {
def matches(event: LoggingEvent): Boolean =
logLevel.forall(_ == event.level) &&
source.forall(_ == sourceOrEmpty(event)) &&
messageContains.forall(messageOrEmpty(event).contains) &&
Expand All @@ -67,33 +67,30 @@ import pekko.testkit.TestKit
mdc.forall { case (key, value) => event.mdc.contains(key) && event.mdc(key) == value } &&
custom.forall(f => f(event))

// loggerName is handled when installing the filter, in `expect`
}
// loggerName is handled when installing the filter, in `expect`

private def messageOrEmpty(event: LoggingEvent): String =
if (event.message == null) "" else event.message

private def sourceOrEmpty(event: LoggingEvent): String =
event.mdc.getOrElse("pekkoSource", "")

def apply(event: LoggingEvent): Boolean = {
def apply(event: LoggingEvent): Boolean =
if (matches(event)) {
if (todo != Int.MaxValue) todo -= 1
true
} else false
}

private def awaitDone(max: Duration): Boolean = {
if (todo != Int.MaxValue && todo > 0) TestKit.awaitCond(todo <= 0, max, noThrow = true)
todo == Int.MaxValue || todo == 0
}

private def awaitNoExcess(max: Duration): Boolean = {
private def awaitNoExcess(max: Duration): Boolean =
if (todo == 0)
!TestKit.awaitCond(todo < 0, max, noThrow = true)
else
todo > 0
}

override def expect[T](code: => T)(implicit system: ActorSystem[_]): T = {
val effectiveLoggerName = loggerName.getOrElse("")
Expand Down Expand Up @@ -127,11 +124,10 @@ import pekko.testkit.TestKit
override def intercept[T](code: => T)(implicit system: ActorSystem[_]): T =
expect(code)(system)

private def checkLogback(system: ActorSystem[_]): Unit = {
private def checkLogback(system: ActorSystem[_]): Unit =
if (!system.dynamicAccess.classIsOnClasspath("ch.qos.logback.classic.spi.ILoggingEvent")) {
throw new IllegalStateException("LoggingEventFilter requires logback-classic dependency in classpath.")
}
}

override def withOccurrences(newOccurrences: Int): LoggingTestKitImpl =
copy(occurrences = newOccurrences)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ private[pekko] final class FunctionRef[-T](override val path: ActorPath, send: (
currentBehaviorProvider: () => Behavior[T])
extends ActorContextImpl[T] {

def this(system: ActorSystemStub, name: String, currentBehaviorProvider: () => Behavior[T]) = {
def this(system: ActorSystemStub, name: String, currentBehaviorProvider: () => Behavior[T]) =
this(system, (system.path / name).withUid(rnd().nextInt()), currentBehaviorProvider)
}

def this(name: String, currentBehaviorProvider: () => Behavior[T]) = {
def this(name: String, currentBehaviorProvider: () => Behavior[T]) =
this(new ActorSystemStub("StubbedActorContext"), name, currentBehaviorProvider)
}

/**
* INTERNAL API
Expand Down Expand Up @@ -141,21 +139,16 @@ private[pekko] final class FunctionRef[-T](override val path: ActorPath, send: (
_children -= child.path.name
}
}
override def watch[U](other: ActorRef[U]): Unit = {
override def watch[U](other: ActorRef[U]): Unit =
checkCurrentActorThread()
}
override def watchWith[U](other: ActorRef[U], message: T): Unit = {
override def watchWith[U](other: ActorRef[U], message: T): Unit =
checkCurrentActorThread()
}
override def unwatch[U](other: ActorRef[U]): Unit = {
override def unwatch[U](other: ActorRef[U]): Unit =
checkCurrentActorThread()
}
override def setReceiveTimeout(d: FiniteDuration, message: T): Unit = {
override def setReceiveTimeout(d: FiniteDuration, message: T): Unit =
checkCurrentActorThread()
}
override def cancelReceiveTimeout(): Unit = {
override def cancelReceiveTimeout(): Unit =
checkCurrentActorThread()
}

override def scheduleOnce[U](delay: FiniteDuration, target: ActorRef[U], message: U): classic.Cancellable =
new classic.Cancellable {
Expand Down Expand Up @@ -223,15 +216,13 @@ private[pekko] final class FunctionRef[-T](override val path: ActorPath, send: (
logger
}

override def setLoggerName(name: String): Unit = {
override def setLoggerName(name: String): Unit =
// nop as we don't track logger
checkCurrentActorThread()
}

override def setLoggerName(clazz: Class[_]): Unit = {
override def setLoggerName(clazz: Class[_]): Unit =
// nop as we don't track logger
checkCurrentActorThread()
}

/**
* The log entries logged through context.log.{debug, info, warn, error} are captured and can be inspected through
Expand All @@ -243,15 +234,13 @@ private[pekko] final class FunctionRef[-T](override val path: ActorPath, send: (
.iterator()
.asScala
.map { evt =>
{
val marker: Option[Marker] = Option(evt.getMarkers).flatMap(_.asScala.headOption)
CapturedLogEvent(
level = evt.getLevel,
message = MessageFormatter.arrayFormat(evt.getMessage, evt.getArgumentArray).getMessage,
cause = Option(evt.getThrowable),
marker = marker)
val marker: Option[Marker] = Option(evt.getMarkers).flatMap(_.asScala.headOption)
CapturedLogEvent(
level = evt.getLevel,
message = MessageFormatter.arrayFormat(evt.getMessage, evt.getArgumentArray).getMessage,
cause = Option(evt.getThrowable),
marker = marker)

}
}
.toList
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ import java.util.Collections
filter(loggingEvent)
}

private def filter(event: LoggingEvent): Boolean = {
private def filter(event: LoggingEvent): Boolean =
filters.exists(f =>
try {
try
f.apply(event)
} catch {
catch {
case _: Exception => false
})
}

def addTestFilter(filter: LoggingTestKitImpl): Unit = synchronized {
filters ::= filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,8 @@ private[pekko] final class TestProbeImpl[M](name: String, system: ActorSystem[_]

private def assertFail(msg: String): Nothing = throw new AssertionError(msg)

override def stop(): Unit = {
override def stop(): Unit =
testActor.asInstanceOf[ActorRef[AnyRef]] ! Stop
}

def tell(m: M) = testActor.tell(m)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ object ActorTestKit {
* an error is printed to stdout when the system did not shutdown but
* no exception is thrown.
*/
def shutdown(system: ActorSystem[_], duration: Duration, throwIfShutdownTimesOut: Boolean): Unit = {
def shutdown(system: ActorSystem[_], duration: Duration, throwIfShutdownTimesOut: Boolean): Unit =
TestKitUtils.shutdown(system, duration.asScala, throwIfShutdownTimesOut)
}

/**
* Shutdown the given [[pekko.actor.typed.ActorSystem]] and block until it shuts down,
Expand Down
Loading

0 comments on commit 68e2102

Please sign in to comment.