blob: 417a7a14d02777924de0f5c4f2e8ab6d5a955a3d [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
Mark Sleea3302652006-10-25 19:03:32 +000095 if (framed) {
96 shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +000097 transport = framedSocket;
Mark Sleea3302652006-10-25 19:03:32 +000098 } else {
99 shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
100 transport = bufferedSocket;
101 }
102
David Reisse71115b2010-10-06 17:09:56 +0000103 shared_ptr< TBinaryProtocolT<TBufferBase> > protocol(
104 new TBinaryProtocolT<TBufferBase>(transport));
David Reissb7762a02010-10-06 17:10:00 +0000105 ThriftTestClientT< TBinaryProtocolT<TBufferBase> > testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000106
107 uint64_t time_min = 0;
108 uint64_t time_max = 0;
109 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000110
Mark Sleee8540632006-05-30 09:24:40 +0000111 int test = 0;
112 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000113
Mark Slee95771002006-06-07 06:53:25 +0000114 try {
Mark Sleea3302652006-10-25 19:03:32 +0000115 transport->open();
Mark Slee95771002006-06-07 06:53:25 +0000116 } catch (TTransportException& ttx) {
Mark Sleeb9ff32a2006-11-16 01:00:24 +0000117 printf("Connect failed: %s\n", ttx.what());
Mark Sleee8540632006-05-30 09:24:40 +0000118 continue;
119 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000120
Mark Sleed788b2e2006-09-07 01:26:35 +0000121 /**
122 * CONNECT TEST
123 */
124 printf("Test #%d, connect %s:%d\n", test+1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000125
126 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000127
Mark Sleee8540632006-05-30 09:24:40 +0000128 /**
129 * VOID TEST
130 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000131 try {
132 printf("testVoid()");
133 testClient.testVoid();
134 printf(" = void\n");
135 } catch (TApplicationException tax) {
136 printf("%s\n", tax.what());
137 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000138
Mark Sleee8540632006-05-30 09:24:40 +0000139 /**
140 * STRING TEST
141 */
142 printf("testString(\"Test\")");
Mark Slee1921d202007-01-24 19:43:06 +0000143 string s;
144 testClient.testString(s, "Test");
Mark Sleee8540632006-05-30 09:24:40 +0000145 printf(" = \"%s\"\n", s.c_str());
David Reiss0c90f6f2008-02-06 22:18:40 +0000146
Mark Sleee8540632006-05-30 09:24:40 +0000147 /**
148 * BYTE TEST
149 */
150 printf("testByte(1)");
151 uint8_t u8 = testClient.testByte(1);
152 printf(" = %d\n", (int)u8);
David Reiss0c90f6f2008-02-06 22:18:40 +0000153
Mark Sleee8540632006-05-30 09:24:40 +0000154 /**
155 * I32 TEST
156 */
157 printf("testI32(-1)");
158 int32_t i32 = testClient.testI32(-1);
159 printf(" = %d\n", i32);
160
161 /**
Mark Sleee8540632006-05-30 09:24:40 +0000162 * I64 TEST
163 */
164 printf("testI64(-34359738368)");
Marc Slemkobf4fd192006-08-15 21:29:39 +0000165 int64_t i64 = testClient.testI64(-34359738368LL);
David Reissbc3dddb2007-08-22 23:20:24 +0000166 printf(" = %"PRId64"\n", i64);
Mark Sleec98d0502006-09-06 02:42:25 +0000167
168 /**
169 * DOUBLE TEST
170 */
171 printf("testDouble(-5.2098523)");
172 double dub = testClient.testDouble(-5.2098523);
173 printf(" = %lf\n", dub);
David Reiss0c90f6f2008-02-06 22:18:40 +0000174
Mark Sleee8540632006-05-30 09:24:40 +0000175 /**
176 * STRUCT TEST
177 */
Mark Slee6e536442006-06-30 18:28:50 +0000178 printf("testStruct({\"Zero\", 1, -3, -5})");
Mark Sleee8540632006-05-30 09:24:40 +0000179 Xtruct out;
180 out.string_thing = "Zero";
181 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000182 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000183 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000184 Xtruct in;
185 testClient.testStruct(in, out);
David Reissbc3dddb2007-08-22 23:20:24 +0000186 printf(" = {\"%s\", %d, %d, %"PRId64"}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000187 in.string_thing.c_str(),
188 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000189 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000190 in.i64_thing);
David Reiss0c90f6f2008-02-06 22:18:40 +0000191
Mark Sleee8540632006-05-30 09:24:40 +0000192 /**
193 * NESTED STRUCT TEST
194 */
Mark Slee6e536442006-06-30 18:28:50 +0000195 printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
Mark Sleee8540632006-05-30 09:24:40 +0000196 Xtruct2 out2;
197 out2.byte_thing = 1;
198 out2.struct_thing = out;
199 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000200 Xtruct2 in2;
201 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000202 in = in2.struct_thing;
David Reissbc3dddb2007-08-22 23:20:24 +0000203 printf(" = {%d, {\"%s\", %d, %d, %"PRId64"}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000204 in2.byte_thing,
205 in.string_thing.c_str(),
206 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000207 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000208 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000209 in2.i32_thing);
Mark Sleee8540632006-05-30 09:24:40 +0000210
211 /**
212 * MAP TEST
213 */
214 map<int32_t,int32_t> mapout;
215 for (int32_t i = 0; i < 5; ++i) {
216 mapout.insert(make_pair(i, i-10));
217 }
218 printf("testMap({");
219 map<int32_t, int32_t>::const_iterator m_iter;
220 bool first = true;
221 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
222 if (first) {
223 first = false;
224 } else {
225 printf(", ");
226 }
227 printf("%d => %d", m_iter->first, m_iter->second);
228 }
229 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000230 map<int32_t,int32_t> mapin;
231 testClient.testMap(mapin, mapout);
Mark Sleee8540632006-05-30 09:24:40 +0000232 printf(" = {");
233 first = true;
234 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
235 if (first) {
236 first = false;
237 } else {
238 printf(", ");
239 }
240 printf("%d => %d", m_iter->first, m_iter->second);
241 }
242 printf("}\n");
243
244 /**
245 * SET TEST
246 */
247 set<int32_t> setout;
248 for (int32_t i = -2; i < 3; ++i) {
249 setout.insert(i);
250 }
251 printf("testSet({");
252 set<int32_t>::const_iterator s_iter;
253 first = true;
254 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
255 if (first) {
256 first = false;
257 } else {
258 printf(", ");
259 }
260 printf("%d", *s_iter);
261 }
262 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000263 set<int32_t> setin;
264 testClient.testSet(setin, setout);
Mark Sleee8540632006-05-30 09:24:40 +0000265 printf(" = {");
266 first = true;
267 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
268 if (first) {
269 first = false;
270 } else {
271 printf(", ");
272 }
273 printf("%d", *s_iter);
274 }
275 printf("}\n");
276
277 /**
278 * LIST TEST
279 */
Mark Sleeb9acf982006-10-10 01:57:32 +0000280 vector<int32_t> listout;
Mark Sleee8540632006-05-30 09:24:40 +0000281 for (int32_t i = -2; i < 3; ++i) {
282 listout.push_back(i);
283 }
284 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000285 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000286 first = true;
287 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
288 if (first) {
289 first = false;
290 } else {
291 printf(", ");
292 }
293 printf("%d", *l_iter);
294 }
295 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000296 vector<int32_t> listin;
297 testClient.testList(listin, listout);
Mark Sleee8540632006-05-30 09:24:40 +0000298 printf(" = {");
299 first = true;
300 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
301 if (first) {
302 first = false;
303 } else {
304 printf(", ");
305 }
306 printf("%d", *l_iter);
307 }
308 printf("}\n");
309
310 /**
311 * ENUM TEST
312 */
313 printf("testEnum(ONE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000314 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Mark Sleee8540632006-05-30 09:24:40 +0000315 printf(" = %d\n", ret);
316
317 printf("testEnum(TWO)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000318 ret = testClient.testEnum(Numberz::TWO);
Mark Sleee8540632006-05-30 09:24:40 +0000319 printf(" = %d\n", ret);
320
321 printf("testEnum(THREE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000322 ret = testClient.testEnum(Numberz::THREE);
Mark Sleee8540632006-05-30 09:24:40 +0000323 printf(" = %d\n", ret);
324
325 printf("testEnum(FIVE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000326 ret = testClient.testEnum(Numberz::FIVE);
Mark Sleee8540632006-05-30 09:24:40 +0000327 printf(" = %d\n", ret);
328
329 printf("testEnum(EIGHT)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000330 ret = testClient.testEnum(Numberz::EIGHT);
Mark Sleee8540632006-05-30 09:24:40 +0000331 printf(" = %d\n", ret);
332
333 /**
334 * TYPEDEF TEST
335 */
336 printf("testTypedef(309858235082523)");
Marc Slemkobf4fd192006-08-15 21:29:39 +0000337 UserId uid = testClient.testTypedef(309858235082523LL);
David Reissbc3dddb2007-08-22 23:20:24 +0000338 printf(" = %"PRId64"\n", uid);
Mark Sleee8540632006-05-30 09:24:40 +0000339
340 /**
341 * NESTED MAP TEST
342 */
343 printf("testMapMap(1)");
Mark Slee1921d202007-01-24 19:43:06 +0000344 map<int32_t, map<int32_t, int32_t> > mm;
345 testClient.testMapMap(mm, 1);
Mark Sleee8540632006-05-30 09:24:40 +0000346 printf(" = {");
347 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
348 for (mi = mm.begin(); mi != mm.end(); ++mi) {
349 printf("%d => {", mi->first);
350 map<int32_t, int32_t>::const_iterator mi2;
351 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
352 printf("%d => %d, ", mi2->first, mi2->second);
353 }
354 printf("}, ");
355 }
356 printf("}\n");
357
358 /**
359 * INSANITY TEST
360 */
361 Insanity insane;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000362 insane.userMap.insert(make_pair(Numberz::FIVE, 5000));
Mark Sleee8540632006-05-30 09:24:40 +0000363 Xtruct truck;
364 truck.string_thing = "Truck";
365 truck.byte_thing = 8;
Mark Sleee8540632006-05-30 09:24:40 +0000366 truck.i32_thing = 8;
Mark Sleee8540632006-05-30 09:24:40 +0000367 truck.i64_thing = 8;
368 insane.xtructs.push_back(truck);
369 printf("testInsanity()");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000370 map<UserId, map<Numberz::type,Insanity> > whoa;
Mark Slee1921d202007-01-24 19:43:06 +0000371 testClient.testInsanity(whoa, insane);
Mark Sleee8540632006-05-30 09:24:40 +0000372 printf(" = {");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000373 map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000374 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
David Reissbc3dddb2007-08-22 23:20:24 +0000375 printf("%"PRId64" => {", i_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000376 map<Numberz::type,Insanity>::const_iterator i2_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000377 for (i2_iter = i_iter->second.begin();
378 i2_iter != i_iter->second.end();
379 ++i2_iter) {
380 printf("%d => {", i2_iter->first);
Bryan Duxbury833ae492010-09-27 17:26:02 +0000381 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
382 map<Numberz::type, UserId>::const_iterator um;
Mark Sleee8540632006-05-30 09:24:40 +0000383 printf("{");
384 for (um = userMap.begin(); um != userMap.end(); ++um) {
David Reissbc3dddb2007-08-22 23:20:24 +0000385 printf("%d => %"PRId64", ", um->first, um->second);
Mark Sleee8540632006-05-30 09:24:40 +0000386 }
387 printf("}, ");
388
Mark Sleeb9acf982006-10-10 01:57:32 +0000389 vector<Xtruct> xtructs = i2_iter->second.xtructs;
390 vector<Xtruct>::const_iterator x;
Mark Sleee8540632006-05-30 09:24:40 +0000391 printf("{");
392 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
David Reissbc3dddb2007-08-22 23:20:24 +0000393 printf("{\"%s\", %d, %d, %"PRId64"}, ",
Mark Sleee8540632006-05-30 09:24:40 +0000394 x->string_thing.c_str(),
395 (int)x->byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000396 x->i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000397 x->i64_thing);
398 }
399 printf("}");
400
401 printf("}, ");
402 }
403 printf("}, ");
404 }
405 printf("}\n");
406
Marc Slemko71d4e472006-08-15 22:34:04 +0000407 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +0000408
Marc Slemkobf4fd192006-08-15 21:29:39 +0000409 try {
Marc Slemko71d4e472006-08-15 22:34:04 +0000410 printf("testClient.testException(\"Xception\") =>");
411 testClient.testException("Xception");
412 printf(" void\nFAILURE\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000413
Mark Sleeb9ff32a2006-11-16 01:00:24 +0000414 } catch(Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000415 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000416 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000417
Marc Slemkobf4fd192006-08-15 21:29:39 +0000418 try {
Marc Slemko71d4e472006-08-15 22:34:04 +0000419 printf("testClient.testException(\"success\") =>");
420 testClient.testException("success");
421 printf(" void\n");
422 } catch(...) {
423 printf(" exception\nFAILURE\n");
424 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000425
Marc Slemko71d4e472006-08-15 22:34:04 +0000426 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +0000427
Marc Slemko71d4e472006-08-15 22:34:04 +0000428 try {
429 printf("testClient.testMultiException(\"Xception\", \"test 1\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000430 Xtruct result;
431 testClient.testMultiException(result, "Xception", "test 1");
Marc Slemko71d4e472006-08-15 22:34:04 +0000432 printf(" result\nFAILURE\n");
Mark Sleed3d733a2006-09-01 22:19:06 +0000433 } catch(Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000434 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
435 }
436
437 try {
438 printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000439 Xtruct result;
440 testClient.testMultiException(result, "Xception2", "test 2");
Marc Slemko71d4e472006-08-15 22:34:04 +0000441 printf(" result\nFAILURE\n");
David Reiss0c90f6f2008-02-06 22:18:40 +0000442
Mark Sleed3d733a2006-09-01 22:19:06 +0000443 } catch(Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000444 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000445 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000446
Marc Slemko71d4e472006-08-15 22:34:04 +0000447 try {
448 printf("testClient.testMultiException(\"success\", \"test 3\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000449 Xtruct result;
450 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +0000451 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
452 } catch(...) {
453 printf(" exception\nFAILURE\n");
454 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000455
David Reissc51986f2009-03-24 20:01:25 +0000456 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +0000457 {
David Reiss6ce401d2009-03-24 20:01:58 +0000458 printf("testClient.testOneway(3) =>");
459 uint64_t startOneway = now();
460 testClient.testOneway(3);
461 uint64_t elapsed = now() - startOneway;
David Reiss2ab6fe82008-02-18 02:11:44 +0000462 if (elapsed > 200 * 1000) { // 0.2 seconds
463 printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0);
464 } else {
465 printf(" success - took %.2f ms\n", (double)elapsed/1000.0);
466 }
467 }
468
David Reiss2845b522008-02-18 02:11:52 +0000469 /**
David Reissc51986f2009-03-24 20:01:25 +0000470 * redo a simple test after the oneway to make sure we aren't "off by one" --
471 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +0000472 * fail since it will get the void confirmation rather than the correct
473 * result. In this circumstance, the client will throw the exception:
474 *
475 * TApplicationException: Wrong method namea
476 */
477 /**
478 * I32 TEST
479 */
480 printf("re-test testI32(-1)");
481 i32 = testClient.testI32(-1);
482 printf(" = %d\n", i32);
483
484
Marc Slemkobf4fd192006-08-15 21:29:39 +0000485 uint64_t stop = now();
Mark Sleed788b2e2006-09-07 01:26:35 +0000486 uint64_t tot = stop-start;
487
David Reissbc3dddb2007-08-22 23:20:24 +0000488 printf("Total time: %"PRIu64" us\n", stop-start);
David Reiss0c90f6f2008-02-06 22:18:40 +0000489
Mark Sleed788b2e2006-09-07 01:26:35 +0000490 time_tot += tot;
491 if (time_min == 0 || tot < time_min) {
492 time_min = tot;
493 }
494 if (tot > time_max) {
495 time_max = tot;
496 }
497
Mark Sleea3302652006-10-25 19:03:32 +0000498 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +0000499 }
500
Marc Slemko6be374b2006-08-04 03:16:25 +0000501 // printf("\nSocket syscalls: %u", g_socket_syscalls);
Mark Sleee8540632006-05-30 09:24:40 +0000502 printf("\nAll tests done.\n");
Mark Sleed788b2e2006-09-07 01:26:35 +0000503
504 uint64_t time_avg = time_tot / numTests;
505
David Reissbc3dddb2007-08-22 23:20:24 +0000506 printf("Min time: %"PRIu64" us\n", time_min);
507 printf("Max time: %"PRIu64" us\n", time_max);
508 printf("Avg time: %"PRIu64" us\n", time_avg);
Mark Sleed788b2e2006-09-07 01:26:35 +0000509
Mark Sleee8540632006-05-30 09:24:40 +0000510 return 0;
511}