David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
Roger Meier | d3b9dca | 2011-06-24 14:01:10 +0000 | [diff] [blame] | 20 | #define __STDC_FORMAT_MACROS |
| 21 | #include <inttypes.h> |
| 22 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 23 | #include <iostream> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 24 | #include <unistd.h> |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 25 | #include <sys/time.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 26 | #include <protocol/TBinaryProtocol.h> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 27 | #include <protocol/TJSONProtocol.h> |
| 28 | #include <transport/THttpClient.h> |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 29 | #include <transport/TTransportUtils.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 30 | #include <transport/TSocket.h> |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 31 | #include <transport/TSSLSocket.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 32 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 33 | #include <boost/shared_ptr.hpp> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 34 | #include <boost/program_options.hpp> |
| 35 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 36 | #include "ThriftTest.h" |
| 37 | |
| 38 | using namespace boost; |
| 39 | using namespace std; |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 40 | using namespace apache::thrift; |
| 41 | using namespace apache::thrift::protocol; |
| 42 | using namespace apache::thrift::transport; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 43 | using namespace thrift::test; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 44 | |
| 45 | //extern uint32_t g_socket_syscalls; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 46 | |
| 47 | // Current time, microseconds since the epoch |
| 48 | uint64_t now() |
| 49 | { |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 50 | int64_t ret; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 51 | struct timeval tv; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 52 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 53 | gettimeofday(&tv, NULL); |
| 54 | ret = tv.tv_sec; |
| 55 | ret = ret*1000*1000 + tv.tv_usec; |
| 56 | return ret; |
| 57 | } |
| 58 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 59 | int main(int argc, char** argv) { |
| 60 | string host = "localhost"; |
| 61 | int port = 9090; |
| 62 | int numTests = 1; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 63 | bool ssl = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 64 | string transport_type = "buffered"; |
| 65 | string protocol_type = "binary"; |
| 66 | string domain_socket = ""; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 67 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 68 | program_options::options_description desc("Allowed options"); |
| 69 | desc.add_options() |
| 70 | ("help,h", "produce help message") |
| 71 | ("host", program_options::value<string>(&host)->default_value(host), "Host to connect") |
| 72 | ("port", program_options::value<int>(&port)->default_value(port), "Port number to connect") |
| 73 | ("domain-socket", program_options::value<string>(&domain_socket)->default_value(domain_socket), "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port") |
| 74 | ("transport", program_options::value<string>(&transport_type)->default_value(transport_type), "Transport: buffered, framed, http") |
| 75 | ("protocol", program_options::value<string>(&protocol_type)->default_value(protocol_type), "Protocol: binary, json") |
| 76 | ("ssl", "Encrypted Transport using SSL") |
| 77 | ("testloops,n", program_options::value<int>(&numTests)->default_value(numTests), "Number of Tests") |
| 78 | ; |
| 79 | |
| 80 | program_options::variables_map vm; |
| 81 | program_options::store(program_options::parse_command_line(argc, argv, desc), vm); |
| 82 | program_options::notify(vm); |
| 83 | |
| 84 | if (vm.count("help")) { |
| 85 | cout << desc << "\n"; |
| 86 | return 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 87 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 88 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 89 | try { |
| 90 | if (!protocol_type.empty()) { |
| 91 | if (protocol_type == "binary") { |
| 92 | } else if (protocol_type == "json") { |
| 93 | } else { |
| 94 | throw invalid_argument("Unknown protocol type "+protocol_type); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if (!transport_type.empty()) { |
| 99 | if (transport_type == "buffered") { |
| 100 | } else if (transport_type == "framed") { |
| 101 | } else if (transport_type == "http") { |
| 102 | } else { |
| 103 | throw invalid_argument("Unknown transport type "+transport_type); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | } catch (std::exception& e) { |
| 108 | cerr << e.what() << endl; |
| 109 | cout << desc << "\n"; |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | if (vm.count("ssl")) { |
| 114 | ssl = true; |
| 115 | } |
| 116 | |
| 117 | shared_ptr<TTransport> transport; |
| 118 | shared_ptr<TProtocol> protocol; |
| 119 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 120 | shared_ptr<TSocket> socket; |
| 121 | shared_ptr<TSSLSocketFactory> factory; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 122 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 123 | if (ssl) { |
| 124 | factory = shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
| 125 | factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
| 126 | factory->loadTrustedCertificates("./trusted-ca-certificate.pem"); |
| 127 | factory->authenticate(true); |
| 128 | socket = factory->createSocket(host, port); |
| 129 | } else { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 130 | if (domain_socket != "") { |
| 131 | socket = shared_ptr<TSocket>(new TSocket(domain_socket)); |
| 132 | port = 0; |
| 133 | } |
| 134 | else { |
| 135 | socket = shared_ptr<TSocket>(new TSocket(host, port)); |
| 136 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 137 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 138 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 139 | if (transport_type.compare("http") == 0) { |
| 140 | shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service")); |
| 141 | transport = httpSocket; |
| 142 | } else if (transport_type.compare("framed") == 0){ |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 143 | shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 144 | transport = framedSocket; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 145 | } else{ |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 146 | shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); |
| 147 | transport = bufferedSocket; |
| 148 | } |
| 149 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 150 | if (protocol_type.compare("json") == 0) { |
| 151 | shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport)); |
| 152 | protocol = jsonProtocol; |
| 153 | } else{ |
| 154 | shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport)); |
| 155 | protocol = binaryProtocol; |
| 156 | } |
| 157 | |
| 158 | // Connection info |
| 159 | cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: " << domain_socket; |
| 160 | if (port != 0) { |
| 161 | cout << host << ":" << port; |
| 162 | } |
| 163 | cout << endl; |
| 164 | |
| 165 | ThriftTestClient testClient(protocol); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 166 | |
| 167 | uint64_t time_min = 0; |
| 168 | uint64_t time_max = 0; |
| 169 | uint64_t time_tot = 0; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 170 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 171 | int test = 0; |
| 172 | for (test = 0; test < numTests; ++test) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 173 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 174 | try { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 175 | transport->open(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 176 | } catch (TTransportException& ttx) { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 177 | printf("Connect failed: %s\n", ttx.what()); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 178 | continue; |
| 179 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 180 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 181 | /** |
| 182 | * CONNECT TEST |
| 183 | */ |
| 184 | printf("Test #%d, connect %s:%d\n", test+1, host.c_str(), port); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 185 | |
| 186 | uint64_t start = now(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 187 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 188 | /** |
| 189 | * VOID TEST |
| 190 | */ |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 191 | try { |
| 192 | printf("testVoid()"); |
| 193 | testClient.testVoid(); |
| 194 | printf(" = void\n"); |
| 195 | } catch (TApplicationException tax) { |
| 196 | printf("%s\n", tax.what()); |
| 197 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 198 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 199 | /** |
| 200 | * STRING TEST |
| 201 | */ |
| 202 | printf("testString(\"Test\")"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 203 | string s; |
| 204 | testClient.testString(s, "Test"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 205 | printf(" = \"%s\"\n", s.c_str()); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 206 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 207 | /** |
| 208 | * BYTE TEST |
| 209 | */ |
| 210 | printf("testByte(1)"); |
| 211 | uint8_t u8 = testClient.testByte(1); |
| 212 | printf(" = %d\n", (int)u8); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 213 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 214 | /** |
| 215 | * I32 TEST |
| 216 | */ |
| 217 | printf("testI32(-1)"); |
| 218 | int32_t i32 = testClient.testI32(-1); |
| 219 | printf(" = %d\n", i32); |
| 220 | |
| 221 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 222 | * I64 TEST |
| 223 | */ |
| 224 | printf("testI64(-34359738368)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 225 | int64_t i64 = testClient.testI64(-34359738368LL); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 226 | printf(" = %"PRId64"\n", i64); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * DOUBLE TEST |
| 230 | */ |
| 231 | printf("testDouble(-5.2098523)"); |
| 232 | double dub = testClient.testDouble(-5.2098523); |
| 233 | printf(" = %lf\n", dub); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 234 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 235 | /** |
| 236 | * STRUCT TEST |
| 237 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 238 | printf("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 239 | Xtruct out; |
| 240 | out.string_thing = "Zero"; |
| 241 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 242 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 243 | out.i64_thing = -5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 244 | Xtruct in; |
| 245 | testClient.testStruct(in, out); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 246 | printf(" = {\"%s\", %d, %d, %"PRId64"}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 247 | in.string_thing.c_str(), |
| 248 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 249 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 250 | in.i64_thing); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 251 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 252 | /** |
| 253 | * NESTED STRUCT TEST |
| 254 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 255 | printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 256 | Xtruct2 out2; |
| 257 | out2.byte_thing = 1; |
| 258 | out2.struct_thing = out; |
| 259 | out2.i32_thing = 5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 260 | Xtruct2 in2; |
| 261 | testClient.testNest(in2, out2); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 262 | in = in2.struct_thing; |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 263 | printf(" = {%d, {\"%s\", %d, %d, %"PRId64"}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 264 | in2.byte_thing, |
| 265 | in.string_thing.c_str(), |
| 266 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 267 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 268 | in.i64_thing, |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 269 | in2.i32_thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * MAP TEST |
| 273 | */ |
| 274 | map<int32_t,int32_t> mapout; |
| 275 | for (int32_t i = 0; i < 5; ++i) { |
| 276 | mapout.insert(make_pair(i, i-10)); |
| 277 | } |
| 278 | printf("testMap({"); |
| 279 | map<int32_t, int32_t>::const_iterator m_iter; |
| 280 | bool first = true; |
| 281 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 282 | if (first) { |
| 283 | first = false; |
| 284 | } else { |
| 285 | printf(", "); |
| 286 | } |
| 287 | printf("%d => %d", m_iter->first, m_iter->second); |
| 288 | } |
| 289 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 290 | map<int32_t,int32_t> mapin; |
| 291 | testClient.testMap(mapin, mapout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 292 | printf(" = {"); |
| 293 | first = true; |
| 294 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 295 | if (first) { |
| 296 | first = false; |
| 297 | } else { |
| 298 | printf(", "); |
| 299 | } |
| 300 | printf("%d => %d", m_iter->first, m_iter->second); |
| 301 | } |
| 302 | printf("}\n"); |
| 303 | |
| 304 | /** |
| 305 | * SET TEST |
| 306 | */ |
| 307 | set<int32_t> setout; |
| 308 | for (int32_t i = -2; i < 3; ++i) { |
| 309 | setout.insert(i); |
| 310 | } |
| 311 | printf("testSet({"); |
| 312 | set<int32_t>::const_iterator s_iter; |
| 313 | first = true; |
| 314 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 315 | if (first) { |
| 316 | first = false; |
| 317 | } else { |
| 318 | printf(", "); |
| 319 | } |
| 320 | printf("%d", *s_iter); |
| 321 | } |
| 322 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 323 | set<int32_t> setin; |
| 324 | testClient.testSet(setin, setout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 325 | printf(" = {"); |
| 326 | first = true; |
| 327 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 328 | if (first) { |
| 329 | first = false; |
| 330 | } else { |
| 331 | printf(", "); |
| 332 | } |
| 333 | printf("%d", *s_iter); |
| 334 | } |
| 335 | printf("}\n"); |
| 336 | |
| 337 | /** |
| 338 | * LIST TEST |
| 339 | */ |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 340 | vector<int32_t> listout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 341 | for (int32_t i = -2; i < 3; ++i) { |
| 342 | listout.push_back(i); |
| 343 | } |
| 344 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 345 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 346 | first = true; |
| 347 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 348 | if (first) { |
| 349 | first = false; |
| 350 | } else { |
| 351 | printf(", "); |
| 352 | } |
| 353 | printf("%d", *l_iter); |
| 354 | } |
| 355 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 356 | vector<int32_t> listin; |
| 357 | testClient.testList(listin, listout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 358 | printf(" = {"); |
| 359 | first = true; |
| 360 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 361 | if (first) { |
| 362 | first = false; |
| 363 | } else { |
| 364 | printf(", "); |
| 365 | } |
| 366 | printf("%d", *l_iter); |
| 367 | } |
| 368 | printf("}\n"); |
| 369 | |
| 370 | /** |
| 371 | * ENUM TEST |
| 372 | */ |
| 373 | printf("testEnum(ONE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 374 | Numberz::type ret = testClient.testEnum(Numberz::ONE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 375 | printf(" = %d\n", ret); |
| 376 | |
| 377 | printf("testEnum(TWO)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 378 | ret = testClient.testEnum(Numberz::TWO); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 379 | printf(" = %d\n", ret); |
| 380 | |
| 381 | printf("testEnum(THREE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 382 | ret = testClient.testEnum(Numberz::THREE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 383 | printf(" = %d\n", ret); |
| 384 | |
| 385 | printf("testEnum(FIVE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 386 | ret = testClient.testEnum(Numberz::FIVE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 387 | printf(" = %d\n", ret); |
| 388 | |
| 389 | printf("testEnum(EIGHT)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 390 | ret = testClient.testEnum(Numberz::EIGHT); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 391 | printf(" = %d\n", ret); |
| 392 | |
| 393 | /** |
| 394 | * TYPEDEF TEST |
| 395 | */ |
| 396 | printf("testTypedef(309858235082523)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 397 | UserId uid = testClient.testTypedef(309858235082523LL); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 398 | printf(" = %"PRId64"\n", uid); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 399 | |
| 400 | /** |
| 401 | * NESTED MAP TEST |
| 402 | */ |
| 403 | printf("testMapMap(1)"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 404 | map<int32_t, map<int32_t, int32_t> > mm; |
| 405 | testClient.testMapMap(mm, 1); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 406 | printf(" = {"); |
| 407 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 408 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 409 | printf("%d => {", mi->first); |
| 410 | map<int32_t, int32_t>::const_iterator mi2; |
| 411 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
| 412 | printf("%d => %d, ", mi2->first, mi2->second); |
| 413 | } |
| 414 | printf("}, "); |
| 415 | } |
| 416 | printf("}\n"); |
| 417 | |
| 418 | /** |
| 419 | * INSANITY TEST |
| 420 | */ |
| 421 | Insanity insane; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 422 | insane.userMap.insert(make_pair(Numberz::FIVE, 5000)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 423 | Xtruct truck; |
| 424 | truck.string_thing = "Truck"; |
| 425 | truck.byte_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 426 | truck.i32_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 427 | truck.i64_thing = 8; |
| 428 | insane.xtructs.push_back(truck); |
| 429 | printf("testInsanity()"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 430 | map<UserId, map<Numberz::type,Insanity> > whoa; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 431 | testClient.testInsanity(whoa, insane); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 432 | printf(" = {"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 433 | map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 434 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 435 | printf("%"PRId64" => {", i_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 436 | map<Numberz::type,Insanity>::const_iterator i2_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 437 | for (i2_iter = i_iter->second.begin(); |
| 438 | i2_iter != i_iter->second.end(); |
| 439 | ++i2_iter) { |
| 440 | printf("%d => {", i2_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 441 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 442 | map<Numberz::type, UserId>::const_iterator um; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 443 | printf("{"); |
| 444 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 445 | printf("%d => %"PRId64", ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 446 | } |
| 447 | printf("}, "); |
| 448 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 449 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 450 | vector<Xtruct>::const_iterator x; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 451 | printf("{"); |
| 452 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 453 | printf("{\"%s\", %d, %d, %"PRId64"}, ", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 454 | x->string_thing.c_str(), |
| 455 | (int)x->byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 456 | x->i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 457 | x->i64_thing); |
| 458 | } |
| 459 | printf("}"); |
| 460 | |
| 461 | printf("}, "); |
| 462 | } |
| 463 | printf("}, "); |
| 464 | } |
| 465 | printf("}\n"); |
| 466 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 467 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 468 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 469 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 470 | printf("testClient.testException(\"Xception\") =>"); |
| 471 | testClient.testException("Xception"); |
| 472 | printf(" void\nFAILURE\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 473 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 474 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 475 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 476 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 477 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 478 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 479 | printf("testClient.testException(\"success\") =>"); |
| 480 | testClient.testException("success"); |
| 481 | printf(" void\n"); |
| 482 | } catch(...) { |
| 483 | printf(" exception\nFAILURE\n"); |
| 484 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 485 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 486 | /* test multi exception */ |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 487 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 488 | try { |
| 489 | printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 490 | Xtruct result; |
| 491 | testClient.testMultiException(result, "Xception", "test 1"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 492 | printf(" result\nFAILURE\n"); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 493 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 494 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 495 | } |
| 496 | |
| 497 | try { |
| 498 | printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 499 | Xtruct result; |
| 500 | testClient.testMultiException(result, "Xception2", "test 2"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 501 | printf(" result\nFAILURE\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 502 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 503 | } catch(Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 504 | printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 505 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 506 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 507 | try { |
| 508 | printf("testClient.testMultiException(\"success\", \"test 3\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 509 | Xtruct result; |
| 510 | testClient.testMultiException(result, "success", "test 3"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 511 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
| 512 | } catch(...) { |
| 513 | printf(" exception\nFAILURE\n"); |
| 514 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 515 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 516 | /* test oneway void */ |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 517 | { |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 518 | printf("testClient.testOneway(3) =>"); |
| 519 | uint64_t startOneway = now(); |
| 520 | testClient.testOneway(3); |
| 521 | uint64_t elapsed = now() - startOneway; |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 522 | if (elapsed > 200 * 1000) { // 0.2 seconds |
| 523 | printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0); |
| 524 | } else { |
| 525 | printf(" success - took %.2f ms\n", (double)elapsed/1000.0); |
| 526 | } |
| 527 | } |
| 528 | |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 529 | /** |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 530 | * redo a simple test after the oneway to make sure we aren't "off by one" -- |
| 531 | * if the server treated oneway void like normal void, this next test will |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 532 | * fail since it will get the void confirmation rather than the correct |
| 533 | * result. In this circumstance, the client will throw the exception: |
| 534 | * |
| 535 | * TApplicationException: Wrong method namea |
| 536 | */ |
| 537 | /** |
| 538 | * I32 TEST |
| 539 | */ |
| 540 | printf("re-test testI32(-1)"); |
| 541 | i32 = testClient.testI32(-1); |
| 542 | printf(" = %d\n", i32); |
| 543 | |
| 544 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 545 | uint64_t stop = now(); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 546 | uint64_t tot = stop-start; |
| 547 | |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 548 | printf("Total time: %"PRIu64" us\n", stop-start); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 549 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 550 | time_tot += tot; |
| 551 | if (time_min == 0 || tot < time_min) { |
| 552 | time_min = tot; |
| 553 | } |
| 554 | if (tot > time_max) { |
| 555 | time_max = tot; |
| 556 | } |
| 557 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 558 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 561 | // printf("\nSocket syscalls: %u", g_socket_syscalls); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 562 | printf("\nAll tests done.\n"); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 563 | |
| 564 | uint64_t time_avg = time_tot / numTests; |
| 565 | |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 566 | printf("Min time: %"PRIu64" us\n", time_min); |
| 567 | printf("Max time: %"PRIu64" us\n", time_max); |
| 568 | printf("Avg time: %"PRIu64" us\n", time_avg); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 569 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 570 | return 0; |
| 571 | } |