Skip to content
Permalink
Browse files

Merge pull request #954 from square/jesse+jem/use-wires-grpcclient-in…

…stead-of-misks

Use wire Grpc client instead of misks
  • Loading branch information...
swankjesse committed May 2, 2019
2 parents ea5e842 + 72c23dd commit 255d803a9fd3ab1236fe90eebe95fc7f8cd7ad94
@@ -76,8 +76,9 @@ ext.dep = [
"tracingJaeger": "com.uber.jaeger:jaeger-core:0.24.0",
"tracingZipkin": "io.opentracing.brave:brave-opentracing:0.29.0",
"vitess": "io.vitess:vitess-jdbc:3.0.0",
"wireRuntime": "com.squareup.wire:wire-runtime:3.0.0-alpha01",
"wireGrpcClient": "com.squareup.wire:wire-grpc-client:3.0.0-alpha01",
"wirePlugin": "com.squareup.wire:wire-gradle-plugin:3.0.0-alpha01",
"wireRuntime": "com.squareup.wire:wire-runtime:3.0.0-alpha01",
"zipkinBrave": "io.zipkin.brave:brave:4.17.2",
"zipkinReporter": "io.zipkin.reporter2:zipkin-sender-okhttp3:2.4.1",
"zookeeper": "org.apache.zookeeper:zookeeper:3.5.4-beta",
@@ -37,6 +37,9 @@ wire {
sourceSets {
main.java.srcDirs += 'build/generated/source/proto/main/grpc'
main.java.srcDirs += 'build/generated/source/proto/main/java'

// TODO(jwilson): we do this to make IntelliJ happy but the Wire Gradle plugin should do that.
main.java.srcDirs += 'build/generated/src/main/java'
}

dependencies {
@@ -45,6 +48,7 @@ dependencies {
compile dep.grpcNetty
compile dep.grpcProtobuf
compile dep.grpcStub
compile dep.wireGrpcClient
compile project(':misk')
compile project(':misk-testing')
}
@@ -0,0 +1,41 @@
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: routeguide/RouteGuideProto.proto
package routeguide

import com.squareup.wire.Service
import com.squareup.wire.WireRpc
import kotlin.Pair
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.SendChannel

// TODO(jwilson): generate this and remove it from git.
interface RouteGuide : Service {
@WireRpc(
path = "/routeguide.RouteGuide/GetFeature",
requestAdapter = "routeguide.Point#ADAPTER",
responseAdapter = "routeguide.Feature#ADAPTER"
)
suspend fun GetFeature(request: Point): Feature

@WireRpc(
path = "/routeguide.RouteGuide/ListFeatures",
requestAdapter = "routeguide.Rectangle#ADAPTER",
responseAdapter = "routeguide.Feature#ADAPTER"
)
suspend fun ListFeatures(request: Rectangle): ReceiveChannel<Feature>

@WireRpc(
path = "/routeguide.RouteGuide/RecordRoute",
requestAdapter = "routeguide.Point#ADAPTER",
responseAdapter = "routeguide.RouteSummary#ADAPTER"
)
suspend fun RecordRoute(): Pair<SendChannel<Point>, Deferred<RouteSummary>>

@WireRpc(
path = "/routeguide.RouteGuide/RouteChat",
requestAdapter = "routeguide.RouteNote#ADAPTER",
responseAdapter = "routeguide.RouteNote#ADAPTER"
)
suspend fun RouteChat(): Pair<SendChannel<RouteNote>, ReceiveChannel<RouteNote>>
}
@@ -1,16 +1,17 @@
package misk.grpc.miskclient

import com.google.inject.Provides
import com.squareup.wire.GrpcClient
import misk.client.HttpClientEndpointConfig
import misk.client.HttpClientModule
import misk.client.HttpClientSSLConfig
import misk.client.HttpClientsConfig
import misk.grpc.GrpcClient
import misk.inject.KAbstractModule
import misk.security.ssl.SslLoader
import misk.security.ssl.TrustStoreConfig
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import routeguide.RouteGuide
import javax.inject.Named
import javax.inject.Singleton

@@ -43,5 +44,14 @@ class MiskGrpcClientModule : KAbstractModule() {
fun provideGrpcClient(
client: OkHttpClient,
@Named("grpc server") url: HttpUrl
) = GrpcClient(client, url)
): GrpcClient {
return GrpcClient.Builder()
.client(client)
.baseUrl(url.toString()) // TODO(jwilson): this should also take a URL. Come on guys.
.build()
}

@Provides
@Singleton
fun provideRouteGuide(grpcClient: GrpcClient): RouteGuide = grpcClient.create(RouteGuide::class)
}
@@ -1,6 +1,7 @@
package misk.grpc

import com.google.inject.util.Modules
import kotlinx.coroutines.runBlocking
import misk.grpc.miskclient.MiskGrpcClientModule
import misk.grpc.miskserver.RouteGuideMiskServiceModule
import misk.testing.MiskTest
@@ -9,6 +10,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import routeguide.Feature
import routeguide.Point
import routeguide.RouteGuide
import javax.inject.Inject
import javax.inject.Provider

@@ -19,20 +21,20 @@ class MiskClientMiskServerTest {
MiskGrpcClientModule(),
RouteGuideMiskServiceModule())

@Inject lateinit var grpcClientProvider: Provider<GrpcClient>
@Inject lateinit var routeGuideProvider: Provider<RouteGuide>

@Test
fun requestResponse() {
val grpcMethod = GrpcMethod("/routeguide.RouteGuide/GetFeature",
routeguide.Point.ADAPTER, routeguide.Feature.ADAPTER)
runBlocking {
val routeGuide = routeGuideProvider.get()

val grpcClient = grpcClientProvider.get()
val feature = grpcClient.call(grpcMethod, Point(
latitude = 43,
longitude = -80))
assertThat(feature).isEqualTo(Feature(
name = "maple tree",
location = Point(latitude = 43, longitude = -80)
))
val feature = routeGuide.GetFeature(Point(
latitude = 43,
longitude = -80))
assertThat(feature).isEqualTo(Feature(
name = "maple tree",
location = Point(latitude = 43, longitude = -80)
))
}
}
}
@@ -1,6 +1,7 @@
package misk.grpc

import com.google.inject.util.Modules
import kotlinx.coroutines.runBlocking
import misk.MiskTestingServiceModule
import misk.grpc.miskclient.MiskGrpcClientModule
import misk.grpc.protocserver.RouteGuideProtocServiceModule
@@ -10,6 +11,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import routeguide.Feature
import routeguide.Point
import routeguide.RouteGuide
import javax.inject.Inject
import javax.inject.Provider

@@ -21,18 +23,20 @@ class MiskClientProtocServerTest {
RouteGuideProtocServiceModule(),
MiskTestingServiceModule())

@Inject lateinit var grpcClientProvider: Provider<GrpcClient>
@Inject lateinit var routeGuideProvider: Provider<RouteGuide>

@Test
fun requestResponse() {
val grpcMethod = GrpcMethod("/routeguide.RouteGuide/GetFeature",
routeguide.Point.ADAPTER, routeguide.Feature.ADAPTER)
runBlocking {
val routeGuide = routeGuideProvider.get()

val grpcClient = grpcClientProvider.get()
val feature = grpcClient.call(grpcMethod, Point(latitude = 43, longitude = -80))
assertThat(feature).isEqualTo(Feature(
name = "pine tree",
location = Point(latitude = 43, longitude = -80)
))
val feature = routeGuide.GetFeature(Point(
latitude = 43,
longitude = -80))
assertThat(feature).isEqualTo(Feature(
name = "pine tree",
location = Point(latitude = 43, longitude = -80)
))
}
}
}

This file was deleted.

Oops, something went wrong.

0 comments on commit 255d803

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