Skip to content

Commit

Permalink
Upgrade scala and fix test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongl committed Nov 28, 2023
1 parent 15552be commit 23254f2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
12 changes: 5 additions & 7 deletions all/src/main/scala/zhongl/stream/netty/all/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import scala.reflect.ClassTag

package object all {

implicit val sct: Transport[SocketChannel] = findAvailable[SocketTransports, SocketChannel]
implicit val ssct: Transport[ServerSocketChannel] = findAvailable[SocketTransports, ServerSocketChannel]
implicit val dsct: Transport[DomainSocketChannel] = findAvailable[DomainSocketTransports, DomainSocketChannel]
implicit val sdsct: Transport[ServerDomainSocketChannel] = findAvailable[DomainSocketTransports, ServerDomainSocketChannel]
implicit def sct: Transport[SocketChannel] = findAvailable[SocketTransports, SocketChannel]
implicit def ssct: Transport[ServerSocketChannel] = findAvailable[SocketTransports, ServerSocketChannel]
implicit def dsct: Transport[DomainSocketChannel] = findAvailable[DomainSocketTransports, DomainSocketChannel]
implicit def sdsct: Transport[ServerDomainSocketChannel] = findAvailable[DomainSocketTransports, ServerDomainSocketChannel]

implicit private def stss: Seq[SocketTransports] = Seq(EpollTransports, KQueueTransports, NioTransports)
implicit private def dstss: Seq[DomainSocketTransports] = Seq(EpollTransports, KQueueTransports)
Expand All @@ -37,9 +37,7 @@ package object all {
c: ClassTag[C],
g: GetTransport[T, C]
): Transport[C] = {
s.find(_.available).map(g(_)).getOrElse {
throw new IllegalStateException(s"${c.runtimeClass.getName} is unavailable in your environment")
}
s.find(_.available).map(g(_)).getOrElse { Transport.dummy[C] }
}

}
10 changes: 7 additions & 3 deletions all/src/test/scala/zhongl/stream/netty/all/ImplicitlySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zhongl.stream.netty.all

import java.net._
import java.nio.file.Files
import scala.concurrent.Future
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, Materializer}
import akka.stream.scaladsl.{Flow, Sink, Source}
Expand Down Expand Up @@ -45,7 +46,7 @@ class ImplicitlySpec extends TestKit(ActorSystem("implicitly")) with AsyncWordSp
} else if (Epoll.isAvailable) {
cc shouldBe classOf[EpollDomainSocketChannel]
} else {
assertThrows[IllegalStateException](cc)
cc shouldBe classOf[DomainSocketChannel]
}
}

Expand All @@ -62,7 +63,10 @@ class ImplicitlySpec extends TestKit(ActorSystem("implicitly")) with AsyncWordSp
}
}

private def runEcho[C <: DuplexChannel, S <: ServerChannel](address: SocketAddress)(implicit t: Transport[C], s: Transport[S]) = {
private def runEcho[C <: DuplexChannel, S <: ServerChannel](
address: SocketAddress
)(implicit t: Transport[C], s: Transport[S]): Future[Assertion] = {
if (t.isInstanceOf[Transport.Dummy[C]]) return Future(Assertions.succeed)
Netty().bindAndHandle[S](Flow[ByteString].map(identity), address).flatMap { sb =>
val msg = ByteString("a")
Source
Expand All @@ -73,5 +77,5 @@ class ImplicitlySpec extends TestKit(ActorSystem("implicitly")) with AsyncWordSp
.flatMap(a => sb.unbind().map(_ => a))
}
}
override protected def afterAll(): Unit = TestKit.shutdownActorSystem(system)
override protected def afterAll(): Unit = TestKit.shutdownActorSystem(system)
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inThisBuild(
"-encoding",
"UTF-8"
),
crossScalaVersions := Seq(scalaVersion.value, "2.12.15"),
crossScalaVersions := Seq(scalaVersion.value, "2.12.18"),
organization := "com.github.zhongl",
homepage := Some(url("https://github.com/hanabix/akka-stream-netty")),
licenses := List(
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/scala/zhongl/stream/netty/Transport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ object Transport {
override def channel = implicitly[ClassTag[C]].runtimeClass.asInstanceOf[Class[C]]
override def group = _group
}

def dummy[C <: Channel: ClassTag] = new Dummy(implicitly[ClassTag[C]])

class Dummy[C <: Channel](c: ClassTag[C]) extends Transport[C] {
override def channel: Class[_ <: C] = c.runtimeClass.asInstanceOf[Class[C]]
override def group: EventLoopGroup = throw new UnsupportedOperationException(s"${channel.getName} is unavailable in your environment")

}
}

0 comments on commit 23254f2

Please sign in to comment.