diff --git a/all/src/main/scala/zhongl/stream/netty/all/package.scala b/all/src/main/scala/zhongl/stream/netty/all/package.scala index a1a2604..c100212 100644 --- a/all/src/main/scala/zhongl/stream/netty/all/package.scala +++ b/all/src/main/scala/zhongl/stream/netty/all/package.scala @@ -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) @@ -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] } } } diff --git a/all/src/test/scala/zhongl/stream/netty/all/ImplicitlySpec.scala b/all/src/test/scala/zhongl/stream/netty/all/ImplicitlySpec.scala index 6185c5f..c5c1758 100644 --- a/all/src/test/scala/zhongl/stream/netty/all/ImplicitlySpec.scala +++ b/all/src/test/scala/zhongl/stream/netty/all/ImplicitlySpec.scala @@ -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} @@ -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] } } @@ -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 @@ -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) } diff --git a/build.sbt b/build.sbt index faa60f9..0a1ae95 100644 --- a/build.sbt +++ b/build.sbt @@ -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( diff --git a/core/src/main/scala/zhongl/stream/netty/Transport.scala b/core/src/main/scala/zhongl/stream/netty/Transport.scala index b9974cc..135e393 100644 --- a/core/src/main/scala/zhongl/stream/netty/Transport.scala +++ b/core/src/main/scala/zhongl/stream/netty/Transport.scala @@ -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") + + } }