/
RPCMethodNameTests.scala
106 lines (84 loc) · 3.27 KB
/
RPCMethodNameTests.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright 2017-2019 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package higherkindness.mu.rpc.protocol
import cats.Applicative
import cats.syntax.applicative._
import higherkindness.mu.rpc.common._
import higherkindness.mu.rpc.protocol.Utils._
import org.scalacheck.Prop._
import org.scalatest._
import org.scalatestplus.scalacheck.Checkers
class RPCMethodNameTests extends RpcBaseTestSuite with BeforeAndAfterAll with Checkers {
object RPCService {
case class Request(s: String)
case class Response(length: Int)
@service(Protobuf, Identity, None, Capitalize) trait ProtoRPCServiceDef[F[_]] {
def proto1(req: Request): F[Response]
}
@service(Avro, Identity, None, Capitalize) trait AvroRPCServiceDef[F[_]] {
def avro(req: Request): F[Response]
}
@service(AvroWithSchema, Identity, None, Capitalize) trait AvroWithSchemaRPCServiceDef[F[_]] {
def avroWithSchema(req: Request): F[Response]
}
class RPCServiceDefImpl[F[_]: Applicative]
extends ProtoRPCServiceDef[F]
with AvroRPCServiceDef[F]
with AvroWithSchemaRPCServiceDef[F] {
def proto1(bd: Request): F[Response] = Response(bd.s.length).pure
def avro(bd: Request): F[Response] = Response(bd.s.length).pure
def avroWithSchema(bd: Request): F[Response] = Response(bd.s.length).pure
}
}
"A RPC server" should {
import RPCService._
import higherkindness.mu.rpc.TestsImplicits._
implicit val H: RPCServiceDefImpl[ConcurrentMonad] = new RPCServiceDefImpl[ConcurrentMonad]
"be able to call a service with a capitalized method using proto" in {
withClient(
ProtoRPCServiceDef.bindService[ConcurrentMonad],
ProtoRPCServiceDef.clientFromChannel[ConcurrentMonad](_)) { client =>
check {
forAll { s: String =>
client.proto1(Request(s)).map(_.length).unsafeRunSync() == s.length
}
}
}
}
"be able to call a service with a capitalized method using avro" in {
withClient(
AvroRPCServiceDef.bindService[ConcurrentMonad],
AvroRPCServiceDef.clientFromChannel[ConcurrentMonad](_)) { client =>
check {
forAll { s: String =>
client.avro(Request(s)).map(_.length).unsafeRunSync() == s.length
}
}
}
}
"be able to call a service with a capitalized method using avro with schema" in {
withClient(
AvroWithSchemaRPCServiceDef.bindService[ConcurrentMonad],
AvroWithSchemaRPCServiceDef.clientFromChannel[ConcurrentMonad](_)) { client =>
check {
forAll { s: String =>
client.avroWithSchema(Request(s)).map(_.length).unsafeRunSync() == s.length
}
}
}
}
}
}