Skip to content

Commit a24bfb5

Browse files
committed
updated grpc tests to use explicit streaming call classes
1 parent a1823b3 commit a24bfb5

File tree

7 files changed

+292
-34
lines changed

7 files changed

+292
-34
lines changed

gen-tests.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ val generateGrpcTests by tasks.creating(JavaExec::class) {
564564
args = listOf(
565565
"--proto_path=wire-grpc-tests/src/test/proto",
566566
"--kotlin_out=wire-grpc-tests/src/test/proto-grpc",
567+
"--kotlin_explicit_streaming_calls",
567568
"routeguide/RouteGuideProto.proto"
568569
) + GRPC_PROTOS
569570
}

wire-grpc-tests/src/test/java/com/squareup/wire/GrpcClientTest.kt

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import assertk.assertions.isNotNull
3030
import assertk.assertions.isNotZero
3131
import assertk.assertions.isNull
3232
import assertk.assertions.isTrue
33-
import assertk.assertions.message
3433
import assertk.assertions.messageContains
3534
import assertk.assertions.startsWith
3635
import com.google.common.util.concurrent.SettableFuture
@@ -279,12 +278,12 @@ class GrpcClientTest {
279278
mockService.enqueue(SendCompleted)
280279
mockService.enqueue(ReceiveComplete)
281280

282-
val (requestChannel, responseChannel) = routeGuideService.RecordRoute().execute()
283281
runBlocking {
282+
val (requestChannel, deferredResponse) = routeGuideService.RecordRoute().executeIn(this)
284283
requestChannel.send(Point(3, 3))
285284
requestChannel.send(Point(9, 6))
286285
requestChannel.close()
287-
assertThat(responseChannel.receive()).isEqualTo(RouteSummary(point_count = 2))
286+
assertThat(deferredResponse.await()).isEqualTo(RouteSummary(point_count = 2))
288287
}
289288
}
290289

@@ -301,7 +300,7 @@ class GrpcClientTest {
301300
requestChannel.write(Point(3, 3))
302301
requestChannel.write(Point(9, 6))
303302
requestChannel.close()
304-
assertThat(deferredResponse.read()).isEqualTo(RouteSummary(point_count = 2))
303+
assertThat(deferredResponse.get()).isEqualTo(RouteSummary(point_count = 2))
305304
}
306305

