Skip to content

Commit 246ba77

Browse files
committed
Accessing endpoints from multiple servers
1 parent bec1dca commit 246ba77

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

modules/smithy4sTests/src/main/smithy/spec.smithy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,20 @@ operation Pong {
5050
pong: String
5151
}
5252
}
53+
54+
@jsonRPC
55+
service WeatherService {
56+
operations: [GetWeather]
57+
}
58+
59+
@jsonRequest("getWeather")
60+
operation GetWeather {
61+
input := {
62+
@required
63+
city: String
64+
}
65+
output := {
66+
@required
67+
weather: String
68+
}
69+
}

modules/smithy4sTests/src/test/scala/jsonrpclib/smithy4sinterop/TestServerSpec.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cats.effect.IO
44
import fs2.Stream
55
import test.TestServer
66
import test.TestClient
7+
import test.WeatherService
78
import weaver._
89
import smithy4s.kinds.FunctorAlgebra
910
import cats.syntax.all._
@@ -13,6 +14,8 @@ import jsonrpclib.fs2._
1314
import test.GreetOutput
1415
import io.circe.Encoder
1516
import test.GreetInput
17+
import test.GetWeatherOutput
18+
import test.GetWeatherInput
1619
import test.NotWelcomeError
1720
import io.circe.Decoder
1821
import smithy4s.Service
@@ -178,4 +181,36 @@ object TestServerSpec extends SimpleIOSuite {
178181
}
179182
}
180183
}
184+
185+
testRes("accessing endpoints from multiple servers") {
186+
class WeatherServiceImpl() extends WeatherService[IO] {
187+
override def getWeather(city: String): IO[GetWeatherOutput] = IO(GetWeatherOutput("sunny"))
188+
}
189+
190+
for {
191+
clientSideChannel <- setupAux(
192+
None,
193+
channel => {
194+
val testClient = ClientStub(TestClient, channel)
195+
Seq(AlgebraWrapper(new ServerImpl(testClient)), AlgebraWrapper(new WeatherServiceImpl()))
196+
},
197+
_ => Seq.empty
198+
)
199+
greetResult <- {
200+
implicit val inputEncoder: Encoder[GreetInput] = CirceJsonCodec.fromSchema
201+
implicit val outputDecoder: Decoder[GreetOutput] = CirceJsonCodec.fromSchema
202+
val remoteFunction = clientSideChannel.simpleStub[GreetInput, GreetOutput]("greet")
203+
remoteFunction(GreetInput("Bob")).toStream
204+
}
205+
getWeatherResult <- {
206+
implicit val inputEncoder: Encoder[GetWeatherInput] = CirceJsonCodec.fromSchema
207+
implicit val outputDecoder: Decoder[GetWeatherOutput] = CirceJsonCodec.fromSchema
208+
val remoteFunction = clientSideChannel.simpleStub[GetWeatherInput, GetWeatherOutput]("getWeather")
209+
remoteFunction(GetWeatherInput("Warsaw")).toStream
210+
}
211+
} yield {
212+
expect.same(greetResult.message, "Hello Bob") &&
213+
expect.same(getWeatherResult.weather, "sunny")
214+
}
215+
}
181216
}

0 commit comments

Comments
 (0)