Skip to content
Permalink
Browse files

Streaming GRPC test

  • Loading branch information...
Jeremy Mawson
Jeremy Mawson committed May 1, 2019
1 parent 98796ad commit 8731b2c3ae8879fa41826640f60bbd18cece66c8
@@ -2,6 +2,7 @@ package misk.grpc.protocserver

import io.grpc.stub.StreamObserver
import routeguide.RouteGuideGrpc.RouteGuideImplBase
import routeguide.RouteGuideProto
import routeguide.RouteGuideProto.Feature
import routeguide.RouteGuideProto.Point
import javax.inject.Inject
@@ -16,4 +17,24 @@ internal class RouteGuideProtocService @Inject constructor() : RouteGuideImplBas
.build())
responseObserver.onCompleted()
}

override fun routeChat(
responseObserver: StreamObserver<RouteGuideProto.RouteNote>):
StreamObserver<RouteGuideProto.RouteNote> {
return object : StreamObserver<RouteGuideProto.RouteNote> {
override fun onNext(value: RouteGuideProto.RouteNote) {
responseObserver.onNext(RouteGuideProto.RouteNote.newBuilder()
.setMessage(value.message.reversed())
.build())
}

override fun onError(t: Throwable?) {
responseObserver.onCompleted()
}

override fun onCompleted() {
responseObserver.onCompleted()
}
}
}
}
@@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test
import routeguide.Feature
import routeguide.Point
import routeguide.RouteGuide
import routeguide.RouteNote
import javax.inject.Inject
import javax.inject.Provider

@@ -39,4 +40,18 @@ class MiskClientProtocServerTest {
))
}
}

@Test
fun streamingResponse() {
runBlocking {
val routeGuide = routeGuideProvider.get()

val (sendChannel, receiveChannel) = routeGuide.RouteChat()
sendChannel.send(RouteNote(message = "Taco cat"))
assertThat(receiveChannel.receive().message).isEqualTo("tac ocaT")
sendChannel.send(RouteNote(message = "A nut for a jar of tuna"))
assertThat(receiveChannel.receive().message).isEqualTo("anut fo raj a rof tun A")
sendChannel.close()
}
}
}

0 comments on commit 8731b2c

Please sign in to comment.
You can’t perform that action at this time.