Skip to content

Commit

Permalink
Drop 2.12 support, add scalafmt, scalafix, MiMa
Browse files Browse the repository at this point in the history
Source and binary compat preserved.

The code changes:
- scalafmt and scalafix formatting applied
- added type annotations to public members and implicits
- migrated to Scala 3 syntax for imports
- since 2.12 is not supported anymore, replaced CurrentThreadExecutionContext wrapper with direct usage of ExecutionContext.parasitic. This as well leads to removal of the direct dependency on executor-tools as it is not used in the project anymore.
  • Loading branch information
migesok committed Sep 3, 2024
1 parent 9ffa9fe commit 566ce7f
Show file tree
Hide file tree
Showing 29 changed files with 294 additions and 220 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
matrix:
scala:
- 2.13.14
- 2.12.19
- 3.3.3

steps:
Expand All @@ -25,7 +24,7 @@ jobs:
java-version: [email protected]

- name: build ${{ matrix.scala }}
run: sbt ++${{ matrix.scala }} clean coverage test
run: sbt ++${{ matrix.scala }} clean check coverage test

- name: test coverage
if: success()
Expand Down
7 changes: 7 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules = [OrganizeImports]

OrganizeImports {
preset = INTELLIJ_2020_3
removeUnused = false # `true` is not supported in Scala 3.3.0
targetDialect = Auto
}
40 changes: 40 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version = 3.8.3

runner.dialect = scala213source3

maxColumn = 110
trailingCommas = multiple

align.preset = some
indent.defnSite = 2
indent.caseSite = 5
indent.extendSite = 2
indentOperator.exclude = "^(&&|\\|\\||~)$"
newlines.avoidForSimpleOverflow = [punct, tooLong, slc]
newlines.source = keep
newlines.implicitParamListModifierForce = [after]
spaces.beforeContextBoundColon = always
spaces.inInterpolatedStringCurlyBraces = true
verticalMultiline.atDefnSite = true
verticalMultiline.arityThreshold = 3
verticalMultiline.newlineAfterOpenParen = true
danglingParentheses.exclude = []
docstrings.oneline = fold
docstrings.wrap = no
importSelectors = singleLine

rewrite.rules = [
RedundantParens,
SortModifiers,
]

rewrite.sortModifiers.order = [
"override",
"private",
"protected",
"implicit",
"final",
"sealed",
"abstract",
"lazy",
]
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package com.evolutiongaming.concurrent.sequentially

import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations.*

import org.openjdk.jmh.annotations._
import java.util.concurrent.TimeUnit

@State(Scope.Benchmark)
@Warmup(iterations = 5)
@Measurement(iterations = 10)
@Fork(value = 1, jvmArgs = Array(
"-server",
"-Xms1g",
"-Xmx1g",
"-XX:NewSize=512m",
"-XX:MaxNewSize=512m",
"-XX:InitialCodeCacheSize=256m",
"-XX:ReservedCodeCacheSize=256m",
"-XX:-UseBiasedLocking",
"-XX:+AlwaysPreTouch",
"-XX:+UseParallelGC"))
@Fork(
value = 1,
jvmArgs = Array(
"-server",
"-Xms1g",
"-Xmx1g",
"-XX:NewSize=512m",
"-XX:MaxNewSize=512m",
"-XX:InitialCodeCacheSize=256m",
"-XX:ReservedCodeCacheSize=256m",
"-XX:-UseBiasedLocking",
"-XX:+AlwaysPreTouch",
"-XX:+UseParallelGC",
),
)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
abstract class Common {

}
abstract class Common {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import akka.stream.Materializer
import org.openjdk.jmh.annotations.{Benchmark, Level, Setup, TearDown}

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.duration.*

class SequentiallyAsyncBenchmark extends Common {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.evolutiongaming.concurrent.sequentially

import akka.actor.ActorSystem
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.annotations.*

import scala.concurrent.Await
import scala.concurrent.duration._

import scala.concurrent.duration.*

class SequentiallyBenchmark extends Common {

Expand All @@ -28,4 +27,4 @@ class SequentiallyBenchmark extends Common {
Await.ready(system.terminate(), 15.seconds)
()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import akka.stream.Materializer
import org.openjdk.jmh.annotations.{Benchmark, Level, Setup, TearDown}

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.duration.*

class SequentiallyHandlerBenchmark extends Common {

Expand All @@ -32,4 +32,3 @@ class SequentiallyHandlerBenchmark extends Common {
()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import akka.stream.Materializer
import org.openjdk.jmh.annotations.{Benchmark, Level, Setup, TearDown}

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.duration.*

class SequentiallyStreamBenchmark extends Common {

Expand Down
41 changes: 29 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
lazy val commonSettings = Seq(
organization := "com.evolutiongaming",
homepage := Some(new URL("http://github.com/evolution-gaming/sequentially")),
homepage := Some(url("https://github.com/evolution-gaming/sequentially")),
startYear := Some(2018),
organizationName := "Evolution",
organizationHomepage := Some(url("http://evolution.com")),
organizationHomepage := Some(url("https://evolution.com")),
scalaVersion := crossScalaVersions.value.head,
crossScalaVersions := Seq("2.13.14", "2.12.19", "3.3.3"),
crossScalaVersions := Seq("2.13.14", "3.3.3"),
Compile / scalacOptions ++= {
if (scalaBinaryVersion.value == "2.13") {
Seq(
"-Xsource:3"
)
} else Seq.empty
},
Compile / doc / scalacOptions += "-no-link-warnings",
publishTo := Some(Resolver.evolutionReleases),
licenses := Seq(("MIT", url("https://opensource.org/licenses/MIT"))),
releaseCrossBuild := true,
versionScheme := Some("semver-spec"))
versionScheme := Some("semver-spec"),
)

// Your next release will be binary compatible with the previous one,
// but it may not be source compatible (ie, it will be a minor release).
ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible

lazy val root = (project
in file(".")
settings (name := "sequentially-root")
settings commonSettings
settings (publish / skip := true)
aggregate(sequentially, benchmark, `sequentially-metrics`))
aggregate (sequentially, benchmark, `sequentially-metrics`))

lazy val sequentially = (project
in file("sequentially")
settings (name := "sequentially")
settings commonSettings
settings (libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-stream" % "2.6.21",
"com.typesafe.akka" %% "akka-testkit" % "2.6.21" % Test,
"com.evolutiongaming" %% "executor-tools" % "1.0.4",
"com.evolutiongaming" %% "future-helper" % "1.0.7",
"org.scalatest" %% "scalatest" % "3.2.10" % Test)))
"com.typesafe.akka" %% "akka-stream" % "2.6.21",
"com.typesafe.akka" %% "akka-testkit" % "2.6.21" % Test,
"com.evolutiongaming" %% "future-helper" % "1.0.7",
"org.scalatest" %% "scalatest" % "3.2.10" % Test,
)))

lazy val benchmark = (project
in file("benchmark")
enablePlugins(JmhPlugin)
enablePlugins JmhPlugin
settings (name := "benchmark")
settings commonSettings
dependsOn sequentially)
Expand All @@ -47,4 +58,10 @@ lazy val `sequentially-metrics` = (project
"com.evolutiongaming" %% "prometheus-tools" % "1.0.8"
)))

