]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/test/org/apache/thrift/test/TestClient.java
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / lib / java / test / org / apache / thrift / test / TestClient.java
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
20 package org.apache.thrift.test;
21
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;
27 import java.util.Map;
28 import java.util.Set;
29
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;
46
47 // Generated code
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;
56
57 /**
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.
61 *
62 */
63 public class TestClient {
64
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;
71
72 public static void main(String [] args) {
73 String host = "localhost";
74 int port = 9090;
75 int numTests = 1;
76 String protocol_type = "binary";
77 String transport_type = "buffered";
78 boolean ssl = false;
79
80 int socketTimeout = 1000;
81
82 try {
83 for (int i = 0; i < args.length; ++i) {
84 if (args[i].startsWith("--host")) {
85 host = args[i].split("=")[1];
86 host.trim();
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];
96 protocol_type.trim();
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")) {
101 ssl = true;
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");
111 System.exit(0);
112 }
113 }
114 } catch (Exception x) {
115 System.err.println("Can not parse arguments! See --help");
116 System.exit(ERR_UNKNOWN);
117 }
118
119 try {
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")) {
126 } else {
127 throw new Exception("Unknown protocol type! " + protocol_type);
128 }
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")) {
133 } else {
134 throw new Exception("Unknown transport type! " + transport_type);
135 }
136 if (transport_type.equals("http") && ssl == true) {
137 throw new Exception("SSL is not supported over http.");
138 }
139 } catch (Exception e) {
140 System.err.println("Error: " + e.getMessage());
141 System.exit(ERR_UNKNOWN);
142 }
143
144 TTransport transport = null;
145
146 try {
147 if (transport_type.equals("http")) {
148 String url = "http://" + host + ":" + port + "/service";
149 transport = new THttpClient(url);
150 } else {
151 TSocket socket = null;
152 if (ssl == true) {
153 socket = TSSLTransportFactory.getClientSocket(host, port, 0);
154 } else {
155 socket = new TSocket(host, port);
156 }
157 socket.setTimeout(socketTimeout);
158 transport = socket;
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);
164 }
165 }
166 } catch (Exception x) {
167 x.printStackTrace();
168 System.exit(ERR_UNKNOWN);
169 }
170
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);
177 } else {
178 tProtocol = new TBinaryProtocol(transport);
179 }
180
181 if (protocol_type.startsWith("multi")) {
182 tProtocol2 = new TMultiplexedProtocol(tProtocol, "SecondService");
183 tProtocol = new TMultiplexedProtocol(tProtocol, "ThriftTest");
184 }
185
186 ThriftTest.Client testClient = new ThriftTest.Client(tProtocol);
187 Insanity insane = new Insanity();
188
189 long timeMin = 0;
190 long timeMax = 0;
191 long timeTot = 0;
192
193 int returnCode = 0;
194 for (int test = 0; test < numTests; ++test) {
195 try {
196 /**
197 * CONNECT TEST
198 */
199 System.out.println("Test #" + (test+1) + ", " + "connect " + host + ":" + port);
200
201 if (transport.isOpen() == false) {
202 try {
203 transport.open();
204 } catch (TTransportException ttx) {
205 ttx.printStackTrace();
206 System.out.println("Connect failed: " + ttx.getMessage());
207 System.exit(ERR_UNKNOWN);
208 }
209 }
210
211 long start = System.nanoTime();
212
213 /**
214 * VOID TEST
215 */
216 try {
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;
223 }
224
225 /**
226 * STRING TEST
227 */
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");
234 }
235
236 /**
237 * Multiplexed test
238 */
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");
247 }
248 }
249 /**
250 * BYTE TEST
251 */
252 System.out.print("testByte(1)");
253 byte i8 = testClient.testByte((byte)1);
254 System.out.print(" = " + i8 + "\n");
255 if (i8 != 1) {
256 returnCode |= ERR_BASETYPES;
257 System.out.println("*** FAILURE ***\n");
258 }
259
260 /**
261 * I32 TEST
262 */
263 System.out.print("testI32(-1)");
264 int i32 = testClient.testI32(-1);
265 System.out.print(" = " + i32 + "\n");
266 if (i32 != -1) {
267 returnCode |= ERR_BASETYPES;
268 System.out.println("*** FAILURE ***\n");
269 }
270
271 /**
272 * I64 TEST
273 */
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");
280 }
281
282 /**
283 * DOUBLE TEST
284 */
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");
291 }
292
293 /**
294 * BINARY TEST
295 */
296 try {
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));
300 bin.mark();
301 byte[] bytes = new byte[bin.limit() - bin.position()];
302 bin.get(bytes);
303 bin.reset();
304 System.out.print("{");
305 boolean first = true;
306 for (int i = 0; i < bytes.length; ++i) {
307 if (first)
308 first = false;
309 else
310 System.out.print(", ");
311 System.out.print(bytes[i]);
312 }
313 System.out.println("}");
314 if (!ByteBuffer.wrap(data).equals(bin)) {
315 returnCode |= ERR_BASETYPES;
316 System.out.println("*** FAILURE ***\n");
317 }
318 } catch (Exception ex) {
319 returnCode |= ERR_BASETYPES;
320 System.out.println("\n*** FAILURE ***\n");
321 ex.printStackTrace(System.out);
322 }
323
324 /**
325 * STRUCT TEST
326 */
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;
331 out.i32_thing = -3;
332 out.i64_thing = -5;
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");
342 }
343
344 /**
345 * NESTED STRUCT TEST
346 */
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;
351 out2.i32_thing = 5;
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");
363 }
364
365 /**
366 * MAP TEST
367 */
368 Map<Integer,Integer> mapout = new HashMap<Integer,Integer>();
369 for (int i = 0; i < 5; ++i) {
370 mapout.put(i, i-10);
371 }
372 System.out.print("testMap({");
373 boolean first = true;
374 for (int key : mapout.keySet()) {
375 if (first) {
376 first = false;
377 } else {
378 System.out.print(", ");
379 }
380 System.out.print(key + " => " + mapout.get(key));
381 }
382 System.out.print("})");
383 Map<Integer,Integer> mapin = testClient.testMap(mapout);
384 System.out.print(" = {");
385 first = true;
386 for (int key : mapin.keySet()) {
387 if (first) {
388 first = false;
389 } else {
390 System.out.print(", ");
391 }
392 System.out.print(key + " => " + mapout.get(key));
393 }
394 System.out.print("}\n");
395 if (!mapout.equals(mapin)) {
396 returnCode |= ERR_CONTAINERS;
397 System.out.println("*** FAILURE ***\n");
398 }
399
400 /**
401 * STRING MAP TEST
402 */
403 try {
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()) {
409 if (first) {
410 first = false;
411 } else {
412 System.out.print(", ");
413 }
414 System.out.print(key + " => " + smapout.get(key));
415 }
416 System.out.print("})");
417 Map<String, String> smapin = testClient.testStringMap(smapout);
418 System.out.print(" = {");
419 first = true;
420 for (String key : smapin.keySet()) {
421 if (first) {
422 first = false;
423 } else {
424 System.out.print(", ");
425 }
426 System.out.print(key + " => " + smapout.get(key));
427 }
428 System.out.print("}\n");
429 if (!smapout.equals(smapin)) {
430 returnCode |= ERR_CONTAINERS;
431 System.out.println("*** FAILURE ***\n");
432 }
433 } catch (Exception ex) {
434 returnCode |= ERR_CONTAINERS;
435 System.out.println("*** FAILURE ***\n");
436 ex.printStackTrace(System.out);
437 }
438
439 /**
440 * SET TEST
441 */
442 Set<Integer> setout = new HashSet<Integer>();
443 for (int i = -2; i < 3; ++i) {
444 setout.add(i);
445 }
446 System.out.print("testSet({");
447 first = true;
448 for (int elem : setout) {
449 if (first) {
450 first = false;
451 } else {
452 System.out.print(", ");
453 }
454 System.out.print(elem);
455 }
456 System.out.print("})");
457 Set<Integer> setin = testClient.testSet(setout);
458 System.out.print(" = {");
459 first = true;
460 for (int elem : setin) {
461 if (first) {
462 first = false;
463 } else {
464 System.out.print(", ");
465 }
466 System.out.print(elem);
467 }
468 System.out.print("}\n");
469 if (!setout.equals(setin)) {
470 returnCode |= ERR_CONTAINERS;
471 System.out.println("*** FAILURE ***\n");
472 }
473
474 /**
475 * LIST TEST
476 */
477 List<Integer> listout = new ArrayList<Integer>();
478 for (int i = -2; i < 3; ++i) {
479 listout.add(i);
480 }
481 System.out.print("testList({");
482 first = true;
483 for (int elem : listout) {
484 if (first) {
485 first = false;
486 } else {
487 System.out.print(", ");
488 }
489 System.out.print(elem);
490 }
491 System.out.print("})");
492 List<Integer> listin = testClient.testList(listout);
493 System.out.print(" = {");
494 first = true;
495 for (int elem : listin) {
496 if (first) {
497 first = false;
498 } else {
499 System.out.print(", ");
500 }
501 System.out.print(elem);
502 }
503 System.out.print("}\n");
504 if (!listout.equals(listin)) {
505 returnCode |= ERR_CONTAINERS;
506 System.out.println("*** FAILURE ***\n");
507 }
508
509 /**
510 * ENUM TEST
511 */
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");
518 }
519
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");
526 }
527
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");
534 }
535
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");
542 }
543
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");
550 }
551
552 /**
553 * TYPEDEF TEST
554 */
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");
561 }
562
563 /**
564 * NESTED MAP TEST
565 */
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) + ", ");
575 }
576 System.out.print("}, ");
577 }
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");
582 } else {
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");
589 }
590 }
591
592 /**
593 * INSANITY TEST
594 */
595
596 boolean insanityFailed = true;
597 try {
598 Xtruct hello = new Xtruct();
599 hello.string_thing = "Hello2";
600 hello.byte_thing = 2;
601 hello.i32_thing = 2;
602 hello.i64_thing = 2;
603
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;
609
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);
616
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 + " => {");
624
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) + ", ");
633 }
634 }
635 System.out.print("}, ");
636
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 + "}, ");
642 }
643 }
644 System.out.print("}");
645
646 System.out.print("}, ");
647 }
648 System.out.print("}, ");
649 }
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) {
666 // OK
667 insanityFailed = false;
668 }
669 }
670 }
671 } catch (Exception ex) {
672 returnCode |= ERR_STRUCTS;
673 System.out.println("*** FAILURE ***\n");
674 ex.printStackTrace(System.out);
675 insanityFailed = false;
676 }
677 if (insanityFailed) {
678 returnCode |= ERR_STRUCTS;
679 System.out.println("*** FAILURE ***\n");
680 }
681
682 /**
683 * EXECPTION TEST
684 */
685 try {
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);
692 }
693
694 try {
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());
701 }
702
703 try {
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;
710 }
711
712
713 /**
714 * MULTI EXCEPTION TEST
715 */
716
717 try {
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);
724 }
725
726 try {
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);
733 }
734
735 try {
736 System.out.print("testClient.testMultiException(\"success\", \"test 3\") =>");
737 Xtruct result;
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;
743 }
744
745
746
747 /**
748 * ONEWAY TEST
749 */
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) +
757 "ms");
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;
765 } else {
766 System.out.println("Success - fire and forget only took " +
767 Long.toString(onewayElapsedMillis) +
768 "ms");
769 }
770
771
772 long stop = System.nanoTime();
773 long tot = stop-start;
774
775 System.out.println("Total time: " + tot/1000 + "us");
776
777 if (timeMin == 0 || tot < timeMin) {
778 timeMin = tot;
779 }
780 if (tot > timeMax) {
781 timeMax = tot;
782 }
783 timeTot += tot;
784
785 transport.close();
786 } catch (Exception x) {
787 System.out.printf("*** FAILURE ***\n");
788 x.printStackTrace();
789 returnCode |= ERR_UNKNOWN;
790 }
791 }
792
793 long timeAvg = timeTot / numTests;
794
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");
798
799 try {
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 ***");
804 x.printStackTrace();
805 returnCode |= ERR_BASETYPES;
806 }
807
808
809 System.exit(returnCode);
810 }
811 }