Skip to content

Commit e541e1c

Browse files
committed
Version 0.6.0
1 parent 59165ab commit e541e1c

File tree

6 files changed

+60
-40
lines changed

6 files changed

+60
-40
lines changed

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/GrpcClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import kotlinx.rpc.RpcCall
1212
import kotlinx.rpc.RpcClient
1313
import kotlinx.rpc.grpc.descriptor.GrpcClientDelegate
1414
import kotlinx.rpc.grpc.descriptor.GrpcServiceDescriptor
15-
import kotlinx.rpc.internal.utils.map.ConcurrentHashMap
15+
import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap
1616
import kotlin.coroutines.CoroutineContext
1717

1818
/**
@@ -23,7 +23,7 @@ import kotlin.coroutines.CoroutineContext
2323
public class GrpcClient internal constructor(private val channel: ManagedChannel) : RpcClient {
2424
override val coroutineContext: CoroutineContext = SupervisorJob()
2525

26-
private val stubs = ConcurrentHashMap<Long, GrpcClientDelegate>()
26+
private val stubs = RpcInternalConcurrentHashMap<Long, GrpcClientDelegate>()
2727

2828
override suspend fun <T> call(call: RpcCall): T {
2929
return call.delegate().call(call)

protobuf-plugin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919

2020
testImplementation(projects.grpc.grpcCore)
2121
testImplementation(libs.coroutines.core)
22+
testImplementation(libs.coroutines.test)
2223
testImplementation(libs.kotlin.test)
2324

2425
testImplementation(libs.grpc.stub)

protobuf-plugin/src/main/kotlin/kotlinx/rpc/protobuf/model/NameResolver.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,16 @@ internal class NameResolver private constructor(
107107
}
108108

109109
private fun resolveFromNode(start: Node, parents: List<String>, simpleName: String): ResolveResult {
110+
val declarationOnlyResolve = start.fqName != FqName.Package.Root && start.fqName is FqName.Package
110111
var node: Node? = start
111112
var i = 0
112113
var entered = false
113114
while (i != parents.size) {
114115
node = node?.children[parents[i++]]
115116
if (node == null) {
116117
break
118+
} else if (node.fqName is FqName.Package && declarationOnlyResolve) {
119+
return ResolveResult.NoResolve
117120
}
118121
entered = true
119122
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.protobuf.test
6+
7+
import kotlinx.coroutines.sync.Mutex
8+
import kotlinx.coroutines.sync.withLock
9+
import kotlinx.coroutines.test.runTest
10+
import kotlinx.rpc.RpcServer
11+
import kotlinx.rpc.grpc.GrpcClient
12+
import kotlinx.rpc.grpc.GrpcServer
13+
14+
abstract class GrpcServerTest {
15+
private val serverMutex = Mutex()
16+
17+
abstract fun RpcServer.registerServices()
18+
19+
protected fun runGrpcTest(test: suspend (GrpcClient) -> Unit, ) = runTest {
20+
serverMutex.withLock {
21+
val grpcClient = GrpcClient("localhost", 8080) {
22+
usePlaintext()
23+
}
24+
25+
val grpcServer = GrpcServer(8080) {
26+
registerServices()
27+
}
28+
29+
grpcServer.start()
30+
test(grpcClient)
31+
grpcServer.shutdown()
32+
grpcServer.awaitTermination()
33+
}
34+
}
35+
}

protobuf-plugin/src/test/kotlin/kotlinx/rpc/protobuf/test/TestPrimitiveService.kt

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
package kotlinx.rpc.protobuf.test
66

7-
import kotlinx.coroutines.runBlocking
8-
import kotlinx.rpc.grpc.GrpcClient
9-
import kotlinx.rpc.grpc.GrpcServer
7+
import kotlinx.rpc.RpcServer
108
import kotlinx.rpc.registerService
119
import kotlinx.rpc.withService
1210
import kotlin.test.Test
@@ -18,19 +16,13 @@ class PrimitiveServiceImpl : PrimitiveService {
1816
}
1917
}
2018

21-
class TestPrimitiveService {
22-
@Test
23-
fun testPrimitive(): Unit = runBlocking {
24-
val grpcClient = GrpcClient("localhost", 8080) {
25-
usePlaintext()
26-
}
27-
28-
val grpcServer = GrpcServer(8080) {
29-
registerService<PrimitiveService> { PrimitiveServiceImpl() }
30-
}
31-
32-
grpcServer.start()
19+
class TestPrimitiveService : GrpcServerTest() {
20+
override fun RpcServer.registerServices() {
21+
registerService<PrimitiveService> { PrimitiveServiceImpl() }
22+
}
3323

24+
@Test
25+
fun testPrimitive(): Unit = runGrpcTest { grpcClient ->
3426
val service = grpcClient.withService<PrimitiveService>()
3527
val result = service.Echo(AllPrimitives {
3628
int32 = 42

protobuf-plugin/src/test/kotlin/kotlinx/rpc/protobuf/test/TestReferenceService.kt

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import References
99
import invoke
1010
import Other
1111
import kotlinx.coroutines.runBlocking
12+
import kotlinx.coroutines.sync.Mutex
13+
import kotlinx.coroutines.sync.withLock
14+
import kotlinx.coroutines.test.runTest
15+
import kotlinx.rpc.RpcServer
1216
import kotlinx.rpc.grpc.GrpcClient
1317
import kotlinx.rpc.grpc.GrpcServer
1418
import kotlinx.rpc.registerService
@@ -36,11 +40,13 @@ class ReferenceTestServiceImpl : ReferenceTestService {
3640
}
3741
}
3842

39-
class TestReferenceService {
40-
@Test
41-
fun testReferenceService()= runBlocking {
42-
val grpcClient = initializeServerAndClient()
43+
class TestReferenceService : GrpcServerTest() {
44+
override fun RpcServer.registerServices() {
45+
registerService<ReferenceTestService> { ReferenceTestServiceImpl() }
46+
}
4347

48+
@Test
49+
fun testReferenceService()= runGrpcTest { grpcClient ->
4450
val service = grpcClient.withService<ReferenceTestService>()
4551
val result = service.Get(References {
4652
other = Other {
@@ -53,9 +59,7 @@ class TestReferenceService {
5359
}
5460

5561
@Test
56-
fun testEnum() = runBlocking {
57-
val grpcClient = initializeServerAndClient()
58-
62+
fun testEnum() = runGrpcTest { grpcClient ->
5963
val service = grpcClient.withService<ReferenceTestService>()
6064
val result = service.Enum(UsingEnum {
6165
enum = Enum.ONE
@@ -65,9 +69,7 @@ class TestReferenceService {
6569
}
6670

6771
@Test
68-
fun testOptional() = runBlocking {
69-
val grpcClient = initializeServerAndClient()
70-
72+
fun testOptional() = runGrpcTest { grpcClient ->
7173
val service = grpcClient.withService<ReferenceTestService>()
7274
val resultNotNull = service.Optional(OptionalTypes {
7375
name = "test"
@@ -91,17 +93,4 @@ class TestReferenceService {
9193
assertEquals(null, resultNullable.age)
9294
assertEquals(null, resultNullable.reference)
9395
}
94-
95-
private fun initializeServerAndClient(): GrpcClient {
96-
val grpcClient = GrpcClient("localhost", 8080) {
97-
usePlaintext()
98-
}
99-
100-
val grpcServer = GrpcServer(8080) {
101-
registerService<ReferenceTestService> { ReferenceTestServiceImpl() }
102-
}
103-
104-
grpcServer.start()
105-
return grpcClient
106-
}
10796
}

0 commit comments

Comments
 (0)