1
+ /*
2
+ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ package kotlinx.rpc.grpc.test.proto
6
+
7
+ import com.google.protobuf.kotlin.Empty
8
+ import com.google.protobuf.kotlin.EmptyInternal
9
+ import com.google.protobuf.kotlin.invoke
10
+ import kotlinx.rpc.RpcServer
11
+ import kotlinx.rpc.grpc.ManagedChannelBuilder
12
+ import kotlinx.rpc.grpc.buildChannel
13
+ import kotlinx.rpc.grpc.internal.MethodType
14
+ import kotlinx.rpc.grpc.internal.methodDescriptor
15
+ import kotlinx.rpc.grpc.internal.unaryRpc
16
+ import kotlinx.rpc.grpc.test.withJavaPkg.TheService
17
+ import kotlinx.rpc.registerService
18
+ import kotlinx.rpc.withService
19
+ import kotlin.test.Test
20
+
21
+ class TheServiceImpl : TheService {
22
+ override suspend fun TheMethod (message : Empty ): Empty {
23
+ return Empty {}
24
+ }
25
+ }
26
+
27
+ /* *
28
+ * Tests proto service with java_package that differs from the `package` name.
29
+ * While the generated Kotlin sources should be generated in the java_package,
30
+ * the service name must use the `package` name.
31
+ */
32
+ class JavaPackageOptionTest : GrpcProtoTest () {
33
+
34
+ /* *
35
+ * Tests that the generated service descriptor uses the `package` name.
36
+ */
37
+ @Test
38
+ fun testJavaPackageOptionRaw () = runGrpcTest { _ ->
39
+ val channel = ManagedChannelBuilder (" localhost" , PORT )
40
+ .usePlaintext()
41
+ .buildChannel()
42
+
43
+ val descriptor = methodDescriptor(
44
+ fullMethodName = " protopackage.TheService/TheMethod" ,
45
+ requestCodec = EmptyInternal .CODEC ,
46
+ responseCodec = EmptyInternal .CODEC ,
47
+ type = MethodType .UNARY ,
48
+ schemaDescriptor = Unit ,
49
+ idempotent = true ,
50
+ safe = true ,
51
+ sampledToLocalTracing = true ,
52
+ )
53
+
54
+ unaryRpc(channel.platformApi, descriptor, Empty {})
55
+
56
+ // just reach this without an error
57
+ }
58
+
59
+ /* *
60
+ * Tests that the generated client uses the `package` name to call the service.
61
+ */
62
+ @Test
63
+ fun testJavaPackageOptionStub () = runGrpcTest { client ->
64
+ val service = client.withService<TheService >()
65
+ service.TheMethod (Empty {})
66
+
67
+ // just reach this without an error
68
+ }
69
+
70
+ override fun RpcServer.registerServices () {
71
+ registerService<TheService > { TheServiceImpl () }
72
+ }
73
+ }
0 commit comments