blob: 7e37e85616c87563f0662918b25940ead15690fa [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
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
Mark Sleee8540632006-05-30 09:24:40 +000020#include <stdio.h>
21#include <unistd.h>
Mark Slee95771002006-06-07 06:53:25 +000022#include <sys/time.h>
Marc Slemko6be374b2006-08-04 03:16:25 +000023#include <protocol/TBinaryProtocol.h>
Mark Sleea3302652006-10-25 19:03:32 +000024#include <transport/TTransportUtils.h>
Marc Slemko6be374b2006-08-04 03:16:25 +000025#include <transport/TSocket.h>
Bryan Duxburycd9aea12011-02-22 18:12:06 +000026#include <transport/TSSLSocket.h>
Mark Sleee8540632006-05-30 09:24:40 +000027
Marc Slemko6be374b2006-08-04 03:16:25 +000028#include <boost/shared_ptr.hpp>
29#include "ThriftTest.h"
30
David Reissbc3dddb2007-08-22 23:20:24 +000031#define __STDC_FORMAT_MACROS
32#include <inttypes.h>
33
Marc Slemko6be374b2006-08-04 03:16:25 +000034using namespace boost;
35using namespace std;
T Jake Lucianib5e62212009-01-31 22:36:20 +000036using namespace apache::thrift;
37using namespace apache::thrift::protocol;
38using namespace apache::thrift::transport;
Marc Slemkobf4fd192006-08-15 21:29:39 +000039using namespace thrift::test;
Marc Slemko6be374b2006-08-04 03:16:25 +000040
41//extern uint32_t g_socket_syscalls;
Mark Slee95771002006-06-07 06:53:25 +000042
43// Current time, microseconds since the epoch
44uint64_t now()
45{
Roger Meier5f9614c2010-11-21 16:59:05 +000046 int64_t ret;
Mark Slee95771002006-06-07 06:53:25 +000047 struct timeval tv;
David Reiss0c90f6f2008-02-06 22:18:40 +000048
Mark Slee95771002006-06-07 06:53:25 +000049 gettimeofday(&tv, NULL);
50 ret = tv.tv_sec;
51 ret = ret*1000*1000 + tv.tv_usec;
52 return ret;
53}
54
Mark Sleee8540632006-05-30 09:24:40 +000055int main(int argc, char** argv) {
56 string host = "localhost";
57 int port = 9090;
58 int numTests = 1;
Mark Sleea3302652006-10-25 19:03:32 +000059 bool framed = false;
Bryan Duxburycd9aea12011-02-22 18:12:06 +000060 bool ssl = false;
Mark Sleee8540632006-05-30 09:24:40 +000061
Mark Sleea3302652006-10-25 19:03:32 +000062 for (int i = 0; i < argc; ++i) {
63 if (strcmp(argv[i], "-h") == 0) {
64 char* pch = strtok(argv[++i], ":");
65 if (pch != NULL) {
66 host = string(pch);
67 }
68 pch = strtok(NULL, ":");
69 if (pch != NULL) {
70 port = atoi(pch);
71 }
72 } else if (strcmp(argv[i], "-n") == 0) {
73 numTests = atoi(argv[++i]);
74 } else if (strcmp(argv[i], "-f") == 0) {
75 framed = true;
Bryan Duxburycd9aea12011-02-22 18:12:06 +000076 } else if (strcmp(argv[i], "--ssl") == 0) {
77 ssl = true;
Mark Sleea3302652006-10-25 19:03:32 +000078 }
Mark Sleee8540632006-05-30 09:24:40 +000079 }
Mark Sleea3302652006-10-25 19:03:32 +000080
Bryan Duxburycd9aea12011-02-22 18:12:06 +000081 shared_ptr<TSocket> socket;
82 shared_ptr<TSSLSocketFactory> factory;
83 if (ssl) {
84 factory = shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
85 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
86 factory->loadTrustedCertificates("./trusted-ca-certificate.pem");
87 factory->authenticate(true);
88 socket = factory->createSocket(host, port);
89 } else {
90 socket = shared_ptr<TSocket>(new TSocket(host, port));
91 }
Mark Sleea3302652006-10-25 19:03:32 +000092
David Reisse71115b2010-10-06 17:09:56 +000093 shared_ptr<TBufferBase> transport;
Mark Sleee8540632006-05-30 09:24:40 +000094
Marc Slemko6be374b2006-08-04 03:16:25 +000095 shared_ptr<TSocket> socket(new TSocket(host, port));
David Reiss0c90f6f2008-02-06 22:18:40 +000096
Mark Sleea3302652006-10-25 19:03:32 +000097 if (framed) {
98 shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +000099 transport = framedSocket;
Mark Sleea3302652006-10-25 19:03:32 +0000100 } else {
101 shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
102 transport = bufferedSocket;
103 }
104
David Reisse71115b2010-10-06 17:09:56 +0000105 shared_ptr< TBinaryProtocolT<TBufferBase> > protocol(
106 new TBinaryProtocolT<TBufferBase>(transport));
David Reissb7762a02010-10-06 17:10:00 +0000107 ThriftTestClientT< TBinaryProtocolT<TBufferBase> > testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000108
109 uint64_t time_min = 0;
110 uint64_t time_max = 0;
111 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000112
Mark Sleee8540632006-05-30 09:24:40 +0000113 int test = 0;
114 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000115
Mark Slee95771002006-06-07 06:53:25 +0000116 try {
Mark Sleea3302652006-10-25 19:03:32 +0000117 transport->open();
Mark Slee95771002006-06-07 06:53:25 +0000118 } catch (TTransportException& ttx) {
Mark Sleeb9ff32a2006-11-16 01:00:24 +0000119 printf("Connect failed: %s\n", ttx.what());
Mark Sleee8540632006-05-30 09:24:40 +0000120 continue;
121 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000122
Mark Sleed788b2e2006-09-07 01:26:35 +0000123 /**
124 * CONNECT TEST
125 */
126 printf("Test #%d, connect %s:%d\n", test+1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000127
128 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000129
Mark Sleee8540632006-05-30 09:24:40 +0000130 /**
131 * VOID TEST
132 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000133 try {
134 printf("testVoid()");
135 testClient.testVoid();
136 printf(" = void\n");
137 } catch (TApplicationException tax) {
138 printf("%s\n", tax.what());
139 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000140
Mark Sleee8540632006-05-30 09:24:40 +0000141 /**
142 * STRING TEST
143 */
144 printf("testString(\"Test\")");
Mark Slee1921d202007-01-24 19:43:06 +0000145 string s;
146 testClient.testString(s, "Test");
Mark Sleee8540632006-05-30 09:24:40 +0000147 printf(" = \"%s\"\n", s.c_str());
David Reiss0c90f6f2008-02-06 22:18:40 +0000148
Mark Sleee8540632006-05-30 09:24:40 +0000149 /**
150 * BYTE TEST
151 */
152 printf("testByte(1)");
153 uint8_t u8 = testClient.testByte(1);
154 printf(" = %d\n", (int)u8);
David Reiss0c90f6f2008-02-06 22:18:40 +0000155
Mark Sleee8540632006-05-30 09:24:40 +0000156 /**
157 * I32 TEST
158 */
159 printf("testI32(-1)");
160 int32_t i32 = testClient.testI32(-1);
161 printf(" = %d\n", i32);
162
163 /**
Mark Sleee8540632006-05-30 09:24:40 +0000164 * I64 TEST
165 */
166 printf("testI64(-34359738368)");
Marc Slemkobf4fd192006-08-15 21:29:39 +0000167 int64_t i64 = testClient.testI64(-34359738368LL);
David Reissbc3dddb2007-08-22 23:20:24 +0000168 printf(" = %"PRId64"\n", i64);
Mark Sleec98d0502006-09-06 02:42:25 +0000169
170 /**
171 * DOUBLE TEST
172 */
173 printf("testDouble(-5.2098523)");
174 double dub = testClient.testDouble(-5.2098523);
175 printf(" = %lf\n", dub);
David Reiss0c90f6f2008-02-06 22:18:40 +0000176
Mark Sleee8540632006-05-30 09:24:40 +0000177 /**
178 * STRUCT TEST
179 */
Mark Slee6e536442006-06-30 18:28:50 +0000180 printf("testStruct({\"Zero\", 1, -3, -5})");
Mark Sleee8540632006-05-30 09:24:40 +0000181 Xtruct out;
182 out.string_thing = "Zero";
183 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000184 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000185 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000186 Xtruct in;
187 testClient.testStruct(in, out);
David Reissbc3dddb2007-08-22 23:20:24 +0000188 printf(" = {\"%s\", %d, %d, %"PRId64"}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000189 in.string_thing.c_str(),
190 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000191 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000192 in.i64_thing);
David Reiss0c90f6f2008-02-06 22:18:40 +0000193
Mark Sleee8540632006-05-30 09:24:40 +0000194 /**
195 * NESTED STRUCT TEST
196 */
Mark Slee6e536442006-06-30 18:28:50 +0000197 printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
Mark Sleee8540632006-05-30 09:24:40 +0000198 Xtruct2 out2;
199 out2.byte_thing = 1;
200 out2.struct_thing = out;
201 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000202 Xtruct2 in2;
203 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000204 in = in2.struct_thing;
David Reissbc3dddb2007-08-22 23:20:24 +0000205 printf(" = {%d, {\"%s\", %d, %d, %"PRId64"}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000206 in2.byte_thing,
207 in.string_thing.c_str(),
208 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000209 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000210 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000211 in2.i32_thing);
Mark Sleee8540632006-05-30 09:24:40 +0000212
213 /**
214 * MAP TEST
215 */
216 map<int32_t,int32_t> mapout;
217 for (int32_t i = 0; i < 5; ++i) {
218 mapout.insert(make_pair(i, i-10));
219 }
220 printf("testMap({");
221 map<int32_t, int32_t>::const_iterator m_iter;
222 bool first = true;
223 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
224 if (first) {
225 first = false;
226 } else {
227 printf(", ");
228 }
229 printf("%d => %d", m_iter->first, m_iter->second);
230 }
231 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000232 map<int32_t,int32_t> mapin;
233 testClient.testMap(mapin, mapout);
Mark Sleee8540632006-05-30 09:24:40 +0000234 printf(" = {");
235 first = true;
236 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
237 if (first) {
238 first = false;
239 } else {
240 printf(", ");
241 }
242 printf("%d => %d", m_iter->first, m_iter->second);
243 }
244 printf("}\n");
245
246 /**
247 * SET TEST
248 */
249 set<int32_t> setout;
250 for (int32_t i = -2; i < 3; ++i) {
251 setout.insert(i);
252 }
253 printf("testSet({");
254 set<int32_t>::const_iterator s_iter;
255 first = true;
256 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
257 if (first) {
258 first = false;
259 } else {
260 printf(", ");
261 }
262 printf("%d", *s_iter);
263 }
264 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000265 set<int32_t> setin;
266 testClient.testSet(setin, setout);
Mark Sleee8540632006-05-30 09:24:40 +0000267 printf(" = {");
268 first = true;
269 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
270 if (first) {
271 first = false;
272 } else {
273 printf(", ");
274 }
275 printf("%d", *s_iter);
276 }
277 printf("}\n");
278
279 /**
280 * LIST TEST
281 */
Mark Sleeb9acf982006-10-10 01:57:32 +0000282 vector<int32_t> listout;
Mark Sleee8540632006-05-30 09:24:40 +0000283 for (int32_t i = -2; i < 3; ++i) {
284 listout.push_back(i);
285 }
286 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000287 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000288 first = true;
289 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
290 if (first) {
291 first = false;
292 } else {
293 printf(", ");
294 }
295 printf("%d", *l_iter);
296 }
297 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000298 vector<int32_t> listin;
299 testClient.testList(listin, listout);
Mark Sleee8540632006-05-30 09:24:40 +0000300 printf(" = {");
301 first = true;
302 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
303 if (first) {
304 first = false;
305 } else {
306 printf(", ");
307 }
308 printf("%d", *l_iter);
309 }
310 printf("}\n");
311
312 /**
313 * ENUM TEST
314 */
315 printf("testEnum(ONE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000316 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Mark Sleee8540632006-05-30 09:24:40 +0000317 printf(" = %d\n", ret);
318
319 printf("testEnum(TWO)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000320 ret = testClient.testEnum(Numberz::TWO);
Mark Sleee8540632006-05-30 09:24:40 +0000321 printf(" = %d\n", ret);
322
323 printf("testEnum(THREE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000324 ret = testClient.testEnum(Numberz::THREE);
Mark Sleee8540632006-05-30 09:24:40 +0000325 printf(" = %d\n", ret);
326
327 printf("testEnum(FIVE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000328 ret = testClient.testEnum(Numberz::FIVE);
Mark Sleee8540632006-05-30 09:24:40 +0000329 printf(" = %d\n", ret);
330
331 printf("testEnum(EIGHT)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000332 ret = testClient.testEnum(Numberz::EIGHT);
Mark Sleee8540632006-05-30 09:24:40 +0000333 printf(" = %d\n", ret);
334
335 /**
336 * TYPEDEF TEST
337 */
338 printf("testTypedef(309858235082523)");
Marc Slemkobf4fd192006-08-15 21:29:39 +0000339 UserId uid = testClient.testTypedef(309858235082523LL);
David Reissbc3dddb2007-08-22 23:20:24 +0000340 printf(" = %"PRId64"\n", uid);
Mark Sleee8540632006-05-30 09:24:40 +0000341
342 /**
343 * NESTED MAP TEST
344 */
345 printf("testMapMap(1)");
Mark Slee1921d202007-01-24 19:43:06 +0000346 map<int32_t, map<int32_t, int32_t> > mm;
347 testClient.testMapMap(mm, 1);
Mark Sleee8540632006-05-30 09:24:40 +0000348 printf(" = {");
349 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
350 for (mi = mm.begin(); mi != mm.end(); ++mi) {
351 printf("%d => {", mi->first);
352 map<int32_t, int32_t>::const_iterator mi2;
353 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
354 printf("%d => %d, ", mi2->first, mi2->second);
355 }
356 printf("}, ");
357 }
358 printf("}\n");
359
360 /**
361 * INSANITY TEST
362 */
363 Insanity insane;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000364 insane.userMap.insert(make_pair(Numberz::FIVE, 5000));
Mark Sleee8540632006-05-30 09:24:40 +0000365 Xtruct truck;
366 truck.string_thing = "Truck";
367 truck.byte_thing = 8;
Mark Sleee8540632006-05-30 09:24:40 +0000368 truck.i32_thing = 8;
Mark Sleee8540632006-05-30 09:24:40 +0000369 truck.i64_thing = 8;
370 insane.xtructs.push_back(truck);
371 printf("testInsanity()");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000372 map<UserId, map<Numberz::type,Insanity> > whoa;
Mark Slee1921d202007-01-24 19:43:06 +0000373 testClient.testInsanity(whoa, insane);
Mark Sleee8540632006-05-30 09:24:40 +0000374 printf(" = {");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000375 map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000376 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
David Reissbc3dddb2007-08-22 23:20:24 +0000377 printf("%"PRId64" => {", i_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000378 map<Numberz::type,Insanity>::const_iterator i2_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000379 for (i2_iter = i_iter->second.begin();
380 i2_iter != i_iter->second.end();
381 ++i2_iter) {
382 printf("%d => {", i2_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000383 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
384 map<Numberz::type, UserId>::const_iterator um;
Mark Sleee8540632006-05-30 09:24:40 +0000385 printf("{");
386 for (um = userMap.begin(); um != userMap.end(); ++um) {
David Reissbc3dddb2007-08-22 23:20:24 +0000387 printf("%d => %"PRId64", ", um->first, um->second);
Mark Sleee8540632006-05-30 09:24:40 +0000388 }
389 printf("}, ");
390
Mark Sleeb9acf982006-10-10 01:57:32 +0000391 vector<Xtruct> xtructs = i2_iter->second.xtructs;
392 vector<Xtruct>::const_iterator x;
Mark Sleee8540632006-05-30 09:24:40 +0000393 printf("{");
394 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
David Reissbc3dddb2007-08-22 23:20:24 +0000395 printf("{\"%s\", %d, %d, %"PRId64"}, ",
Mark Sleee8540632006-05-30 09:24:40 +0000396 x->string_thing.c_str(),
397 (int)x->byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000398 x->i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000399 x->i64_thing);
400 }
401 printf("}");
402
403 printf("}, ");
404 }
405 printf("}, ");
406 }
407 printf("}\n");
408
Marc Slemko71d4e472006-08-15 22:34:04 +0000409 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +0000410
Marc Slemkobf4fd192006-08-15 21:29:39 +0000411 try {
Marc Slemko71d4e472006-08-15 22:34:04 +0000412 printf("testClient.testException(\"Xception\") =>");
413 testClient.testException("Xception");
414 printf(" void\nFAILURE\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000415
Mark Sleeb9ff32a2006-11-16 01:00:24 +0000416 } catch(Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000417 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000418 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000419
Marc Slemkobf4fd192006-08-15 21:29:39 +0000420 try {
Marc Slemko71d4e472006-08-15 22:34:04 +0000421 printf("testClient.testException(\"success\") =>");
422 testClient.testException("success");
423 printf(" void\n");
424 } catch(...) {
425 printf(" exception\nFAILURE\n");
426 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000427
Marc Slemko71d4e472006-08-15 22:34:04 +0000428 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +0000429
Marc Slemko71d4e472006-08-15 22:34:04 +0000430 try {
431 printf("testClient.testMultiException(\"Xception\", \"test 1\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000432 Xtruct result;
433 testClient.testMultiException(result, "Xception", "test 1");
Marc Slemko71d4e472006-08-15 22:34:04 +0000434 printf(" result\nFAILURE\n");
Mark Sleed3d733a2006-09-01 22:19:06 +0000435 } catch(Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000436 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
437 }
438
439 try {
440 printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000441 Xtruct result;
442 testClient.testMultiException(result, "Xception2", "test 2");
Marc Slemko71d4e472006-08-15 22:34:04 +0000443 printf(" result\nFAILURE\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000444
Mark Sleed3d733a2006-09-01 22:19:06 +0000445 } catch(Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000446 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000447 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000448
Marc Slemko71d4e472006-08-15 22:34:04 +0000449 try {
450 printf("testClient.testMultiException(\"success\", \"test 3\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000451 Xtruct result;
452 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +0000453 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
454 } catch(...) {
455 printf(" exception\nFAILURE\n");
456 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000457
David Reissc51986f2009-03-24 20:01:25 +0000458 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +0000459 {
David Reiss6ce401d2009-03-24 20:01:58 +0000460 printf("testClient.testOneway(3) =>");
461 uint64_t startOneway = now();
462 testClient.testOneway(3);
463 uint64_t elapsed = now() - startOneway;
David Reiss2ab6fe82008-02-18 02:11:44 +0000464 if (elapsed > 200 * 1000) { // 0.2 seconds
465 printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0);
466 } else {
467 printf(" success - took %.2f ms\n", (double)elapsed/1000.0);
468 }
469 }
470
David Reiss2845b522008-02-18 02:11:52 +0000471 /**
David Reissc51986f2009-03-24 20:01:25 +0000472 * redo a simple test after the oneway to make sure we aren't "off by one" --
473 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +0000474 * fail since it will get the void confirmation rather than the correct
475 * result. In this circumstance, the client will throw the exception:
476 *
477 * TApplicationException: Wrong method namea
478 */
479 /**
480 * I32 TEST
481 */
482 printf("re-test testI32(-1)");
483 i32 = testClient.testI32(-1);
484 printf(" = %d\n", i32);
485
486
Marc Slemkobf4fd192006-08-15 21:29:39 +0000487 uint64_t stop = now();
Mark Sleed788b2e2006-09-07 01:26:35 +0000488 uint64_t tot = stop-start;
489
David Reissbc3dddb2007-08-22 23:20:24 +0000490 printf("Total time: %"PRIu64" us\n", stop-start);
David Reiss0c90f6f2008-02-06 22:18:40 +0000491
Mark Sleed788b2e2006-09-07 01:26:35 +0000492 time_tot += tot;
493 if (time_min == 0 || tot < time_min) {
494 time_min = tot;
495 }
496 if (tot > time_max) {
497 time_max = tot;
498 }
499
Mark Sleea3302652006-10-25 19:03:32 +0000500 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +0000501 }
502
Marc Slemko6be374b2006-08-04 03:16:25 +0000503 // printf("\nSocket syscalls: %u", g_socket_syscalls);
Mark Sleee8540632006-05-30 09:24:40 +0000504 printf("\nAll tests done.\n");
Mark Sleed788b2e2006-09-07 01:26:35 +0000505
506 uint64_t time_avg = time_tot / numTests;
507
David Reissbc3dddb2007-08-22 23:20:24 +0000508 printf("Min time: %"PRIu64" us\n", time_min);
509 printf("Max time: %"PRIu64" us\n", time_max);
510 printf("Avg time: %"PRIu64" us\n", time_avg);
Mark Sleed788b2e2006-09-07 01:26:35 +0000511
Mark Sleee8540632006-05-30 09:24:40 +0000512 return 0;
513}