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 | |
| 234 | info!("testBool"); |
| 235 | verify_expected_result(thrift_test_client.test_bool(true), true)?; |
| 236 | |
| 237 | info!("testBool"); |
| 238 | verify_expected_result(thrift_test_client.test_bool(false), false)?; |
| 239 | |
| 240 | info!("testByte"); |
| 241 | verify_expected_result(thrift_test_client.test_byte(42), 42)?; |
| 242 | |
| 243 | info!("testi32"); |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 244 | 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] | 245 | |
| 246 | info!("testi64"); |
| 247 | // try!(verify_expected_result(thrift_test_client.test_i64(-8651829879438294565), |
| 248 | // -8651829879438294565)); |
| 249 | verify_expected_result( |
| 250 | thrift_test_client.test_i64(i64::min_value()), |
| 251 | i64::min_value(), |
| 252 | )?; |
| 253 | |
| 254 | info!("testDouble"); |
| 255 | verify_expected_result( |
| 256 | thrift_test_client.test_double(OrderedFloat::from(42.42)), |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 257 | OrderedFloat::from(42.42), |
| 258 | )?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 259 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 260 | info!("testTypedef"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 261 | { |
| 262 | let u_snd: UserId = 2348; |
| 263 | let u_cmp: UserId = 2348; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 264 | verify_expected_result(thrift_test_client.test_typedef(u_snd), u_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 265 | } |
| 266 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 267 | info!("testEnum"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 268 | { |
Allen George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame] | 269 | verify_expected_result(thrift_test_client.test_enum(Numberz::TWO), Numberz::TWO)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 270 | } |
| 271 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 272 | info!("testBinary"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 273 | { |
| 274 | let b_snd = vec![0x77, 0x30, 0x30, 0x74, 0x21, 0x20, 0x52, 0x75, 0x73, 0x74]; |
| 275 | 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] | 276 | verify_expected_result(thrift_test_client.test_binary(b_snd), b_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 277 | } |
| 278 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 279 | info!("testStruct"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 280 | { |
| 281 | let x_snd = Xtruct { |
| 282 | string_thing: Some("foo".to_owned()), |
| 283 | byte_thing: Some(12), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 284 | i32_thing: Some(219_129), |
| 285 | i64_thing: Some(12_938_492_818), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 286 | }; |
| 287 | let x_cmp = 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 | }; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 293 | verify_expected_result(thrift_test_client.test_struct(x_snd), x_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | // Xtruct again, with optional values |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 297 | // FIXME: apparently the erlang thrift server does not like opt-in-req-out |
| 298 | // parameters that are undefined. Joy. |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 299 | // { |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 300 | // let x_snd = Xtruct { string_thing: Some("foo".to_owned()), byte_thing: None, |
| 301 | // i32_thing: None, i64_thing: Some(12938492818) }; |
| 302 | // let x_cmp = Xtruct { string_thing: Some("foo".to_owned()), byte_thing: |
| 303 | // Some(0), i32_thing: Some(0), i64_thing: Some(12938492818) }; // the C++ |
| 304 | // server is responding correctly |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 305 | // 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] | 306 | // } |
| 307 | // |
| 308 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 309 | info!("testNest"); // (FIXME: try Xtruct2 with optional values) |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 310 | { |
| 311 | let x_snd = Xtruct2 { |
| 312 | byte_thing: Some(32), |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 313 | struct_thing: Some(Xtruct { |
| 314 | string_thing: Some("foo".to_owned()), |
| 315 | byte_thing: Some(1), |
| 316 | i32_thing: Some(324_382_098), |
| 317 | i64_thing: Some(12_938_492_818), |
| 318 | }), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 319 | i32_thing: Some(293_481_098), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 320 | }; |
| 321 | let x_cmp = Xtruct2 { |
| 322 | byte_thing: Some(32), |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 323 | struct_thing: Some(Xtruct { |
| 324 | string_thing: Some("foo".to_owned()), |
| 325 | byte_thing: Some(1), |
| 326 | i32_thing: Some(324_382_098), |
| 327 | i64_thing: Some(12_938_492_818), |
| 328 | }), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 329 | i32_thing: Some(293_481_098), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 330 | }; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 331 | verify_expected_result(thrift_test_client.test_nest(x_snd), x_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 332 | } |
| 333 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 334 | // do the multiplexed calls while making the main ThriftTest calls |
| 335 | if let Some(ref mut client) = second_service_client.as_mut() { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 336 | info!("SecondService secondtestString"); |
| 337 | { |
| 338 | verify_expected_result( |
| 339 | client.secondtest_string("test_string".to_owned()), |
| 340 | "testString(\"test_string\")".to_owned(), |
| 341 | )?; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | info!("testList"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 346 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 347 | let v_snd: Vec<i32> = vec![29384, 238, 32498]; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 348 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 349 | let v_cmp: Vec<i32> = vec![29384, 238, 32498]; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 350 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 351 | verify_expected_result(thrift_test_client.test_list(v_snd), v_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 352 | } |
| 353 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 354 | info!("testSet"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 355 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 356 | let s_snd: BTreeSet<i32> = BTreeSet::from([293_481, 23, 3234]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 357 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 358 | let s_cmp: BTreeSet<i32> = BTreeSet::from([293_481, 23, 3234]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 359 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 360 | verify_expected_result(thrift_test_client.test_set(s_snd), s_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 361 | } |
| 362 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 363 | info!("testMap"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 364 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 365 | 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] | 366 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 367 | 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] | 368 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 369 | verify_expected_result(thrift_test_client.test_map(m_snd), m_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 370 | } |
| 371 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 372 | info!("testStringMap"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 373 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 374 | let m_snd: BTreeMap<String, String> = BTreeMap::from([ |
| 375 | ("2".to_owned(), "4_string".to_owned()), |
| 376 | ("4".to_owned(), "6_string".to_owned()), |
| 377 | ("8".to_owned(), "7_string".to_owned()), |
| 378 | ]); |
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_rcv: 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 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 386 | 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] | 387 | } |
| 388 | |
| 389 | // nested map |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 390 | // expect : {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 |
| 391 | // => 2, 3 => 3, 4 => 4, }, } |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 392 | info!("testMapMap"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 393 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 394 | let m_cmp_nested_0: BTreeMap<i32, i32> = (-4..0).map(|i| (i, i)).collect(); |
| 395 | 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] | 396 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 397 | let m_cmp: BTreeMap<i32, BTreeMap<i32, i32>> = |
| 398 | BTreeMap::from([(-4, m_cmp_nested_0), (4, m_cmp_nested_1)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 399 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 400 | verify_expected_result(thrift_test_client.test_map_map(42), m_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 403 | info!("testMulti"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 404 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 405 | let m_snd: BTreeMap<i16, String> = |
| 406 | BTreeMap::from([(1298, "fizz".to_owned()), (-148, "buzz".to_owned())]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 407 | |
| 408 | let s_cmp = Xtruct { |
| 409 | string_thing: Some("Hello2".to_owned()), |
| 410 | byte_thing: Some(1), |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 411 | i32_thing: Some(-123_948), |
| 412 | i64_thing: Some(-19_234_123_981), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 413 | }; |
| 414 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 415 | verify_expected_result( |
Allen George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame] | 416 | 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] | 417 | s_cmp, |
| 418 | )?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | // Insanity |
| 422 | // returns: |
| 423 | // { 1 => { 2 => argument, |
| 424 | // 3 => argument, |
| 425 | // }, |
| 426 | // 2 => { 6 => <empty Insanity struct>, }, |
| 427 | // } |
| 428 | { |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 429 | let arg_map_usermap: BTreeMap<Numberz, i64> = |
| 430 | BTreeMap::from([(Numberz::ONE, 4289), (Numberz::EIGHT, 19)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 431 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 432 | let arg_vec_xtructs: Vec<Xtruct> = vec![ |
| 433 | Xtruct { |
| 434 | string_thing: Some("foo".to_owned()), |
| 435 | byte_thing: Some(8), |
| 436 | i32_thing: Some(29), |
| 437 | i64_thing: Some(92384), |
| 438 | }, |
| 439 | Xtruct { |
| 440 | string_thing: Some("bar".to_owned()), |
| 441 | byte_thing: Some(28), |
| 442 | i32_thing: Some(2), |
| 443 | i64_thing: Some(-1281), |
| 444 | }, |
| 445 | Xtruct { |
| 446 | string_thing: Some("baz".to_owned()), |
| 447 | byte_thing: Some(0), |
| 448 | i32_thing: Some(3_948_539), |
| 449 | i64_thing: Some(-12_938_492), |
| 450 | }, |
| 451 | ]; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 452 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 453 | let insanity = Insanity { |
| 454 | user_map: Some(arg_map_usermap), |
| 455 | xtructs: Some(arg_vec_xtructs), |
| 456 | }; |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 457 | let s_cmp_nested_1: BTreeMap<Numberz, Insanity> = BTreeMap::from([ |
| 458 | (Numberz::TWO, insanity.clone()), |
| 459 | (Numberz::THREE, insanity.clone()), |
| 460 | ]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 461 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 462 | let empty_insanity = Insanity { |
| 463 | user_map: Some(BTreeMap::new()), |
| 464 | xtructs: Some(Vec::new()), |
| 465 | }; |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 466 | let s_cmp_nested_2: BTreeMap<Numberz, Insanity> = |
| 467 | BTreeMap::from([(Numberz::SIX, empty_insanity)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 468 | |
Tdxdxoz | 85d82bf | 2022-07-17 14:14:12 +0200 | [diff] [blame] | 469 | let s_cmp: BTreeMap<UserId, BTreeMap<Numberz, Insanity>> = |
| 470 | BTreeMap::from([(1, s_cmp_nested_1), (2, s_cmp_nested_2)]); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 471 | |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 472 | verify_expected_result(thrift_test_client.test_insanity(insanity), s_cmp)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 473 | } |
| 474 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 475 | info!("testException - remote throws Xception"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 476 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 477 | let r = thrift_test_client.test_exception("Xception".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 478 | let x = match r { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 479 | Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception>() { |
| 480 | Some(x) => Ok(x), |
| 481 | None => Err(thrift::Error::User( |
| 482 | "did not get expected Xception struct".into(), |
| 483 | )), |
| 484 | }, |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 485 | _ => Err(thrift::Error::User("did not get exception".into())), |
| 486 | }?; |
| 487 | |
| 488 | let x_cmp = Xception { |
| 489 | error_code: Some(1001), |
| 490 | message: Some("Xception".to_owned()), |
| 491 | }; |
| 492 | |
| 493 | verify_expected_result(Ok(x), &x_cmp)?; |
| 494 | } |
| 495 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 496 | info!("testException - remote throws TApplicationException"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 497 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 498 | let r = thrift_test_client.test_exception("TException".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 499 | match r { |
| 500 | Err(thrift::Error::Application(ref e)) => { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 501 | info!("received an {:?}", e); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 502 | Ok(()) |
| 503 | } |
| 504 | _ => Err(thrift::Error::User("did not get exception".into())), |
| 505 | }?; |
| 506 | } |
| 507 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 508 | info!("testException - remote succeeds"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 509 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 510 | let r = thrift_test_client.test_exception("foo".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 511 | match r { |
| 512 | Ok(_) => Ok(()), |
| 513 | _ => Err(thrift::Error::User("received an exception".into())), |
| 514 | }?; |
| 515 | } |
| 516 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 517 | info!("testMultiException - remote throws Xception"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 518 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 519 | let r = |
| 520 | thrift_test_client.test_multi_exception("Xception".to_owned(), "ignored".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 521 | let x = match r { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 522 | Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception>() { |
| 523 | Some(x) => Ok(x), |
| 524 | None => Err(thrift::Error::User( |
| 525 | "did not get expected Xception struct".into(), |
| 526 | )), |
| 527 | }, |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 528 | _ => Err(thrift::Error::User("did not get exception".into())), |
| 529 | }?; |
| 530 | |
| 531 | let x_cmp = Xception { |
| 532 | error_code: Some(1001), |
| 533 | message: Some("This is an Xception".to_owned()), |
| 534 | }; |
| 535 | |
| 536 | verify_expected_result(Ok(x), &x_cmp)?; |
| 537 | } |
| 538 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 539 | info!("testMultiException - remote throws Xception2"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 540 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 541 | let r = |
| 542 | thrift_test_client.test_multi_exception("Xception2".to_owned(), "ignored".to_owned()); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 543 | let x = match r { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 544 | Err(thrift::Error::User(ref e)) => match e.downcast_ref::<Xception2>() { |
| 545 | Some(x) => Ok(x), |
| 546 | None => Err(thrift::Error::User( |
| 547 | "did not get expected Xception struct".into(), |
| 548 | )), |
| 549 | }, |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 550 | _ => Err(thrift::Error::User("did not get exception".into())), |
| 551 | }?; |
| 552 | |
| 553 | let x_cmp = Xception2 { |
| 554 | error_code: Some(2002), |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 555 | struct_thing: Some(Xtruct { |
| 556 | string_thing: Some("This is an Xception2".to_owned()), |
| 557 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 558 | byte_thing: Some(0), |
| 559 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 560 | i32_thing: Some(0), |
| 561 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 562 | i64_thing: Some(0), |
| 563 | }), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 564 | }; |
| 565 | |
| 566 | verify_expected_result(Ok(x), &x_cmp)?; |
| 567 | } |
| 568 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 569 | info!("testMultiException - remote succeeds"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 570 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 571 | 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] | 572 | let x = match r { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 573 | Err(e) => Err(thrift::Error::User( |
| 574 | format!("received an unexpected exception {:?}", e).into(), |
| 575 | )), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 576 | _ => r, |
| 577 | }?; |
| 578 | |
| 579 | let x_cmp = Xtruct { |
| 580 | string_thing: Some("RETURNED".to_owned()), |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 581 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 582 | byte_thing: Some(0), |
| 583 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 584 | i32_thing: Some(0), |
| 585 | // since this is an OPT_IN_REQ_OUT field the sender sets a default |
| 586 | i64_thing: Some(0), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 587 | }; |
| 588 | |
| 589 | verify_expected_result(Ok(x), x_cmp)?; |
| 590 | } |
| 591 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 592 | info!("testOneWay - remote sleeps for 1 second"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 593 | { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 594 | thrift_test_client.test_oneway(1)?; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 595 | } |
| 596 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 597 | // final test to verify that the connection is still writable after the one-way |
| 598 | // call |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 599 | thrift_test_client.test_void() |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 600 | } |
| 601 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 602 | fn verify_expected_result<T: Debug + PartialEq + Sized>( |
| 603 | actual: Result<T, thrift::Error>, |
| 604 | expected: T, |
| 605 | ) -> Result<(), thrift::Error> { |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 606 | info!("*** EXPECTED: Ok({:?})", expected); |
| 607 | info!("*** ACTUAL : {:?}", actual); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 608 | match actual { |
| 609 | Ok(v) => { |
| 610 | if v == expected { |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 611 | info!("*** OK ***"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 612 | Ok(()) |
| 613 | } else { |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 614 | info!("*** FAILED ***"); |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 615 | Err(thrift::Error::User( |
| 616 | format!("expected {:?} but got {:?}", &expected, &v).into(), |
| 617 | )) |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | Err(e) => Err(e), |
| 621 | } |
| 622 | } |