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 env_logger; |
| 20 | use log::*; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 21 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 22 | use std::collections::{BTreeMap, BTreeSet}; |
| 23 | use std::thread; |
| 24 | use std::time::Duration; |
| 25 | |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 26 | use thrift; |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 27 | use thrift::protocol::{ |
| 28 | TBinaryInputProtocolFactory, TBinaryOutputProtocolFactory, TCompactInputProtocolFactory, |
| 29 | TCompactOutputProtocolFactory, TInputProtocolFactory, TOutputProtocolFactory, |
| 30 | }; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 31 | use thrift::server::{TMultiplexedProcessor, TServer}; |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 32 | use thrift::transport::{ |
| 33 | TBufferedReadTransportFactory, TBufferedWriteTransportFactory, TFramedReadTransportFactory, |
| 34 | TFramedWriteTransportFactory, TReadTransportFactory, TWriteTransportFactory, |
| 35 | }; |
| 36 | use thrift::OrderedFloat; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 37 | use thrift_test::*; |
| 38 | |
| 39 | fn main() { |
Allen George | 7ddbcc0 | 2020-11-08 09:51:19 -0500 | [diff] [blame] | 40 | env_logger::init(); |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 41 | |
| 42 | debug!("initialized logger - running cross-test server"); |
| 43 | |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 44 | match run() { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 45 | Ok(()) => info!("cross-test server succeeded"), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 46 | Err(e) => { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 47 | info!("cross-test server failed with error {:?}", e); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 48 | std::process::exit(1); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | fn run() -> thrift::Result<()> { |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 54 | // unsupported options: |
Jens Geyer | 4a33b18 | 2020-03-22 13:46:34 +0100 | [diff] [blame] | 55 | // --pipe |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 56 | // --ssl |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 57 | let matches = clap_app!(rust_test_client => |
| 58 | (version: "1.0") |
| 59 | (author: "Apache Thrift Developers <dev@thrift.apache.org>") |
| 60 | (about: "Rust Thrift test server") |
| 61 | (@arg port: --port +takes_value "port on which the test server listens") |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame^] | 62 | (@arg domain_socket: --("domain-socket") +takes_value "Unix Domain Socket on which the test server listens") |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 63 | (@arg transport: --transport +takes_value "transport implementation to use (\"buffered\", \"framed\")") |
| 64 | (@arg protocol: --protocol +takes_value "protocol implementation to use (\"binary\", \"compact\")") |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame^] | 65 | (@arg server_type: --("server-type") +takes_value "type of server instantiated (\"simple\", \"thread-pool\")") |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 66 | (@arg workers: -n --workers +takes_value "number of thread-pool workers (\"4\")") |
| 67 | ) |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame^] | 68 | .get_matches(); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 69 | |
| 70 | let port = value_t!(matches, "port", u16).unwrap_or(9090); |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame^] | 71 | let domain_socket = matches.value_of("domain_socket"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 72 | let transport = matches.value_of("transport").unwrap_or("buffered"); |
| 73 | let protocol = matches.value_of("protocol").unwrap_or("binary"); |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 74 | let server_type = matches.value_of("server_type").unwrap_or("thread-pool"); |
| 75 | let workers = value_t!(matches, "workers", usize).unwrap_or(4); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 76 | let listen_address = format!("127.0.0.1:{}", port); |
| 77 | |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame^] | 78 | match domain_socket { |
| 79 | None => info!("Server is binding to {}", listen_address), |
| 80 | Some(domain_socket) => info!("Server is binding to {} (UDS)", domain_socket), |
| 81 | } |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 82 | |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 83 | let (i_transport_factory, o_transport_factory): ( |
| 84 | Box<dyn TReadTransportFactory>, |
| 85 | Box<dyn TWriteTransportFactory>, |
| 86 | ) = match &*transport { |
| 87 | "buffered" => ( |
| 88 | Box::new(TBufferedReadTransportFactory::new()), |
| 89 | Box::new(TBufferedWriteTransportFactory::new()), |
| 90 | ), |
| 91 | "framed" => ( |
| 92 | Box::new(TFramedReadTransportFactory::new()), |
| 93 | Box::new(TFramedWriteTransportFactory::new()), |
| 94 | ), |
| 95 | unknown => { |
| 96 | return Err(format!("unsupported transport type {}", unknown).into()); |
| 97 | } |
| 98 | }; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 99 | |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 100 | let (i_protocol_factory, o_protocol_factory): ( |
| 101 | Box<dyn TInputProtocolFactory>, |
| 102 | Box<dyn TOutputProtocolFactory>, |
| 103 | ) = match &*protocol { |
| 104 | "binary" | "multi" | "multi:binary" => ( |
| 105 | Box::new(TBinaryInputProtocolFactory::new()), |
| 106 | Box::new(TBinaryOutputProtocolFactory::new()), |
| 107 | ), |
| 108 | "compact" | "multic" | "multi:compact" => ( |
| 109 | Box::new(TCompactInputProtocolFactory::new()), |
| 110 | Box::new(TCompactOutputProtocolFactory::new()), |
| 111 | ), |
| 112 | unknown => { |
| 113 | return Err(format!("unsupported transport type {}", unknown).into()); |
| 114 | } |
| 115 | }; |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 116 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 117 | let test_processor = ThriftTestSyncProcessor::new(ThriftTestSyncHandlerImpl {}); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 118 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 119 | match &*server_type { |
| 120 | "simple" | "thread-pool" => { |
| 121 | if protocol == "multi" || protocol == "multic" { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 122 | let second_service_processor = |
| 123 | SecondServiceSyncProcessor::new(SecondServiceSyncHandlerImpl {}); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 124 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 125 | let mut multiplexed_processor = TMultiplexedProcessor::new(); |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 126 | multiplexed_processor.register("ThriftTest", Box::new(test_processor), true)?; |
| 127 | multiplexed_processor.register( |
| 128 | "SecondService", |
| 129 | Box::new(second_service_processor), |
| 130 | false, |
| 131 | )?; |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 132 | |
| 133 | let mut server = TServer::new( |
| 134 | i_transport_factory, |
| 135 | i_protocol_factory, |
| 136 | o_transport_factory, |
| 137 | o_protocol_factory, |
| 138 | multiplexed_processor, |
| 139 | workers, |
| 140 | ); |
| 141 | |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame^] | 142 | match domain_socket { |
| 143 | None => server.listen(&listen_address), |
| 144 | Some(domain_socket) => server.listen_uds(domain_socket), |
| 145 | } |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 146 | } else { |
| 147 | let mut server = TServer::new( |
| 148 | i_transport_factory, |
| 149 | i_protocol_factory, |
| 150 | o_transport_factory, |
| 151 | o_protocol_factory, |
| 152 | test_processor, |
| 153 | workers, |
| 154 | ); |
| 155 | |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame^] | 156 | match domain_socket { |
| 157 | None => server.listen(&listen_address), |
| 158 | Some(domain_socket) => server.listen_uds(domain_socket), |
| 159 | } |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 160 | } |
| 161 | } |
tokcum | f033641 | 2022-03-30 11:39:08 +0200 | [diff] [blame^] | 162 | |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 163 | unknown => Err(format!("unsupported server type {}", unknown).into()), |
| 164 | } |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | struct ThriftTestSyncHandlerImpl; |
| 168 | impl ThriftTestSyncHandler for ThriftTestSyncHandlerImpl { |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 169 | fn handle_test_void(&self) -> thrift::Result<()> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 170 | info!("testVoid()"); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 171 | Ok(()) |
| 172 | } |
| 173 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 174 | fn handle_test_string(&self, thing: String) -> thrift::Result<String> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 175 | info!("testString({})", &thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 176 | Ok(thing) |
| 177 | } |
| 178 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 179 | fn handle_test_bool(&self, thing: bool) -> thrift::Result<bool> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 180 | info!("testBool({})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 181 | Ok(thing) |
| 182 | } |
| 183 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 184 | fn handle_test_byte(&self, thing: i8) -> thrift::Result<i8> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 185 | info!("testByte({})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 186 | Ok(thing) |
| 187 | } |
| 188 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 189 | fn handle_test_i32(&self, thing: i32) -> thrift::Result<i32> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 190 | info!("testi32({})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 191 | Ok(thing) |
| 192 | } |
| 193 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 194 | fn handle_test_i64(&self, thing: i64) -> thrift::Result<i64> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 195 | info!("testi64({})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 196 | Ok(thing) |
| 197 | } |
| 198 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 199 | fn handle_test_double(&self, thing: OrderedFloat<f64>) -> thrift::Result<OrderedFloat<f64>> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 200 | info!("testDouble({})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 201 | Ok(thing) |
| 202 | } |
| 203 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 204 | fn handle_test_binary(&self, thing: Vec<u8>) -> thrift::Result<Vec<u8>> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 205 | info!("testBinary({:?})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 206 | Ok(thing) |
| 207 | } |
| 208 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 209 | fn handle_test_struct(&self, thing: Xtruct) -> thrift::Result<Xtruct> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 210 | info!("testStruct({:?})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 211 | Ok(thing) |
| 212 | } |
| 213 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 214 | fn handle_test_nest(&self, thing: Xtruct2) -> thrift::Result<Xtruct2> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 215 | info!("testNest({:?})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 216 | Ok(thing) |
| 217 | } |
| 218 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 219 | fn handle_test_map(&self, thing: BTreeMap<i32, i32>) -> thrift::Result<BTreeMap<i32, i32>> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 220 | info!("testMap({:?})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 221 | Ok(thing) |
| 222 | } |
| 223 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 224 | fn handle_test_string_map( |
| 225 | &self, |
| 226 | thing: BTreeMap<String, String>, |
| 227 | ) -> thrift::Result<BTreeMap<String, String>> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 228 | info!("testStringMap({:?})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 229 | Ok(thing) |
| 230 | } |
| 231 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 232 | fn handle_test_set(&self, thing: BTreeSet<i32>) -> thrift::Result<BTreeSet<i32>> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 233 | info!("testSet({:?})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 234 | Ok(thing) |
| 235 | } |
| 236 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 237 | fn handle_test_list(&self, thing: Vec<i32>) -> thrift::Result<Vec<i32>> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 238 | info!("testList({:?})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 239 | Ok(thing) |
| 240 | } |
| 241 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 242 | fn handle_test_enum(&self, thing: Numberz) -> thrift::Result<Numberz> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 243 | info!("testEnum({:?})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 244 | Ok(thing) |
| 245 | } |
| 246 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 247 | fn handle_test_typedef(&self, thing: UserId) -> thrift::Result<UserId> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 248 | info!("testTypedef({})", thing); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 249 | Ok(thing) |
| 250 | } |
| 251 | |
| 252 | /// @return map<i32,map<i32,i32>> - returns a dictionary with these values: |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 253 | /// {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => |
| 254 | /// 2, 3 => 3, 4 => 4, }, } |
| 255 | fn handle_test_map_map(&self, hello: i32) -> thrift::Result<BTreeMap<i32, BTreeMap<i32, i32>>> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 256 | info!("testMapMap({})", hello); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 257 | |
| 258 | let mut inner_map_0: BTreeMap<i32, i32> = BTreeMap::new(); |
| 259 | for i in -4..(0 as i32) { |
| 260 | inner_map_0.insert(i, i); |
| 261 | } |
| 262 | |
| 263 | let mut inner_map_1: BTreeMap<i32, i32> = BTreeMap::new(); |
| 264 | for i in 1..5 { |
| 265 | inner_map_1.insert(i, i); |
| 266 | } |
| 267 | |
| 268 | let mut ret_map: BTreeMap<i32, BTreeMap<i32, i32>> = BTreeMap::new(); |
| 269 | ret_map.insert(-4, inner_map_0); |
| 270 | ret_map.insert(4, inner_map_1); |
| 271 | |
| 272 | Ok(ret_map) |
| 273 | } |
| 274 | |
| 275 | /// Creates a the returned map with these values and prints it out: |
| 276 | /// { 1 => { 2 => argument, |
| 277 | /// 3 => argument, |
| 278 | /// }, |
| 279 | /// 2 => { 6 => <empty Insanity struct>, }, |
| 280 | /// } |
| 281 | /// return map<UserId, map<Numberz,Insanity>> - a map with the above values |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 282 | fn handle_test_insanity( |
| 283 | &self, |
| 284 | argument: Insanity, |
| 285 | ) -> thrift::Result<BTreeMap<UserId, BTreeMap<Numberz, Insanity>>> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 286 | info!("testInsanity({:?})", argument); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 287 | let mut map_0: BTreeMap<Numberz, Insanity> = BTreeMap::new(); |
Allen George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame] | 288 | map_0.insert(Numberz::TWO, argument.clone()); |
| 289 | map_0.insert(Numberz::THREE, argument); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 290 | |
| 291 | let mut map_1: BTreeMap<Numberz, Insanity> = BTreeMap::new(); |
| 292 | let insanity = Insanity { |
| 293 | user_map: None, |
| 294 | xtructs: None, |
| 295 | }; |
Allen George | 2e90ef5 | 2021-03-01 14:47:04 -0500 | [diff] [blame] | 296 | map_1.insert(Numberz::SIX, insanity); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 297 | |
| 298 | let mut ret: BTreeMap<UserId, BTreeMap<Numberz, Insanity>> = BTreeMap::new(); |
| 299 | ret.insert(1, map_0); |
| 300 | ret.insert(2, map_1); |
| 301 | |
| 302 | Ok(ret) |
| 303 | } |
| 304 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 305 | /// returns an Xtruct with: |
| 306 | /// string_thing = "Hello2", byte_thing = arg0, i32_thing = arg1 and |
| 307 | /// i64_thing = arg2 |
| 308 | fn handle_test_multi( |
| 309 | &self, |
| 310 | arg0: i8, |
| 311 | arg1: i32, |
| 312 | arg2: i64, |
| 313 | _: BTreeMap<i16, String>, |
| 314 | _: Numberz, |
| 315 | _: UserId, |
| 316 | ) -> thrift::Result<Xtruct> { |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 317 | let x_ret = Xtruct { |
| 318 | string_thing: Some("Hello2".to_owned()), |
| 319 | byte_thing: Some(arg0), |
| 320 | i32_thing: Some(arg1), |
| 321 | i64_thing: Some(arg2), |
| 322 | }; |
| 323 | |
| 324 | Ok(x_ret) |
| 325 | } |
| 326 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 327 | /// if arg == "Xception" throw Xception with errorCode = 1001 and message = |
| 328 | /// arg |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 329 | /// else if arg == "TException" throw TException |
| 330 | /// else do not throw anything |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 331 | fn handle_test_exception(&self, arg: String) -> thrift::Result<()> { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 332 | info!("testException({})", arg); |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 333 | |
| 334 | match &*arg { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 335 | "Xception" => Err((Xception { |
| 336 | error_code: Some(1001), |
| 337 | message: Some(arg), |
| 338 | }) |
| 339 | .into()), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 340 | "TException" => Err("this is a random error".into()), |
| 341 | _ => Ok(()), |
| 342 | } |
| 343 | } |
| 344 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 345 | /// if arg0 == "Xception": |
| 346 | /// throw Xception with errorCode = 1001 and message = "This is an |
| 347 | /// Xception" |
| 348 | /// else if arg0 == "Xception2": |
| 349 | /// throw Xception2 with errorCode = 2002 and struct_thing.string_thing = |
| 350 | /// "This is an Xception2" |
| 351 | // else: |
| 352 | // do not throw anything and return Xtruct with string_thing = arg1 |
| 353 | fn handle_test_multi_exception(&self, arg0: String, arg1: String) -> thrift::Result<Xtruct> { |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 354 | match &*arg0 { |
Allen George | 55c3e4c | 2021-03-01 23:19:52 -0500 | [diff] [blame] | 355 | "Xception" => Err((Xception { |
| 356 | error_code: Some(1001), |
| 357 | message: Some("This is an Xception".to_owned()), |
| 358 | }) |
| 359 | .into()), |
| 360 | "Xception2" => Err((Xception2 { |
| 361 | error_code: Some(2002), |
| 362 | struct_thing: Some(Xtruct { |
| 363 | string_thing: Some("This is an Xception2".to_owned()), |
| 364 | byte_thing: None, |
| 365 | i32_thing: None, |
| 366 | i64_thing: None, |
| 367 | }), |
| 368 | }) |
| 369 | .into()), |
| 370 | _ => Ok(Xtruct { |
| 371 | string_thing: Some(arg1), |
| 372 | byte_thing: None, |
| 373 | i32_thing: None, |
| 374 | i64_thing: None, |
| 375 | }), |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Allen George | 0e22c36 | 2017-01-30 07:15:00 -0500 | [diff] [blame] | 379 | fn handle_test_oneway(&self, seconds_to_sleep: i32) -> thrift::Result<()> { |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 380 | thread::sleep(Duration::from_secs(seconds_to_sleep as u64)); |
| 381 | Ok(()) |
| 382 | } |
| 383 | } |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 384 | |
| 385 | struct SecondServiceSyncHandlerImpl; |
| 386 | impl SecondServiceSyncHandler for SecondServiceSyncHandlerImpl { |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 387 | fn handle_secondtest_string(&self, thing: String) -> thrift::Result<String> { |
James E. King, III | 20e16bc | 2017-11-18 22:37:54 -0500 | [diff] [blame] | 388 | info!("(second)testString({})", &thing); |
Allen George | bc1344d | 2017-04-28 10:22:03 -0400 | [diff] [blame] | 389 | let ret = format!("testString(\"{}\")", &thing); |
| 390 | Ok(ret) |
| 391 | } |
| 392 | } |