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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 package org
.apache
.thrift
.test
;
22 import java
.nio
.ByteBuffer
;
23 import java
.util
.ArrayList
;
24 import java
.util
.HashMap
;
25 import java
.util
.HashSet
;
26 import java
.util
.List
;
30 import org
.apache
.thrift
.TApplicationException
;
31 import org
.apache
.thrift
.TException
;
32 import org
.apache
.thrift
.TSerializer
;
33 import org
.apache
.thrift
.protocol
.TBinaryProtocol
;
34 import org
.apache
.thrift
.protocol
.TCompactProtocol
;
35 import org
.apache
.thrift
.protocol
.TJSONProtocol
;
36 import org
.apache
.thrift
.protocol
.TMultiplexedProtocol
;
37 import org
.apache
.thrift
.protocol
.TProtocol
;
38 import org
.apache
.thrift
.protocol
.TSimpleJSONProtocol
;
39 import org
.apache
.thrift
.transport
.TFastFramedTransport
;
40 import org
.apache
.thrift
.transport
.TFramedTransport
;
41 import org
.apache
.thrift
.transport
.THttpClient
;
42 import org
.apache
.thrift
.transport
.TSSLTransportFactory
;
43 import org
.apache
.thrift
.transport
.TSocket
;
44 import org
.apache
.thrift
.transport
.TTransport
;
45 import org
.apache
.thrift
.transport
.TTransportException
;
48 import thrift
.test
.Insanity
;
49 import thrift
.test
.Numberz
;
50 import thrift
.test
.SecondService
;
51 import thrift
.test
.ThriftTest
;
52 import thrift
.test
.Xception
;
53 import thrift
.test
.Xception2
;
54 import thrift
.test
.Xtruct
;
55 import thrift
.test
.Xtruct2
;
58 * Test Java client for thrift. Essentially just a copy of the C++ version,
59 * this makes a variety of requests to enable testing for both performance and
60 * correctness of the output.
63 public class TestClient
{
65 private static int ERR_BASETYPES
= 1;
66 private static int ERR_STRUCTS
= 2;
67 private static int ERR_CONTAINERS
= 4;
68 private static int ERR_EXCEPTIONS
= 8;
69 private static int ERR_PROTOCOLS
= 16;
70 private static int ERR_UNKNOWN
= 64;
72 public static void main(String
[] args
) {
73 String host
= "localhost";
76 String protocol_type
= "binary";
77 String transport_type
= "buffered";
80 int socketTimeout
= 1000;
83 for (int i
= 0; i
< args
.length
; ++i
) {
84 if (args
[i
].startsWith("--host")) {
85 host
= args
[i
].split("=")[1];
87 } else if (args
[i
].startsWith("--port")) {
88 port
= Integer
.valueOf(args
[i
].split("=")[1]);
89 } else if (args
[i
].startsWith("--n") ||
90 args
[i
].startsWith("--testloops")){
91 numTests
= Integer
.valueOf(args
[i
].split("=")[1]);
92 } else if (args
[i
].equals("--timeout")) {
93 socketTimeout
= Integer
.valueOf(args
[i
].split("=")[1]);
94 } else if (args
[i
].startsWith("--protocol")) {
95 protocol_type
= args
[i
].split("=")[1];
97 } else if (args
[i
].startsWith("--transport")) {
98 transport_type
= args
[i
].split("=")[1];
99 transport_type
.trim();
100 } else if (args
[i
].equals("--ssl")) {
102 } else if (args
[i
].equals("--help")) {
103 System
.out
.println("Allowed options:");
104 System
.out
.println(" --help\t\t\tProduce help message");
105 System
.out
.println(" --host=arg (=" + host
+ ")\tHost to connect");
106 System
.out
.println(" --port=arg (=" + port
+ ")\tPort number to connect");
107 System
.out
.println(" --transport=arg (=" + transport_type
+ ")\n\t\t\t\tTransport: buffered, framed, fastframed, http");
108 System
.out
.println(" --protocol=arg (=" + protocol_type
+ ")\tProtocol: binary, compact, json, multi, multic, multij");
109 System
.out
.println(" --ssl\t\t\tEncrypted Transport using SSL");
110 System
.out
.println(" --testloops[--n]=arg (=" + numTests
+ ")\tNumber of Tests");
114 } catch (Exception x
) {
115 System
.err
.println("Can not parse arguments! See --help");
116 System
.exit(ERR_UNKNOWN
);
120 if (protocol_type
.equals("binary")) {
121 } else if (protocol_type
.equals("compact")) {
122 } else if (protocol_type
.equals("json")) {
123 } else if (protocol_type
.equals("multi")) {
124 } else if (protocol_type
.equals("multic")) {
125 } else if (protocol_type
.equals("multij")) {
127 throw new Exception("Unknown protocol type! " + protocol_type
);
129 if (transport_type
.equals("buffered")) {
130 } else if (transport_type
.equals("framed")) {
131 } else if (transport_type
.equals("fastframed")) {
132 } else if (transport_type
.equals("http")) {
134 throw new Exception("Unknown transport type! " + transport_type
);
136 if (transport_type
.equals("http") && ssl
== true) {
137 throw new Exception("SSL is not supported over http.");
139 } catch (Exception e
) {
140 System
.err
.println("Error: " + e
.getMessage());
141 System
.exit(ERR_UNKNOWN
);
144 TTransport transport
= null;
147 if (transport_type
.equals("http")) {
148 String url
= "http://" + host
+ ":" + port
+ "/service";
149 transport
= new THttpClient(url
);
151 TSocket socket
= null;
153 socket
= TSSLTransportFactory
.getClientSocket(host
, port
, 0);
155 socket
= new TSocket(host
, port
);
157 socket
.setTimeout(socketTimeout
);
159 if (transport_type
.equals("buffered")) {
160 } else if (transport_type
.equals("framed")) {
161 transport
= new TFramedTransport(transport
);
162 } else if (transport_type
.equals("fastframed")) {
163 transport
= new TFastFramedTransport(transport
);
166 } catch (Exception x
) {
168 System
.exit(ERR_UNKNOWN
);
171 TProtocol tProtocol
= null;
172 TProtocol tProtocol2
= null;
173 if (protocol_type
.equals("json") || protocol_type
.equals("multij")) {
174 tProtocol
= new TJSONProtocol(transport
);
175 } else if (protocol_type
.equals("compact") || protocol_type
.equals("multic")) {
176 tProtocol
= new TCompactProtocol(transport
);
178 tProtocol
= new TBinaryProtocol(transport
);
181 if (protocol_type
.startsWith("multi")) {
182 tProtocol2
= new TMultiplexedProtocol(tProtocol
, "SecondService");
183 tProtocol
= new TMultiplexedProtocol(tProtocol
, "ThriftTest");
186 ThriftTest
.Client testClient
= new ThriftTest
.Client(tProtocol
);
187 Insanity insane
= new Insanity();
194 for (int test
= 0; test
< numTests
; ++test
) {
199 System
.out
.println("Test #" + (test
+1) + ", " + "connect " + host
+ ":" + port
);
201 if (transport
.isOpen() == false) {
204 } catch (TTransportException ttx
) {
205 ttx
.printStackTrace();
206 System
.out
.println("Connect failed: " + ttx
.getMessage());
207 System
.exit(ERR_UNKNOWN
);
211 long start
= System
.nanoTime();
217 System
.out
.print("testVoid()");
218 testClient
.testVoid();
219 System
.out
.print(" = void\n");
220 } catch (TApplicationException tax
) {
221 tax
.printStackTrace();
222 returnCode
|= ERR_BASETYPES
;
228 System
.out
.print("testString(\"Test\")");
229 String s
= testClient
.testString("Test");
230 System
.out
.print(" = \"" + s
+ "\"\n");
231 if (!s
.equals("Test")) {
232 returnCode
|= ERR_BASETYPES
;
233 System
.out
.println("*** FAILURE ***\n");
239 if (protocol_type
.startsWith("multi")) {
240 SecondService
.Client secondClient
= new SecondService
.Client(tProtocol2
);
241 System
.out
.print("secondtestString(\"Test2\")");
242 s
= secondClient
.secondtestString("Test2");
243 System
.out
.print(" = \"" + s
+ "\"\n");
244 if (!s
.equals("testString(\"Test2\")")) {
245 returnCode
|= ERR_PROTOCOLS
;
246 System
.out
.println("*** FAILURE ***\n");
252 System
.out
.print("testByte(1)");
253 byte i8
= testClient
.testByte((byte)1);
254 System
.out
.print(" = " + i8
+ "\n");
256 returnCode
|= ERR_BASETYPES
;
257 System
.out
.println("*** FAILURE ***\n");
263 System
.out
.print("testI32(-1)");
264 int i32
= testClient
.testI32(-1);
265 System
.out
.print(" = " + i32
+ "\n");
267 returnCode
|= ERR_BASETYPES
;
268 System
.out
.println("*** FAILURE ***\n");
274 System
.out
.print("testI64(-34359738368)");
275 long i64
= testClient
.testI64(-34359738368L);
276 System
.out
.print(" = " + i64
+ "\n");
277 if (i64
!= -34359738368L) {
278 returnCode
|= ERR_BASETYPES
;
279 System
.out
.println("*** FAILURE ***\n");
285 System
.out
.print("testDouble(-5.325098235)");
286 double dub
= testClient
.testDouble(-5.325098235);
287 System
.out
.print(" = " + dub
+ "\n");
288 if (Math
.abs(dub
- (-5.325098235)) > 0.001) {
289 returnCode
|= ERR_BASETYPES
;
290 System
.out
.println("*** FAILURE ***\n");
297 System
.out
.print("testBinary(-128...127) = ");
298 byte[] data
= new byte[] {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127};
299 ByteBuffer bin
= testClient
.testBinary(ByteBuffer
.wrap(data
));
301 byte[] bytes
= new byte[bin
.limit() - bin
.position()];
304 System
.out
.print("{");
305 boolean first
= true;
306 for (int i
= 0; i
< bytes
.length
; ++i
) {
310 System
.out
.print(", ");
311 System
.out
.print(bytes
[i
]);
313 System
.out
.println("}");
314 if (!ByteBuffer
.wrap(data
).equals(bin
)) {
315 returnCode
|= ERR_BASETYPES
;
316 System
.out
.println("*** FAILURE ***\n");
318 } catch (Exception ex
) {
319 returnCode
|= ERR_BASETYPES
;
320 System
.out
.println("\n*** FAILURE ***\n");
321 ex
.printStackTrace(System
.out
);
327 System
.out
.print("testStruct({\"Zero\", 1, -3, -5})");
328 Xtruct out
= new Xtruct();
329 out
.string_thing
= "Zero";
330 out
.byte_thing
= (byte) 1;
333 Xtruct in
= testClient
.testStruct(out
);
334 System
.out
.print(" = {" + "\"" +
335 in
.string_thing
+ "\"," +
336 in
.byte_thing
+ ", " +
337 in
.i32_thing
+ ", " +
338 in
.i64_thing
+ "}\n");
339 if (!in
.equals(out
)) {
340 returnCode
|= ERR_STRUCTS
;
341 System
.out
.println("*** FAILURE ***\n");
347 System
.out
.print("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
348 Xtruct2 out2
= new Xtruct2();
349 out2
.byte_thing
= (short)1;
350 out2
.struct_thing
= out
;
352 Xtruct2 in2
= testClient
.testNest(out2
);
353 in
= in2
.struct_thing
;
354 System
.out
.print(" = {" + in2
.byte_thing
+ ", {" + "\"" +
355 in
.string_thing
+ "\", " +
356 in
.byte_thing
+ ", " +
357 in
.i32_thing
+ ", " +
358 in
.i64_thing
+ "}, " +
359 in2
.i32_thing
+ "}\n");
360 if (!in2
.equals(out2
)) {
361 returnCode
|= ERR_STRUCTS
;
362 System
.out
.println("*** FAILURE ***\n");
368 Map
<Integer
,Integer
> mapout
= new HashMap
<Integer
,Integer
>();
369 for (int i
= 0; i
< 5; ++i
) {
372 System
.out
.print("testMap({");
373 boolean first
= true;
374 for (int key
: mapout
.keySet()) {
378 System
.out
.print(", ");
380 System
.out
.print(key
+ " => " + mapout
.get(key
));
382 System
.out
.print("})");
383 Map
<Integer
,Integer
> mapin
= testClient
.testMap(mapout
);
384 System
.out
.print(" = {");
386 for (int key
: mapin
.keySet()) {
390 System
.out
.print(", ");
392 System
.out
.print(key
+ " => " + mapout
.get(key
));
394 System
.out
.print("}\n");
395 if (!mapout
.equals(mapin
)) {
396 returnCode
|= ERR_CONTAINERS
;
397 System
.out
.println("*** FAILURE ***\n");
404 Map
<String
, String
> smapout
= new HashMap
<String
, String
>();
405 smapout
.put("a", "2");
406 smapout
.put("b", "blah");
407 smapout
.put("some", "thing");
408 for (String key
: smapout
.keySet()) {
412 System
.out
.print(", ");
414 System
.out
.print(key
+ " => " + smapout
.get(key
));
416 System
.out
.print("})");
417 Map
<String
, String
> smapin
= testClient
.testStringMap(smapout
);
418 System
.out
.print(" = {");
420 for (String key
: smapin
.keySet()) {
424 System
.out
.print(", ");
426 System
.out
.print(key
+ " => " + smapout
.get(key
));
428 System
.out
.print("}\n");
429 if (!smapout
.equals(smapin
)) {
430 returnCode
|= ERR_CONTAINERS
;
431 System
.out
.println("*** FAILURE ***\n");
433 } catch (Exception ex
) {
434 returnCode
|= ERR_CONTAINERS
;
435 System
.out
.println("*** FAILURE ***\n");
436 ex
.printStackTrace(System
.out
);
442 Set
<Integer
> setout
= new HashSet
<Integer
>();
443 for (int i
= -2; i
< 3; ++i
) {
446 System
.out
.print("testSet({");
448 for (int elem
: setout
) {
452 System
.out
.print(", ");
454 System
.out
.print(elem
);
456 System
.out
.print("})");
457 Set
<Integer
> setin
= testClient
.testSet(setout
);
458 System
.out
.print(" = {");
460 for (int elem
: setin
) {
464 System
.out
.print(", ");
466 System
.out
.print(elem
);
468 System
.out
.print("}\n");
469 if (!setout
.equals(setin
)) {
470 returnCode
|= ERR_CONTAINERS
;
471 System
.out
.println("*** FAILURE ***\n");
477 List
<Integer
> listout
= new ArrayList
<Integer
>();
478 for (int i
= -2; i
< 3; ++i
) {
481 System
.out
.print("testList({");
483 for (int elem
: listout
) {
487 System
.out
.print(", ");
489 System
.out
.print(elem
);
491 System
.out
.print("})");
492 List
<Integer
> listin
= testClient
.testList(listout
);
493 System
.out
.print(" = {");
495 for (int elem
: listin
) {
499 System
.out
.print(", ");
501 System
.out
.print(elem
);
503 System
.out
.print("}\n");
504 if (!listout
.equals(listin
)) {
505 returnCode
|= ERR_CONTAINERS
;
506 System
.out
.println("*** FAILURE ***\n");
512 System
.out
.print("testEnum(ONE)");
513 Numberz ret
= testClient
.testEnum(Numberz
.ONE
);
514 System
.out
.print(" = " + ret
+ "\n");
515 if (ret
!= Numberz
.ONE
) {
516 returnCode
|= ERR_STRUCTS
;
517 System
.out
.println("*** FAILURE ***\n");
520 System
.out
.print("testEnum(TWO)");
521 ret
= testClient
.testEnum(Numberz
.TWO
);
522 System
.out
.print(" = " + ret
+ "\n");
523 if (ret
!= Numberz
.TWO
) {
524 returnCode
|= ERR_STRUCTS
;
525 System
.out
.println("*** FAILURE ***\n");
528 System
.out
.print("testEnum(THREE)");
529 ret
= testClient
.testEnum(Numberz
.THREE
);
530 System
.out
.print(" = " + ret
+ "\n");
531 if (ret
!= Numberz
.THREE
) {
532 returnCode
|= ERR_STRUCTS
;
533 System
.out
.println("*** FAILURE ***\n");
536 System
.out
.print("testEnum(FIVE)");
537 ret
= testClient
.testEnum(Numberz
.FIVE
);
538 System
.out
.print(" = " + ret
+ "\n");
539 if (ret
!= Numberz
.FIVE
) {
540 returnCode
|= ERR_STRUCTS
;
541 System
.out
.println("*** FAILURE ***\n");
544 System
.out
.print("testEnum(EIGHT)");
545 ret
= testClient
.testEnum(Numberz
.EIGHT
);
546 System
.out
.print(" = " + ret
+ "\n");
547 if (ret
!= Numberz
.EIGHT
) {
548 returnCode
|= ERR_STRUCTS
;
549 System
.out
.println("*** FAILURE ***\n");
555 System
.out
.print("testTypedef(309858235082523)");
556 long uid
= testClient
.testTypedef(309858235082523L);
557 System
.out
.print(" = " + uid
+ "\n");
558 if (uid
!= 309858235082523L) {
559 returnCode
|= ERR_BASETYPES
;
560 System
.out
.println("*** FAILURE ***\n");
566 System
.out
.print("testMapMap(1)");
567 Map
<Integer
,Map
<Integer
,Integer
>> mm
=
568 testClient
.testMapMap(1);
569 System
.out
.print(" = {");
570 for (int key
: mm
.keySet()) {
571 System
.out
.print(key
+ " => {");
572 Map
<Integer
,Integer
> m2
= mm
.get(key
);
573 for (int k2
: m2
.keySet()) {
574 System
.out
.print(k2
+ " => " + m2
.get(k2
) + ", ");
576 System
.out
.print("}, ");
578 System
.out
.print("}\n");
579 if (mm
.size() != 2 || !mm
.containsKey(4) || !mm
.containsKey(-4)) {
580 returnCode
|= ERR_CONTAINERS
;
581 System
.out
.println("*** FAILURE ***\n");
583 Map
<Integer
, Integer
> m1
= mm
.get(4);
584 Map
<Integer
, Integer
> m2
= mm
.get(-4);
585 if (m1
.get(1) != 1 || m1
.get(2) != 2 || m1
.get(3) != 3 || m1
.get(4) != 4 ||
586 m2
.get(-1) != -1 || m2
.get(-2) != -2 || m2
.get(-3) != -3 || m2
.get(-4) != -4) {
587 returnCode
|= ERR_CONTAINERS
;
588 System
.out
.println("*** FAILURE ***\n");
596 boolean insanityFailed
= true;
598 Xtruct hello
= new Xtruct();
599 hello
.string_thing
= "Hello2";
600 hello
.byte_thing
= 2;
604 Xtruct goodbye
= new Xtruct();
605 goodbye
.string_thing
= "Goodbye4";
606 goodbye
.byte_thing
= (byte)4;
607 goodbye
.i32_thing
= 4;
608 goodbye
.i64_thing
= (long)4;
610 insane
.userMap
= new HashMap
<Numberz
, Long
>();
611 insane
.userMap
.put(Numberz
.EIGHT
, (long)8);
612 insane
.userMap
.put(Numberz
.FIVE
, (long)5);
613 insane
.xtructs
= new ArrayList
<Xtruct
>();
614 insane
.xtructs
.add(goodbye
);
615 insane
.xtructs
.add(hello
);
617 System
.out
.print("testInsanity()");
618 Map
<Long
,Map
<Numberz
,Insanity
>> whoa
=
619 testClient
.testInsanity(insane
);
620 System
.out
.print(" = {");
621 for (long key
: whoa
.keySet()) {
622 Map
<Numberz
,Insanity
> val
= whoa
.get(key
);
623 System
.out
.print(key
+ " => {");
625 for (Numberz k2
: val
.keySet()) {
626 Insanity v2
= val
.get(k2
);
627 System
.out
.print(k2
+ " => {");
628 Map
<Numberz
, Long
> userMap
= v2
.userMap
;
629 System
.out
.print("{");
630 if (userMap
!= null) {
631 for (Numberz k3
: userMap
.keySet()) {
632 System
.out
.print(k3
+ " => " + userMap
.get(k3
) + ", ");
635 System
.out
.print("}, ");
637 List
<Xtruct
> xtructs
= v2
.xtructs
;
638 System
.out
.print("{");
639 if (xtructs
!= null) {
640 for (Xtruct x
: xtructs
) {
641 System
.out
.print("{" + "\"" + x
.string_thing
+ "\", " + x
.byte_thing
+ ", " + x
.i32_thing
+ ", "+ x
.i64_thing
+ "}, ");
644 System
.out
.print("}");
646 System
.out
.print("}, ");
648 System
.out
.print("}, ");
650 System
.out
.print("}\n");
651 if (whoa
.size() == 2 && whoa
.containsKey(1L) && whoa
.containsKey(2L)) {
652 Map
<Numberz
, Insanity
> first_map
= whoa
.get(1L);
653 Map
<Numberz
, Insanity
> second_map
= whoa
.get(2L);
654 if (first_map
.size() == 2 &&
655 first_map
.containsKey(Numberz
.TWO
) &&
656 first_map
.containsKey(Numberz
.THREE
) &&
657 second_map
.size() == 1 &&
658 second_map
.containsKey(Numberz
.SIX
) &&
659 insane
.equals(first_map
.get(Numberz
.TWO
)) &&
660 insane
.equals(first_map
.get(Numberz
.THREE
))) {
661 Insanity six
=second_map
.get(Numberz
.SIX
);
662 // Cannot use "new Insanity().equals(six)" because as of now, struct/container
663 // fields with default requiredness have isset=false for local instances and yet
664 // received empty values from other languages like C++ have isset=true .
665 if (six
.getUserMapSize() == 0 && six
.getXtructsSize() == 0) {
667 insanityFailed
= false;
671 } catch (Exception ex
) {
672 returnCode
|= ERR_STRUCTS
;
673 System
.out
.println("*** FAILURE ***\n");
674 ex
.printStackTrace(System
.out
);
675 insanityFailed
= false;
677 if (insanityFailed
) {
678 returnCode
|= ERR_STRUCTS
;
679 System
.out
.println("*** FAILURE ***\n");
686 System
.out
.print("testClient.testException(\"Xception\") =>");
687 testClient
.testException("Xception");
688 System
.out
.print(" void\n*** FAILURE ***\n");
689 returnCode
|= ERR_EXCEPTIONS
;
690 } catch(Xception e
) {
691 System
.out
.printf(" {%d, \"%s\"}\n", e
.errorCode
, e
.message
);
695 System
.out
.print("testClient.testException(\"TException\") =>");
696 testClient
.testException("TException");
697 System
.out
.print(" void\n*** FAILURE ***\n");
698 returnCode
|= ERR_EXCEPTIONS
;
699 } catch(TException e
) {
700 System
.out
.printf(" {\"%s\"}\n", e
.getMessage());
704 System
.out
.print("testClient.testException(\"success\") =>");
705 testClient
.testException("success");
706 System
.out
.print(" void\n");
707 }catch(Exception e
) {
708 System
.out
.printf(" exception\n*** FAILURE ***\n");
709 returnCode
|= ERR_EXCEPTIONS
;
714 * MULTI EXCEPTION TEST
718 System
.out
.printf("testClient.testMultiException(\"Xception\", \"test 1\") =>");
719 testClient
.testMultiException("Xception", "test 1");
720 System
.out
.print(" result\n*** FAILURE ***\n");
721 returnCode
|= ERR_EXCEPTIONS
;
722 } catch(Xception e
) {
723 System
.out
.printf(" {%d, \"%s\"}\n", e
.errorCode
, e
.message
);
727 System
.out
.printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
728 testClient
.testMultiException("Xception2", "test 2");
729 System
.out
.print(" result\n*** FAILURE ***\n");
730 returnCode
|= ERR_EXCEPTIONS
;
731 } catch(Xception2 e
) {
732 System
.out
.printf(" {%d, {\"%s\"}}\n", e
.errorCode
, e
.struct_thing
.string_thing
);
736 System
.out
.print("testClient.testMultiException(\"success\", \"test 3\") =>");
738 result
= testClient
.testMultiException("success", "test 3");
739 System
.out
.printf(" {{\"%s\"}}\n", result
.string_thing
);
740 } catch(Exception e
) {
741 System
.out
.printf(" exception\n*** FAILURE ***\n");
742 returnCode
|= ERR_EXCEPTIONS
;
750 System
.out
.print("testOneway(3)...");
751 long startOneway
= System
.nanoTime();
752 testClient
.testOneway(3);
753 long onewayElapsedMillis
= (System
.nanoTime() - startOneway
) / 1000000;
754 if (onewayElapsedMillis
> 200) {
755 System
.out
.println("Oneway test took too long to execute failed: took " +
756 Long
.toString(onewayElapsedMillis
) +
758 System
.out
.println("oneway calls are 'fire and forget' and therefore should not cause blocking.");
759 System
.out
.println("Some transports (HTTP) have a required response, and typically this failure");
760 System
.out
.println("means the transport response was delayed until after the execution");
761 System
.out
.println("of the RPC. The server should post the transport response immediately and");
762 System
.out
.println("before executing the RPC.");
763 System
.out
.println("*** FAILURE ***");
764 returnCode
|= ERR_BASETYPES
;
766 System
.out
.println("Success - fire and forget only took " +
767 Long
.toString(onewayElapsedMillis
) +
772 long stop
= System
.nanoTime();
773 long tot
= stop
-start
;
775 System
.out
.println("Total time: " + tot
/1000 + "us");
777 if (timeMin
== 0 || tot
< timeMin
) {
786 } catch (Exception x
) {
787 System
.out
.printf("*** FAILURE ***\n");
789 returnCode
|= ERR_UNKNOWN
;
793 long timeAvg
= timeTot
/ numTests
;
795 System
.out
.println("Min time: " + timeMin
/1000 + "us");
796 System
.out
.println("Max time: " + timeMax
/1000 + "us");
797 System
.out
.println("Avg time: " + timeAvg
/1000 + "us");
800 String json
= (new TSerializer(new TSimpleJSONProtocol
.Factory())).toString(insane
);
801 System
.out
.println("\nSample TSimpleJSONProtocol output:\n" + json
);
802 } catch (TException x
) {
803 System
.out
.println("*** FAILURE ***");
805 returnCode
|= ERR_BASETYPES
;
809 System
.exit(returnCode
);