Rename client to channel
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use tonic::transport::Client;
|
||||
use tonic::transport::Channel;
|
||||
|
||||
pub mod hello_world {
|
||||
include!(concat!(env!("OUT_DIR"), "/helloworld.rs"));
|
||||
@@ -9,7 +9,7 @@ pub mod hello_world {
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let origin = http::Uri::from_static("http://[::1]:50051");
|
||||
|
||||
let svc = Client::builder().build(origin)?;
|
||||
let svc = Channel::builder().build(origin)?;
|
||||
|
||||
let mut client = hello_world::GreeterClient::new(svc);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use futures::TryStreamExt;
|
||||
use route_guide::{Point, RouteNote};
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::timer::Interval;
|
||||
use tonic::{transport::Client, Request};
|
||||
use tonic::{transport::Channel, Request};
|
||||
|
||||
mod route_guide {
|
||||
include!(concat!(env!("OUT_DIR"), "/routeguide.rs"));
|
||||
@@ -13,7 +13,7 @@ mod route_guide {
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let origin = http::Uri::from_static("http://[::1]:10000");
|
||||
|
||||
let svc = Client::builder().build(origin)?;
|
||||
let svc = Channel::builder().build(origin)?;
|
||||
let mut client = route_guide::RouteGuideClient::new(svc);
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
use structopt::{clap::arg_enum, StructOpt};
|
||||
use tonic_interop::client;
|
||||
use tonic::transport::Channel;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct Opts {
|
||||
@@ -25,8 +26,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let addr = "localhost:10000";
|
||||
let origin = http::Uri::from_shared(format!("http://{}", addr).into()).unwrap();
|
||||
|
||||
let mut client = client::create(origin.clone()).await?;
|
||||
let mut unimplemented_client = client::create_unimplemented(origin).await?;
|
||||
let channel = Channel::builder()
|
||||
// .tls(ca)
|
||||
// .tls_override_domain("foo.test.google.fr")
|
||||
.build(origin)?;
|
||||
|
||||
let mut client = client::TestClient::new(channel.clone());
|
||||
let mut unimplemented_client = client::UnimplementedClient::new(channel);
|
||||
|
||||
let mut failures = Vec::new();
|
||||
|
||||
for test_case in test_cases {
|
||||
println!("{:?}:", test_case);
|
||||
@@ -63,9 +71,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
for result in test_results {
|
||||
println!(" {}", result);
|
||||
|
||||
if result.is_failed() {
|
||||
failures.push(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !failures.is_empty() {
|
||||
println!("{} tests failed", failures.len());
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -1,11 +1,11 @@
|
||||
use crate::{pb::*, test_assert, TestAssertion};
|
||||
use futures_util::{future, stream, SinkExt, StreamExt};
|
||||
use tokio::sync::mpsc;
|
||||
use tonic::transport::Client;
|
||||
use tonic::transport::Channel;
|
||||
use tonic::{metadata::MetadataValue, Code, Request, Response, Status};
|
||||
|
||||
pub type TestClient = TestServiceClient<Client>;
|
||||
pub type UnimplementedClient = UnimplementedServiceClient<Client>;
|
||||
pub type TestClient = TestServiceClient<Channel>;
|
||||
pub type UnimplementedClient = UnimplementedServiceClient<Channel>;
|
||||
|
||||
tonic::client!(service = "grpc.testing.TestService", proto = "crate::pb");
|
||||
tonic::client!(
|
||||
@@ -22,11 +22,11 @@ const SPECIAL_TEST_STATUS_MESSAGE: &'static str =
|
||||
"\t\ntest with whitespace\r\nand Unicode BMP ☺ and non-BMP 😈\t\n";
|
||||
|
||||
pub async fn create(origin: http::Uri) -> Result<TestClient, Box<dyn std::error::Error>> {
|
||||
let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?;
|
||||
// let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?;
|
||||
|
||||
let svc = Client::builder()
|
||||
.tls(ca)
|
||||
.tls_override_domain("foo.test.google.fr")
|
||||
let svc = Channel::builder()
|
||||
// .tls(ca)
|
||||
// .tls_override_domain("foo.test.google.fr")
|
||||
.build(origin)?;
|
||||
|
||||
Ok(TestServiceClient::new(svc))
|
||||
@@ -35,11 +35,11 @@ pub async fn create(origin: http::Uri) -> Result<TestClient, Box<dyn std::error:
|
||||
pub async fn create_unimplemented(
|
||||
origin: http::Uri,
|
||||
) -> Result<UnimplementedClient, Box<dyn std::error::Error>> {
|
||||
let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?;
|
||||
// let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?;
|
||||
|
||||
let svc = Client::builder()
|
||||
.tls(ca)
|
||||
.tls_override_domain("foo.test.google.fr")
|
||||
let svc = Channel::builder()
|
||||
// .tls(ca)
|
||||
// .tls_override_domain("foo.test.google.fr")
|
||||
.build(origin)?;
|
||||
|
||||
Ok(UnimplementedServiceClient::new(svc))
|
||||
|
||||
@@ -47,6 +47,15 @@ pub enum TestAssertion {
|
||||
},
|
||||
}
|
||||
|
||||
impl TestAssertion {
|
||||
pub fn is_failed(&self) -> bool {
|
||||
match self {
|
||||
TestAssertion::Failed { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for TestAssertion {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use console::{style, Emoji};
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
SERVER="tonic-interop/bin/darwin/server"
|
||||
|
||||
# run the test server
|
||||
./"${SERVER}" &
|
||||
SERVER_PID=$!
|
||||
echo ":; started grpc-go test server."
|
||||
|
||||
# trap exits to make sure we kill the server process when the script exits,
|
||||
# regardless of why (errors, SIGTERM, etc).
|
||||
trap 'echo ":; killing test server"; kill ${SERVER_PID};' EXIT
|
||||
|
||||
cargo run -p tonic-interop --bin client -- \
|
||||
--test_case=empty_unary,large_unary,client_streaming,server_streaming,ping_pong,\
|
||||
empty_stream,status_code_and_message,special_status_message,unimplemented_method,\
|
||||
|
||||
+2
-2
@@ -27,12 +27,12 @@ tower-make = "=0.1.0-alpha.2"
|
||||
tower-reconnect = { path = "../../tower/tower-reconnect", optional = true }
|
||||
tower-buffer = { path = "../../tower/tower-buffer", optional = true }
|
||||
|
||||
# openssl
|
||||
# openssl
|
||||
tokio-openssl = { version = "=0.4.0-alpha.4", optional = true }
|
||||
openssl = { version = "0.10", optional = true }
|
||||
|
||||
# rustls
|
||||
tokio-rustls = { path = "../../tokio-rustls", optional = true }
|
||||
tokio-rustls = { version = "0.12.0-alpha.2", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["transport"]
|
||||
|
||||
@@ -26,17 +26,17 @@ type Inner = Box<
|
||||
>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Client {
|
||||
pub struct Channel {
|
||||
svc: Buffer<Inner, Request<BoxBody>>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
impl Channel {
|
||||
pub fn builder() -> Builder {
|
||||
Builder::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl GrpcService<BoxBody> for Client {
|
||||
impl GrpcService<BoxBody> for Channel {
|
||||
type ResponseBody = hyper::Body;
|
||||
type Error = super::Error;
|
||||
|
||||
@@ -89,7 +89,7 @@ impl Builder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build<T>(&self, uri: T) -> Result<Client, super::Error>
|
||||
pub fn build<T>(&self, uri: T) -> Result<Channel, super::Error>
|
||||
where
|
||||
Uri: http::HttpTryFrom<T>,
|
||||
{
|
||||
@@ -107,7 +107,7 @@ impl Builder {
|
||||
.unwrap_or_else(|| uri.to_string());
|
||||
|
||||
#[cfg(not(any(feature = "openssl-1", feature = "rustls")))]
|
||||
panic!("tls configured when no tls implementation feature was selected!");
|
||||
unreachable!("tls configured when no tls implementation feature was selected!");
|
||||
|
||||
#[cfg(feature = "openssl-1")]
|
||||
let connector = super::openssl::TlsConnector::new(ca.clone(), domain)?;
|
||||
@@ -131,9 +131,7 @@ impl Builder {
|
||||
let svc = BoxService::new(svc);
|
||||
Buffer::new(Box::new(svc) as Inner, 100)
|
||||
};
|
||||
// let connector = super::rustls::TlsConnector::load(ca).await?;
|
||||
// let connector = super::openssl::TlsConnector::load(ca).await?;
|
||||
|
||||
Ok(Client { svc })
|
||||
Ok(Channel { svc })
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
mod client;
|
||||
mod channel;
|
||||
#[cfg(feature = "openssl-1")]
|
||||
mod openssl;
|
||||
#[cfg(feature = "rustls")]
|
||||
mod rustls;
|
||||
|
||||
pub use self::client::Client;
|
||||
pub use self::channel::Channel;
|
||||
|
||||
use std::{error, fmt};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ impl TlsConnector {
|
||||
pub fn new(ca: Vec<u8>, domain: String) -> Result<Self, super::Error> {
|
||||
let mut config = SslConnector::builder(SslMethod::tls()).unwrap();
|
||||
|
||||
config.set_alpn_protos(b"\x02h2").unwrap();
|
||||
config.set_alpn_protos(b"\x06h2").unwrap();
|
||||
|
||||
let ca = X509::from_pem(&ca[..]).unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user