Skip to content

Commit 5ab54ec

Browse files
committed
formatting and bump protoc
1 parent 79f40ca commit 5ab54ec

File tree

11 files changed

+214
-174
lines changed

11 files changed

+214
-174
lines changed

compiler/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dependencies {
3333
testImplementation(libs.guava)
3434
testImplementation(libs.jimfs)
3535
testImplementation(libs.protobuf.gradle.plugin)
36+
testImplementation(libs.protobuf.java)
3637
testImplementation(libs.mockito.kotlin)
3738
testImplementation(libs.junit.jupiter.engine)
3839
testImplementation(libs.mockito.core)

examples/client/build.gradle.kts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,29 @@ tasks.register<JavaExec>("AnimalsClient") {
3030
mainClass.set("io.grpc.examples.animals.AnimalsClientKt")
3131
}
3232

33-
val helloWorldClientStartScripts = tasks.register<CreateStartScripts>("helloWorldClientStartScripts") {
34-
mainClass.set("io.grpc.examples.helloworld.HelloWorldClientKt")
35-
applicationName = "hello-world-client"
36-
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
37-
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
38-
}
39-
40-
val routeGuideClientStartScripts = tasks.register<CreateStartScripts>("routeGuideClientStartScripts") {
41-
mainClass.set("io.grpc.examples.routeguide.RouteGuideClientKt")
42-
applicationName = "route-guide-client"
43-
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
44-
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
45-
}
46-
47-
val animalsClientStartScripts = tasks.register<CreateStartScripts>("animalsClientStartScripts") {
48-
mainClass.set("io.grpc.examples.animals.AnimalsClientKt")
49-
applicationName = "animals-client"
50-
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
51-
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
52-
}
33+
val helloWorldClientStartScripts =
34+
tasks.register<CreateStartScripts>("helloWorldClientStartScripts") {
35+
mainClass.set("io.grpc.examples.helloworld.HelloWorldClientKt")
36+
applicationName = "hello-world-client"
37+
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
38+
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
39+
}
40+
41+
val routeGuideClientStartScripts =
42+
tasks.register<CreateStartScripts>("routeGuideClientStartScripts") {
43+
mainClass.set("io.grpc.examples.routeguide.RouteGuideClientKt")
44+
applicationName = "route-guide-client"
45+
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
46+
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
47+
}
48+
49+
val animalsClientStartScripts =
50+
tasks.register<CreateStartScripts>("animalsClientStartScripts") {
51+
mainClass.set("io.grpc.examples.animals.AnimalsClientKt")
52+
applicationName = "animals-client"
53+
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
54+
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
55+
}
5356

5457
tasks.named("startScripts") {
5558
dependsOn(helloWorldClientStartScripts)

examples/client/src/main/kotlin/io/grpc/examples/routeguide/RouteGuideClient.kt

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class RouteGuideClient(private val channel: ManagedChannel) : Closeable {
3636
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS)
3737
}
3838

39-
suspend fun getFeature(latitude: Int, longitude: Int) {
39+
suspend fun getFeature(
40+
latitude: Int,
41+
longitude: Int,
42+
) {
4043
println("*** GetFeature: lat=$latitude lon=$longitude")
4144

4245
val request = point(latitude, longitude)
@@ -49,13 +52,19 @@ class RouteGuideClient(private val channel: ManagedChannel) : Closeable {
4952
}
5053
}
5154

52-
suspend fun listFeatures(lowLat: Int, lowLon: Int, hiLat: Int, hiLon: Int) {
55+
suspend fun listFeatures(
56+
lowLat: Int,
57+
lowLon: Int,
58+
hiLat: Int,
59+
hiLon: Int,
60+
) {
5361
println("*** ListFeatures: lowLat=$lowLat lowLon=$lowLon hiLat=$hiLat liLon=$hiLon")
5462

55-
val request = rectangle {
56-
lo = point(lowLat, lowLon)
57-
hi = point(hiLat, hiLon)
58-
}
63+
val request =
64+
rectangle {
65+
lo = point(lowLat, lowLon)
66+
hi = point(hiLat, hiLon)
67+
}
5968
var i = 1
6069
stub.listFeatures(request).collect { feature ->
6170
println("Result #${i++}: $feature")
@@ -72,14 +81,18 @@ class RouteGuideClient(private val channel: ManagedChannel) : Closeable {
7281
println("It took $duration seconds.")
7382
}
7483

75-
fun generateRoutePoints(features: List<Feature>, numPoints: Int): Flow<Point> = flow {
76-
for (i in 1..numPoints) {
77-
val feature = features.random(random)
78-
println("Visiting point ${feature.location.toStr()}")
79-
emit(feature.location)
80-
delay(timeMillis = random.nextLong(500L..1500L))
84+
fun generateRoutePoints(
85+
features: List<Feature>,
86+
numPoints: Int,
87+
): Flow<Point> =
88+
flow {
89+
for (i in 1..numPoints) {
90+
val feature = features.random(random)
91+
println("Visiting point ${feature.location.toStr()}")
92+
emit(feature.location)
93+
delay(timeMillis = random.nextLong(500L..1500L))
94+
}
8195
}
82-
}
8396

8497
suspend fun routeChat() {
8598
println("*** RouteChat")
@@ -90,35 +103,37 @@ class RouteGuideClient(private val channel: ManagedChannel) : Closeable {
90103
println("Finished RouteChat")
91104
}
92105

93-
private fun generateOutgoingNotes(): Flow<RouteNote> = flow {
94-
val notes = listOf(
95-
routeNote {
96-
message = "First message"
97-
location = point(0, 0)
98-
},
99-
routeNote {
100-
message = "Second message"
101-
location = point(0, 0)
102-
},
103-
routeNote {
104-
message = "Third message"
105-
location = point(10000000, 0)
106-
},
107-
routeNote {
108-
message = "Fourth message"
109-
location = point(10000000, 10000000)
110-
},
111-
routeNote {
112-
message = "Last message"
113-
location = point(0, 0)
106+
private fun generateOutgoingNotes(): Flow<RouteNote> =
107+
flow {
108+
val notes =
109+
listOf(
110+
routeNote {
111+
message = "First message"
112+
location = point(0, 0)
113+
},
114+
routeNote {
115+
message = "Second message"
116+
location = point(0, 0)
117+
},
118+
routeNote {
119+
message = "Third message"
120+
location = point(10000000, 0)
121+
},
122+
routeNote {
123+
message = "Fourth message"
124+
location = point(10000000, 10000000)
125+
},
126+
routeNote {
127+
message = "Last message"
128+
location = point(0, 0)
129+
},
130+
)
131+
for (note in notes) {
132+
println("Sending message \"${note.message}\" at ${note.location.toStr()}")
133+
emit(note)
134+
delay(500)
114135
}
115-
)
116-
for (note in notes) {
117-
println("Sending message \"${note.message}\" at ${note.location.toStr()}")
118-
emit(note)
119-
delay(500)
120136
}
121-
}
122137
}
123138

124139
suspend fun main() {
@@ -135,7 +150,11 @@ suspend fun main() {
135150
}
136151
}
137152

138-
private fun point(lat: Int, lon: Int): Point = point {
139-
latitude = lat
140-
longitude = lon
141-
}
153+
private fun point(
154+
lat: Int,
155+
lon: Int,
156+
): Point =
157+
point {
158+
latitude = lat
159+
longitude = lon
160+
}

examples/server/build.gradle.kts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,29 @@ tasks.register<JavaExec>("AnimalsServer") {
3535
mainClass.set("io.grpc.examples.animals.AnimalsServerKt")
3636
}
3737

38-
val helloWorldServerStartScripts = tasks.register<CreateStartScripts>("helloWorldServerStartScripts") {
39-
mainClass.set("io.grpc.examples.helloworld.HelloWorldServerKt")
40-
applicationName = "hello-world-server"
41-
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
42-
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
43-
}
38+
val helloWorldServerStartScripts =
39+
tasks.register<CreateStartScripts>("helloWorldServerStartScripts") {
40+
mainClass.set("io.grpc.examples.helloworld.HelloWorldServerKt")
41+
applicationName = "hello-world-server"
42+
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
43+
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
44+
}
4445

45-
val routeGuideServerStartScripts = tasks.register<CreateStartScripts>("routeGuideServerStartScripts") {
46-
mainClass.set("io.grpc.examples.routeguide.RouteGuideServerKt")
47-
applicationName = "route-guide-server"
48-
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
49-
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
50-
}
46+
val routeGuideServerStartScripts =
47+
tasks.register<CreateStartScripts>("routeGuideServerStartScripts") {
48+
mainClass.set("io.grpc.examples.routeguide.RouteGuideServerKt")
49+
applicationName = "route-guide-server"
50+
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
51+
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
52+
}
5153

52-
val animalsServerStartScripts = tasks.register<CreateStartScripts>("animalsServerStartScripts") {
53-
mainClass.set("io.grpc.examples.animals.AnimalsServerKt")
54-
applicationName = "animals-server"
55-
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
56-
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
57-
}
54+
val animalsServerStartScripts =
55+
tasks.register<CreateStartScripts>("animalsServerStartScripts") {
56+
mainClass.set("io.grpc.examples.animals.AnimalsServerKt")
57+
applicationName = "animals-server"
58+
outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir
59+
classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath
60+
}
5861

5962
tasks.named("startScripts") {
6063
dependsOn(helloWorldServerStartScripts)
@@ -66,7 +69,12 @@ tasks.withType<Test> {
6669
useJUnit()
6770

6871
testLogging {
69-
events = setOf(org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED, org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED, org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED)
72+
events =
73+
setOf(
74+
org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED,
75+
org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED,
76+
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
77+
)
7078
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
7179
showStandardStreams = true
7280
}
@@ -76,4 +84,4 @@ jib {
7684
container {
7785
mainClass = "io.grpc.examples.helloworld.HelloWorldServerKt"
7886
}
79-
}
87+
}

examples/server/src/main/kotlin/io/grpc/examples/animals/AnimalsServer.kt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import io.grpc.Server
2020
import io.grpc.ServerBuilder
2121

2222
class AnimalsServer constructor(private val port: Int) {
23-
val server: Server = ServerBuilder
24-
.forPort(port)
25-
.addService(DogService())
26-
.addService(PigService())
27-
.addService(SheepService())
28-
.build()
23+
val server: Server =
24+
ServerBuilder
25+
.forPort(port)
26+
.addService(DogService())
27+
.addService(PigService())
28+
.addService(SheepService())
29+
.build()
2930

3031
fun start() {
3132
server.start()
@@ -35,7 +36,7 @@ class AnimalsServer constructor(private val port: Int) {
3536
println("*** shutting down gRPC server since JVM is shutting down")
3637
this@AnimalsServer.stop()
3738
println("*** server shut down")
38-
}
39+
},
3940
)
4041
}
4142

@@ -48,21 +49,24 @@ class AnimalsServer constructor(private val port: Int) {
4849
}
4950

5051
internal class DogService : DogGrpcKt.DogCoroutineImplBase() {
51-
override suspend fun bark(request: BarkRequest) = barkReply {
52-
message = "Bark!"
53-
}
52+
override suspend fun bark(request: BarkRequest) =
53+
barkReply {
54+
message = "Bark!"
55+
}
5456
}
5557

5658
internal class PigService : PigGrpcKt.PigCoroutineImplBase() {
57-
override suspend fun oink(request: OinkRequest) = oinkReply {
58-
message = "Oink!"
59-
}
59+
override suspend fun oink(request: OinkRequest) =
60+
oinkReply {
61+
message = "Oink!"
62+
}
6063
}
6164

6265
internal class SheepService : SheepGrpcKt.SheepCoroutineImplBase() {
63-
override suspend fun baa(request: BaaRequest) = baaReply {
64-
message = "Baa!"
65-
}
66+
override suspend fun baa(request: BaaRequest) =
67+
baaReply {
68+
message = "Baa!"
69+
}
6670
}
6771
}
6872

examples/server/src/main/kotlin/io/grpc/examples/helloworld/HelloWorldServer.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import io.grpc.Server
2020
import io.grpc.ServerBuilder
2121

2222
class HelloWorldServer(private val port: Int) {
23-
val server: Server = ServerBuilder
24-
.forPort(port)
25-
.addService(HelloWorldService())
26-
.build()
23+
val server: Server =
24+
ServerBuilder
25+
.forPort(port)
26+
.addService(HelloWorldService())
27+
.build()
2728

2829
fun start() {
2930
server.start()
@@ -33,7 +34,7 @@ class HelloWorldServer(private val port: Int) {
3334
println("*** shutting down gRPC server since JVM is shutting down")
3435
this@HelloWorldServer.stop()
3536
println("*** server shut down")
36-
}
37+
},
3738
)
3839
}
3940

@@ -46,9 +47,10 @@ class HelloWorldServer(private val port: Int) {
4647
}
4748

4849
internal class HelloWorldService : GreeterGrpcKt.GreeterCoroutineImplBase() {
49-
override suspend fun sayHello(request: HelloRequest) = helloReply {
50-
message = "Hello ${request.name}"
51-
}
50+
override suspend fun sayHello(request: HelloRequest) =
51+
helloReply {
52+
message = "Hello ${request.name}"
53+
}
5254
}
5355
}
5456

0 commit comments

Comments
 (0)