addCommandAlias("check", "show version")
//used by evolution-gaming/scala-github-actions
addCommandAlias(
"check",
"all versionPolicyCheck Compile/doc scalafmtCheckAll scalafmtSbtCheck; scalafixEnable; scalafixAll --check",
)

addCommandAlias("fmtAll", "all scalafmtAll scalafmtSbt; scalafixEnable; scalafixAll")
10 changes: 4 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")

addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.11")

addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")
addSbtPlugin("com.evolution" % "sbt-scalac-opts-plugin" % "0.0.9")

addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.1")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@ import scala.concurrent.Future

object MeteredSequentiallyAsync {

def apply[K](sequentially: SequentiallyAsync[K],
name: String,
sequentiallyMetrics: SequentiallyMetrics.Factory,
def apply[K](
sequentially: SequentiallyAsync[K],
name: String,
sequentiallyMetrics: SequentiallyMetrics.Factory,
): SequentiallyAsync[K] = {
apply(sequentially, sequentiallyMetrics(name))
}

def apply[K](sequentially: SequentiallyAsync[K],
metrics: SequentiallyMetrics,
): SequentiallyAsync[K] = new SequentiallyAsync[K] {
def async[KK <: K, T](key: K)(task: => Future[T]): Future[T] = {
val start = System.nanoTime()
def apply[K](
sequentially: SequentiallyAsync[K],
metrics: SequentiallyMetrics,
): SequentiallyAsync[K] =
new SequentiallyAsync[K] {
def async[KK <: K, T](key: K)(task: => Future[T]): Future[T] = {
val start = System.nanoTime()

def run(): Future[T] = {
metrics.queue(start)
metrics.run(task)
}
def run(): Future[T] = {
metrics.queue(start)
metrics.run(task)
}

sequentially.async(key)(run())
sequentially.async(key)(run())
}
}
}

trait Factory {
def apply[K](name: String): SequentiallyAsync[K]
Expand All @@ -38,8 +41,9 @@ object MeteredSequentiallyAsync {
def apply[K]: SequentiallyAsync[K]
}

def apply(provider: Provider,
sequentiallyMetrics: SequentiallyMetrics.Factory,
def apply(
provider: Provider,
sequentiallyMetrics: SequentiallyMetrics.Factory,
): Factory = new Factory {
override def apply[K](name: String): SequentiallyAsync[K] =
MeteredSequentiallyAsync(provider.apply[K], sequentiallyMetrics(name))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.evolutiongaming.concurrent

import com.evolutiongaming.prometheus.PrometheusHelper._
import com.evolutiongaming.prometheus.PrometheusHelper.*
import io.prometheus.client.{CollectorRegistry, Summary}

import scala.concurrent.Future
Expand All @@ -13,30 +13,27 @@ trait SequentiallyMetrics {
object SequentiallyMetrics {

def empty: SequentiallyMetrics = new SequentiallyMetrics {
def queue(startNanos: Long): Unit = ()
def queue(startNanos: Long): Unit = ()
def run[T](future: => Future[T]): Future[T] = future
}

/**
* name: String => SequentiallyMetrics
*/
/** name: String => SequentiallyMetrics */
type Factory = String => SequentiallyMetrics

object Factory {

def empty: Factory = _ => SequentiallyMetrics.empty

/**
* @note Must be singleton as metric names must be unique.
* @see CollectorRegistry#register
*/
/** @note Must be singleton as metric names must be unique.
* @see CollectorRegistry#register
*/
def apply(
prometheusRegistry: CollectorRegistry,
prefix: String = "sequentially",
): Factory = {
prometheusRegistry: CollectorRegistry,
prefix: String = "sequentially",
): Factory = {
val time = Summary
.build()
.name(s"${prefix}_time")
.name(s"${ prefix }_time")
.help("Latency of Sequentially operations (queue, run) (by name)")
.labelNames("name", "operation")
.defaultQuantiles()
Expand Down
Loading

0 comments on commit 566ce7f

Please sign in to comment.