Skip to content

Commit e648c28

Browse files
committed
Add grpcServer constructor
1 parent 9ecfd9a commit e648c28

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

jacodb-ets/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ dependencies {
2020

2121
testImplementation(kotlin("test"))
2222
testImplementation(Libs.mockk)
23-
testImplementation(Libs.grpc_api)
2423

2524
testFixturesImplementation(Libs.kotlin_logging)
2625
testFixturesImplementation(Libs.junit_jupiter_api)

jacodb-ets/src/test/kotlin/org/jacodb/ets/test/WireTest.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ package org.jacodb.ets.test
1818

1919
import greeter.GreeterClient
2020
import greeter.HelloRequest
21-
import io.grpc.ServerBuilder
2221
import mu.KotlinLogging
23-
import org.jacodb.ets.service.GreeterService
2422
import org.jacodb.ets.service.createGrpcClient
23+
import org.jacodb.ets.service.grpcServer
2524
import kotlin.test.Test
2625

2726
private val logger = KotlinLogging.logger {}
@@ -33,10 +32,7 @@ class WireTest {
3332

3433
@Test
3534
fun `test Greeter`() {
36-
val server = ServerBuilder
37-
.forPort(PORT)
38-
.addService(GreeterService())
39-
.build()
35+
val server = grpcServer(PORT)
4036
server.start()
4137
logger.info { "Server listening on port ${server.port}" }
4238

jacodb-ets/wire-server/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ buildscript {
1313
dependencies {
1414
protoSource(project(":jacodb-ets:wire-protos"))
1515
api(Libs.wire_grpc_server)
16+
api(Libs.grpc_api)
1617
implementation(Libs.grpc_protobuf)
1718
implementation(Libs.grpc_services) // for ProtoReflectionService
1819
implementation(Libs.kotlin_logging)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2022 UnitTestBot contributors (utbot.org)
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jacodb.ets.service
18+
19+
import io.grpc.Server
20+
import io.grpc.ServerBuilder
21+
import io.grpc.protobuf.services.ProtoReflectionService
22+
23+
fun grpcServer(
24+
port: Int,
25+
addReflection: Boolean = true,
26+
setup: ServerBuilder<*>.() -> Unit = {},
27+
): Server = ServerBuilder
28+
.forPort(port)
29+
.apply(setup)
30+
.apply {
31+
if (addReflection) addService(@Suppress("DEPRECATION") ProtoReflectionService.newInstance())
32+
}
33+
.build()

0 commit comments

Comments
 (0)