Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 1 | // Licensed to the Apache Software Foundation (ASF) under one |
| 2 | // or more contributor license agreements. See the NOTICE file |
| 3 | // distributed with this work for additional information |
| 4 | // regarding copyright ownership. The ASF licenses this file |
| 5 | // to you under the Apache License, Version 2.0 (the |
| 6 | // "License"); you may not use this file except in compliance |
| 7 | // with the License. You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, |
| 12 | // software distributed under the License is distributed on an |
| 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | // KIND, either express or implied. See the License for the |
| 15 | // specific language governing permissions and limitations |
| 16 | // under the License. |
| 17 | |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 18 | use clap::{clap_app, value_t}; |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 19 | use log::*; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 20 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 21 | use std::collections::{BTreeMap, BTreeSet}; |
| 22 | use std::fmt::Debug; |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 23 | use std::net::{TcpStream, ToSocketAddrs}; |
| 24 | |
| 25 | #[cfg(unix)] |
| 26 | use std::os::unix::net::UnixStream; |
| 27 | #[cfg(unix)] |
| 28 | use std::path::Path; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 29 | |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 30 | use thrift::protocol::{ |
| 31 | TBinaryInputProtocol, TBinaryOutputProtocol, TCompactInputProtocol, TCompactOutputProtocol, |
| 32 | TInputProtocol, TMultiplexedOutputProtocol, TOutputProtocol, |
| 33 | }; |
| 34 | use thrift::transport::{ |
| 35 | TBufferedReadTransport, TBufferedWriteTransport, TFramedReadTransport, TFramedWriteTransport, |
| 36 | TIoChannel, TReadTransport, TTcpChannel, TWriteTransport, |
| 37 | }; |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 38 | use thrift::OrderedFloat; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 39 | use thrift_test::*; |
| 40 | |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 41 | type ThriftClientPair = ( |
| 42 | ThriftTestSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>, |
| 43 | Option<SecondServiceSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>>, |
| 44 | ); |
| 45 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 46 | fn main() { |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 47 | env_logger::init(); |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 48 | |
| 49 | debug!("initialized logger - running cross-test client"); |
| 50 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 51 | match run() { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 52 | Ok(()) => info!("cross-test client succeeded"), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 53 | Err(e) => { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 54 | info!("cross-test client failed with error {:?}", e); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 55 | std::process::exit(1); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | fn run() -> thrift::Result<()> { |
| 61 | // unsupported options: |
Jens Geyer | 4a33b18 | 2020-03-22 13:46:34 +0100 | [diff] [blame] | 62 | // --pipe |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 63 | // --anon-pipes |
| 64 | // --ssl |
| 65 | // --threads |
| 66 | let matches = clap_app!(rust_test_client => |
| 67 | (version: "1.0") |
| 68 | (author: "Apache Thrift Developers <dev@thrift.apache.org>") |
| 69 | (about: "Rust Thrift test client") |
| 70 | (@arg host: --host +takes_value "Host on which the Thrift test server is located") |
| 71 | (@arg port: --port +takes_value "Port on which the Thrift test server is listening") |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 72 | (@arg domain_socket: --("domain-socket") +takes_value "Unix Domain Socket on which the Thrift test server is listening") |
James E. King III | 9804ab9 | 2019-02-07 16:59:05 -0500 | [diff] [blame] | 73 | (@arg protocol: --protocol +takes_value "Thrift protocol implementation to use (\"binary\", \"compact\", \"multi\", \"multic\")") |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 74 | (@arg transport: --transport +takes_value "Thrift transport implementation to use (\"buffered\", \"framed\")") |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 75 | (@arg testloops: -n --testloops +takes_value "Number of times to run tests") |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 76 | ) |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 77 | .get_matches(); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 78 | |
| 79 | let host = matches.value_of("host").unwrap_or("127.0.0.1"); |
| 80 | let port = value_t!(matches, "port", u16).unwrap_or(9090); |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 81 | let domain_socket = matches.value_of("domain_socket"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 82 | let protocol = matches.value_of("protocol").unwrap_or("binary"); |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 83 | let transport = matches.value_of("transport").unwrap_or("buffered"); |
| 84 | let testloops = value_t!(matches, "testloops", u8).unwrap_or(1); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 85 | |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 86 | let (mut thrift_test_client, mut second_service_client) = match domain_socket { |
| 87 | None => { |
| 88 | let listen_address = format!("{}:{}", host, port); |
| 89 | info!( |
| 90 | "Client binds to {} with {}+{} stack", |
| 91 | listen_address, protocol, transport |
| 92 | ); |
| 93 | bind(listen_address.as_str(), protocol, transport)? |
| 94 | } |
| 95 | Some(domain_socket) => { |
| 96 | info!( |
| 97 | "Client binds to {} (UDS) with {}+{} stack", |
| 98 | domain_socket, protocol, transport |
| 99 | ); |
| 100 | bind_uds(domain_socket, protocol, transport)? |
| 101 | } |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 102 | }; |
| 103 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 104 | for _ in 0..testloops { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 105 | make_thrift_calls(&mut thrift_test_client, &mut second_service_client)? |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | Ok(()) |
| 109 | } |
| 110 | |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 111 | fn bind<A: ToSocketAddrs>( |
| 112 | listen_address: A, |
| 113 | protocol: &str, |
| 114 | transport: &str, |
| 115 | ) -> Result<ThriftClientPair, thrift::Error> { |
| 116 | // create a TCPStream that will be shared by all Thrift clients |
| 117 | // service calls from multiple Thrift clients will be interleaved over the same connection |
| 118 | // this isn't a problem for us because we're single-threaded and all calls block to completion |
| 119 | let shared_stream = TcpStream::connect(listen_address)?; |
| 120 | |
| 121 | let second_service_client = if protocol.starts_with("multi") { |
| 122 | let shared_stream_clone = shared_stream.try_clone()?; |
| 123 | let channel = TTcpChannel::with_stream(shared_stream_clone); |
| 124 | let (i_prot, o_prot) = build(channel, transport, protocol, "SecondService")?; |
| 125 | Some(SecondServiceSyncClient::new(i_prot, o_prot)) |
| 126 | } else { |
| 127 | None |
| 128 | }; |
| 129 | |
| 130 | let thrift_test_client = { |
| 131 | let channel = TTcpChannel::with_stream(shared_stream); |
| 132 | let (i_prot, o_prot) = build(channel, transport, protocol, "ThriftTest")?; |
| 133 | ThriftTestSyncClient::new(i_prot, o_prot) |
| 134 | }; |
| 135 | |
| 136 | Ok((thrift_test_client, second_service_client)) |
| 137 | } |
| 138 | |
| 139 | #[cfg(unix)] |
| 140 | fn bind_uds<P: AsRef<Path>>( |
| 141 | domain_socket: P, |
| 142 | protocol: &str, |
| 143 | transport: &str, |
| 144 | ) -> Result<ThriftClientPair, thrift::Error> { |
| 145 | // create a UnixStream that will be shared by all Thrift clients |
| 146 | // service calls from multiple Thrift clients will be interleaved over the same connection |
| 147 | // this isn't a problem for us because we're single-threaded and all calls block to completion |
| 148 | let shared_stream = UnixStream::connect(domain_socket)?; |
| 149 | |
| 150 | let second_service_client = if protocol.starts_with("multi") { |
| 151 | let shared_stream_clone = shared_stream.try_clone()?; |
| 152 | let (i_prot, o_prot) = build(shared_stream_clone, transport, protocol, "SecondService")?; |
| 153 | Some(SecondServiceSyncClient::new(i_prot, o_prot)) |
| 154 | } else { |
| 155 | None |
| 156 | }; |
| 157 | |
| 158 | let thrift_test_client = { |
| 159 | let (i_prot, o_prot) = build(shared_stream, transport, protocol, "ThriftTest")?; |
| 160 | ThriftTestSyncClient::new(i_prot, o_prot) |
| 161 | }; |
| 162 | |
| 163 | Ok((thrift_test_client, second_service_client)) |
| 164 | } |
| 165 | |
| 166 | fn build<C: TIoChannel + 'static>( |
| 167 | channel: C, |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 168 | transport: &str, |
| 169 | protocol: &str, |
| 170 | service_name: &str, |
Allen George | b0d1413 | 2020-03-29 11:48:55 -0400 | [diff] [blame] | 171 | ) -> thrift::Result<(Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>)> { |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame] | 172 | let (i_chan, o_chan) = channel.split()?; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 173 | |
Allen George | b0d1413 | 2020-03-29 11:48:55 -0400 | [diff] [blame] | 174 | let (i_tran, o_tran): (Box<dyn TReadTransport>, Box<dyn TWriteTransport>) = match transport { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 175 | "buffered" => ( |
| 176 | Box::new(TBufferedReadTransport::new(i_chan)), |
| 177 | Box::new(TBufferedWriteTransport::new(o_chan)), |
| 178 | ), |
| 179 | "framed" => ( |
| 180 | Box::new(TFramedReadTransport::new(i_chan)), |
| 181 | Box::new(TFramedWriteTransport::new(o_chan)), |
| 182 | ), |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 183 | unmatched => return Err(format!("unsupported transport {}", unmatched).into()), |
| 184 | }; |
| 185 | |
Allen George | b0d1413 | 2020-03-29 11:48:55 -0400 | [diff] [blame] | 186 | let (i_prot, o_prot): (Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>) = match protocol { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 187 | "binary" => ( |
| 188 | Box::new(TBinaryInputProtocol::new(i_tran, true)), |
| 189 | Box::new(TBinaryOutputProtocol::new(o_tran, true)), |
| 190 | ), |
| 191 | "multi" => ( |
| 192 | Box::new(TBinaryInputProtocol::new(i_tran, true)), |
| 193 | Box::new(TMultiplexedOutputProtocol::new( |
| 194 | service_name, |
| 195 | TBinaryOutputProtocol::new(o_tran, true), |
| 196 | )), |
| 197 | ), |
| 198 | "compact" => ( |
| 199 | Box::new(TCompactInputProtocol::new(i_tran)), |
| 200 | Box::new(TCompactOutputProtocol::new(o_tran)), |
| 201 | ), |
| 202 | "multic" => ( |
| 203 | Box::new(TCompactInputProtocol::new(i_tran)), |
| 204 | Box::new(TMultiplexedOutputProtocol::new( |
| 205 | service_name, |
| 206 | TCompactOutputProtocol::new(o_tran), |
| 207 | )), |
| 208 | ), |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 209 | unmatched => return Err(format!("unsupported protocol {}", unmatched).into()), |
| 210 | }; |
| 211 | |
| 212 | Ok((i_prot, o_prot)) |
| 213 | } |
| 214 | |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 215 | type BuildThriftTestClient = |
| 216 | ThriftTestSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>; |
| 217 | type BuiltSecondServiceClient = |
| 218 | SecondServiceSyncClient<Box<dyn TInputProtocol>, Box<dyn TOutputProtocol>>; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 219 | |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 220 | #[allow(clippy::cognitive_complexity)] |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 221 | fn make_thrift_calls( |
| 222 | thrift_test_client: &mut BuildThriftTestClient, |
| 223 | second_service_client: &mut Option<BuiltSecondServiceClient>, |
| 224 | ) -> Result<(), thrift::Error> { |
| 225 | info!("testVoid"); |
| 226 | thrift_test_client.test_void()?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 227 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 228 | info!("testString"); |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 229 | verify_expected_result( |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 230 | thrift_test_client.test_string("thing".to_owned()), |
| 231 | "thing".to_owned(), |
| 232 | )?; |
| 233 | |
Jiayu Liu | b6b6dc7 | 2022-10-08 14:28:44 +0800 | [diff] [blame] | 234 | info!("testUuid"); |
| 235 | verify_expected_result( |
| 236 | thrift_test_client.test_uuid(uuid::uuid!("00010203-0405-0607-0809-0a0b0c0d0e0f")), |
| 237 | uuid::uuid!("00010203-0405-0607-0809-0a0b0c0d0e0f"), |
| 238 | )?; |
| 239 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 240 | info!("testBool"); |
| 241 | verify_expected_result(thrift_test_client.test_bool(true), true)?; |
| 242 | |
| 243 | info!("testBool"); |
| 244 | verify_expected_result(thrift_test_client.test_bool(false), false)?; |
| 245 | |
| 246 | info!("testByte"); |
| 247 | verify_expected_result(thrift_test_client.test_byte(42), 42)?; |
| 248 | |
| 249 | info!("testi32"); |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 250 | verify_expected_result(thrift_test_client.test_i32(1_159_348_374), 1_159_348_374)?; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 251 | |
| 252 | info!("testi64"); |
| 253 | // try!(verify_expected_result(thrift_test_client.test_i64(-8651829879438294565), |
| 254 | // -8651829879438294565)); |
| 255 | verify_expected_result( |
| 256 | thrift_test_client.test_i64(i64::min_value()), |
| 257 | i64::min_value(), |
| 258 | )?; |
| 259 | |
| 260 | info!("testDouble"); |
| 261 | verify_expected_result( |
| 262 | thrift_test_client.test_double(OrderedFloat::from(42.42)), |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 263 | OrderedFloat::from(42.42), |
| 264 | )?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 265 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 266 | info!("testTypedef"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 267 | { |
| 268 | let u_snd: UserId = 2348; |
| 269 | let u_cmp: UserId = 2348; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 270 | verify_expected_result(thrift_test_client.test_typedef(u_snd), u_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 273 | info!("testEnum"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 274 | { |
Allen George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame] | 275 | verify_expected_result(thrift_test_client.test_enum(Numberz::TWO), Numberz::TWO)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 276 | } |
| 277 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 278 | info!("testBinary"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 279 | { |
| 280 | let b_snd = vec![0x77, 0x30, 0x30, 0x74, 0x21, 0x20, 0x52, 0x75, 0x73, 0x74]; |
| 281 | let b_cmp = vec![0x77, 0x30, 0x30, 0x74, 0x21, 0x20, 0x52, 0x75, 0x73, 0x74]; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 282 | verify_expected_result(thrift_test_client.test_binary(b_snd), b_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 285 | info!("testStruct"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 286 | { |
| 287 | let x_snd = Xtruct { |
| 288 | string_thing: Some("foo".to_owned()), |
| 289 | byte_thing: Some(12), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 290 | i32_thing: Some(219_129), |
| 291 | i64_thing: Some(12_938_492_818), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 292 | }; |
| 293 | let x_cmp = Xtruct { |
| 294 | string_thing: Some("foo".to_owned()), |
| 295 | byte_thing: Some(12), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 296 | i32_thing: Some(219_129), |
| 297 | i64_thing: Some(12_938_492_818), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 298 | }; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 299 | verify_expected_result(thrift_test_client.test_struct(x_snd), x_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | // Xtruct again, with optional values |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 303 | // FIXME: apparently the erlang thrift server does not like opt-in-req-out |
| 304 | // parameters that are undefined. Joy. |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 305 | // { |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 306 | // let x_snd = Xtruct { string_thing: Some("foo".to_owned()), byte_thing: None, |
| 307 | // i32_thing: None, i64_thing: Some(12938492818) }; |
| 308 | // let x_cmp = Xtruct { string_thing: Some("foo".to_owned()), byte_thing: |
| 309 | // Some(0), i32_thing: Some(0), i64_thing: Some(12938492818) }; // the C++ |
| 310 | // server is responding correctly |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 311 | // try!(verify_expected_result(thrift_test_client.test_struct(x_snd), x_cmp)); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 312 | // } |
| 313 | // |
| 314 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 315 | info!("testNest"); // (FIXME: try Xtruct2 with optional values) |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 316 | { |
| 317 | let x_snd = Xtruct2 { |
| 318 | byte_thing: Some(32), |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 319 | struct_thing: Some(Xtruct { |
| 320 | string_thing: Some("foo".to_owned()), |
| 321 | byte_thing: Some(1), |
| 322 | i32_thing: Some(324_382_098), |
| 323 | i64_thing: Some(12_938_492_818), |
| 324 | }), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 325 | i32_thing: Some(293_481_098), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 326 | }; |
| 327 | let x_cmp = Xtruct2 { |
| 328 | byte_thing: Some(32), |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 329 | struct_thing: Some(Xtruct { |
| 330 | string_thing: Some("foo".to_owned()), |
| 331 | byte_thing: Some(1), |
| 332 | i32_thing: Some(324_382_098), |
| 333 | i64_thing: Some(12_938_492_818), |
| 334 | }), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 335 | i32_thing: Some(293_481_098), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 336 | }; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 337 | verify_expected_result(thrift_test_client.test_nest(x_snd), x_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 338 | } |
| 339 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 340 | // do the multiplexed calls while making the main ThriftTest calls |
| 341 | if let Some(ref mut client) = second_service_client.as_mut() { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 342 | info!("SecondService secondtestString"); |
| 343 | { |
| 344 | verify_expected_result( |
| 345 | client.secondtest_string("test_string".to_owned()), |
| 346 | "testString(\"test_string\")".to_owned(), |
| 347 | )?; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | info!("testList"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 352 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 353 | let v_snd: Vec<i32> = vec![29384, 238, 32498]; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 354 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 355 | let v_cmp: Vec<i32> = vec![29384, 238, 32498]; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 356 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 357 | verify_expected_result(thrift_test_client.test_list(v_snd), v_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 358 | } |
| 359 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 360 | info!("testSet"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 361 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 362 | let s_snd: BTreeSet<i32> = BTreeSet::from([293_481, 23, 3234]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 363 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 364 | let s_cmp: BTreeSet<i32> = BTreeSet::from([293_481, 23, 3234]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 365 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 366 | verify_expected_result(thrift_test_client.test_set(s_snd), s_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 367 | } |
| 368 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 369 | info!("testMap"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 370 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 371 | let m_snd: BTreeMap<i32, i32> = BTreeMap::from([(2, 4), (4, 6), (8, 7)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 372 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 373 | let m_cmp: BTreeMap<i32, i32> = BTreeMap::from([(2, 4), (4, 6), (8, 7)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 374 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 375 | verify_expected_result(thrift_test_client.test_map(m_snd), m_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 376 | } |
| 377 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 378 | info!("testStringMap"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 379 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 380 | let m_snd: BTreeMap<String, String> = BTreeMap::from([ |
| 381 | ("2".to_owned(), "4_string".to_owned()), |
| 382 | ("4".to_owned(), "6_string".to_owned()), |
| 383 | ("8".to_owned(), "7_string".to_owned()), |
| 384 | ]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 385 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 386 | let m_rcv: BTreeMap<String, String> = BTreeMap::from([ |
| 387 | ("2".to_owned(), "4_string".to_owned()), |
| 388 | ("4".to_owned(), "6_string".to_owned()), |
| 389 | ("8".to_owned(), "7_string".to_owned()), |
| 390 | ]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 391 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 392 | verify_expected_result(thrift_test_client.test_string_map(m_snd), m_rcv)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // nested map |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 396 | // expect : {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 |
| 397 | // => 2, 3 => 3, 4 => 4, }, } |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 398 | info!("testMapMap"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 399 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 400 | let m_cmp_nested_0: BTreeMap<i32, i32> = (-4..0).map(|i| (i, i)).collect(); |
| 401 | let m_cmp_nested_1: BTreeMap<i32, i32> = (1..5).map(|i| (i, i)).collect(); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 402 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 403 | let m_cmp: BTreeMap<i32, BTreeMap<i32, i32>> = |
| 404 | BTreeMap::from([(-4, m_cmp_nested_0), (4, m_cmp_nested_1)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 405 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 406 | verify_expected_result(thrift_test_client.test_map_map(42), m_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 407 | } |
| 408 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 409 | info!("testMulti"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 410 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 411 | let m_snd: BTreeMap<i16, String> = |
| 412 | BTreeMap::from([(1298, "fizz".to_owned()), (-148, "buzz".to_owned())]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 413 | |
| 414 | let s_cmp = Xtruct { |
| 415 | string_thing: Some("Hello2".to_owned()), |
| 416 | byte_thing: Some(1), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 417 | i32_thing: Some(-123_948), |
| 418 | i64_thing: Some(-19_234_123_981), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 419 | }; |
| 420 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 421 | verify_expected_result( |
Allen George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame] | 422 | thrift_test_client.test_multi(1, -123_948, -19_234_123_981, m_snd, Numberz::EIGHT, 81), |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 423 | s_cmp, |
| 424 | )?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | // Insanity |
| 428 | // returns: |
| 429 | // { 1 => { 2 => argument, |
| 430 | // 3 => argument, |
| 431 | // }, |
| 432 | // 2 => { 6 => <empty Insanity struct>, }, |
| 433 | // } |
| 434 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 435 | let arg_map_usermap: BTreeMap<Numberz, i64> = |
| 436 | BTreeMap::from([(Numberz::ONE, 4289), (Numberz::EIGHT, 19)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 437 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 438 | let arg_vec_xtructs: Vec<Xtruct> = vec![ |
| 439 | Xtruct { |
| 440 | string_thing: Some("foo".to_owned()), |
| 441 | byte_thing: Some(8), |
| 442 | i32_thing: Some(29), |
| 443 | i64_thing: Some(92384), |
| 444 | }, |
| 445 | Xtruct { |
| 446 | string_thing: Some("bar".to_owned()), |
| 447 | byte_thing: Some(28), |
| 448 | i32_thing: Some(2), |
| 449 | i64_thing: Some(-1281), |
| 450 | }, |
| 451 | Xtruct { |
| 452 | string_thing: Some("baz".to_owned()), |
| 453 | byte_thing: Some(0), |
| 454 | i32_thing: Some(3_948_539), |
| 455 | i64_thing: Some(-12_938_492), |
| 456 | }, |
| 457 | ]; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 458 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 459 | let insanity = Insanity { |
| 460 | user_map: Some(arg_map_usermap), |
| 461 | xtructs: Some(arg_vec_xtructs), |
| 462 | }; |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 463 | let s_cmp_nested_1: BTreeMap<Numberz, Insanity> = BTreeMap::from([ |
| 464 | (Numberz::TWO, insanity.clone()), |
| 465 | (Numberz::THREE, insanity.clone()), |
| 466 | ]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 467 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 468 | let empty_insanity = Insanity { |
| 469 | user_map: Some(BTreeMap::new()), |
| 470 | xtructs: Some(Vec::new()), |
| 471 | }; |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 472 | let s_cmp_nested_2: BTreeMap<Numberz, Insanity> = |
| 473 | BTreeMap::from([(Numberz::SIX, empty_insanity)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 474 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 475 | let s_cmp: BTreeMap<UserId, BTreeMap<Numberz, Insanity>> = |
| 476 | BTreeMap::from([(1, s_cmp_nested_1), (2, s_cmp_nested_2)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 477 | |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 478 | verify_expected_result(thrift_test_client.test_insanity(insanity), s_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 479 | } |
| 480 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 481 | info!("testException - remote throws Xception"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 482 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 483 | let r = thrift_test_client.test_exception("Xception".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 484 | let x = match r { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 485 | Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception>() { |
| 486 | Some(x) => Ok(x), |
| 487 | None => Err(thrift::Error::User( |
| 488 | "did not get expected Xception struct".into(), |
| 489 | )), |
| 490 | }, |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 491 | _ => Err(thrift::Error::User("did not get exception".into())), |
| 492 | }?; |
| 493 | |
| 494 | let x_cmp = Xception { |
| 495 | error_code: Some(1001), |
| 496 | message: Some("Xception".to_owned()), |
| 497 | }; |
| 498 | |
| 499 | verify_expected_result(Ok(x), &x_cmp)?; |
| 500 | } |
| 501 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 502 | info!("testException - remote throws TApplicationException"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 503 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 504 | let r = thrift_test_client.test_exception("TException".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 505 | match r { |
| 506 | Err(thrift::Error::Application(ref e)) => { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 507 | info!("received an {:?}", e); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 508 | Ok(()) |
| 509 | } |
| 510 | _ => Err(thrift::Error::User("did not get exception".into())), |
| 511 | }?; |
| 512 | } |
| 513 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 514 | info!("testException - remote succeeds"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 515 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 516 | let r = thrift_test_client.test_exception("foo".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 517 | match r { |
| 518 | Ok(_) => Ok(()), |
| 519 | _ => Err(thrift::Error::User("received an exception".into())), |
| 520 | }?; |
| 521 | } |
| 522 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 523 | info!("testMultiException - remote throws Xception"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 524 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 525 | let r = |
| 526 | thrift_test_client.test_multi_exception("Xception".to_owned(), "ignored".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 527 | let x = match r { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 528 | Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception>() { |
| 529 | Some(x) => Ok(x), |
| 530 | None => Err(thrift::Error::User( |
| 531 | "did not get expected Xception struct".into(), |
| 532 | )), |
| 533 | }, |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 534 | _ => Err(thrift::Error::User("did not get exception".into())), |
| 535 | }?; |
| 536 | |
| 537 | let x_cmp = Xception { |
| 538 | error_code: Some(1001), |
| 539 | message: Some("This is an Xception".to_owned()), |
| 540 | }; |
| 541 | |
| 542 | verify_expected_result(Ok(x), &x_cmp)?; |
| 543 | } |
| 544 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 545 | info!("testMultiException - remote throws Xception2"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 546 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 547 | let r = |
| 548 | thrift_test_client.test_multi_exception("Xception2".to_owned(), "ignored".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 549 | let x = match r { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 550 | Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception2>() { |
| 551 | Some(x) => Ok(x), |
| 552 | None => Err(thrift::Error::User( |
| 553 | "did not get expected Xception struct".into(), |
| 554 | )), |
| 555 | }, |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 556 | _ => Err(thrift::Error::User("did not get exception".into())), |
| 557 | }?; |
| 558 | |
| 559 | let x_cmp = Xception2 { |
| 560 | error_code: Some(2002), |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 561 | struct_thing: Some(Xtruct { |
| 562 | string_thing: Some("This is an Xception2".to_owned()), |
| 563 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 564 | byte_thing: Some(0), |
| 565 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 566 | i32_thing: Some(0), |
| 567 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 568 | i64_thing: Some(0), |
| 569 | }), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | verify_expected_result(Ok(x), &x_cmp)?; |
| 573 | } |
| 574 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 575 | info!("testMultiException - remote succeeds"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 576 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 577 | let r = thrift_test_client.test_multi_exception("haha".to_owned(), "RETURNED".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 578 | let x = match r { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 579 | Err(e) => Err(thrift::Error::User( |
| 580 | format!("received an unexpected exception {:?}", e).into(), |
| 581 | )), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 582 | _ => r, |
| 583 | }?; |
| 584 | |
| 585 | let x_cmp = Xtruct { |
| 586 | string_thing: Some("RETURNED".to_owned()), |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 587 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 588 | byte_thing: Some(0), |
| 589 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 590 | i32_thing: Some(0), |
| 591 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 592 | i64_thing: Some(0), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | verify_expected_result(Ok(x), x_cmp)?; |
| 596 | } |
| 597 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 598 | info!("testOneWay - remote sleeps for 1 second"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 599 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 600 | thrift_test_client.test_oneway(1)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 601 | } |
| 602 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 603 | // final test to verify that the connection is still writable after the one-way |
| 604 | // call |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 605 | thrift_test_client.test_void() |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 606 | } |
| 607 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 608 | fn verify_expected_result<T: Debug + PartialEq + Sized>( |
| 609 | actual: Result<T, thrift::Error>, |
| 610 | expected: T, |
| 611 | ) -> Result<(), thrift::Error> { |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 612 | info!("*** EXPECTED: Ok({:?})", expected); |
| 613 | info!("*** ACTUAL : {:?}", actual); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 614 | match actual { |
| 615 | Ok(v) => { |
| 616 | if v == expected { |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 617 | info!("*** OK ***"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 618 | Ok(()) |
| 619 | } else { |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 620 | info!("*** FAILED ***"); |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 621 | Err(thrift::Error::User( |
| 622 | format!("expected {:?} but got {:?}", &expected, &v).into(), |
| 623 | )) |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | Err(e) => Err(e), |
| 627 | } |
| 628 | } |