]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/test/csharp/TestClient.cs
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / test / csharp / TestClient.cs
CommitLineData
f67539c2
TL
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
20using System;
21using System.Linq;
22using System.Diagnostics;
23using System.Collections.Generic;
24using System.Threading;
25using System.Security.Cryptography.X509Certificates;
26using Thrift.Collections;
27using Thrift.Protocol;
28using Thrift.Transport;
29using Thrift.Test;
30using System.Security.Authentication;
31
32namespace Test
33{
34 public class TestClient
35 {
36 public class TestParams
37 {
38 public int numIterations = 1;
39 public string host = "localhost";
40 public int port = 9090;
41 public string url;
42 public string pipe;
43 public bool buffered;
44 public bool framed;
45 public string protocol;
46 public bool encrypted = false;
47 public bool multiplexed = false;
48 protected bool _isFirstTransport = true;
49
50
51 public TTransport CreateTransport()
52 {
53 if (url == null)
54 {
55 // endpoint transport
56 TTransport trans = null;
57 if (pipe != null)
58 trans = new TNamedPipeClientTransport(pipe);
59 else
60 {
61 if (encrypted)
62 {
63 string certPath = "../keys/client.p12";
64 X509Certificate cert = new X509Certificate2(certPath, "thrift");
65 trans = new TTLSSocket(host, port, 0, cert,
66 (o, c, chain, errors) => true,
67 null, SslProtocols.Tls);
68 }
69 else
70 {
71 trans = new TSocket(host, port);
72 }
73 }
74
75 // layered transport
76 if (buffered)
77 trans = new TBufferedTransport(trans);
78 if (framed)
79 trans = new TFramedTransport(trans);
80
81 if (_isFirstTransport)
82 {
83 //ensure proper open/close of transport
84 trans.Open();
85 trans.Close();
86 _isFirstTransport = false;
87 }
88 return trans;
89 }
90 else
91 {
92 return new THttpClient(new Uri(url));
93 }
94 }
95
96 public TProtocol CreateProtocol(TTransport transport)
97 {
98 if (protocol == "compact")
99 return new TCompactProtocol(transport);
100 else if (protocol == "json")
101 return new TJSONProtocol(transport);
102 else
103 return new TBinaryProtocol(transport);
104 }
105 };
106
107 private const int ErrorBaseTypes = 1;
108 private const int ErrorStructs = 2;
109 private const int ErrorContainers = 4;
110 private const int ErrorExceptions = 8;
111 private const int ErrorProtocol = 16;
112 private const int ErrorUnknown = 64;
113
114 private class ClientTest
115 {
116 private readonly TestParams param;
117 private readonly TTransport transport;
118 private readonly SecondService.Client second;
119 private readonly ThriftTest.Client client;
120 private readonly int numIterations;
121 private bool done;
122
123 public int ReturnCode { get; set; }
124
125 public ClientTest(TestParams paramin)
126 {
127 param = paramin;
128 transport = param.CreateTransport();
129 TProtocol protocol = param.CreateProtocol(transport);
130 if (param.multiplexed)
131 {
132 second = new SecondService.Client(new TMultiplexedProtocol(protocol, "SecondService"));
133 }
134 client = new ThriftTest.Client(protocol);
135 numIterations = param.numIterations;
136 }
137 public void Execute()
138 {
139 if (done)
140 {
141 Console.WriteLine("Execute called more than once");
142 throw new InvalidOperationException();
143 }
144
145 for (int i = 0; i < numIterations; i++)
146 {
147 try
148 {
149 if (!transport.IsOpen)
150 transport.Open();
151 }
152 catch (TTransportException ex)
153 {
154 Console.WriteLine("*** FAILED ***");
155 Console.WriteLine("Connect failed: " + ex.Message);
156 ReturnCode |= ErrorUnknown;
157 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
158 continue;
159 }
160
161 try
162 {
163 ReturnCode |= ExecuteClientTest(client, second, param);
164 }
165 catch (Exception ex)
166 {
167 Console.WriteLine("*** FAILED ***");
168 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
169 ReturnCode |= ErrorUnknown;
170 }
171 }
172 try
173 {
174 transport.Close();
175 }
176 catch(Exception ex)
177 {
178 Console.WriteLine("Error while closing transport");
179 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
180 }
181 done = true;
182 }
183 }
184
185 public static int Execute(string[] args)
186 {
187 try
188 {
189 TestParams param = new TestParams();
190 int numThreads = 1;
191 try
192 {
193 for (int i = 0; i < args.Length; i++)
194 {
195 if (args[i] == "-u")
196 {
197 param.url = args[++i];
198 }
199 else if (args[i] == "-n")
200 {
201 param.numIterations = Convert.ToInt32(args[++i]);
202 }
203 else if (args[i] == "-pipe") // -pipe <name>
204 {
205 param.pipe = args[++i];
206 Console.WriteLine("Using named pipes transport");
207 }
208 else if (args[i].Contains("--host="))
209 {
210 param.host = args[i].Substring(args[i].IndexOf("=") + 1);
211 }
212 else if (args[i].Contains("--port="))
213 {
214 param.port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1));
215 }
216 else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
217 {
218 param.buffered = true;
219 Console.WriteLine("Using buffered sockets");
220 }
221 else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed")
222 {
223 param.framed = true;
224 Console.WriteLine("Using framed transport");
225 }
226 else if (args[i] == "-t")
227 {
228 numThreads = Convert.ToInt32(args[++i]);
229 }
230 else if (args[i] == "--compact" || args[i] == "--protocol=compact" || args[i] == "--protocol=multic")
231 {
232 param.protocol = "compact";
233 Console.WriteLine("Using compact protocol");
234 }
235 else if (args[i] == "--json" || args[i] == "--protocol=json" || args[i] == "--protocol=multij")
236 {
237 param.protocol = "json";
238 Console.WriteLine("Using JSON protocol");
239 }
240 else if (args[i] == "--ssl")
241 {
242 param.encrypted = true;
243 Console.WriteLine("Using encrypted transport");
244 }
245
246 if (args[i].StartsWith("--protocol=multi"))
247 {
248 param.multiplexed = true;
249 }
250 }
251 }
252 catch (Exception ex)
253 {
254 Console.WriteLine("*** FAILED ***");
255 Console.WriteLine("Error while parsing arguments");
256 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
257 return ErrorUnknown;
258 }
259
260 var tests = Enumerable.Range(0, numThreads).Select(_ => new ClientTest(param)).ToArray();
261 //issue tests on separate threads simultaneously
262 var threads = tests.Select(test => new Thread(test.Execute)).ToArray();
263 DateTime start = DateTime.Now;
264 foreach (var t in threads)
265 t.Start();
266 foreach (var t in threads)
267 t.Join();
268 Console.WriteLine("Total time: " + (DateTime.Now - start));
269 Console.WriteLine();
270 return tests.Select(t => t.ReturnCode).Aggregate((r1, r2) => r1 | r2);
271 }
272 catch (Exception outerEx)
273 {
274 Console.WriteLine("*** FAILED ***");
275 Console.WriteLine("Unexpected error");
276 Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace);
277 return ErrorUnknown;
278 }
279 }
280
281 public static string BytesToHex(byte[] data) {
282 return BitConverter.ToString(data).Replace("-", string.Empty);
283 }
284
285 public static byte[] PrepareTestData(bool randomDist, bool huge)
286 {
287 // huge = true tests for THRIFT-4372
288 byte[] retval = new byte[huge ? 0x12345 : 0x100];
289 int initLen = retval.Length;
290
291 // linear distribution, unless random is requested
292 if (!randomDist) {
293 for (var i = 0; i < initLen; ++i) {
294 retval[i] = (byte)i;
295 }
296 return retval;
297 }
298
299 // random distribution
300 for (var i = 0; i < initLen; ++i) {
301 retval[i] = (byte)0;
302 }
303 var rnd = new Random();
304 for (var i = 1; i < initLen; ++i) {
305 while( true) {
306 int nextPos = rnd.Next() % initLen;
307 if (retval[nextPos] == 0) {
308 retval[nextPos] = (byte)i;
309 break;
310 }
311 }
312 }
313 return retval;
314 }
315
316 public static int ExecuteClientTest(ThriftTest.Client client, SecondService.Client second, TestParams param)
317 {
318 int returnCode = 0;
319
320 Console.Write("testVoid()");
321 client.testVoid();
322 Console.WriteLine(" = void");
323
324 Console.Write("testString(\"Test\")");
325 string s = client.testString("Test");
326 Console.WriteLine(" = \"" + s + "\"");
327 if ("Test" != s)
328 {
329 Console.WriteLine("*** FAILED ***");
330 returnCode |= ErrorBaseTypes;
331 }
332
333 if (param.multiplexed)
334 {
335 Console.WriteLine("secondTestString(\"Test2\")");
336 s = second.secondtestString("Test2");
337 Console.WriteLine(" = \"" + s + "\"");
338 if ("testString(\"Test2\")" != s)
339 {
340 Console.WriteLine("*** FAILED ***");
341 returnCode |= ErrorProtocol;
342 }
343 }
344
345 Console.Write("testBool(true)");
346 bool t = client.testBool((bool)true);
347 Console.WriteLine(" = " + t);
348 if (!t)
349 {
350 Console.WriteLine("*** FAILED ***");
351 returnCode |= ErrorBaseTypes;
352 }
353 Console.Write("testBool(false)");
354 bool f = client.testBool((bool)false);
355 Console.WriteLine(" = " + f);
356 if (f)
357 {
358 Console.WriteLine("*** FAILED ***");
359 returnCode |= ErrorBaseTypes;
360 }
361
362 Console.Write("testByte(1)");
363 sbyte i8 = client.testByte((sbyte)1);
364 Console.WriteLine(" = " + i8);
365 if (1 != i8)
366 {
367 Console.WriteLine("*** FAILED ***");
368 returnCode |= ErrorBaseTypes;
369 }
370
371 Console.Write("testI32(-1)");
372 int i32 = client.testI32(-1);
373 Console.WriteLine(" = " + i32);
374 if (-1 != i32)
375 {
376 Console.WriteLine("*** FAILED ***");
377 returnCode |= ErrorBaseTypes;
378 }
379
380 Console.Write("testI64(-34359738368)");
381 long i64 = client.testI64(-34359738368);
382 Console.WriteLine(" = " + i64);
383 if (-34359738368 != i64)
384 {
385 Console.WriteLine("*** FAILED ***");
386 returnCode |= ErrorBaseTypes;
387 }
388
389 // TODO: Validate received message
390 Console.Write("testDouble(5.325098235)");
391 double dub = client.testDouble(5.325098235);
392 Console.WriteLine(" = " + dub);
393 if (5.325098235 != dub)
394 {
395 Console.WriteLine("*** FAILED ***");
396 returnCode |= ErrorBaseTypes;
397 }
398 Console.Write("testDouble(-0.000341012439638598279)");
399 dub = client.testDouble(-0.000341012439638598279);
400 Console.WriteLine(" = " + dub);
401 if (-0.000341012439638598279 != dub)
402 {
403 Console.WriteLine("*** FAILED ***");
404 returnCode |= ErrorBaseTypes;
405 }
406
407 for (i32 = 0; i32 < 2; ++i32)
408 {
409 var huge = (i32 > 0);
410 byte[] binOut = PrepareTestData(false,huge);
411 Console.Write("testBinary(" + BytesToHex(binOut) + ")");
412 try
413 {
414 byte[] binIn = client.testBinary(binOut);
415 Console.WriteLine(" = " + BytesToHex(binIn));
416 if (binIn.Length != binOut.Length)
417 {
418 Console.WriteLine("*** FAILED ***");
419 returnCode |= ErrorBaseTypes;
420 }
421 for (int ofs = 0; ofs < Math.Min(binIn.Length, binOut.Length); ++ofs)
422 if (binIn[ofs] != binOut[ofs])
423 {
424 Console.WriteLine("*** FAILED ***");
425 returnCode |= ErrorBaseTypes;
426 }
427 }
428 catch (Thrift.TApplicationException ex)
429 {
430 Console.WriteLine("*** FAILED ***");
431 returnCode |= ErrorBaseTypes;
432 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
433 }
434 }
435
436 // binary equals? only with hashcode option enabled ...
437 Console.WriteLine("Test CrazyNesting");
438 if( typeof(CrazyNesting).GetMethod("Equals").DeclaringType == typeof(CrazyNesting))
439 {
440 CrazyNesting one = new CrazyNesting();
441 CrazyNesting two = new CrazyNesting();
442 one.String_field = "crazy";
443 two.String_field = "crazy";
444 one.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
445 two.Binary_field = new byte[10] { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xFF };
446 if (!one.Equals(two))
447 {
448 Console.WriteLine("*** FAILED ***");
449 returnCode |= ErrorContainers;
450 throw new Exception("CrazyNesting.Equals failed");
451 }
452 }
453
454 // TODO: Validate received message
455 Console.Write("testStruct({\"Zero\", 1, -3, -5})");
456 Xtruct o = new Xtruct();
457 o.String_thing = "Zero";
458 o.Byte_thing = (sbyte)1;
459 o.I32_thing = -3;
460 o.I64_thing = -5;
461 Xtruct i = client.testStruct(o);
462 Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");
463
464 // TODO: Validate received message
465 Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})");
466 Xtruct2 o2 = new Xtruct2();
467 o2.Byte_thing = (sbyte)1;
468 o2.Struct_thing = o;
469 o2.I32_thing = 5;
470 Xtruct2 i2 = client.testNest(o2);
471 i = i2.Struct_thing;
472 Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");
473
474 Dictionary<int, int> mapout = new Dictionary<int, int>();
475 for (int j = 0; j < 5; j++)
476 {
477 mapout[j] = j - 10;
478 }
479 Console.Write("testMap({");
480 bool first = true;
481 foreach (int key in mapout.Keys)
482 {
483 if (first)
484 {
485 first = false;
486 }
487 else
488 {
489 Console.Write(", ");
490 }
491 Console.Write(key + " => " + mapout[key]);
492 }
493 Console.Write("})");
494
495 Dictionary<int, int> mapin = client.testMap(mapout);
496
497 Console.Write(" = {");
498 first = true;
499 foreach (int key in mapin.Keys)
500 {
501 if (first)
502 {
503 first = false;
504 }
505 else
506 {
507 Console.Write(", ");
508 }
509 Console.Write(key + " => " + mapin[key]);
510 }
511 Console.WriteLine("}");
512
513 // TODO: Validate received message
514 List<int> listout = new List<int>();
515 for (int j = -2; j < 3; j++)
516 {
517 listout.Add(j);
518 }
519 Console.Write("testList({");
520 first = true;
521 foreach (int j in listout)
522 {
523 if (first)
524 {
525 first = false;
526 }
527 else
528 {
529 Console.Write(", ");
530 }
531 Console.Write(j);
532 }
533 Console.Write("})");
534
535 List<int> listin = client.testList(listout);
536
537 Console.Write(" = {");
538 first = true;
539 foreach (int j in listin)
540 {
541 if (first)
542 {
543 first = false;
544 }
545 else
546 {
547 Console.Write(", ");
548 }
549 Console.Write(j);
550 }
551 Console.WriteLine("}");
552
553 //set
554 // TODO: Validate received message
555 THashSet<int> setout = new THashSet<int>();
556 for (int j = -2; j < 3; j++)
557 {
558 setout.Add(j);
559 }
560 Console.Write("testSet({");
561 first = true;
562 foreach (int j in setout)
563 {
564 if (first)
565 {
566 first = false;
567 }
568 else
569 {
570 Console.Write(", ");
571 }
572 Console.Write(j);
573 }
574 Console.Write("})");
575
576 THashSet<int> setin = client.testSet(setout);
577
578 Console.Write(" = {");
579 first = true;
580 foreach (int j in setin)
581 {
582 if (first)
583 {
584 first = false;
585 }
586 else
587 {
588 Console.Write(", ");
589 }
590 Console.Write(j);
591 }
592 Console.WriteLine("}");
593
594
595 Console.Write("testEnum(ONE)");
596 Numberz ret = client.testEnum(Numberz.ONE);
597 Console.WriteLine(" = " + ret);
598 if (Numberz.ONE != ret)
599 {
600 Console.WriteLine("*** FAILED ***");
601 returnCode |= ErrorStructs;
602 }
603
604 Console.Write("testEnum(TWO)");
605 ret = client.testEnum(Numberz.TWO);
606 Console.WriteLine(" = " + ret);
607 if (Numberz.TWO != ret)
608 {
609 Console.WriteLine("*** FAILED ***");
610 returnCode |= ErrorStructs;
611 }
612
613 Console.Write("testEnum(THREE)");
614 ret = client.testEnum(Numberz.THREE);
615 Console.WriteLine(" = " + ret);
616 if (Numberz.THREE != ret)
617 {
618 Console.WriteLine("*** FAILED ***");
619 returnCode |= ErrorStructs;
620 }
621
622 Console.Write("testEnum(FIVE)");
623 ret = client.testEnum(Numberz.FIVE);
624 Console.WriteLine(" = " + ret);
625 if (Numberz.FIVE != ret)
626 {
627 Console.WriteLine("*** FAILED ***");
628 returnCode |= ErrorStructs;
629 }
630
631 Console.Write("testEnum(EIGHT)");
632 ret = client.testEnum(Numberz.EIGHT);
633 Console.WriteLine(" = " + ret);
634 if (Numberz.EIGHT != ret)
635 {
636 Console.WriteLine("*** FAILED ***");
637 returnCode |= ErrorStructs;
638 }
639
640 Console.Write("testTypedef(309858235082523)");
641 long uid = client.testTypedef(309858235082523L);
642 Console.WriteLine(" = " + uid);
643 if (309858235082523L != uid)
644 {
645 Console.WriteLine("*** FAILED ***");
646 returnCode |= ErrorStructs;
647 }
648
649 // TODO: Validate received message
650 Console.Write("testMapMap(1)");
651 Dictionary<int, Dictionary<int, int>> mm = client.testMapMap(1);
652 Console.Write(" = {");
653 foreach (int key in mm.Keys)
654 {
655 Console.Write(key + " => {");
656 Dictionary<int, int> m2 = mm[key];
657 foreach (int k2 in m2.Keys)
658 {
659 Console.Write(k2 + " => " + m2[k2] + ", ");
660 }
661 Console.Write("}, ");
662 }
663 Console.WriteLine("}");
664
665 // TODO: Validate received message
666 Insanity insane = new Insanity();
667 insane.UserMap = new Dictionary<Numberz, long>();
668 insane.UserMap[Numberz.FIVE] = 5000L;
669 Xtruct truck = new Xtruct();
670 truck.String_thing = "Truck";
671 truck.Byte_thing = (sbyte)8;
672 truck.I32_thing = 8;
673 truck.I64_thing = 8;
674 insane.Xtructs = new List<Xtruct>();
675 insane.Xtructs.Add(truck);
676 Console.Write("testInsanity()");
677 Dictionary<long, Dictionary<Numberz, Insanity>> whoa = client.testInsanity(insane);
678 Console.Write(" = {");
679 foreach (long key in whoa.Keys)
680 {
681 Dictionary<Numberz, Insanity> val = whoa[key];
682 Console.Write(key + " => {");
683
684 foreach (Numberz k2 in val.Keys)
685 {
686 Insanity v2 = val[k2];
687
688 Console.Write(k2 + " => {");
689 Dictionary<Numberz, long> userMap = v2.UserMap;
690
691 Console.Write("{");
692 if (userMap != null)
693 {
694 foreach (Numberz k3 in userMap.Keys)
695 {
696 Console.Write(k3 + " => " + userMap[k3] + ", ");
697 }
698 }
699 else
700 {
701 Console.Write("null");
702 }
703 Console.Write("}, ");
704
705 List<Xtruct> xtructs = v2.Xtructs;
706
707 Console.Write("{");
708 if (xtructs != null)
709 {
710 foreach (Xtruct x in xtructs)
711 {
712 Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, ");
713 }
714 }
715 else
716 {
717 Console.Write("null");
718 }
719 Console.Write("}");
720
721 Console.Write("}, ");
722 }
723 Console.Write("}, ");
724 }
725 Console.WriteLine("}");
726
727 sbyte arg0 = 1;
728 int arg1 = 2;
729 long arg2 = long.MaxValue;
730 Dictionary<short, string> multiDict = new Dictionary<short, string>();
731 multiDict[1] = "one";
732 Numberz arg4 = Numberz.FIVE;
733 long arg5 = 5000000;
734 Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
735 Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
736 Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
737 + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");
738
739 try
740 {
741 Console.WriteLine("testException(\"Xception\")");
742 client.testException("Xception");
743 Console.WriteLine("*** FAILED ***");
744 returnCode |= ErrorExceptions;
745 }
746 catch (Xception ex)
747 {
748 if (ex.ErrorCode != 1001 || ex.Message != "Xception")
749 {
750 Console.WriteLine("*** FAILED ***");
751 returnCode |= ErrorExceptions;
752 }
753 }
754 catch (Exception ex)
755 {
756 Console.WriteLine("*** FAILED ***");
757 returnCode |= ErrorExceptions;
758 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
759 }
760 try
761 {
762 Console.WriteLine("testException(\"TException\")");
763 client.testException("TException");
764 Console.WriteLine("*** FAILED ***");
765 returnCode |= ErrorExceptions;
766 }
767 catch (Thrift.TException)
768 {
769 // OK
770 }
771 catch (Exception ex)
772 {
773 Console.WriteLine("*** FAILED ***");
774 returnCode |= ErrorExceptions;
775 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
776 }
777 try
778 {
779 Console.WriteLine("testException(\"ok\")");
780 client.testException("ok");
781 // OK
782 }
783 catch (Exception ex)
784 {
785 Console.WriteLine("*** FAILED ***");
786 returnCode |= ErrorExceptions;
787 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
788 }
789
790 try
791 {
792 Console.WriteLine("testMultiException(\"Xception\", ...)");
793 client.testMultiException("Xception", "ignore");
794 Console.WriteLine("*** FAILED ***");
795 returnCode |= ErrorExceptions;
796 }
797 catch (Xception ex)
798 {
799 if (ex.ErrorCode != 1001 || ex.Message != "This is an Xception")
800 {
801 Console.WriteLine("*** FAILED ***");
802 returnCode |= ErrorExceptions;
803 }
804 }
805 catch (Exception ex)
806 {
807 Console.WriteLine("*** FAILED ***");
808 returnCode |= ErrorExceptions;
809 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
810 }
811 try
812 {
813 Console.WriteLine("testMultiException(\"Xception2\", ...)");
814 client.testMultiException("Xception2", "ignore");
815 Console.WriteLine("*** FAILED ***");
816 returnCode |= ErrorExceptions;
817 }
818 catch (Xception2 ex)
819 {
820 if (ex.ErrorCode != 2002 || ex.Struct_thing.String_thing != "This is an Xception2")
821 {
822 Console.WriteLine("*** FAILED ***");
823 returnCode |= ErrorExceptions;
824 }
825 }
826 catch (Exception ex)
827 {
828 Console.WriteLine("*** FAILED ***");
829 returnCode |= ErrorExceptions;
830 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
831 }
832 try
833 {
834 Console.WriteLine("testMultiException(\"success\", \"OK\")");
835 if ("OK" != client.testMultiException("success", "OK").String_thing)
836 {
837 Console.WriteLine("*** FAILED ***");
838 returnCode |= ErrorExceptions;
839 }
840 }
841 catch (Exception ex)
842 {
843 Console.WriteLine("*** FAILED ***");
844 returnCode |= ErrorExceptions;
845 Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
846 }
847
848 Stopwatch sw = new Stopwatch();
849 sw.Start();
850 Console.WriteLine("Test Oneway(1)");
851 client.testOneway(1);
852 sw.Stop();
853 if (sw.ElapsedMilliseconds > 1000)
854 {
855 Console.WriteLine("*** FAILED ***");
856 returnCode |= ErrorBaseTypes;
857 }
858
859 Console.Write("Test Calltime()");
860 var times = 50;
861 sw.Reset();
862 sw.Start();
863 for (int k = 0; k < times; ++k)
864 client.testVoid();
865 sw.Stop();
866 Console.WriteLine(" = {0} ms a testVoid() call", sw.ElapsedMilliseconds / times);
867 return returnCode;
868 }
869 }
870}