Update interop server

This commit is contained in:
Lucio Franco
2019-09-06 15:37:08 -04:00
parent d0cfafafc6
commit ec5778dfa1
6 changed files with 51 additions and 22 deletions
+1 -1
View File
@@ -3,5 +3,5 @@ members = [
"tonic", "tonic",
"tonic-build", "tonic-build",
"tonic-examples", "tonic-examples",
# "tonic-interop", "tonic-interop",
] ]
+6 -5
View File
@@ -3,12 +3,12 @@ mod data;
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use std::time::Instant; use std::time::Instant;
use tokio::sync::{mpsc, Lock}; use tokio::sync::{mpsc, Lock};
use tonic::transport::Server; use tonic::transport::Server;
use tonic::{Request, Response, Status}; use tonic::{Request, Response, Status};
use std::pin::Pin;
pub mod routeguide { pub mod routeguide {
include!(concat!(env!("OUT_DIR"), "/routeguide.rs")); include!(concat!(env!("OUT_DIR"), "/routeguide.rs"));
@@ -147,7 +147,10 @@ impl routeguide::RouteGuide for RouteGuide {
}; };
// TODO: Clean this up // TODO: Clean this up
Ok(Response::new(Box::pin(output) as Pin<Box<dyn Stream<Item = Result<RouteNote, Status>> + Send + 'static>>)) Ok(Response::new(Box::pin(output)
as Pin<
Box<dyn Stream<Item = Result<RouteNote, Status>> + Send + 'static>,
>))
} }
} }
@@ -167,9 +170,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let svc = routeguide::RouteGuideServer::new(route_guide); let svc = routeguide::RouteGuideServer::new(route_guide);
Server::builder() Server::builder().serve(addr, svc).await?;
.serve(addr, svc)
.await?;
Ok(()) Ok(())
} }
+1
View File
@@ -19,6 +19,7 @@ prost = "0.5"
prost-derive = "0.5" prost-derive = "0.5"
bytes = "0.4" bytes = "0.4"
http = "0.1" http = "0.1"
futures-core-preview = "=0.3.0-alpha.18"
futures-util-preview = "=0.3.0-alpha.18" futures-util-preview = "=0.3.0-alpha.18"
console = "0.7" console = "0.7"
+1 -1
View File
@@ -2,7 +2,7 @@ fn main() {
let files = &["proto/grpc/testing/test.proto"]; let files = &["proto/grpc/testing/test.proto"];
let dirs = &["proto/grpc/testing"]; let dirs = &["proto/grpc/testing"];
tonic_build::compile_protos(files, dirs).unwrap(); tonic_build::compile_protos(files, dirs, "grpc.testing").unwrap();
// prevent needing to rebuild if files (or deps) haven't changed // prevent needing to rebuild if files (or deps) haven't changed
for file in files { for file in files {
+42 -9
View File
@@ -1,12 +1,11 @@
use structopt::StructOpt; use structopt::StructOpt;
use tonic::transport::Server; use tonic::{Code, Request, Response, Status, Server};
use tonic::{Code, Request, Response, Status}; use std::pin::Pin;
pub mod pb { pub mod pb {
#![allow(dead_code)] #![allow(dead_code)]
#![allow(unused_imports)] #![allow(unused_imports)]
include!(concat!(env!("OUT_DIR"), "/grpc.testing.rs")); include!(concat!(env!("OUT_DIR"), "/grpc.testing.rs"));
tonic::client!(service = "grpc.testing.TestService", proto = "self");
} }
use pb::*; use pb::*;
@@ -16,17 +15,21 @@ pub struct TestService {
data: String, data: String,
} }
#[tonic::server(service = "grpc.testing.TestService", proto = "pb")] type Result<T> = std::result::Result<Response<T>, Status>;
impl TestService { type Streaming<T> = Request<tonic::Streaming<T>>;
pub async fn empty_call(&self, _request: Request<Empty>) -> Result<Response<Empty>, Status> { type Stream<T> = Pin<Box<dyn futures_core::Stream<Item = std::result::Result<T, Status>> + Send + 'static>>;
#[tonic::async_trait]
impl pb::TestService for TestService {
async fn empty_call(&self, _request: Request<Empty>) -> Result<Empty> {
println!("empty_call"); println!("empty_call");
Ok(Response::new(Empty {})) Ok(Response::new(Empty {}))
} }
pub async fn unary_call( async fn unary_call(
&self, &self,
request: Request<SimpleRequest>, request: Request<SimpleRequest>,
) -> Result<Response<SimpleResponse>, Status> { ) -> Result<SimpleResponse> {
println!("unary_call"); println!("unary_call");
let req = request.into_inner(); let req = request.into_inner();
@@ -53,6 +56,36 @@ impl TestService {
Ok(Response::new(res)) Ok(Response::new(res))
} }
async fn cacheable_unary_call(&self, _: Request<SimpleRequest>) -> Result<SimpleResponse> {
unimplemented!()
}
type StreamingOutputCallStream = Stream<StreamingOutputCallResponse>;
async fn streaming_output_call(&self, _: Request<StreamingOutputCallRequest>) -> Result<Self::StreamingOutputCallStream> {
unimplemented!()
}
async fn streaming_input_call(&self, _: Streaming<StreamingInputCallRequest>) -> Result<StreamingInputCallResponse> {
unimplemented!()
}
type FullDuplexCallStream = Stream<StreamingOutputCallResponse>;
async fn full_duplex_call(&self, _: Streaming<StreamingOutputCallRequest>) -> Result<Self::FullDuplexCallStream> {
unimplemented!()
}
type HalfDuplexCallStream = Stream<StreamingOutputCallResponse>;
async fn half_duplex_call(&self, _: Streaming<StreamingOutputCallRequest>) -> Result<Self::HalfDuplexCallStream> {
unimplemented!()
}
async fn unimplemented_call(&self, _: Request<Empty>) -> Result<Empty> {
unimplemented!()
}
} }
#[derive(StructOpt)] #[derive(StructOpt)]
@@ -62,7 +95,7 @@ struct Opts {
} }
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let matches = Opts::from_args(); let matches = Opts::from_args();
pretty_env_logger::init(); pretty_env_logger::init();
-6
View File
@@ -7,12 +7,6 @@ use tonic::{metadata::MetadataValue, Code, Request, Response, Status};
pub type TestClient = TestServiceClient<Channel>; pub type TestClient = TestServiceClient<Channel>;
pub type UnimplementedClient = UnimplementedServiceClient<Channel>; pub type UnimplementedClient = UnimplementedServiceClient<Channel>;
tonic::client!(service = "grpc.testing.TestService", proto = "crate::pb");
tonic::client!(
service = "grpc.testing.UnimplementedService",
proto = "crate::pb"
);
const LARGE_REQ_SIZE: usize = 271828; const LARGE_REQ_SIZE: usize = 271828;
const LARGE_RSP_SIZE: i32 = 314159; const LARGE_RSP_SIZE: i32 = 314159;
const REQUEST_LENGTHS: &'static [i32] = &[27182, 8, 1828, 45904]; const REQUEST_LENGTHS: &'static [i32] = &[27182, 8, 1828, 45904];