Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge series/0.23 into main #695

Merged
merged 17 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ name: Continuous Integration

on:
pull_request:
branches: ['**']
branches: ['**', '!update/**']
push:
branches: ['**']
branches: ['**', '!update/**']
tags: [v*]

env:
Expand Down Expand Up @@ -87,6 +87,10 @@ jobs:
- name: Check Java formatting
run: sbt '++${{ matrix.scala }}' '${{ matrix.ci }}' javafmtCheckAll

- name: Check scalafix lints
if: matrix.java == 'temurin@8' && !startsWith(matrix.scala, '3.')
run: sbt '++${{ matrix.scala }}' 'scalafixAll --check'

- name: Check unused compile dependencies
if: matrix.java == 'temurin@8'
run: sbt '++${{ matrix.scala }}' unusedCompileDependenciesTest
Expand Down
7 changes: 7 additions & 0 deletions .scalafix.blaze.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules = [
RedundantSyntax
]

triggered.rules = [
RedundantSyntax
]
15 changes: 15 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
rules = [
Http4sFs2Linters
Http4sGeneralLinters
Http4sUseLiteralsSyntax
LeakingImplicitClassVal
ExplicitResultTypes
OrganizeImports
]

triggered.rules = [
Http4sFs2Linters
Http4sGeneralLinters
Http4sUseLiteralsSyntax
LeakingImplicitClassVal
]
12 changes: 12 additions & 0 deletions .scalafix.test.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rules = [
Http4sGeneralLinters
Http4sUseLiteralsSyntax
LeakingImplicitClassVal
OrganizeImports
]

triggered.rules = [
Http4sGeneralLinters
Http4sUseLiteralsSyntax
LeakingImplicitClassVal
]
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.5.2
version = 3.5.8

style = default

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class Http1ServerStageSpec extends CatsEffectSuite {
.orNotFound

fixture.test("Http1ServerStage: routes should Handle trailing headers") { tw =>
(runRequest(tw, Seq(req("foo")), routes2).result).map { buff =>
runRequest(tw, Seq(req("foo")), routes2).result.map { buff =>
val results = dropDate(ResponseParser.parseBuffer(buff))
assertEquals(results._1, Ok)
assertEquals(results._3, "Foo: Bar")
Expand Down
47 changes: 30 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ ThisBuild / developers ++= List(
"bryce-anderson",
"Bryce L. Anderson",
"[email protected]",
url("https://github.com/bryce-anderson")),
url("https://github.com/bryce-anderson")
),
Developer(
"rossabaker",
"Ross A. Baker",
"[email protected]",
url("https://github.com/rossabaker")),
url("https://github.com/rossabaker")
),
Developer(
"ChristopherDavenport",
"Christopher Davenport",
"[email protected]",
url("https://github.com/ChristopherDavenport"))
url("https://github.com/ChristopherDavenport")
)
)
ThisBuild / startYear := Some(2014)

Expand All @@ -50,7 +53,8 @@ lazy val commonSettings = Seq(
}
},
run / fork := true,
scalafmtConfig := file(".scalafmt.blaze.conf")
scalafmtConfig := file(".scalafmt.blaze.conf"),
scalafixConfig := Some(file(".scalafix.blaze.conf"))
)

// currently only publishing tags
Expand All @@ -60,7 +64,8 @@ ThisBuild / githubWorkflowPublishTargetBranches :=
ThisBuild / githubWorkflowBuild ++= Seq(
WorkflowStep.Sbt(
List("${{ matrix.ci }}", "javafmtCheckAll"),
name = Some("Check Java formatting"))
name = Some("Check Java formatting")
)
)

lazy val blaze = project
Expand Down Expand Up @@ -93,7 +98,8 @@ lazy val core = Project("blaze-core", file("core"))
mimaBinaryIssueFilters ++= Seq(
// private constructor for which there are no sensible defaults
ProblemFilters.exclude[DirectMissingMethodProblem](
"org.http4s.blaze.channel.nio1.NIO1SocketServerGroup.this")
"org.http4s.blaze.channel.nio1.NIO1SocketServerGroup.this"
)
)
)
.dependsOn(testkit % Test)
Expand All @@ -107,14 +113,16 @@ lazy val http = Project("blaze-http", file("http"))
// Test Dependencies
libraryDependencies += asyncHttpClient % Test,
mimaBinaryIssueFilters ++= Seq(
ProblemFilters
.exclude[MissingClassProblem]("org.http4s.blaze.http.http2.PingManager$PingState"),
ProblemFilters
.exclude[MissingClassProblem]("org.http4s.blaze.http.http2.PingManager$PingState$"),
ProblemFilters.exclude[MissingClassProblem](
"org.http4s.blaze.http.http2.PingManager$PingState"),
ProblemFilters.exclude[MissingClassProblem](
"org.http4s.blaze.http.http2.PingManager$PingState$"),
ProblemFilters.exclude[MissingClassProblem](
"org.http4s.blaze.http.http2.client.ALPNClientSelector$ClientProvider"),
"org.http4s.blaze.http.http2.client.ALPNClientSelector$ClientProvider"
),
ProblemFilters.exclude[MissingClassProblem](
"org.http4s.blaze.http.http2.server.ALPNServerSelector$ServerProvider")
"org.http4s.blaze.http.http2.server.ALPNServerSelector$ServerProvider"
)
)
)
.dependsOn(testkit % Test, core % "test->test;compile->compile")
Expand Down Expand Up @@ -159,7 +167,8 @@ lazy val blazeCore = project
.exclude[DirectMissingMethodProblem]("org.http4s.blazecore.util.IdentityWriter.ec")
)
else Seq.empty
}
},
Test / scalafixConfig := Some(file(".scalafix.test.conf"))
)
.dependsOn(http)