307306
/**
@@ -333,7 +332,7 @@ class GrpcClientTest {
333332
val (requestChannel, deferredResponse) = routeGuideService.RecordRoute().executeBlocking()
334333
val e = assertFailsWith<IOException> {
335334
requestChannel.close()
336-
deferredResponse.read()
335+
deferredResponse.get()
337336
}
338337
assertThat(e).hasMessage("stream was reset: CANCEL")
339338
assertThat(e.cause).isNull()
@@ -343,12 +342,12 @@ class GrpcClientTest {
343342
fun cancelStreamingRequestSuspend() {
344343
mockService.enqueue(ReceiveCall("/routeguide.RouteGuide/RecordRoute"))
345344

346-
val (_, responseChannel) = routeGuideService.RecordRoute().execute()
347345
runBlocking {
346+
val (_, deferredResponse) = routeGuideService.RecordRoute().executeIn(this)
348347
// TODO(benoit) Fix it so we don't have to wait.
349348
// We wait for the request to proceed.
350349
delay(200)
351-
responseChannel.cancel()
350+
deferredResponse.cancel()
352351
mockService.awaitSuccess()
353352
assertThat(callReference.get()!!.isCanceled()).isTrue()
354353
}
@@ -375,10 +374,11 @@ class GrpcClientTest {
375374
mockService.enqueueSendFeature(name = "house")
376375
mockService.enqueue(SendCompleted)
377376

378-
val (requestChannel, responseChannel) = routeGuideService.ListFeatures().execute()
379377
runBlocking {
380-
requestChannel.send(Rectangle(lo = Point(0, 0), hi = Point(4, 5)))
381-
requestChannel.close()
378+
val responseChannel = routeGuideService.ListFeatures().executeIn(
379+
this,
380+
Rectangle(lo = Point(0, 0), hi = Point(4, 5)),
381+
)
382382
assertThat(responseChannel.receive()).isEqualTo(Feature(name = "tree"))
383383
assertThat(responseChannel.receive()).isEqualTo(Feature(name = "house"))
384384
assertThat(responseChannel.receiveCatching().getOrNull()).isNull()
@@ -394,9 +394,9 @@ class GrpcClientTest {
394394
mockService.enqueueSendFeature(name = "house")
395395
mockService.enqueue(SendCompleted)
396396

397-
val (requestChannel, responseChannel) = routeGuideService.ListFeatures().executeBlocking()
398-
requestChannel.write(Rectangle(lo = Point(0, 0), hi = Point(4, 5)))
399-
requestChannel.close()
397+
val responseChannel = routeGuideService.ListFeatures().executeBlocking(
398+
Rectangle(lo = Point(0, 0), hi = Point(4, 5)),
399+
)
400400
assertThat(responseChannel.read()).isEqualTo(Feature(name = "tree"))
401401
assertThat(responseChannel.read()).isEqualTo(Feature(name = "house"))
402402
assertThat(responseChannel.read()).isNull()
@@ -412,10 +412,11 @@ class GrpcClientTest {
412412
mockService.enqueueSendFeature(name = "house")
413413
mockService.enqueue(SendCompleted)
414414

415-
val (requestChannel, responseChannel) = routeGuideService.ListFeatures().execute()
416415
runBlocking {
417-
requestChannel.send(Rectangle(lo = Point(0, 0), hi = Point(4, 5)))
418-
requestChannel.close()
416+
val responseChannel = routeGuideService.ListFeatures().executeIn(
417+
this,
418+
Rectangle(lo = Point(0, 0), hi = Point(4, 5)),
419+
)
419420
assertThat(responseChannel.receive()).isEqualTo(Feature(name = "tree"))
420421
responseChannel.cancel()
421422
mockService.awaitSuccess()
@@ -433,9 +434,9 @@ class GrpcClientTest {
433434
mockService.enqueueSendFeature(name = "house")
434435
mockService.enqueue(SendCompleted)
435436

436-
val (requestChannel, responseChannel) = routeGuideService.ListFeatures().executeBlocking()
437-
requestChannel.write(Rectangle(lo = Point(0, 0), hi = Point(4, 5)))
438-
requestChannel.close()
437+
val responseChannel = routeGuideService.ListFeatures().executeBlocking(
438+
Rectangle(lo = Point(0, 0), hi = Point(4, 5)),
439+
)
439440
assertThat(responseChannel.read()).isEqualTo(Feature(name = "tree"))
440441
responseChannel.close()
441442
mockService.awaitSuccessBlocking()
@@ -1558,9 +1559,10 @@ class GrpcClientTest {
15581559
val grpcCall = routeGuideService.ListFeatures()
15591560
grpcCall.requestMetadata = mapOf("request-lucky-number" to "twenty-two")
15601561

1561-
val (requestChannel, responseChannel) = grpcCall.executeBlocking()
1562-
requestChannel.write(Rectangle(lo = Point(0, 0), hi = Point(4, 5)))
1563-
requestChannel.close()
1562+
val responseChannel = grpcCall.executeBlocking(
1563+
Rectangle(lo = Point(0, 0), hi = Point(4, 5)),
1564+
)
1565+
15641566
assertThat(responseChannel.read()).isEqualTo(Feature(name = "tree"))
15651567
assertThat(responseChannel.read()).isEqualTo(Feature(name = "house"))
15661568
assertThat(responseChannel.read()).isNull()
@@ -1615,9 +1617,9 @@ class GrpcClientTest {
16151617
grpcCall.requestMetadata = callMetadata
16161618

16171619
// First call.
1618-
val (requestChannel, responseChannel) = grpcCall.executeBlocking()
1619-
requestChannel.write(Rectangle(lo = Point(0, 0), hi = Point(4, 5)))
1620-
requestChannel.close()
1620+
val responseChannel = grpcCall.executeBlocking(
1621+
Rectangle(lo = Point(0, 0), hi = Point(4, 5)),
1622+
)
16211623
assertThat(responseChannel.read()).isEqualTo(Feature(name = "tree"))
16221624
assertThat(responseChannel.read()).isEqualTo(Feature(name = "house"))
16231625
assertThat(responseChannel.read()).isNull()
@@ -1628,9 +1630,7 @@ class GrpcClientTest {
16281630
// Modifying the original call's metadata should not affect the already cloned `clonedCall`.
16291631
callMetadata["request-lucky-number"] = "one"
16301632
clonedCall.requestMetadata += mapOf("all-in" to "true")
1631-
val (cloneRequestChannel, cloneResponseChannel) = clonedCall.executeBlocking()
1632-
cloneRequestChannel.write(Rectangle(lo = Point(0, 0), hi = Point(14, 15)))
1633-
cloneRequestChannel.close()
1633+
val cloneResponseChannel = clonedCall.executeBlocking(Rectangle(lo = Point(0, 0), hi = Point(14, 15)))
16341634
assertThat(cloneResponseChannel.read()).isEqualTo(Feature(name = "forest"))
16351635
assertThat(cloneResponseChannel.read()).isEqualTo(Feature(name = "cabane"))
16361636
assertThat(cloneResponseChannel.read()).isNull()

wire-grpc-tests/src/test/java/com/squareup/wire/GrpcOnMockWebServerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ class GrpcOnMockWebServerTest {
102102
return@GrpcCall Feature(name = "tree")
103103
}
104104

105-
override fun ListFeatures(): GrpcStreamingCall<Rectangle, Feature> {
105+
override fun ListFeatures(): GrpcServerStreamingCall<Rectangle, Feature> {
106106
TODO("Not yet implemented")
107107
}
108108

109-
override fun RecordRoute(): GrpcStreamingCall<Point, RouteSummary> {
109+
override fun RecordRoute(): GrpcClientStreamingCall<Point, RouteSummary> {
110110
TODO("Not yet implemented")
111111
}
112112

0 commit comments

Comments
 (0)