Skip to content

Commit

Permalink
chore: debug fixes and version bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
owlot committed Sep 26, 2023
1 parent d1c6073 commit 168561b
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 218 deletions.
81 changes: 59 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tower = { version = "0.4", optional = true }
[dependencies.lib-common]
features = ["grpc"]
git = "https://github.com/Arrow-air/lib-common.git"
tag = "v0.1.1-develop.2"
tag = "v0.2.0"

[dependencies.tokio]
features = ["macros", "rt-multi-thread"]
Expand Down
14 changes: 5 additions & 9 deletions client-grpc/examples/grpc.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
//! gRPC client implementation

use lib_common::grpc::get_endpoint_from_env;
use svc_template_rust_client_grpc::client::{ReadyRequest, RpcServiceClient};
use svc_template_rust_client_grpc::service::Client as ServiceClient;
use svc_template_rust_client_grpc::{Client, GrpcClient};
use tonic::transport::Channel;
use svc_template_rust_client_grpc::prelude::*;

/// Example svc-template-rust-client-grpc
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
let connection =
GrpcClient::<RpcServiceClient<Channel>>::new_client(&host, port, "template_rust");
println!("Connection created");
let client = TemplateRustClient::new_client(&host, port, "template_rust");
println!("Client created.");
println!(
"NOTE: Ensure the server is running on {} or this example will fail.",
connection.get_address()
client.get_address()
);

let response = connection.is_ready(ReadyRequest {}).await?;
let response = client.is_ready(template_rust::ReadyRequest {}).await?;

println!("RESPONSE={:?}", response.into_inner());

Expand Down
92 changes: 92 additions & 0 deletions client-grpc/src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//! Client Library: Client Functions, Structs, Traits
#![allow(unused_qualifications)]
include!("grpc.rs");

use super::*;

#[cfg(not(feature = "stub_client"))]
use lib_common::grpc::ClientConnect;
use lib_common::grpc::{Client, GrpcClient};
use rpc_service_client::RpcServiceClient;
/// GrpcClient implementation of the RpcServiceClient
pub type TemplateRustClient = GrpcClient<RpcServiceClient<Channel>>;

cfg_if::cfg_if! {
if #[cfg(feature = "stub_backends")] {
use svc_template_rust::grpc::server::{RpcServiceServer, ServerImpl};
lib_common::grpc_mock_client!(RpcServiceClient, RpcServiceServer, ServerImpl);
super::log_macros!("grpc", "app::client::mock::template_rust");
} else {
lib_common::grpc_client!(RpcServiceClient);
super::log_macros!("grpc", "app::client::template_rust");
}
}

#[cfg(not(feature = "stub_client"))]
#[async_trait]
impl crate::service::Client<RpcServiceClient<Channel>> for TemplateRustClient {
type ReadyRequest = ReadyRequest;
type ReadyResponse = ReadyResponse;

async fn is_ready(
&self,
request: Self::ReadyRequest,
) -> Result<tonic::Response<Self::ReadyResponse>, tonic::Status> {
grpc_info!("(is_ready) {} client.", self.get_name());
grpc_debug!("(is_ready) request: {:?}", request);
self.get_client().await?.is_ready(request).await
}
}

#[cfg(feature = "stub_client")]
#[async_trait]
impl crate::service::Client<RpcServiceClient<Channel>> for TemplateRustClient {
type ReadyRequest = ReadyRequest;
type ReadyResponse = ReadyResponse;

async fn is_ready(
&self,
request: Self::ReadyRequest,
) -> Result<tonic::Response<Self::ReadyResponse>, tonic::Status> {
grpc_warn!("(is_ready MOCK) {} client.", self.get_name());
grpc_debug!("(is_ready MOCK) request: {:?}", request);
Ok(tonic::Response::new(ReadyResponse { ready: true }))
}
}

#[cfg(test)]
mod tests {
use crate::service::Client as ServiceClient;

use super::*;

#[tokio::test]
#[cfg(not(feature = "stub_client"))]
async fn test_client_connect() {
let name = "template_rust";
let (server_host, server_port) =
lib_common::grpc::get_endpoint_from_env("GRPC_HOST", "GRPC_PORT");

let client: TemplateRustClient = GrpcClient::new_client(&server_host, server_port, name);
assert_eq!(client.get_name(), name);

let connection = client.get_client().await;
println!("{:?}", connection);
assert!(connection.is_ok());
}

#[tokio::test]
async fn test_client_is_ready_request() {
let name = "template_rust";
let (server_host, server_port) =
lib_common::grpc::get_endpoint_from_env("GRPC_HOST", "GRPC_PORT");

let client: TemplateRustClient = GrpcClient::new_client(&server_host, server_port, name);
assert_eq!(client.get_name(), name);

let result = client.is_ready(ReadyRequest {}).await;
println!("{:?}", result);
assert!(result.is_ok());
assert_eq!(result.unwrap().into_inner().ready, true);
}
}
Loading

0 comments on commit 168561b

Please sign in to comment.