Skip to content

Commit

Permalink
feat: Cross build for Scala 3 (#30)
Browse files Browse the repository at this point in the history
* also enabled compiler warnings
* switched to commons-text since other was deprecated
  • Loading branch information
patriknw authored Feb 3, 2023
1 parent 37c096e commit a93d5c2
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 103 deletions.
57 changes: 18 additions & 39 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,27 @@ jobs:
- name: Cache Coursier cache
uses: coursier/[email protected]

- name: Set up JDK 17
uses: coursier/[email protected]
with:
jvm: temurin:1.17.0

- name: Code style check and binary-compatibility check
run: |-
cp .jvmopts-ci .jvmopts
sbt scalafmtCheckAll scalafmtSbtCheck headerCheck
compile-with-scala-2_12:
name: Compile with Scala 2.12
runs-on: ubuntu-22.04
if: github.repository == 'akka/akka-diagnostics'
steps:
- name: Checkout
uses: actions/[email protected]
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0
- name: Checkout GitHub merge
if: github.event.pull_request
run: |-
git fetch origin pull/${{ github.event.pull_request.number }}/merge:scratch
git checkout scratch
- name: Cache Coursier cache
uses: coursier/[email protected]

- name: Set up JDK 8
uses: coursier/[email protected]
with:
jvm: temurin:1.8.0

- name: Code style check and binary-compatibility check
- name: Code style check, compilation and binary-compatibility check
run: |-
cp .jvmopts-ci .jvmopts
sbt ++2.12 compile Test/compile
sbt scalafmtCheckAll scalafmtSbtCheck headerCheck +Test/compile
test-diagnostics-11:
name: Run tests 11
test:
name: Run tests
runs-on: ubuntu-22.04
if: github.repository == 'akka/akka-diagnostics'
strategy:
fail-fast: false
matrix:
include:
- { jdkVersion: "1.8.0", jvmName: "temurin:1.8.0" }
- { jdkVersion: "1.11.0", jvmName: "temurin:1.11.0" }
- { jdkVersion: "1.17.0", jvmName: "temurin:1.17.0" }
steps:
- name: Checkout
uses: actions/[email protected]
Expand All @@ -82,18 +62,18 @@ jobs:
- name: Cache Coursier cache
uses: coursier/[email protected]

- name: Set up JDK 11
- name: Set up JDK ${{ matrix.jdkVersion }}
uses: coursier/[email protected]
with:
jvm: temurin:1.11.0
jvm: ${{ matrix.jvmName }}

- name: sbt test
run: |-
cp .jvmopts-ci .jvmopts
sbt test
test-diagnostics-17:
name: Run tests 17
check-docs:
name: Check Docs
runs-on: ubuntu-22.04
if: github.repository == 'akka/akka-diagnostics'
steps:
Expand All @@ -107,6 +87,7 @@ jobs:
run: |-
git fetch origin pull/${{ github.event.pull_request.number }}/merge:scratch
git checkout scratch
- name: Cache Coursier cache
uses: coursier/[email protected]

Expand All @@ -115,7 +96,5 @@ jobs:
with:
jvm: temurin:1.17.0

- name: sbt test
run: |-
cp .jvmopts-ci .jvmopts
sbt test
- name: Create all API docs for artifacts/website and all reference docs
run: sbt "unidoc; docs/paradox"
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ package akka.diagnostics
import java.net.InetAddress
import java.util.Locale
import java.util.concurrent.TimeUnit.MILLISECONDS
import akka.actor.{ ActorSystem, ExtendedActorSystem }
import akka.dispatch.ThreadPoolConfig
import akka.event.Logging
import com.typesafe.config._
import org.apache.commons.lang3.StringUtils

import scala.collection.JavaConverters._
import scala.collection.immutable
import scala.collection.immutable.VectorBuilder
import scala.concurrent.duration._
import scala.util.{ Failure, Success, Try }
import scala.util.Failure
import scala.util.Success
import scala.util.Try

import akka.actor.ActorSystem
import akka.actor.ExtendedActorSystem
import akka.dispatch.ThreadPoolConfig
import akka.event.Logging
import com.typesafe.config._
import org.apache.commons.text.similarity.LevenshteinDistance

object ConfigChecker {

Expand Down Expand Up @@ -221,12 +225,14 @@ class ConfigChecker(system: ExtendedActorSystem, config: Config, reference: Conf

collectLeaves("akka", reference.getConfig("akka").root)
}

private val maxSimilarDistance = 5
private val maxSimilarItems = 3
private lazy val levenshteinDistance = new LevenshteinDistance(maxSimilarDistance)
private def similar(name: String): Seq[String] =
knownSettings
.map { case (key, path) =>
(key, path, StringUtils.getLevenshteinDistance(key, name, maxSimilarDistance))
(key, path, levenshteinDistance.apply(key, name))
}
.filter(_._3 >= 0)
.sortBy(_._3)
Expand Down Expand Up @@ -483,7 +489,7 @@ class ConfigChecker(system: ExtendedActorSystem, config: Config, reference: Conf
checkProvider() ++
checkJvmExitOnFatalError() ++
checkDefaultDispatcherSize() ++
checkInternalDispatcherSize ++
checkInternalDispatcherSize() ++
checkDefaultDispatcherType() ++
checkDispatcherThroughput(defaultDispatcherPath, config.getConfig(defaultDispatcherPath))
}
Expand Down Expand Up @@ -685,7 +691,7 @@ class ConfigChecker(system: ExtendedActorSystem, config: Config, reference: Conf
checkCreateActorRemotely() ++
checkPreferClusterToRemote() ++
checkRemoteDispatcherSize() ++
checkArteryNotEnabled
checkArteryNotEnabled()
} else Vector.empty[ConfigWarning]

private def checkRemoteDispatcher(): List[ConfigWarning] =
Expand Down Expand Up @@ -1029,7 +1035,6 @@ class ConfigChecker(system: ExtendedActorSystem, config: Config, reference: Conf
private def checkSplitBrainResolver(): List[ConfigWarning] =
ifEnabled("split-brain-resolver") { checkerKey =>

val downingProviderPath = "akka.cluster.downing-provider-class"
val sbrStrategyPath = "akka.cluster.split-brain-resolver.active-strategy"
val sbrActive = isClusterConfigAvailable && isSplitBrainResolverConfigAvailable &&
config.getString(sbrStrategyPath).toLowerCase(Locale.ROOT) != "off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import scala.util.Try
import scala.util.control.NoStackTrace
import scala.util.control.NonFatal

abstract class StarvationDetectorSettings { _: StarvationDetectorSettings.StarvationDetectorSettingsImpl =>
def checkInterval: FiniteDuration
def initialDelay: FiniteDuration
def maxDelayWarningThreshold: FiniteDuration
def warningInterval: FiniteDuration
def threadTraceLimit: Int
final class StarvationDetectorSettings(
val checkInterval: FiniteDuration,
val initialDelay: FiniteDuration,
val maxDelayWarningThreshold: FiniteDuration,
val warningInterval: FiniteDuration,
val threadTraceLimit: Int) {

def withCheckInterval(newCheckInterval: FiniteDuration): StarvationDetectorSettings =
copy(checkInterval = newCheckInterval)
Expand All @@ -52,7 +52,21 @@ abstract class StarvationDetectorSettings { _: StarvationDetectorSettings.Starva
copy(threadTraceLimit = Integer.MAX_VALUE)

def isEnabled: Boolean = checkInterval > Duration.Zero

private def copy(
checkInterval: FiniteDuration = checkInterval,
initialDelay: FiniteDuration = initialDelay,
maxDelayWarningThreshold: FiniteDuration = maxDelayWarningThreshold,
warningInterval: FiniteDuration = warningInterval,
threadTraceLimit: Int = threadTraceLimit): StarvationDetectorSettings =
new StarvationDetectorSettings(
checkInterval,
initialDelay,
maxDelayWarningThreshold,
warningInterval,
threadTraceLimit)
}

object StarvationDetectorSettings {
def apply(
checkInterval: FiniteDuration,
Expand All @@ -67,7 +81,7 @@ object StarvationDetectorSettings {
maxDelayWarningThreshold: FiniteDuration,
warningInterval: FiniteDuration,
threadTraceLimit: Int): StarvationDetectorSettings =
StarvationDetectorSettingsImpl(
new StarvationDetectorSettings(
checkInterval,
initialDelay,
maxDelayWarningThreshold,
Expand Down Expand Up @@ -109,15 +123,6 @@ object StarvationDetectorSettings {
})
}

/** INTERNAL API */
@InternalApi
private[StarvationDetectorSettings] final case class StarvationDetectorSettingsImpl(
checkInterval: FiniteDuration,
initialDelay: FiniteDuration,
maxDelayWarningThreshold: FiniteDuration,
warningInterval: FiniteDuration,
threadTraceLimit: Int)
extends StarvationDetectorSettings {}
}

object StarvationDetector {
Expand Down
32 changes: 16 additions & 16 deletions akka-diagnostics/src/test/scala/akka/diagnostics/AkkaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

package akka.diagnostics

import java.lang.reflect.Modifier

import scala.concurrent.Future
import scala.concurrent.duration._

import akka.actor.ActorSystem
import akka.dispatch.Dispatchers
import akka.event.Logging
import akka.event.LoggingAdapter
import akka.testkit.TestEvent.Mute
import akka.testkit.DeadLettersFilter
import akka.testkit.TestEvent.Mute
import akka.testkit.TestKit
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import org.scalactic.CanEqual
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.BeforeAndAfterAll
import org.scalatest.Matchers
import org.scalatest.WordSpecLike

import java.lang.reflect.Modifier
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.language.postfixOps
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

object AkkaSpec {
val testConf: Config = ConfigFactory.parseString("""
Expand Down Expand Up @@ -96,12 +96,12 @@ object AkkaSpec {

abstract class AkkaSpec(_system: ActorSystem)
extends TestKit(_system)
with WordSpecLike
with AnyWordSpecLike
with Matchers
with BeforeAndAfterAll
with ScalaFutures {

implicit val patience = PatienceConfig(testKitSettings.DefaultTimeout.duration)
implicit val patience: PatienceConfig = PatienceConfig(testKitSettings.DefaultTimeout.duration)

def this(config: Config) = this(
ActorSystem(
Expand All @@ -114,7 +114,7 @@ abstract class AkkaSpec(_system: ActorSystem)

def this() = this(ActorSystem(AkkaSpec.testNameFromCallStack(classOf[AkkaSpec]), AkkaSpec.testConf))

val log: LoggingAdapter = Logging(system, this.getClass)
val log: LoggingAdapter = Logging(system, Logging.simpleName(this))

override val invokeBeforeAllAndAfterAllEvenIfNoTestsAreExpected = true

Expand All @@ -130,16 +130,16 @@ abstract class AkkaSpec(_system: ActorSystem)
// TODO not published stopCoroner()
}

protected def atStartup() = {}
protected def atStartup(): Unit = {}

protected def beforeTermination() = {}
protected def beforeTermination(): Unit = {}

protected def afterTermination() = {}
protected def afterTermination(): Unit = {}

def spawn(dispatcherId: String = Dispatchers.DefaultDispatcherId)(body: => Unit): Unit =
Future(body)(system.dispatchers.lookup(dispatcherId))

def expectedTestDuration: FiniteDuration = 60 seconds
def expectedTestDuration: FiniteDuration = 60.seconds

def muteDeadLetters(messageClasses: Class[_]*)(sys: ActorSystem = system): Unit =
if (!sys.log.isDebugEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ConfigCheckerSpec extends AkkaSpec {
akka.diagnostics.checker.disabled-checks = [${allDisabledCheckerKeys.mkString(",")}]
""")
.withFallback(c)
new ConfigChecker(extSys, disabled, reference).check.warnings should ===(Nil)
new ConfigChecker(extSys, disabled, reference).check().warnings should ===(Nil)
}

def assertCheckerKey(warnings: immutable.Seq[ConfigWarning], expectedCheckerKeys: String*): Unit =
Expand Down Expand Up @@ -269,12 +269,12 @@ class ConfigCheckerSpec extends AkkaSpec {

"check internal-dispatcher as default-dispatcher is find" in {
val c = ConfigFactory
.parseString("""
.parseString(s"""
|akka.actor.default-dispatcher = {
| type = "Dispatcher"
| # ...
| }
|akka.actor.internal-dispatcher = ${akka.actor.default-dispatcher} """.stripMargin)
|akka.actor.internal-dispatcher = $${akka.actor.default-dispatcher} """.stripMargin)
.resolve()
.withFallback(reference)

Expand Down
Loading

0 comments on commit a93d5c2

Please sign in to comment.