Expand Down Expand Up @@ -221,7 +230,8 @@ lazy val blazeServer = project
)
)
else Seq.empty,
}
},
Test / scalafixConfig := Some(file(".scalafix.test.conf"))
)
.dependsOn(blazeCore % "compile;test->test")

Expand Down Expand Up @@ -317,7 +327,8 @@ lazy val blazeClient = project
)
)
else Seq.empty
}
},
Test / scalafixConfig := Some(file(".scalafix.test.conf"))
)
.dependsOn(blazeCore % "compile;test->test")

Expand All @@ -330,7 +341,8 @@ lazy val examples = Project("blaze-examples", file("examples"))
"org.http4s" %% "http4s-dsl" % http4sVersion,
"org.http4s" %% "http4s-circe" % http4sVersion,
"io.circe" %% "circe-generic" % "0.14.2"
)
),
Test / scalafixConfig := Some(file(".scalafix.test.conf"))
)
.dependsOn(blazeServer, blazeClient)

Expand All @@ -339,4 +351,5 @@ lazy val examples = Project("blaze-examples", file("examples"))
// use it in the local development process
addCommandAlias(
"validate",
";scalafmtCheckAll ;scalafmtSbtCheck ;javafmtCheckAll ;+test:compile ;test ;unusedCompileDependenciesTest ;mimaReportBinaryIssues")
";scalafmtCheckAll ;scalafmtSbtCheck ;javafmtCheckAll ;+test:compile ;test ;unusedCompileDependenciesTest ;mimaReportBinaryIssues"
)
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ abstract class ServerChannel extends Closeable { self =>
* @return
* true if the hook was successfully registered, false otherwise.
*/
final def addShutdownHook(f: () => Unit)(implicit
ec: ExecutionContext = Execution.directec): Boolean =
final def addShutdownHook(
f: () => Unit
)(implicit ec: ExecutionContext = Execution.directec): Boolean =
shutdownHooks.synchronized {
if (state != Open) false
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import java.util.concurrent.atomic.AtomicBoolean

private[blaze] final class NIO1ClientChannel(
private[this] val underlying: SocketChannel,
private[this] val onClose: () => Unit)
extends NIO1Channel {
private[this] val onClose: () => Unit
) extends NIO1Channel {

private[this] val closed = new AtomicBoolean(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ private[nio1] object NIO1HeadStage {
private def performWrite(
ch: NIO1ClientChannel,
scratch: ByteBuffer,
buffers: Array[ByteBuffer]): WriteResult =
buffers: Array[ByteBuffer]
): WriteResult =
try
if (BufferTools.areDirectOrEmpty(buffers)) {
ch.write(buffers)
Expand Down Expand Up @@ -198,7 +199,7 @@ private[nio1] final class NIO1HeadStage(

// / channel reading bits //////////////////////////////////////////////

final override def readRequest(size: Int): Future[ByteBuffer] = {
override final def readRequest(size: Int): Future[ByteBuffer] = {
logger.trace(s"NIOHeadStage received a read request of size $size")
val p = Promise[ByteBuffer]()

Expand Down Expand Up @@ -238,10 +239,10 @@ private[nio1] final class NIO1HeadStage(

// / channel write bits /////////////////////////////////////////////////

final override def writeRequest(data: ByteBuffer): Future[Unit] =
override final def writeRequest(data: ByteBuffer): Future[Unit] =
writeRequest(data :: Nil)

final override def writeRequest(data: collection.Seq[ByteBuffer]): Future[Unit] = {
override final def writeRequest(data: collection.Seq[ByteBuffer]): Future[Unit] = {
logger.trace(s"NIO1HeadStage Write Request: $data")
val p = Promise[Unit]()
selectorLoop.executeTask(new selectorLoop.LoopRunnable {
Expand Down Expand Up @@ -289,9 +290,9 @@ private[nio1] final class NIO1HeadStage(

// /////////////////////////////// Channel Ops ////////////////////////////////////////

final override def close(cause: Option[Throwable]): Unit = doClosePipeline(cause)
override final def close(cause: Option[Throwable]): Unit = doClosePipeline(cause)

final override protected def doClosePipeline(cause: Option[Throwable]): Unit = {
override protected final def doClosePipeline(cause: Option[Throwable]): Unit = {
// intended to be called from within the SelectorLoop but if
// it's closed it will be performed in the current thread
def doClose(t: Throwable): Unit = {
Expand Down Expand Up @@ -324,7 +325,8 @@ private[nio1] final class NIO1HeadStage(
selectorLoop.executeTask(new Runnable {
def run(): Unit = {
logger.trace(
s"closeWithError($cause); readPromise: $readPromise, writePromise: $writePromise")
s"closeWithError($cause); readPromise: $readPromise, writePromise: $writePromise"
)
val c = cause match {
case Some(ex) =>
logger.error(cause.get)("Abnormal NIO1HeadStage termination")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ private final class NIO1SocketServerGroup private (
acceptorPool: SelectorLoopPool,
workerPool: SelectorLoopPool,
channelOptions: ChannelOptions,
maxConnections: Int)
extends ServerChannelGroup {
maxConnections: Int
) extends ServerChannelGroup {
private[this] val logger = getLogger
// Also acts as our intrinsic lock.
private[this] val listeningSet = new mutable.HashSet[ServerChannelImpl]()
Expand All @@ -140,8 +140,8 @@ private final class NIO1SocketServerGroup private (
private[this] class SocketAcceptor(
key: SelectionKey,
ch: ServerChannelImpl,
service: SocketPipelineBuilder)
extends Selectable {
service: SocketPipelineBuilder
) extends Selectable {
// Save it since once the channel is closed, we're in trouble.
private[this] val closed = new AtomicBoolean(false)

Expand Down Expand Up @@ -192,8 +192,8 @@ private final class NIO1SocketServerGroup private (
// minimize race conditions.
private[this] final class ServerChannelImpl(
val selectableChannel: ServerSocketChannel,
selectorLoop: SelectorLoop)
extends ServerChannel
selectorLoop: SelectorLoop
) extends ServerChannel
with NIO1Channel {
@volatile
private[this] var closed = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ final class SelectorLoop(
*/
def run(scratch: ByteBuffer): Unit

final override def run(): Unit = {
override final def run(): Unit = {
val currentThread = Thread.currentThread
if (currentThread == thread) run(scratch)
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ final class ClientChannelFactory(
group: Option[AsynchronousChannelGroup] = None,
channelOptions: ChannelOptions = ChannelOptions.DefaultOptions,
scheduler: TickWheelExecutor = Execution.scheduler,
connectTimeout: Duration = Duration.Inf) {
connectTimeout: Duration = Duration.Inf
) {
private[this] val logger = getLogger

// for binary compatibility with <=0.14.6
def this(
bufferSize: Int,
group: Option[AsynchronousChannelGroup],
channelOptions: ChannelOptions) =
channelOptions: ChannelOptions
) =
this(bufferSize, group, channelOptions, Execution.scheduler, Duration.Inf)

def connect(
remoteAddress: SocketAddress,
bufferSize: Int = bufferSize): Future[HeadStage[ByteBuffer]] = {
bufferSize: Int = bufferSize
): Future[HeadStage[ByteBuffer]] = {
val p = Promise[HeadStage[ByteBuffer]]()

try {
Expand All @@ -65,7 +68,8 @@ final class ClientChannelFactory(
val onTimeout = new Runnable {
override def run(): Unit = {
val exception = new SocketTimeoutException(
s"An attempt to establish connection with $remoteAddress timed out after $connectTimeout.")
s"An attempt to establish connection with $remoteAddress timed out after $connectTimeout."
)
val finishedWithTimeout = p.tryFailure(exception)
if (finishedWithTimeout)
try ch.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ object LeafBuilder {
*/
final class TrunkBuilder[I1, O] private[pipeline] (
protected val head: MidStage[I1, _],
protected val tail: MidStage[_, O]) {
protected val tail: MidStage[_, O]
) {
def append[N](stage: MidStage[O, N]): TrunkBuilder[I1, N] = {
if (stage._prevStage != null) sys.error(s"Stage $stage must be fresh")
if (stage.isInstanceOf[HeadStage[_]])
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/org/http4s/blaze/pipeline/Stages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import scala.util.control.NonFatal
*/

sealed trait Stage {
final protected val logger = getLogger(this.getClass)
protected final val logger = getLogger(this.getClass)

def name: String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ abstract class TimeoutStageBase[T](timeout: Duration, exec: TickWheelExecutor)
super.stageShutdown()
}

final protected def resetTimeout(): Unit =
protected final def resetTimeout(): Unit =
setAndCancel(exec.schedule(killswitch, timeout))

final protected def cancelTimeout(): Unit =
protected final def cancelTimeout(): Unit =
setAndCancel(Cancelable.NoopCancel)

final protected def startTimeout(): Unit = resetTimeout()
protected final def startTimeout(): Unit = resetTimeout()
}

private object TimeoutStageBase {
Expand Down
Loading