Skip to content

Commit fa553d0

Browse files
xerialxerial-bot
andauthored
http (feature): Support Scala 3.3.1 (#3202)
- internal: Upgrade airspec to 23.9.0 (#3193) - Update scala3-staging, ... to 3.3.1 - deprecate registerTraitFactory #3200 - Fix grpc tests for Scala 3 --------- Co-authored-by: xerial-bot <[email protected]>
1 parent 3158b64 commit fa553d0

File tree

17 files changed

+119
-143
lines changed

17 files changed

+119
-143
lines changed

airframe-di/src/main/scala-3/wvlet/airframe/BinderImpl.scala

+32-32
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
1616
*/
1717
inline def to[B <: A]: DesignWithContext[B] = {
1818
{
19-
registerTraitFactory[B]
19+
// registerTraitFactory[B]
2020
val to = Surface.of[B]
2121
if (self.from == to) {
2222
wvlet.log.Logger("wvlet.airframe.Binder").warn("Binding to the same type is not allowed: " + to.toString)
@@ -28,7 +28,7 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
2828

2929
inline def toEagerSingletonOf[B <: A]: DesignWithContext[B] = {
3030
{
31-
registerTraitFactory[B]
31+
// registerTraitFactory[B]
3232
val to = Surface.of[B]
3333
if (self.from == to) {
3434
wvlet.log.Logger("wvlet.airframe.Binder").warn("Binding to the same type is not allowed: " + to.toString)
@@ -39,7 +39,7 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
3939
}
4040

4141
inline def toProvider[D1](factory: D1 => A): DesignWithContext[A] = {
42-
registerTraitFactory[D1]
42+
// registerTraitFactory[D1]
4343
self.design.addBinding[A](
4444
ProviderBinding(
4545
DependencyFactory(self.from, Seq(Surface.of[D1]), factory),
@@ -50,8 +50,8 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
5050
)
5151
}
5252
inline def toProvider[D1, D2](factory: (D1, D2) => A): DesignWithContext[A] = {
53-
registerTraitFactory[D1]
54-
registerTraitFactory[D2]
53+
// registerTraitFactory[D1]
54+
// registerTraitFactory[D2]
5555
self.design.addBinding[A](
5656
ProviderBinding(
5757
DependencyFactory(self.from, Seq(Surface.of[D1], Surface.of[D2]), factory),
@@ -62,9 +62,9 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
6262
)
6363
}
6464
inline def toProvider[D1, D2, D3](factory: (D1, D2, D3) => A): DesignWithContext[A] = {
65-
registerTraitFactory[D1]
66-
registerTraitFactory[D2]
67-
registerTraitFactory[D3]
65+
// registerTraitFactory[D1]
66+
// registerTraitFactory[D2]
67+
// registerTraitFactory[D3]
6868
self.design.addBinding[A](
6969
ProviderBinding(
7070
DependencyFactory(self.from, Seq(Surface.of[D1], Surface.of[D2], Surface.of[D3]), factory),
@@ -75,10 +75,10 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
7575
)
7676
}
7777
inline def toProvider[D1, D2, D3, D4](factory: (D1, D2, D3, D4) => A): DesignWithContext[A] = {
78-
registerTraitFactory[D1]
79-
registerTraitFactory[D2]
80-
registerTraitFactory[D3]
81-
registerTraitFactory[D4]
78+
// registerTraitFactory[D1]
79+
// registerTraitFactory[D2]
80+
// registerTraitFactory[D3]
81+
// registerTraitFactory[D4]
8282
self.design.addBinding[A](
8383
ProviderBinding(
8484
DependencyFactory(self.from, Seq(Surface.of[D1], Surface.of[D2], Surface.of[D3], Surface.of[D4]), factory),
@@ -89,11 +89,11 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
8989
)
9090
}
9191
inline def toProvider[D1, D2, D3, D4, D5](factory: (D1, D2, D3, D4, D5) => A): DesignWithContext[A] = {
92-
registerTraitFactory[D1]
93-
registerTraitFactory[D2]
94-
registerTraitFactory[D3]
95-
registerTraitFactory[D4]
96-
registerTraitFactory[D5]
92+
// registerTraitFactory[D1]
93+
// registerTraitFactory[D2]
94+
// registerTraitFactory[D3]
95+
// registerTraitFactory[D4]
96+
// registerTraitFactory[D5]
9797
self.design.addBinding[A](
9898
ProviderBinding(
9999
DependencyFactory(
@@ -109,7 +109,7 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
109109
}
110110

111111
inline def toEagerSingletonProvider[D1](factory: D1 => A): DesignWithContext[A] = {
112-
registerTraitFactory[D1]
112+
// registerTraitFactory[D1]
113113
self.design.addBinding[A](
114114
ProviderBinding(
115115
DependencyFactory(self.from, Seq(Surface.of[D1]), factory),
@@ -120,8 +120,8 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
120120
)
121121
}
122122
inline def toEagerSingletonProvider[D1, D2](factory: (D1, D2) => A): DesignWithContext[A] = {
123-
registerTraitFactory[D1]
124-
registerTraitFactory[D2]
123+
// registerTraitFactory[D1]
124+
// registerTraitFactory[D2]
125125
self.design.addBinding[A](
126126
ProviderBinding(
127127
DependencyFactory(self.from, Seq(Surface.of[D1], Surface.of[D2]), factory),
@@ -132,9 +132,9 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
132132
)
133133
}
134134
inline def toEagerSingletonProvider[D1, D2, D3](factory: (D1, D2, D3) => A): DesignWithContext[A] = {
135-
registerTraitFactory[D1]
136-
registerTraitFactory[D2]
137-
registerTraitFactory[D3]
135+
// registerTraitFactory[D1]
136+
// registerTraitFactory[D2]
137+
// registerTraitFactory[D3]
138138
self.design.addBinding[A](
139139
ProviderBinding(
140140
DependencyFactory(self.from, Seq(Surface.of[D1], Surface.of[D2], Surface.of[D3]), factory),
@@ -145,10 +145,10 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
145145
)
146146
}
147147
inline def toEagerSingletonProvider[D1, D2, D3, D4](factory: (D1, D2, D3, D4) => A): DesignWithContext[A] = {
148-
registerTraitFactory[D1]
149-
registerTraitFactory[D2]
150-
registerTraitFactory[D3]
151-
registerTraitFactory[D4]
148+
// registerTraitFactory[D1]
149+
// registerTraitFactory[D2]
150+
// registerTraitFactory[D3]
151+
// registerTraitFactory[D4]
152152
self.design.addBinding[A](
153153
ProviderBinding(
154154
DependencyFactory(self.from, Seq(Surface.of[D1], Surface.of[D2], Surface.of[D3], Surface.of[D4]), factory),
@@ -159,11 +159,11 @@ private[airframe] trait BinderImpl[A] extends LogSupport { self: Binder[A] =>
159159
)
160160
}
161161
inline def toEagerSingletonProvider[D1, D2, D3, D4, D5](factory: (D1, D2, D3, D4, D5) => A): DesignWithContext[A] = {
162-
registerTraitFactory[D1]
163-
registerTraitFactory[D2]
164-
registerTraitFactory[D3]
165-
registerTraitFactory[D4]
166-
registerTraitFactory[D5]
162+
// registerTraitFactory[D1]
163+
// registerTraitFactory[D2]
164+
// registerTraitFactory[D3]
165+
// registerTraitFactory[D4]
166+
// registerTraitFactory[D5]
167167
self.design.addBinding[A](
168168
ProviderBinding(
169169
DependencyFactory(

airframe-di/src/main/scala-3/wvlet/airframe/package.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ package object airframe {
4747
traitFactoryCache.getOrElseUpdate(s, factory)
4848
}
4949

50-
inline def registerTraitFactory[A]: Unit = ${
51-
registerTraitFactoryImpl[A]
50+
@deprecated("Instantiating trait is still experimental in Scala 3.3.1", "23.9.1")
51+
inline def registerTraitFactory[A]: Unit = {
52+
// registerTraitFactoryImpl[A]
5253
}
5354

5455
import scala.quoted._

airframe-di/src/test/scala-3/wvlet/airframe/di/TraitFactoryTest.scala

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ object TraitFactoryTest extends AirSpec {
2323
trait A
2424

2525
test("register trait factory") {
26+
if (isScala3) {
27+
pending("In Scala 3.3.1, creating a new trait instance via macro is still experimental")
28+
}
2629
registerTraitFactory[A]
2730
traitFactoryCache.get(Surface.of[A]) shouldBe defined
2831
}

airframe-http-grpc/src/test/scala/wvlet/airframe/http/grpc/GrpcErrorHandlingTest.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package wvlet.airframe.http.grpc
1616
import io.grpc.Status
1717
import io.grpc.Status.Code
1818
import io.grpc.StatusRuntimeException
19-
import wvlet.airframe.http.{RPCException, RPCStatus, Router}
19+
import wvlet.airframe.http.{RPCException, RPCStatus, Router, RxRouter}
2020
import wvlet.airframe.http.grpc.GrpcErrorLogTest.DemoApiDebug
2121
import wvlet.airframe.http.grpc.example.DemoApi.DemoApiClient
2222
import wvlet.airframe.http.grpc.internal.GrpcException
@@ -30,7 +30,7 @@ object GrpcErrorHandlingTest extends AirSpec {
3030
protected override def design = {
3131
gRPC.server
3232
.withName("error-handling-test-api")
33-
.withRouter(Router.add[DemoApiDebug])
33+
.withRouter(RxRouter.of[DemoApiDebug])
3434
.designWithChannel
3535
}
3636

@@ -45,6 +45,7 @@ object GrpcErrorHandlingTest extends AirSpec {
4545
l.setLogLevel(previousLogLevel)
4646
}
4747
}
48+
4849
test("exception test") { (client: DemoApiClient) =>
4950
warn("Starting a gRPC error handling test")
5051
suppressLog("wvlet.airframe.http.grpc.internal") {

airframe-http-grpc/src/test/scala/wvlet/airframe/http/grpc/GrpcErrorLogTest.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ package wvlet.airframe.http.grpc
1616
import wvlet.airframe.http.grpc.example.DemoApi
1717
import wvlet.airframe.http.grpc.example.DemoApi.DemoApiClient
1818
import wvlet.airframe.http.grpc.internal.GrpcRequestLogger
19-
import wvlet.airframe.http.Router
20-
import wvlet.airframe.http.HttpAccessLogWriter
21-
import wvlet.airspec.AirSpec
19+
import wvlet.airframe.http.{HttpAccessLogWriter, Router, RxRouter}
2220
import wvlet.airframe.rx.Rx
23-
import wvlet.log.Logger
21+
import wvlet.airspec.AirSpec
2422

2523
import scala.util.{Failure, Try}
2624

@@ -44,7 +42,7 @@ object GrpcErrorLogTest extends AirSpec {
4442
}
4543
}
4644

47-
private val router = Router.of[DemoApiDebug]
45+
private val router = RxRouter.of[DemoApiDebug]
4846

4947
protected override def design = {
5048
gRPC.server
@@ -55,6 +53,7 @@ object GrpcErrorLogTest extends AirSpec {
5553
.newLogger(config.name, inMemoryLogWriter)
5654
}
5755
.designWithChannel
56+
.bind[Router].toInstance(Router.of[DemoApiDebug])
5857
}
5958

6059
private def captureAll(body: => Unit): Seq[Map[String, Any]] = {

airframe-http-grpc/src/test/scala/wvlet/airframe/http/grpc/GrpcJsonTest.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package wvlet.airframe.http.grpc
1515

1616
import wvlet.airframe.http.{RPCEncoding, Router}
17-
import wvlet.airframe.http.grpc.example.DemoApi
17+
import wvlet.airframe.http.grpc.example.{DemoApi, DemoApiImpl}
1818
import wvlet.airframe.http.grpc.example.DemoApi.DemoApiClient
1919
import wvlet.airspec.AirSpec
2020
import wvlet.airframe.rx._
@@ -23,7 +23,7 @@ import wvlet.airframe.rx._
2323
*/
2424
class GrpcJsonTest extends AirSpec {
2525

26-
private def router = Router.add[DemoApi]
26+
private def router = Router.add[DemoApiImpl]
2727

2828
protected override def design = gRPC.server.withRouter(router).designWithChannel
2929

airframe-http-grpc/src/test/scala/wvlet/airframe/http/grpc/GrpcRequestLoggerTest.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GrpcRequestLoggerTest extends AirSpec {
5656
log("path") shouldBe "/wvlet.airframe.http.grpc.example.DemoApi/hello"
5757
log("content_type") shouldBe "application/grpc"
5858
log("rpc_interface") shouldBe "wvlet.airframe.http.grpc.example.DemoApi"
59-
log("rpc_class") shouldBe "wvlet.airframe.http.grpc.example.DemoApi"
59+
log("rpc_class") shouldBe "wvlet.airframe.http.grpc.example.DemoApiImpl"
6060
log("rpc_method") shouldBe "hello"
6161
log("rpc_args") shouldBe Map("name" -> "gRPC")
6262
log.contains("time") shouldBe true
@@ -78,7 +78,7 @@ class GrpcRequestLoggerTest extends AirSpec {
7878
log("path") shouldBe "/wvlet.airframe.http.grpc.example.DemoApi/helloClientStreaming"
7979
log("content_type") shouldBe "application/grpc"
8080
log("rpc_interface") shouldBe "wvlet.airframe.http.grpc.example.DemoApi"
81-
log("rpc_class") shouldBe "wvlet.airframe.http.grpc.example.DemoApi"
81+
log("rpc_class") shouldBe "wvlet.airframe.http.grpc.example.DemoApiImpl"
8282
log("rpc_method") shouldBe "helloClientStreaming"
8383
// Do not record rpc_args for client-streaming
8484
log.get("rpc_args") shouldBe empty
@@ -102,7 +102,7 @@ class GrpcRequestLoggerTest extends AirSpec {
102102
log("path") shouldBe "/wvlet.airframe.http.grpc.example.DemoApi/helloStreaming"
103103
log("content_type") shouldBe "application/grpc"
104104
log("rpc_interface") shouldBe "wvlet.airframe.http.grpc.example.DemoApi"
105-
log("rpc_class") shouldBe "wvlet.airframe.http.grpc.example.DemoApi"
105+
log("rpc_class") shouldBe "wvlet.airframe.http.grpc.example.DemoApiImpl"
106106
log("rpc_method") shouldBe "helloStreaming"
107107
// Do not record rpc_args for client-streaming
108108
log("rpc_args") shouldBe Map("name" -> "gRPC")
@@ -126,7 +126,7 @@ class GrpcRequestLoggerTest extends AirSpec {
126126
log("path") shouldBe "/wvlet.airframe.http.grpc.example.DemoApi/helloBidiStreaming"
127127
log("content_type") shouldBe "application/grpc"
128128
log("rpc_interface") shouldBe "wvlet.airframe.http.grpc.example.DemoApi"
129-
log("rpc_class") shouldBe "wvlet.airframe.http.grpc.example.DemoApi"
129+
log("rpc_class") shouldBe "wvlet.airframe.http.grpc.example.DemoApiImpl"
130130
log("rpc_method") shouldBe "helloBidiStreaming"
131131
// Do not record rpc_args for client-streaming
132132
log.get("rpc_args") shouldBe empty

airframe-http-grpc/src/test/scala/wvlet/airframe/http/grpc/GrpcStreamingTest.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package wvlet.airframe.http.grpc
1515

1616
import wvlet.airframe.http.Router
17-
import wvlet.airframe.http.grpc.example.DemoApi
17+
import wvlet.airframe.http.grpc.example.{DemoApi, DemoApiImpl}
1818
import wvlet.airframe.http.grpc.example.DemoApi.DemoApiClient
1919
import wvlet.airframe.rx.Rx
2020
import wvlet.airspec.AirSpec
@@ -23,7 +23,7 @@ import wvlet.airspec.AirSpec
2323
*/
2424
object GrpcStreamingTest extends AirSpec {
2525

26-
private lazy val router: Router = Router.add[DemoApi]
26+
private lazy val router: Router = Router.add[DemoApiImpl]
2727
protected override def design = {
2828
gRPC.server.withRouter(router).designWithChannel
2929
}

airframe-http-grpc/src/test/scala/wvlet/airframe/http/grpc/example/DemoApi.scala

+11-8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import wvlet.airframe.rx.Rx
3535
import wvlet.log.LogSupport
3636
import wvlet.airframe.http.router.Route
3737

38+
class DemoApiImpl extends DemoApi
39+
3840
@RPC
3941
trait DemoApi extends LogSupport {
4042
def getContext: String = {
@@ -132,21 +134,15 @@ object DemoApi extends LogSupport {
132134
}
133135
}
134136

137+
val router = Router.add[DemoApiImpl]
138+
135139
def design: Design = gRPC.server
136140
.withRouter(router)
137141
.withName("DemoApi")
138142
.withInterceptor(contextTestInterceptor)
139143
.designWithChannel
140144
.bind[DemoApiClient].toProvider { (channel: Channel) => new DemoApiClient(channel) }
141145

142-
val router = Router.add[DemoApi]
143-
144-
private def getRoute(name: String): Route = {
145-
router.routes.find(_.methodSurface.name == name).getOrElse {
146-
throw new IllegalArgumentException(s"Route is not found :${name}")
147-
}
148-
}
149-
150146
/**
151147
* Manually build a gRPC client here as we can't use sbt-airframe.
152148
* @param channel
@@ -163,6 +159,13 @@ object DemoApi extends LogSupport {
163159
override def build(channel: Channel, callOptions: CallOptions): DemoApiClient = {
164160
new DemoApiClient(channel, callOptions)
165161
}
162+
163+
private def getRoute(name: String): Route = {
164+
router.routes.find(_.methodSurface.name == name).getOrElse {
165+
throw new IllegalArgumentException(s"Route is not found :${name}")
166+
}
167+
}
168+
166169
private val codec = codecFactory.of[Map[String, Any]]
167170
private val getContextMethodDescriptor =
168171
GrpcServiceBuilder.buildMethodDescriptor(getRoute("getContext"), codecFactory)

airframe-http-grpc/src/test/scala/wvlet/airframe/http/grpc/example/DemoApiV2.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import wvlet.airframe.http.router.Route
3030
* Demo gRPC API used for GrpcClientTest
3131
*/
3232
@RPC
33-
trait DemoApiV2 extends LogSupport {
33+
class DemoApiV2 extends LogSupport {
3434
def hello(name: String): String = {
3535
name match {
3636
case "XXX" =>

airframe-http-grpc/src/test/scala/wvlet/airframe/http/grpc/example/Greeter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import wvlet.airframe.http.router.Route
2222
/**
2323
*/
2424
@RPC
25-
trait Greeter {
25+
class Greeter {
2626
def hello(name: String): String = s"Hello ${name}!"
2727
}
2828

airframe-http-okhttp/src/test/scala/wvlet/airframe/http/okhttp/OkHttpClientTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ case class User(id: Int, name: String, requestId: String) {
1919
case class UserRequest(id: Int, name: String)
2020
case class DeleteRequestBody(force: Boolean)
2121

22-
trait NettyTestApi extends LogSupport {
22+
class NettyTestApi extends LogSupport {
2323
import wvlet.airframe.http.{Endpoint, HttpMethod}
2424

2525
@Endpoint(method = HttpMethod.GET, path = "/")

airframe-http/src/main/scala-3/wvlet/airframe/http/RxRouterBase.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ import wvlet.airframe.surface.Surface
1919

2020
trait RxRouterObjectBase {
2121
inline def of[Controller]: RxRouter = {
22-
wvlet.airframe.registerTraitFactory[Controller]
22+
// wvlet.airframe.registerTraitFactory[Controller]
2323
RxRouter.EndpointNode(Surface.of[Controller], Surface.methodsOf[Controller], None)
2424
}
2525

2626
inline def filter[Filter <: RxHttpFilter]: RxRouter.FilterNode = {
27-
wvlet.airframe.registerTraitFactory[Filter]
27+
// wvlet.airframe.registerTraitFactory[Filter]
2828
RxRouter.FilterNode(None, Surface.of[Filter])
2929
}
3030
}
3131

3232
trait RxRouteFilterBase { self: RxRouter.FilterNode =>
3333
inline def andThen[Filter <: RxHttpFilter]: RxRouter.FilterNode = {
34-
wvlet.airframe.registerTraitFactory[Filter]
34+
// wvlet.airframe.registerTraitFactory[Filter]
3535
val next = RxRouter.FilterNode(None, Surface.of[Filter])
3636
self.andThen(next)
3737
}

0 commit comments

Comments
 (0)