Skip to content

Commit

Permalink
Merge pull request #492 from http4s/dotty
Browse files Browse the repository at this point in the history
Scala 3.0.0-M2 and 3.0.0-M3 support
  • Loading branch information
rossabaker authored Feb 6, 2021
2 parents 6d6731c + afa9130 commit b9305cc
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.13.2]
scala: [2.12.12, 2.13.3, 3.0.0-M2, 3.0.0-M3]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.12]
scala: [2.13.3]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down
15 changes: 8 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ ThisBuild / versionIntroduced := Map(
"3.0.0-M3" -> "0.15.0"
)

ThisBuild / crossScalaVersions := Seq("2.12.12", "2.13.3", "3.0.0-M2", "3.0.0-M3")
ThisBuild / scalaVersion := crossScalaVersions.value.filter(_.startsWith("2.")).last

lazy val commonSettings = Seq(
description := "NIO Framework for Scala",
crossScalaVersions := Seq("2.11.12", "2.12.12", "2.13.3"),
scalaVersion := crossScalaVersions.value.filter(_.startsWith("2.")).last,
scalacOptions in Test ~= (_.filterNot(Set("-Ywarn-dead-code", "-Wdead-code", "-Xfatal-warnings"))), // because mockito
scalacOptions in Test ~= (_.filterNot(Set("-Ywarn-dead-code", "-Wdead-code"))), // because mockito
scalacOptions in (Compile, doc) += "-no-link-warnings",
unmanagedSourceDirectories in Compile ++= {
(unmanagedSourceDirectories in Compile).value.map { dir =>
Expand Down Expand Up @@ -69,8 +70,8 @@ lazy val core = Project("blaze-core", file("core"))
.settings(
libraryDependencies ++= Seq(log4s),
libraryDependencies ++= Seq(
specs2,
specs2Mock,
specs2.withDottyCompat(scalaVersion.value),
specs2Mock.withDottyCompat(scalaVersion.value),
logbackClassic
).map(_ % Test),
buildInfoPackage := "org.http4s.blaze",
Expand Down Expand Up @@ -98,8 +99,8 @@ lazy val http = Project("blaze-http", file("http"))
// Test Dependencies
libraryDependencies ++= Seq(
asyncHttpClient,
scalacheck,
specs2Scalacheck
scalacheck.withDottyCompat(scalaVersion.value),
specs2Scalacheck.withDottyCompat(scalaVersion.value)
).map(_ % Test),
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[MissingClassProblem]("org.http4s.blaze.http.http2.PingManager$PingState"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ private final class NIO1SocketServerGroup private (
// in case we were closed because the event loop was closed,
// we need to be ready to handle a `RejectedExecutionException`.
def doClose(): Unit = {
logger.info(s"Closing NIO1 channel $socketAddress")
this.logger.info(s"Closing NIO1 channel $socketAddress")
closed = true
listeningSet.synchronized {
listeningSet.remove(this)
}
try selectableChannel.close()
catch {
case NonFatal(t) => logger.warn(t)("Failure during channel close.")
case NonFatal(t) => this.logger.warn(t)("Failure during channel close.")
} finally connections.close() // allow the acceptor thread through
}

Expand All @@ -227,7 +227,7 @@ private final class NIO1SocketServerGroup private (
})
catch {
case _: RejectedExecutionException =>
logger.info("Selector loop closed. Closing in local thread.")
this.logger.info("Selector loop closed. Closing in local thread.")
doClose()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ final class SSLStage(engine: SSLEngine, maxWrite: Int = 1024 * 1024)
case DelayedRead(sz, p) => doRead(sz, p)
case DelayedWrite(d, p) => doWrite(d, p)
}

case status =>
handshakeFailure(util.bug(s"Unexpected status: ${status}"))
}

val start = System.nanoTime
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/org/http4s/blaze/channel/EchoStage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package channel

import org.http4s.blaze.pipeline.TailStage
import java.nio.ByteBuffer

import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success}
import org.http4s.blaze.pipeline.Command.EOF

Expand All @@ -28,7 +28,7 @@ class EchoStage extends TailStage[ByteBuffer] {

val msg = "echo: ".getBytes

private implicit def ec = util.Execution.trampoline
private implicit def ec: ExecutionContext = util.Execution.trampoline

final override def stageStartup(): Unit =
channelRead().onComplete {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import org.http4s.blaze.util.{Execution, FutureUnit}
import org.specs2.mutable._
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext

class PipelineSpec extends Specification {
private implicit def ec = Execution.trampoline
private implicit def ec: ExecutionContext = Execution.trampoline

class IntHead extends HeadStage[Int] {
def name = "IntHead"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import scala.concurrent._
import scala.util.control.NonFatal

class SSLStageSpec extends Specification {
implicit def ec = Execution.trampoline
implicit def ec: ExecutionContext = Execution.trampoline

def debug = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import java.nio.ByteBuffer
import org.http4s.blaze.http.http2.SettingsDecoder.SettingsFrame
import org.http4s.blaze.pipeline.TailStage
import org.http4s.blaze.util.{BufferTools, Execution}

import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}

/** Base type for performing the HTTP/2 prior knowledge handshake */
abstract class PriorKnowledgeHandshaker[T](localSettings: ImmutableHttp2Settings)
extends TailStage[ByteBuffer] {
final protected implicit def ec = Execution.trampoline
final protected implicit def ec: ExecutionContext = Execution.trampoline

override def name: String = s"${getClass.getSimpleName}($localSettings)"

Expand Down Expand Up @@ -112,6 +111,9 @@ abstract class PriorKnowledgeHandshaker[T](localSettings: ImmutableHttp2Settings

case Left(http2Exception) => sendGoAway(http2Exception)
}

case None =>
sendGoAway(Http2Exception.INTERNAL_ERROR.goaway("Could not read frame size"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class HeaderNamesSpec extends Specification {
}

"Accept a header with numbers" in {
HeaderNames.validH2HeaderKey('0' to '9' mkString) must_== true
HeaderNames.validH2HeaderKey(('0' to '9').mkString) must_== true
}

"Accept a header with lower case letters" in {
HeaderNames.validH2HeaderKey('a' to 'z' mkString) must_== true
HeaderNames.validH2HeaderKey(('a' to 'z').mkString) must_== true
}

"Accept a header with non-delimiters" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1434,12 +1434,11 @@ class FrameDecoderSpec extends Specification {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)

val listener = new MockFrameListener(false)
var data: ByteBuffer = null
var code: Option[Byte] = None
var flags: Option[Byte] = None
var streamId: Option[Int] = None
val dec = new FrameDecoder(Http2Settings.default, listener) {
var data: ByteBuffer = null
var code: Option[Byte] = None
var flags: Option[Byte] = None
var streamId: Option[Int] = None

override def onExtensionFrame(
_code: Byte,
_streamId: Int,
Expand All @@ -1454,10 +1453,10 @@ class FrameDecoderSpec extends Specification {
}

dec.decodeBuffer(testData) must_== Continue
dec.data must_== ByteBuffer.wrap(new Array[Byte](8))
dec.code must_== Some(0x16)
dec.flags must_== Some(0x00)
dec.streamId must_== Some(0)
data must_== ByteBuffer.wrap(new Array[Byte](8))
code must_== Some(0x16)
flags must_== Some(0x00)
streamId must_== Some(0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}
})

"roundtrip" >> prop { dataFrame: DataFrame =>
"roundtrip" >> prop { (dataFrame: DataFrame) =>
val frame = joinBuffers(
FrameSerializer.mkDataFrame(
dataFrame.streamId,
Expand All @@ -81,7 +81,7 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}

"Decode padded buffers" in {
forall(0 to 256) { i: Int =>
forall(0 to 256) { (i: Int) =>
def dat = mkData(20)
val frame = joinBuffers(FrameSerializer.mkDataFrame(3, false, i, dat))
dec(DataFrame(3, false, dat, i)).decodeBuffer(frame) must_== Continue
Expand Down Expand Up @@ -134,7 +134,7 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}
})

"roundtrip" >> prop { headerFrame: HeadersFrame =>
"roundtrip" >> prop { (headerFrame: HeadersFrame) =>
val buff1 = joinBuffers(
FrameSerializer.mkHeaderFrame(
headerFrame.streamId,
Expand Down Expand Up @@ -191,14 +191,14 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}
})

implicit lazy val arbPriority = Arbitrary(
implicit lazy val arbPriority: Arbitrary[PriorityFrame] = Arbitrary(
for {
streamId <- Gen.posNum[Int]
p <- genPriority.filter(_.dependentStreamId != streamId)
} yield PriorityFrame(streamId, p)
)

"roundtrip" >> prop { p: PriorityFrame =>
"roundtrip" >> prop { (p: PriorityFrame) =>
val buff1 = FrameSerializer.mkPriorityFrame(p.streamId, p.priority)
dec(p).decodeBuffer(buff1) must_== Continue
buff1.remaining() must_== 0
Expand Down Expand Up @@ -237,7 +237,7 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}
})

"roundtrip" >> prop { rst: RstFrame =>
"roundtrip" >> prop { (rst: RstFrame) =>
val buff1 = FrameSerializer.mkRstStreamFrame(rst.streamId, rst.code)
dec(rst).decodeBuffer(buff1) must_== Continue
buff1.remaining() must_== 0
Expand All @@ -257,7 +257,7 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}
})

"roundtrip" >> prop { ack: Boolean =>
"roundtrip" >> prop { (ack: Boolean) =>
val settings = if (ack) None else Some((0 until 100).map(i => Setting(i, i + 3)))

val buff1 = settings match {
Expand Down Expand Up @@ -289,7 +289,7 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}
})

"make a simple round trip" >> prop { pingFrame: PingFrame =>
"make a simple round trip" >> prop { (pingFrame: PingFrame) =>
val pingBuffer = FrameSerializer.mkPingFrame(pingFrame.ack, pingFrame.data)
dec(pingFrame).decodeBuffer(pingBuffer) must_== Continue
}
Expand Down Expand Up @@ -320,7 +320,7 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}
})

"roundtrip" >> prop { goAway: GoAwayFrame =>
"roundtrip" >> prop { (goAway: GoAwayFrame) =>
val encodedGoAway = FrameSerializer.mkGoAwayFrame(goAway.lastStream, goAway.err, goAway.data)
dec(goAway).decodeBuffer(encodedGoAway) must_== Continue
}
Expand All @@ -345,7 +345,7 @@ class FrameSerializerSpec extends Specification with ScalaCheck {
}
})

"roundtrip" >> prop { updateFrame: WindowUpdateFrame =>
"roundtrip" >> prop { (updateFrame: WindowUpdateFrame) =>
val updateBuffer =
FrameSerializer.mkWindowUpdateFrame(updateFrame.streamId, updateFrame.increment)
dec(updateFrame).decodeBuffer(updateBuffer) must_== Continue
Expand Down
Loading

0 comments on commit b9305cc

Please sign in to comment.