@@ -30,7 +30,6 @@ import assertk.assertions.isNotNull
30
30
import assertk.assertions.isNotZero
31
31
import assertk.assertions.isNull
32
32
import assertk.assertions.isTrue
33
- import assertk.assertions.message
34
33
import assertk.assertions.messageContains
35
34
import assertk.assertions.startsWith
36
35
import com.google.common.util.concurrent.SettableFuture
@@ -279,12 +278,12 @@ class GrpcClientTest {
279
278
mockService.enqueue(SendCompleted )
280
279
mockService.enqueue(ReceiveComplete )
281
280
282
- val (requestChannel, responseChannel) = routeGuideService.RecordRoute ().execute()
283
281
runBlocking {
282
+ val (requestChannel, deferredResponse) = routeGuideService.RecordRoute ().executeIn(this )
284
283
requestChannel.send(Point (3 , 3 ))
285
284
requestChannel.send(Point (9 , 6 ))
286
285
requestChannel.close()
287
- assertThat(responseChannel.receive ()).isEqualTo(RouteSummary (point_count = 2 ))
286
+ assertThat(deferredResponse.await ()).isEqualTo(RouteSummary (point_count = 2 ))
288
287
}
289
288
}
290
289
@@ -301,7 +300,7 @@ class GrpcClientTest {
301
300
requestChannel.write(Point (3 , 3 ))
302
301
requestChannel.write(Point (9 , 6 ))
303
302
requestChannel.close()
304
- assertThat(deferredResponse.read ()).isEqualTo(RouteSummary (point_count = 2 ))
303
+ assertThat(deferredResponse.get ()).isEqualTo(RouteSummary (point_count = 2 ))
305
304
}
306
305
307
306
/* *
@@ -333,7 +332,7 @@ class GrpcClientTest {
333
332
val (requestChannel, deferredResponse) = routeGuideService.RecordRoute ().executeBlocking()
334
333
val e = assertFailsWith<IOException > {
335
334
requestChannel.close()
336
- deferredResponse.read ()
335
+ deferredResponse.get ()
337
336
}
338
337
assertThat(e).hasMessage(" stream was reset: CANCEL" )
339
338
assertThat(e.cause).isNull()
@@ -343,12 +342,12 @@ class GrpcClientTest {
343
342
fun cancelStreamingRequestSuspend () {
344
343
mockService.enqueue(ReceiveCall (" /routeguide.RouteGuide/RecordRoute" ))
345
344
346
- val (_, responseChannel) = routeGuideService.RecordRoute ().execute()
347
345
runBlocking {
346
+ val (_, deferredResponse) = routeGuideService.RecordRoute ().executeIn(this )
348
347
// TODO(benoit) Fix it so we don't have to wait.
349
348
// We wait for the request to proceed.
350
349
delay(200 )
351
- responseChannel .cancel()
350
+ deferredResponse .cancel()
352
351
mockService.awaitSuccess()
353
352
assertThat(callReference.get()!! .isCanceled()).isTrue()
354
353
}
@@ -375,10 +374,11 @@ class GrpcClientTest {
375
374
mockService.enqueueSendFeature(name = " house" )
376
375
mockService.enqueue(SendCompleted )
377
376
378
- val (requestChannel, responseChannel) = routeGuideService.ListFeatures ().execute()
379
377
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
+ )
382
382
assertThat(responseChannel.receive()).isEqualTo(Feature (name = " tree" ))
383
383
assertThat(responseChannel.receive()).isEqualTo(Feature (name = " house" ))
384
384
assertThat(responseChannel.receiveCatching().getOrNull()).isNull()
@@ -394,9 +394,9 @@ class GrpcClientTest {
394
394
mockService.enqueueSendFeature(name = " house" )
395
395
mockService.enqueue(SendCompleted )
396
396
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
+ )
400
400
assertThat(responseChannel.read()).isEqualTo(Feature (name = " tree" ))
401
401
assertThat(responseChannel.read()).isEqualTo(Feature (name = " house" ))
402
402
assertThat(responseChannel.read()).isNull()
@@ -412,10 +412,11 @@ class GrpcClientTest {
412
412
mockService.enqueueSendFeature(name = " house" )
413
413
mockService.enqueue(SendCompleted )
414
414
415
- val (requestChannel, responseChannel) = routeGuideService.ListFeatures ().execute()
416
415
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
+ )
419
420
assertThat(responseChannel.receive()).isEqualTo(Feature (name = " tree" ))
420
421
responseChannel.cancel()
421
422
mockService.awaitSuccess()
@@ -433,9 +434,9 @@ class GrpcClientTest {
433
434
mockService.enqueueSendFeature(name = " house" )
434
435
mockService.enqueue(SendCompleted )
435
436
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
+ )
439
440
assertThat(responseChannel.read()).isEqualTo(Feature (name = " tree" ))
440
441
responseChannel.close()
441
442
mockService.awaitSuccessBlocking()
@@ -1558,9 +1559,10 @@ class GrpcClientTest {
1558
1559
val grpcCall = routeGuideService.ListFeatures ()
1559
1560
grpcCall.requestMetadata = mapOf (" request-lucky-number" to " twenty-two" )
1560
1561
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
+
1564
1566
assertThat(responseChannel.read()).isEqualTo(Feature (name = " tree" ))
1565
1567
assertThat(responseChannel.read()).isEqualTo(Feature (name = " house" ))
1566
1568
assertThat(responseChannel.read()).isNull()
@@ -1615,9 +1617,9 @@ class GrpcClientTest {
1615
1617
grpcCall.requestMetadata = callMetadata
1616
1618
1617
1619
// 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
+ )
1621
1623
assertThat(responseChannel.read()).isEqualTo(Feature (name = " tree" ))
1622
1624
assertThat(responseChannel.read()).isEqualTo(Feature (name = " house" ))
1623
1625
assertThat(responseChannel.read()).isNull()
@@ -1628,9 +1630,7 @@ class GrpcClientTest {
1628
1630
// Modifying the original call's metadata should not affect the already cloned `clonedCall`.
1629
1631
callMetadata[" request-lucky-number" ] = " one"
1630
1632
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 )))
1634
1634
assertThat(cloneResponseChannel.read()).isEqualTo(Feature (name = " forest" ))
1635
1635
assertThat(cloneResponseChannel.read()).isEqualTo(Feature (name = " cabane" ))
1636
1636
assertThat(cloneResponseChannel.read()).isNull()
0 commit comments