summaryrefslogtreecommitdiff
path: root/test/rs
diff options
context:
space:
mode:
authorAllen George <allengeorge@apache.org>2021-03-01 23:19:52 -0500
committerGitHub <noreply@github.com>2021-03-01 23:19:52 -0500
commit55c3e4c2eff86b61eae1b098803e72d682bdaafb (patch)
treebf8f63ef1cdc0678c7ecbed0be8d4dbd8c179fbb /test/rs
parent1ab156ab17b6f3268a1ba57034b4d4dc96f4f306 (diff)
downloadthrift-55c3e4c2eff86b61eae1b098803e72d682bdaafb.tar.gz
Reformat rust code using 1.40 rustfmt and fail build if rustfmt fails (#2339)
Diffstat (limited to 'test/rs')
-rw-r--r--test/rs/Makefile.am1
-rw-r--r--test/rs/src/bin/test_client.rs220
-rw-r--r--test/rs/src/bin/test_server.rs166
3 files changed, 185 insertions, 202 deletions
diff --git a/test/rs/Makefile.am b/test/rs/Makefile.am
index 4b061eae0..afb2cad03 100644
--- a/test/rs/Makefile.am
+++ b/test/rs/Makefile.am
@@ -22,6 +22,7 @@ stubs: ../ThriftTest.thrift
precross: stubs
$(CARGO) build
+ $(CARGO) fmt --all -- --check
[ -d bin ] || mkdir bin
cp target/debug/test_server bin/test_server
cp target/debug/test_client bin/test_client
diff --git a/test/rs/src/bin/test_client.rs b/test/rs/src/bin/test_client.rs
index 476f9eb25..8623915d4 100644
--- a/test/rs/src/bin/test_client.rs
+++ b/test/rs/src/bin/test_client.rs
@@ -15,22 +15,24 @@
// specific language governing permissions and limitations
// under the License.
+use clap::{clap_app, value_t};
use env_logger;
use log::*;
-use clap::{clap_app, value_t};
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Debug;
use std::net::TcpStream;
use thrift;
+use thrift::protocol::{
+ TBinaryInputProtocol, TBinaryOutputProtocol, TCompactInputProtocol, TCompactOutputProtocol,
+ TInputProtocol, TMultiplexedOutputProtocol, TOutputProtocol,
+};
+use thrift::transport::{
+ TBufferedReadTransport, TBufferedWriteTransport, TFramedReadTransport, TFramedWriteTransport,
+ TIoChannel, TReadTransport, TTcpChannel, TWriteTransport,
+};
use thrift::OrderedFloat;
-use thrift::protocol::{TBinaryInputProtocol, TBinaryOutputProtocol, TCompactInputProtocol,
- TCompactOutputProtocol, TInputProtocol, TMultiplexedOutputProtocol,
- TOutputProtocol};
-use thrift::transport::{TBufferedReadTransport, TBufferedWriteTransport,
- TFramedReadTransport, TFramedWriteTransport, TIoChannel, TReadTransport,
- TTcpChannel, TWriteTransport};
use thrift_test::*;
fn main() {
@@ -92,10 +94,7 @@ fn run() -> thrift::Result<()> {
info!(
"connecting to {}:{} with {}+{} stack",
- host,
- port,
- protocol,
- transport
+ host, port, protocol, transport
);
for _ in 0..testloops {
@@ -115,47 +114,50 @@ fn build(
let (i_chan, o_chan) = c.split()?;
let (i_tran, o_tran): (Box<dyn TReadTransport>, Box<dyn TWriteTransport>) = match transport {
- "buffered" => {
- (Box::new(TBufferedReadTransport::new(i_chan)),
- Box::new(TBufferedWriteTransport::new(o_chan)))
- }
- "framed" => {
- (Box::new(TFramedReadTransport::new(i_chan)),
- Box::new(TFramedWriteTransport::new(o_chan)))
- }
+ "buffered" => (
+ Box::new(TBufferedReadTransport::new(i_chan)),
+ Box::new(TBufferedWriteTransport::new(o_chan)),
+ ),
+ "framed" => (
+ Box::new(TFramedReadTransport::new(i_chan)),
+ Box::new(TFramedWriteTransport::new(o_chan)),
+ ),
unmatched => return Err(format!("unsupported transport {}", unmatched).into()),
};
let (i_prot, o_prot): (Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>) = match protocol {
- "binary" => {
- (Box::new(TBinaryInputProtocol::new(i_tran, true)),
- Box::new(TBinaryOutputProtocol::new(o_tran, true)))
- }
- "multi" => {
- (Box::new(TBinaryInputProtocol::new(i_tran, true)),
- Box::new(
- TMultiplexedOutputProtocol::new(
- service_name,
- TBinaryOutputProtocol::new(o_tran, true),
- ),
- ))
- }
- "compact" => {
- (Box::new(TCompactInputProtocol::new(i_tran)),
- Box::new(TCompactOutputProtocol::new(o_tran)))
- }
- "multic" => {
- (Box::new(TCompactInputProtocol::new(i_tran)),
- Box::new(TMultiplexedOutputProtocol::new(service_name, TCompactOutputProtocol::new(o_tran)),))
- }
+ "binary" => (
+ Box::new(TBinaryInputProtocol::new(i_tran, true)),
+ Box::new(TBinaryOutputProtocol::new(o_tran, true)),
+ ),
+ "multi" => (
+ Box::new(TBinaryInputProtocol::new(i_tran, true)),
+ Box::new(TMultiplexedOutputProtocol::new(
+ service_name,
+ TBinaryOutputProtocol::new(o_tran, true),
+ )),
+ ),
+ "compact" => (
+ Box::new(TCompactInputProtocol::new(i_tran)),
+ Box::new(TCompactOutputProtocol::new(o_tran)),
+ ),
+ "multic" => (
+ Box::new(TCompactInputProtocol::new(i_tran)),
+ Box::new(TMultiplexedOutputProtocol::new(
+ service_name,
+ TCompactOutputProtocol::new(o_tran),
+ )),
+ ),
unmatched => return Err(format!("unsupported protocol {}", unmatched).into()),
};
Ok((i_prot, o_prot))
}
-type BuildThriftTestClient = ThriftTestSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>;
-type BuiltSecondServiceClient = SecondServiceSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>;
+type BuildThriftTestClient =
+ ThriftTestSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>;
+type BuiltSecondServiceClient =
+ SecondServiceSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>;
#[allow(clippy::cognitive_complexity)]
fn make_thrift_calls(
@@ -250,26 +252,22 @@ fn make_thrift_calls(
{
let x_snd = Xtruct2 {
byte_thing: Some(32),
- struct_thing: Some(
- Xtruct {
- string_thing: Some("foo".to_owned()),
- byte_thing: Some(1),
- i32_thing: Some(324_382_098),
- i64_thing: Some(12_938_492_818),
- },
- ),
+ struct_thing: Some(Xtruct {
+ string_thing: Some("foo".to_owned()),
+ byte_thing: Some(1),
+ i32_thing: Some(324_382_098),
+ i64_thing: Some(12_938_492_818),
+ }),
i32_thing: Some(293_481_098),
};
let x_cmp = Xtruct2 {
byte_thing: Some(32),
- struct_thing: Some(
- Xtruct {
- string_thing: Some("foo".to_owned()),
- byte_thing: Some(1),
- i32_thing: Some(324_382_098),
- i64_thing: Some(12_938_492_818),
- },
- ),
+ struct_thing: Some(Xtruct {
+ string_thing: Some("foo".to_owned()),
+ byte_thing: Some(1),
+ i32_thing: Some(324_382_098),
+ i64_thing: Some(12_938_492_818),
+ }),
i32_thing: Some(293_481_098),
};
verify_expected_result(thrift_test_client.test_nest(x_snd), x_cmp)?;
@@ -399,30 +397,24 @@ fn make_thrift_calls(
arg_map_usermap.insert(Numberz::EIGHT, 19);
let mut arg_vec_xtructs: Vec<Xtruct> = Vec::new();
- arg_vec_xtructs.push(
- Xtruct {
- string_thing: Some("foo".to_owned()),
- byte_thing: Some(8),
- i32_thing: Some(29),
- i64_thing: Some(92384),
- },
- );
- arg_vec_xtructs.push(
- Xtruct {
- string_thing: Some("bar".to_owned()),
- byte_thing: Some(28),
- i32_thing: Some(2),
- i64_thing: Some(-1281),
- },
- );
- arg_vec_xtructs.push(
- Xtruct {
- string_thing: Some("baz".to_owned()),
- byte_thing: Some(0),
- i32_thing: Some(3_948_539),
- i64_thing: Some(-12_938_492),
- },
- );
+ arg_vec_xtructs.push(Xtruct {
+ string_thing: Some("foo".to_owned()),
+ byte_thing: Some(8),
+ i32_thing: Some(29),
+ i64_thing: Some(92384),
+ });
+ arg_vec_xtructs.push(Xtruct {
+ string_thing: Some("bar".to_owned()),
+ byte_thing: Some(28),
+ i32_thing: Some(2),
+ i64_thing: Some(-1281),
+ });
+ arg_vec_xtructs.push(Xtruct {
+ string_thing: Some("baz".to_owned()),
+ byte_thing: Some(0),
+ i32_thing: Some(3_948_539),
+ i64_thing: Some(-12_938_492),
+ });
let mut s_cmp_nested_1: BTreeMap<Numberz, Insanity> = BTreeMap::new();
let insanity = Insanity {
@@ -450,12 +442,12 @@ fn make_thrift_calls(
{
let r = thrift_test_client.test_exception("Xception".to_owned());
let x = match r {
- Err(thrift::Error::User(ref e)) => {
- match e.downcast_ref::<Xception>() {
- Some(x) => Ok(x),
- None => Err(thrift::Error::User("did not get expected Xception struct".into()),),
- }
- }
+ Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception>() {
+ Some(x) => Ok(x),
+ None => Err(thrift::Error::User(
+ "did not get expected Xception struct".into(),
+ )),
+ },
_ => Err(thrift::Error::User("did not get exception".into())),
}?;
@@ -493,12 +485,12 @@ fn make_thrift_calls(
let r =
thrift_test_client.test_multi_exception("Xception".to_owned(), "ignored".to_owned());
let x = match r {
- Err(thrift::Error::User(ref e)) => {
- match e.downcast_ref::<Xception>() {
- Some(x) => Ok(x),
- None => Err(thrift::Error::User("did not get expected Xception struct".into()),),
- }
- }
+ Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception>() {
+ Some(x) => Ok(x),
+ None => Err(thrift::Error::User(
+ "did not get expected Xception struct".into(),
+ )),
+ },
_ => Err(thrift::Error::User("did not get exception".into())),
}?;
@@ -515,28 +507,26 @@ fn make_thrift_calls(
let r =
thrift_test_client.test_multi_exception("Xception2".to_owned(), "ignored".to_owned());
let x = match r {
- Err(thrift::Error::User(ref e)) => {
- match e.downcast_ref::<Xception2>() {
- Some(x) => Ok(x),
- None => Err(thrift::Error::User("did not get expected Xception struct".into()),),
- }
- }
+ Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception2>() {
+ Some(x) => Ok(x),
+ None => Err(thrift::Error::User(
+ "did not get expected Xception struct".into(),
+ )),
+ },
_ => Err(thrift::Error::User("did not get exception".into())),
}?;
let x_cmp = Xception2 {
error_code: Some(2002),
- struct_thing: Some(
- Xtruct {
- string_thing: Some("This is an Xception2".to_owned()),
- // since this is an OPT_IN_REQ_OUT field the sender sets a default
- byte_thing: Some(0),
- // since this is an OPT_IN_REQ_OUT field the sender sets a default
- i32_thing: Some(0),
- // since this is an OPT_IN_REQ_OUT field the sender sets a default
- i64_thing: Some(0),
- },
- ),
+ struct_thing: Some(Xtruct {
+ string_thing: Some("This is an Xception2".to_owned()),
+ // since this is an OPT_IN_REQ_OUT field the sender sets a default
+ byte_thing: Some(0),
+ // since this is an OPT_IN_REQ_OUT field the sender sets a default
+ i32_thing: Some(0),
+ // since this is an OPT_IN_REQ_OUT field the sender sets a default
+ i64_thing: Some(0),
+ }),
};
verify_expected_result(Ok(x), &x_cmp)?;
@@ -546,7 +536,9 @@ fn make_thrift_calls(
{
let r = thrift_test_client.test_multi_exception("haha".to_owned(), "RETURNED".to_owned());
let x = match r {
- Err(e) => Err(thrift::Error::User(format!("received an unexpected exception {:?}", e).into(),),),
+ Err(e) => Err(thrift::Error::User(
+ format!("received an unexpected exception {:?}", e).into(),
+ )),
_ => r,
}?;
@@ -586,7 +578,9 @@ fn verify_expected_result<T: Debug + PartialEq + Sized>(
Ok(())
} else {
info!("*** FAILED ***");
- Err(thrift::Error::User(format!("expected {:?} but got {:?}", &expected, &v).into()),)
+ Err(thrift::Error::User(
+ format!("expected {:?} but got {:?}", &expected, &v).into(),
+ ))
}
}
Err(e) => Err(e),
diff --git a/test/rs/src/bin/test_server.rs b/test/rs/src/bin/test_server.rs
index c1f31758a..6a05e79e5 100644
--- a/test/rs/src/bin/test_server.rs
+++ b/test/rs/src/bin/test_server.rs
@@ -15,23 +15,25 @@
// specific language governing permissions and limitations
// under the License.
+use clap::{clap_app, value_t};
use env_logger;
use log::*;
-use clap::{clap_app, value_t};
use std::collections::{BTreeMap, BTreeSet};
use std::thread;
use std::time::Duration;
use thrift;
-use thrift::OrderedFloat;
-use thrift::protocol::{TBinaryInputProtocolFactory, TBinaryOutputProtocolFactory,
- TCompactInputProtocolFactory, TCompactOutputProtocolFactory,
- TInputProtocolFactory, TOutputProtocolFactory};
+use thrift::protocol::{
+ TBinaryInputProtocolFactory, TBinaryOutputProtocolFactory, TCompactInputProtocolFactory,
+ TCompactOutputProtocolFactory, TInputProtocolFactory, TOutputProtocolFactory,
+};
use thrift::server::{TMultiplexedProcessor, TServer};
-use thrift::transport::{TBufferedReadTransportFactory, TBufferedWriteTransportFactory,
- TFramedReadTransportFactory, TFramedWriteTransportFactory,
- TReadTransportFactory, TWriteTransportFactory};
+use thrift::transport::{
+ TBufferedReadTransportFactory, TBufferedWriteTransportFactory, TFramedReadTransportFactory,
+ TFramedWriteTransportFactory, TReadTransportFactory, TWriteTransportFactory,
+};
+use thrift::OrderedFloat;
use thrift_test::*;
fn main() {
@@ -49,7 +51,6 @@ fn main() {
}
fn run() -> thrift::Result<()> {
-
// unsupported options:
// --domain-socket
// --pipe
@@ -75,50 +76,55 @@ fn run() -> thrift::Result<()> {
info!("binding to {}", listen_address);
- let (i_transport_factory, o_transport_factory): (Box<dyn TReadTransportFactory>,
- Box<dyn TWriteTransportFactory>) =
- match &*transport {
- "buffered" => {
- (Box::new(TBufferedReadTransportFactory::new()),
- Box::new(TBufferedWriteTransportFactory::new()))
- }
- "framed" => {
- (Box::new(TFramedReadTransportFactory::new()),
- Box::new(TFramedWriteTransportFactory::new()))
- }
- unknown => {
- return Err(format!("unsupported transport type {}", unknown).into());
- }
- };
-
- let (i_protocol_factory, o_protocol_factory): (Box<dyn TInputProtocolFactory>,
- Box<dyn TOutputProtocolFactory>) =
- match &*protocol {
- "binary" | "multi" | "multi:binary" => {
- (Box::new(TBinaryInputProtocolFactory::new()),
- Box::new(TBinaryOutputProtocolFactory::new()))
- }
- "compact" | "multic" | "multi:compact" => {
- (Box::new(TCompactInputProtocolFactory::new()),
- Box::new(TCompactOutputProtocolFactory::new()))
- }
- unknown => {
- return Err(format!("unsupported transport type {}", unknown).into());
- }
- };
+ let (i_transport_factory, o_transport_factory): (
+ Box<dyn TReadTransportFactory>,
+ Box<dyn TWriteTransportFactory>,
+ ) = match &*transport {
+ "buffered" => (
+ Box::new(TBufferedReadTransportFactory::new()),
+ Box::new(TBufferedWriteTransportFactory::new()),
+ ),
+ "framed" => (
+ Box::new(TFramedReadTransportFactory::new()),
+ Box::new(TFramedWriteTransportFactory::new()),
+ ),
+ unknown => {
+ return Err(format!("unsupported transport type {}", unknown).into());
+ }
+ };
+
+ let (i_protocol_factory, o_protocol_factory): (
+ Box<dyn TInputProtocolFactory>,
+ Box<dyn TOutputProtocolFactory>,
+ ) = match &*protocol {
+ "binary" | "multi" | "multi:binary" => (
+ Box::new(TBinaryInputProtocolFactory::new()),
+ Box::new(TBinaryOutputProtocolFactory::new()),
+ ),
+ "compact" | "multic" | "multi:compact" => (
+ Box::new(TCompactInputProtocolFactory::new()),
+ Box::new(TCompactOutputProtocolFactory::new()),
+ ),
+ unknown => {
+ return Err(format!("unsupported transport type {}", unknown).into());
+ }
+ };
let test_processor = ThriftTestSyncProcessor::new(ThriftTestSyncHandlerImpl {});
match &*server_type {
"simple" | "thread-pool" => {
if protocol == "multi" || protocol == "multic" {
- let second_service_processor = SecondServiceSyncProcessor::new(SecondServiceSyncHandlerImpl {},);
+ let second_service_processor =
+ SecondServiceSyncProcessor::new(SecondServiceSyncHandlerImpl {});
let mut multiplexed_processor = TMultiplexedProcessor::new();
- multiplexed_processor
- .register("ThriftTest", Box::new(test_processor), true)?;
- multiplexed_processor
- .register("SecondService", Box::new(second_service_processor), false)?;
+ multiplexed_processor.register("ThriftTest", Box::new(test_processor), true)?;
+ multiplexed_processor.register(
+ "SecondService",
+ Box::new(second_service_processor),
+ false,
+ )?;
let mut server = TServer::new(
i_transport_factory,
@@ -315,15 +321,11 @@ impl ThriftTestSyncHandler for ThriftTestSyncHandlerImpl {
info!("testException({})", arg);
match &*arg {
- "Xception" => {
- Err(
- (Xception {
- error_code: Some(1001),
- message: Some(arg),
- })
- .into(),
- )
- }
+ "Xception" => Err((Xception {
+ error_code: Some(1001),
+ message: Some(arg),
+ })
+ .into()),
"TException" => Err("this is a random error".into()),
_ => Ok(()),
}
@@ -339,41 +341,27 @@ impl ThriftTestSyncHandler for ThriftTestSyncHandlerImpl {
// do not throw anything and return Xtruct with string_thing = arg1
fn handle_test_multi_exception(&self, arg0: String, arg1: String) -> thrift::Result<Xtruct> {
match &*arg0 {
- "Xception" => {
- Err(
- (Xception {
- error_code: Some(1001),
- message: Some("This is an Xception".to_owned()),
- })
- .into(),
- )
- }
- "Xception2" => {
- Err(
- (Xception2 {
- error_code: Some(2002),
- struct_thing: Some(
- Xtruct {
- string_thing: Some("This is an Xception2".to_owned()),
- byte_thing: None,
- i32_thing: None,
- i64_thing: None,
- },
- ),
- })
- .into(),
- )
- }
- _ => {
- Ok(
- Xtruct {
- string_thing: Some(arg1),
- byte_thing: None,
- i32_thing: None,
- i64_thing: None,
- },
- )
- }
+ "Xception" => Err((Xception {
+ error_code: Some(1001),
+ message: Some("This is an Xception".to_owned()),
+ })
+ .into()),
+ "Xception2" => Err((Xception2 {
+ error_code: Some(2002),
+ struct_thing: Some(Xtruct {
+ string_thing: Some("This is an Xception2".to_owned()),
+ byte_thing: None,
+ i32_thing: None,
+ i64_thing: None,
+ }),
+ })
+ .into()),
+ _ => Ok(Xtruct {
+ string_thing: Some(arg1),
+ byte_thing: None,
+ i32_thing: None,
+ i64_thing: None,
+ }),
}
}