1 // 2 // Copyright (c) ZeroC, Inc. All rights reserved. 3 // 4 5 using System; 6 using System.Collections.Generic; 7 using System.Diagnostics; 8 using System.Threading; 9 using System.Threading.Tasks; 10 11 namespace Ice 12 { 13 namespace ami 14 { 15 public class AllTests : global::Test.AllTests 16 { 17 public class PingReplyI : Test.PingReplyDisp_ 18 { reply(Ice.Current current)19 public override void reply(Ice.Current current) 20 { 21 _received = true; 22 } 23 checkReceived()24 public bool checkReceived() 25 { 26 return _received; 27 } 28 29 private bool _received = false; 30 } 31 32 private class Cookie 33 { Cookie(int i)34 public Cookie(int i) 35 { 36 val = i; 37 } 38 39 public int val; 40 } 41 42 public class Progress : IProgress<bool> 43 { Progress(Action<bool> report)44 public Progress(Action<bool> report) 45 { 46 _report = report; 47 } 48 Report(bool sentSynchronously)49 public void Report(bool sentSynchronously) 50 { 51 _report(sentSynchronously); 52 } 53 54 Action<bool> _report; 55 } 56 57 public class ProgresCallback : IProgress<bool> 58 { 59 public bool Sent 60 { 61 get 62 { 63 lock(this) 64 { 65 return _sent; 66 } 67 } 68 set 69 { 70 lock(this) 71 { 72 _sent = value; 73 } 74 } 75 } 76 77 public bool SentSynchronously 78 { 79 get 80 { 81 lock(this) 82 { 83 return _sentSynchronously; 84 } 85 } 86 set 87 { 88 lock(this) 89 { 90 _sentSynchronously = value; 91 } 92 } 93 } 94 Report(bool sentSynchronously)95 public void Report(bool sentSynchronously) 96 { 97 SentSynchronously = sentSynchronously; 98 Sent = true; 99 } 100 101 private bool _sent = false; 102 private bool _sentSynchronously = false; 103 } 104 105 private class CallbackBase 106 { CallbackBase()107 internal CallbackBase() 108 { 109 _called = false; 110 } 111 check()112 public virtual void check() 113 { 114 lock(this) 115 { 116 while(!_called) 117 { 118 Monitor.Wait(this); 119 } 120 _called = false; 121 } 122 } 123 called()124 public virtual void called() 125 { 126 lock(this) 127 { 128 Debug.Assert(!_called); 129 _called = true; 130 Monitor.Pulse(this); 131 } 132 } 133 134 private bool _called; 135 } 136 137 private class AsyncCallback : CallbackBase 138 { AsyncCallback()139 public AsyncCallback() 140 { 141 } 142 AsyncCallback(Cookie cookie)143 public AsyncCallback(Cookie cookie) 144 { 145 _cookie = cookie; 146 } 147 148 public void isA(Ice.AsyncResult result)149 isA(Ice.AsyncResult result) 150 { 151 test(result.AsyncState == _cookie); 152 test(result.getProxy().end_ice_isA(result)); 153 called(); 154 } 155 156 public void ping(Ice.AsyncResult result)157 ping(Ice.AsyncResult result) 158 { 159 test(result.AsyncState == _cookie); 160 result.getProxy().end_ice_ping(result); 161 called(); 162 } 163 164 public void id(Ice.AsyncResult result)165 id(Ice.AsyncResult result) 166 { 167 test(result.AsyncState == _cookie); 168 test(result.getProxy().end_ice_id(result).Equals("::Test::TestIntf")); 169 called(); 170 } 171 172 public void ids(Ice.AsyncResult result)173 ids(Ice.AsyncResult result) 174 { 175 test(result.AsyncState == _cookie); 176 test(result.getProxy().end_ice_ids(result).Length == 2); 177 called(); 178 } 179 180 public void connection(Ice.AsyncResult result)181 connection(Ice.AsyncResult result) 182 { 183 test(result.AsyncState == _cookie); 184 test(result.getProxy().end_ice_getConnection(result) != null); 185 called(); 186 } 187 188 public void op(Ice.AsyncResult result)189 op(Ice.AsyncResult result) 190 { 191 test(result.AsyncState == _cookie); 192 Test.TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_op(result); 193 called(); 194 } 195 196 public void opWithResult(Ice.AsyncResult result)197 opWithResult(Ice.AsyncResult result) 198 { 199 test(result.AsyncState == _cookie); 200 test(Test.TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_opWithResult(result) == 15); 201 called(); 202 } 203 204 public void opWithUE(Ice.AsyncResult result)205 opWithUE(Ice.AsyncResult result) 206 { 207 test(result.AsyncState == _cookie); 208 try 209 { 210 Test.TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_opWithUE(result); 211 test(false); 212 } 213 catch(Test.TestIntfException) 214 { 215 called(); 216 } 217 catch(Ice.Exception) 218 { 219 test(false); 220 } 221 } 222 223 public void isAEx(Ice.AsyncResult result)224 isAEx(Ice.AsyncResult result) 225 { 226 test(result.AsyncState == _cookie); 227 try 228 { 229 result.getProxy().end_ice_isA(result); 230 test(false); 231 } 232 catch(Ice.NoEndpointException) 233 { 234 called(); 235 } 236 catch(Ice.Exception) 237 { 238 test(false); 239 } 240 } 241 242 public void pingEx(Ice.AsyncResult result)243 pingEx(Ice.AsyncResult result) 244 { 245 test(result.AsyncState == _cookie); 246 try 247 { 248 result.getProxy().end_ice_ping(result); 249 test(false); 250 } 251 catch(Ice.NoEndpointException) 252 { 253 called(); 254 } 255 catch(Ice.Exception) 256 { 257 test(false); 258 } 259 } 260 261 public void idEx(Ice.AsyncResult result)262 idEx(Ice.AsyncResult result) 263 { 264 test(result.AsyncState == _cookie); 265 try 266 { 267 result.getProxy().end_ice_id(result); 268 test(false); 269 } 270 catch(Ice.NoEndpointException) 271 { 272 called(); 273 } 274 catch(Ice.Exception) 275 { 276 test(false); 277 } 278 } 279 280 public void idsEx(Ice.AsyncResult result)281 idsEx(Ice.AsyncResult result) 282 { 283 test(result.AsyncState == _cookie); 284 try 285 { 286 result.getProxy().end_ice_ids(result); 287 test(false); 288 } 289 catch(Ice.NoEndpointException) 290 { 291 called(); 292 } 293 catch(Ice.Exception) 294 { 295 test(false); 296 } 297 } 298 299 public void connectionEx(Ice.AsyncResult result)300 connectionEx(Ice.AsyncResult result) 301 { 302 test(result.AsyncState == _cookie); 303 try 304 { 305 result.getProxy().end_ice_getConnection(result); 306 test(false); 307 } 308 catch(Ice.NoEndpointException) 309 { 310 called(); 311 } 312 catch(Ice.Exception) 313 { 314 test(false); 315 } 316 } 317 318 public void opEx(Ice.AsyncResult result)319 opEx(Ice.AsyncResult result) 320 { 321 test(result.AsyncState == _cookie); 322 try 323 { 324 Test.TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_op(result); 325 test(false); 326 } 327 catch(Ice.NoEndpointException) 328 { 329 called(); 330 } 331 catch(Ice.Exception) 332 { 333 test(false); 334 } 335 } 336 337 private Cookie _cookie; 338 } 339 340 private class ResponseCallback : CallbackBase 341 { ResponseCallback()342 public ResponseCallback() 343 { 344 } 345 346 public void isA(bool r)347 isA(bool r) 348 { 349 test(r); 350 called(); 351 } 352 353 public void ping()354 ping() 355 { 356 called(); 357 } 358 359 public void id(string id)360 id(string id) 361 { 362 test(id.Equals("::Test::TestIntf")); 363 called(); 364 } 365 366 public void ids(string[] ids)367 ids(string[] ids) 368 { 369 test(ids.Length == 2); 370 called(); 371 } 372 373 public void connection(Ice.Connection conn)374 connection(Ice.Connection conn) 375 { 376 test(conn != null); 377 called(); 378 } 379 380 public void op()381 op() 382 { 383 called(); 384 } 385 386 public void opWithResult(int r)387 opWithResult(int r) 388 { 389 test(r == 15); 390 called(); 391 } 392 393 public void opWithUE(Ice.Exception e)394 opWithUE(Ice.Exception e) 395 { 396 try 397 { 398 throw e; 399 } 400 catch(Test.TestIntfException) 401 { 402 called(); 403 } 404 catch(Ice.Exception) 405 { 406 test(false); 407 } 408 } 409 410 } 411 412 private class ExceptionCallback : CallbackBase 413 { ExceptionCallback()414 public ExceptionCallback() 415 { 416 } 417 418 public void isA(bool r)419 isA(bool r) 420 { 421 test(false); 422 } 423 424 public void ping()425 ping() 426 { 427 test(false); 428 } 429 430 public void id(string id)431 id(string id) 432 { 433 test(false); 434 } 435 436 public void ids(string[] ids)437 ids(string[] ids) 438 { 439 test(false); 440 } 441 442 public void connection(Ice.Connection conn)443 connection(Ice.Connection conn) 444 { 445 test(false); 446 } 447 448 public void op()449 op() 450 { 451 test(false); 452 } 453 454 public void opWithUE(Ice.Exception e)455 opWithUE(Ice.Exception e) 456 { 457 try 458 { 459 throw e; 460 } 461 catch(Test.TestIntfException) 462 { 463 called(); 464 } 465 catch(Ice.Exception) 466 { 467 test(false); 468 } 469 } 470 471 public void ex(Ice.Exception ex)472 ex(Ice.Exception ex) 473 { 474 test(ex is Ice.NoEndpointException); 475 called(); 476 } 477 478 public void noEx(Ice.Exception ex)479 noEx(Ice.Exception ex) 480 { 481 test(false); 482 } 483 } 484 485 private class SentCallback : CallbackBase 486 { SentCallback()487 public SentCallback() 488 { 489 _thread = Thread.CurrentThread; 490 } 491 492 public void isA(bool r)493 isA(bool r) 494 { 495 } 496 497 public void ping()498 ping() 499 { 500 } 501 502 public void id(string s)503 id(string s) 504 { 505 } 506 507 public void ids(string[] s)508 ids(string[] s) 509 { 510 } 511 512 public void opAsync(Ice.AsyncResult r)513 opAsync(Ice.AsyncResult r) 514 { 515 } 516 517 public void op()518 op() 519 { 520 } 521 522 public void ex(Ice.Exception ex)523 ex(Ice.Exception ex) 524 { 525 } 526 527 public void sentAsync(Ice.AsyncResult r)528 sentAsync(Ice.AsyncResult r) 529 { 530 test(r.sentSynchronously() && _thread == Thread.CurrentThread || 531 !r.sentSynchronously() && _thread != Thread.CurrentThread); 532 called(); 533 } 534 535 public void sent(bool ss)536 sent(bool ss) 537 { 538 test(ss && _thread == Thread.CurrentThread || !ss && _thread != Thread.CurrentThread); 539 540 called(); 541 } 542 543 Thread _thread; 544 } 545 546 private class FlushCallback : CallbackBase 547 { FlushCallback()548 public FlushCallback() 549 { 550 _thread = Thread.CurrentThread; 551 } 552 FlushCallback(Cookie cookie)553 public FlushCallback(Cookie cookie) 554 { 555 _thread = Thread.CurrentThread; 556 _cookie = cookie; 557 } 558 559 public void completedAsync(Ice.AsyncResult r)560 completedAsync(Ice.AsyncResult r) 561 { 562 test(false); 563 } 564 565 public void exception(Ice.Exception ex)566 exception(Ice.Exception ex) 567 { 568 test(false); 569 } 570 571 public void sentAsync(Ice.AsyncResult r)572 sentAsync(Ice.AsyncResult r) 573 { 574 test(r.AsyncState == _cookie); 575 test(r.sentSynchronously() && _thread == Thread.CurrentThread || 576 !r.sentSynchronously() && _thread != Thread.CurrentThread); 577 called(); 578 } 579 580 public void sent(bool sentSynchronously)581 sent(bool sentSynchronously) 582 { 583 test(sentSynchronously && _thread == Thread.CurrentThread || 584 !sentSynchronously && _thread != Thread.CurrentThread); 585 called(); 586 } 587 588 Cookie _cookie; 589 Thread _thread; 590 } 591 592 private class FlushExCallback : CallbackBase 593 { FlushExCallback()594 public FlushExCallback() 595 { 596 } 597 FlushExCallback(Cookie cookie)598 public FlushExCallback(Cookie cookie) 599 { 600 _cookie = cookie; 601 } 602 603 public void completedAsync(Ice.AsyncResult r)604 completedAsync(Ice.AsyncResult r) 605 { 606 test(r.AsyncState == _cookie); 607 try 608 { 609 if(r.getConnection() != null) 610 { 611 r.getConnection().end_flushBatchRequests(r); 612 } 613 else 614 { 615 r.getProxy().end_ice_flushBatchRequests(r); 616 } 617 test(false); 618 } 619 catch(Ice.LocalException) 620 { 621 called(); 622 } 623 } 624 625 public void exception(Ice.Exception ex)626 exception(Ice.Exception ex) 627 { 628 called(); 629 } 630 631 public void sentAsync(Ice.AsyncResult r)632 sentAsync(Ice.AsyncResult r) 633 { 634 test(false); 635 } 636 637 public void sent(bool sentSynchronously)638 sent(bool sentSynchronously) 639 { 640 test(false); 641 } 642 643 Cookie _cookie; 644 } 645 646 enum ThrowType { LocalException, UserException, OtherException }; 647 648 private class Thrower : CallbackBase 649 { Thrower(ThrowType t)650 public Thrower(ThrowType t) 651 { 652 _t = t; 653 } 654 655 public void opAsync(Ice.AsyncResult r)656 opAsync(Ice.AsyncResult r) 657 { 658 called(); 659 throwEx(); 660 } 661 662 public void op()663 op() 664 { 665 called(); 666 throwEx(); 667 } 668 669 public void noOp()670 noOp() 671 { 672 } 673 674 public void ex(Ice.Exception ex)675 ex(Ice.Exception ex) 676 { 677 called(); 678 throwEx(); 679 } 680 681 public void sent(bool ss)682 sent(bool ss) 683 { 684 called(); 685 throwEx(); 686 } 687 688 private void throwEx()689 throwEx() 690 { 691 switch(_t) 692 { 693 case ThrowType.LocalException: 694 { 695 throw new Ice.ObjectNotExistException(); 696 } 697 case ThrowType.UserException: 698 { 699 throw new Test.TestIntfException(); 700 } 701 case ThrowType.OtherException: 702 { 703 throw new System.Exception(); 704 } 705 default: 706 { 707 Debug.Assert(false); 708 break; 709 } 710 } 711 } 712 713 ThrowType _t; 714 } 715 allTests(global::Test.TestHelper helper, bool collocated)716 public static void allTests(global::Test.TestHelper helper, bool collocated) 717 { 718 Ice.Communicator communicator = helper.communicator(); 719 string sref = "test:" + helper.getTestEndpoint(0); 720 Ice.ObjectPrx obj = communicator.stringToProxy(sref); 721 test(obj != null); 722 723 Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj); 724 sref = "testController:" + helper.getTestEndpoint(1); 725 obj = communicator.stringToProxy(sref); 726 test(obj != null); 727 728 Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj); 729 730 var output = helper.getWriter(); 731 732 output.Write("testing async invocation..."); 733 output.Flush(); 734 { 735 Dictionary<string, string> ctx = new Dictionary<string, string>(); 736 737 test(p.ice_isAAsync("::Test::TestIntf").Result); 738 test(p.ice_isAAsync("::Test::TestIntf", ctx).Result); 739 740 p.ice_pingAsync().Wait(); 741 p.ice_pingAsync(ctx).Wait(); 742 743 test(p.ice_idAsync().Result.Equals("::Test::TestIntf")); 744 test(p.ice_idAsync(ctx).Result.Equals("::Test::TestIntf")); 745 746 test(p.ice_idsAsync().Result.Length == 2); 747 test(p.ice_idsAsync(ctx).Result.Length == 2); 748 749 if(!collocated) 750 { 751 test(p.ice_getConnectionAsync().Result != null); 752 } 753 754 p.opAsync().Wait(); 755 p.opAsync(ctx).Wait(); 756 757 test(p.opWithResultAsync().Result == 15); 758 test(p.opWithResultAsync(ctx).Result == 15); 759 760 try 761 { 762 p.opWithUEAsync().Wait(); 763 test(false); 764 } 765 catch(AggregateException ae) 766 { 767 ae.Handle(ex => ex is Test.TestIntfException); 768 } 769 770 try 771 { 772 p.opWithUEAsync(ctx).Wait(); 773 test(false); 774 } 775 catch(AggregateException ae) 776 { 777 ae.Handle(ex => ex is Test.TestIntfException); 778 } 779 } 780 output.WriteLine("ok"); 781 782 output.Write("testing async/await..."); 783 output.Flush(); 784 { 785 Task.Run(async() => 786 { 787 Dictionary<string, string> ctx = new Dictionary<string, string>(); 788 789 test(await p.ice_isAAsync("::Test::TestIntf")); 790 test(await p.ice_isAAsync("::Test::TestIntf", ctx)); 791 792 await p.ice_pingAsync(); 793 await p.ice_pingAsync(ctx); 794 795 var id = await p.ice_idAsync(); 796 test(id.Equals("::Test::TestIntf")); 797 id = await p.ice_idAsync(ctx); 798 test(id.Equals("::Test::TestIntf")); 799 800 var ids = await p.ice_idsAsync(); 801 test(ids.Length == 2); 802 ids = await p.ice_idsAsync(ctx); 803 test(ids.Length == 2); 804 805 if(!collocated) 806 { 807 var conn = await p.ice_getConnectionAsync(); 808 test(conn != null); 809 } 810 811 await p.opAsync(); 812 await p.opAsync(ctx); 813 814 var result = await p.opWithResultAsync(); 815 test(result == 15); 816 result = await p.opWithResultAsync(ctx); 817 test(result == 15); 818 819 try 820 { 821 await p.opWithUEAsync(); 822 test(false); 823 } 824 catch(System.Exception ex) 825 { 826 test(ex is Test.TestIntfException); 827 } 828 829 try 830 { 831 await p.opWithUEAsync(ctx); 832 test(false); 833 } 834 catch(System.Exception ex) 835 { 836 test(ex is Test.TestIntfException); 837 } 838 }).Wait(); 839 } 840 output.WriteLine("ok"); 841 842 output.Write("testing async continuations..."); 843 output.Flush(); 844 { 845 Dictionary<string, string> ctx = new Dictionary<string, string>(); 846 847 p.ice_isAAsync("::Test::TestIntf").ContinueWith(previous => 848 { 849 test(previous.Result); 850 }).Wait(); 851 852 p.ice_isAAsync("::Test::TestIntf", ctx).ContinueWith(previous => 853 { 854 test(previous.Result); 855 }).Wait(); 856 857 p.ice_pingAsync().ContinueWith(previous => 858 { 859 previous.Wait(); 860 }).Wait(); 861 862 p.ice_pingAsync(ctx).ContinueWith(previous => 863 { 864 previous.Wait(); 865 }).Wait(); 866 867 p.ice_idAsync().ContinueWith(previous => 868 { 869 test(previous.Result.Equals("::Test::TestIntf")); 870 }).Wait(); 871 872 p.ice_idAsync(ctx).ContinueWith(previous => 873 { 874 test(previous.Result.Equals("::Test::TestIntf")); 875 }).Wait(); 876 877 p.ice_idsAsync().ContinueWith(previous => 878 { 879 test(previous.Result.Length == 2); 880 }).Wait(); 881 882 p.ice_idsAsync(ctx).ContinueWith(previous => 883 { 884 test(previous.Result.Length == 2); 885 }).Wait(); 886 887 if(!collocated) 888 { 889 p.ice_getConnectionAsync().ContinueWith(previous => 890 { 891 test(previous.Result != null); 892 }).Wait(); 893 } 894 895 p.opAsync().ContinueWith(previous => previous.Wait()).Wait(); 896 p.opAsync(ctx).ContinueWith(previous => previous.Wait()).Wait(); 897 898 p.opWithResultAsync().ContinueWith(previous => 899 { 900 test(previous.Result == 15); 901 }).Wait(); 902 903 p.opWithResultAsync(ctx).ContinueWith(previous => 904 { 905 test(previous.Result == 15); 906 }).Wait(); 907 908 p.opWithUEAsync().ContinueWith(previous => 909 { 910 try 911 { 912 previous.Wait(); 913 } 914 catch(AggregateException ae) 915 { 916 ae.Handle(ex => ex is Test.TestIntfException); 917 } 918 }).Wait(); 919 920 p.opWithUEAsync(ctx).ContinueWith(previous => 921 { 922 try 923 { 924 previous.Wait(); 925 } 926 catch(AggregateException ae) 927 { 928 ae.Handle(ex => ex is Test.TestIntfException); 929 } 930 }).Wait(); 931 } 932 output.WriteLine("ok"); 933 934 output.Write("testing begin/end invocation... "); 935 output.Flush(); 936 { 937 Ice.AsyncResult result; 938 Dictionary<string, string> ctx = new Dictionary<string, string>(); 939 940 result = p.begin_ice_isA("::Test::TestIntf"); 941 test(p.end_ice_isA(result)); 942 result = p.begin_ice_isA("::Test::TestIntf", ctx); 943 test(p.end_ice_isA(result)); 944 945 result = p.begin_ice_ping(); 946 p.end_ice_ping(result); 947 result = p.begin_ice_ping(ctx); 948 p.end_ice_ping(result); 949 950 result = p.begin_ice_id(); 951 test(p.end_ice_id(result).Equals("::Test::TestIntf")); 952 result = p.begin_ice_id(ctx); 953 test(p.end_ice_id(result).Equals("::Test::TestIntf")); 954 955 result = p.begin_ice_ids(); 956 test(p.end_ice_ids(result).Length == 2); 957 result = p.begin_ice_ids(ctx); 958 test(p.end_ice_ids(result).Length == 2); 959 960 if(!collocated) 961 { 962 result = p.begin_ice_getConnection(); 963 test(p.end_ice_getConnection(result) != null); 964 } 965 966 result = p.begin_op(); 967 p.end_op(result); 968 result = p.begin_op(ctx); 969 p.end_op(result); 970 971 result = p.begin_opWithResult(); 972 test(p.end_opWithResult(result) == 15); 973 result = p.begin_opWithResult(ctx); 974 test(p.end_opWithResult(result) == 15); 975 976 result = p.begin_opWithUE(); 977 try 978 { 979 p.end_opWithUE(result); 980 test(false); 981 } 982 catch(Test.TestIntfException) 983 { 984 } 985 result = p.begin_opWithUE(ctx); 986 try 987 { 988 p.end_opWithUE(result); 989 test(false); 990 } 991 catch(Test.TestIntfException) 992 { 993 } 994 } 995 output.WriteLine("ok"); 996 997 output.Write("testing async callback... "); 998 output.Flush(); 999 { 1000 AsyncCallback cb = new AsyncCallback(); 1001 Dictionary<string, string> ctx = new Dictionary<string, string>(); 1002 Cookie cookie = new Cookie(5); 1003 AsyncCallback cbWC = new AsyncCallback(cookie); 1004 1005 p.begin_ice_isA("::Test::TestIntf", cb.isA, null); 1006 cb.check(); 1007 p.begin_ice_isA("::Test::TestIntf", cbWC.isA, cookie); 1008 cbWC.check(); 1009 p.begin_ice_isA("::Test::TestIntf", ctx, cb.isA, null); 1010 cb.check(); 1011 p.begin_ice_isA("::Test::TestIntf", ctx, cbWC.isA, cookie); 1012 cbWC.check(); 1013 1014 p.begin_ice_ping(cb.ping, null); 1015 cb.check(); 1016 p.begin_ice_ping(cbWC.ping, cookie); 1017 cbWC.check(); 1018 p.begin_ice_ping(ctx, cb.ping, null); 1019 cb.check(); 1020 p.begin_ice_ping(ctx, cbWC.ping, cookie); 1021 cbWC.check(); 1022 1023 p.begin_ice_id(cb.id, null); 1024 cb.check(); 1025 p.begin_ice_id(cbWC.id, cookie); 1026 cbWC.check(); 1027 p.begin_ice_id(ctx, cb.id, null); 1028 cb.check(); 1029 p.begin_ice_id(ctx, cbWC.id, cookie); 1030 cbWC.check(); 1031 1032 p.begin_ice_ids(cb.ids, null); 1033 cb.check(); 1034 p.begin_ice_ids(cbWC.ids, cookie); 1035 cbWC.check(); 1036 p.begin_ice_ids(ctx, cb.ids, null); 1037 cb.check(); 1038 p.begin_ice_ids(ctx, cbWC.ids, cookie); 1039 cbWC.check(); 1040 1041 if(!collocated) 1042 { 1043 p.begin_ice_getConnection(cb.connection, null); 1044 cb.check(); 1045 p.begin_ice_getConnection(cbWC.connection, cookie); 1046 cbWC.check(); 1047 } 1048 1049 p.begin_op(cb.op, null); 1050 cb.check(); 1051 p.begin_op(cbWC.op, cookie); 1052 cbWC.check(); 1053 p.begin_op(ctx, cb.op, null); 1054 cb.check(); 1055 p.begin_op(ctx, cbWC.op, cookie); 1056 cbWC.check(); 1057 1058 p.begin_opWithResult(cb.opWithResult, null); 1059 cb.check(); 1060 p.begin_opWithResult(cbWC.opWithResult, cookie); 1061 cbWC.check(); 1062 p.begin_opWithResult(ctx, cb.opWithResult, null); 1063 cb.check(); 1064 p.begin_opWithResult(ctx, cbWC.opWithResult, cookie); 1065 cbWC.check(); 1066 1067 p.begin_opWithUE(cb.opWithUE, null); 1068 cb.check(); 1069 p.begin_opWithUE(cbWC.opWithUE, cookie); 1070 cbWC.check(); 1071 p.begin_opWithUE(ctx, cb.opWithUE, null); 1072 cb.check(); 1073 p.begin_opWithUE(ctx, cbWC.opWithUE, cookie); 1074 cbWC.check(); 1075 } 1076 output.WriteLine("ok"); 1077 1078 output.Write("testing response callback... "); 1079 output.Flush(); 1080 { 1081 ResponseCallback cb = new ResponseCallback(); 1082 Dictionary<string, string> ctx = new Dictionary<string, string>(); 1083 1084 p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, null); 1085 cb.check(); 1086 p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted(cb.isA, null); 1087 cb.check(); 1088 1089 p.begin_ice_ping().whenCompleted(cb.ping, null); 1090 cb.check(); 1091 p.begin_ice_ping(ctx).whenCompleted(cb.ping, null); 1092 cb.check(); 1093 1094 p.begin_ice_id().whenCompleted(cb.id, null); 1095 cb.check(); 1096 p.begin_ice_id(ctx).whenCompleted(cb.id, null); 1097 cb.check(); 1098 1099 p.begin_ice_ids().whenCompleted(cb.ids, null); 1100 cb.check(); 1101 p.begin_ice_ids(ctx).whenCompleted(cb.ids, null); 1102 cb.check(); 1103 1104 if(!collocated) 1105 { 1106 p.begin_ice_getConnection().whenCompleted(cb.connection, null); 1107 cb.check(); 1108 } 1109 1110 p.begin_op().whenCompleted(cb.op, null); 1111 cb.check(); 1112 p.begin_op(ctx).whenCompleted(cb.op, null); 1113 cb.check(); 1114 1115 p.begin_opWithResult().whenCompleted(cb.opWithResult, null); 1116 cb.check(); 1117 p.begin_opWithResult(ctx).whenCompleted(cb.opWithResult, null); 1118 cb.check(); 1119 1120 p.begin_opWithUE().whenCompleted(cb.op, cb.opWithUE); 1121 cb.check(); 1122 p.begin_opWithUE(ctx).whenCompleted(cb.op, cb.opWithUE); 1123 cb.check(); 1124 } 1125 output.WriteLine("ok"); 1126 1127 output.Write("testing lambda callback... "); 1128 output.Flush(); 1129 { 1130 ResponseCallback cb = new ResponseCallback(); 1131 Dictionary<string, string> ctx = new Dictionary<string, string>(); 1132 1133 p.begin_ice_isA("::Test::TestIntf").whenCompleted( 1134 (bool r) => 1135 { 1136 cb.isA(r); 1137 }, null); 1138 cb.check(); 1139 p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted( 1140 (bool r) => 1141 { 1142 cb.isA(r); 1143 }, null); 1144 cb.check(); 1145 1146 p.begin_ice_ping().whenCompleted( 1147 () => 1148 { 1149 cb.ping(); 1150 }, null); 1151 cb.check(); 1152 p.begin_ice_ping(ctx).whenCompleted( 1153 () => 1154 { 1155 cb.ping(); 1156 }, null); 1157 cb.check(); 1158 1159 p.begin_ice_id().whenCompleted( 1160 (string id) => 1161 { 1162 cb.id(id); 1163 }, null); 1164 cb.check(); 1165 p.begin_ice_id(ctx).whenCompleted( 1166 (string id) => 1167 { 1168 cb.id(id); 1169 }, null); 1170 cb.check(); 1171 1172 p.begin_ice_ids().whenCompleted( 1173 (string[] ids) => 1174 { 1175 cb.ids(ids); 1176 }, null); 1177 cb.check(); 1178 p.begin_ice_ids(ctx).whenCompleted( 1179 (string[] ids) => 1180 { 1181 cb.ids(ids); 1182 }, null); 1183 cb.check(); 1184 1185 if(!collocated) 1186 { 1187 p.begin_ice_getConnection().whenCompleted( 1188 (Ice.Connection conn) => 1189 { 1190 cb.connection(conn); 1191 }, null); 1192 cb.check(); 1193 } 1194 1195 p.begin_op().whenCompleted( 1196 () => 1197 { 1198 cb.op(); 1199 }, null); 1200 cb.check(); 1201 p.begin_op(ctx).whenCompleted( 1202 () => 1203 { 1204 cb.op(); 1205 }, null); 1206 cb.check(); 1207 1208 p.begin_opWithResult().whenCompleted( 1209 (int r) => 1210 { 1211 cb.opWithResult(r); 1212 }, null); 1213 cb.check(); 1214 p.begin_opWithResult(ctx).whenCompleted( 1215 (int r) => 1216 { 1217 cb.opWithResult(r); 1218 }, null); 1219 cb.check(); 1220 1221 p.begin_opWithUE().whenCompleted( 1222 () => 1223 { 1224 cb.op(); 1225 }, 1226 (Ice.Exception ex) => 1227 { 1228 cb.opWithUE(ex); 1229 }); 1230 cb.check(); 1231 p.begin_opWithUE(ctx).whenCompleted( 1232 () => 1233 { 1234 cb.op(); 1235 }, 1236 (Ice.Exception ex) => 1237 { 1238 cb.opWithUE(ex); 1239 }); 1240 cb.check(); 1241 } 1242 output.WriteLine("ok"); 1243 1244 output.Write("testing local exceptions... "); 1245 output.Flush(); 1246 { 1247 Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1248 Ice.AsyncResult r; 1249 1250 r = indirect.begin_op(); 1251 try 1252 { 1253 indirect.end_op(r); 1254 test(false); 1255 } 1256 catch(Ice.NoEndpointException) 1257 { 1258 } 1259 1260 try 1261 { 1262 r =((Test.TestIntfPrx)p.ice_oneway()).begin_opWithResult(); 1263 test(false); 1264 } 1265 catch(ArgumentException) 1266 { 1267 } 1268 1269 // 1270 // Check that CommunicatorDestroyedException is raised directly. 1271 // 1272 if(p.ice_getConnection() != null) 1273 { 1274 Ice.InitializationData initData = new Ice.InitializationData(); 1275 initData.properties = communicator.getProperties().ice_clone_(); 1276 Ice.Communicator ic = helper.initialize(initData); 1277 Ice.ObjectPrx o = ic.stringToProxy(p.ToString()); 1278 Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o); 1279 ic.destroy(); 1280 1281 try 1282 { 1283 p2.begin_op(); 1284 test(false); 1285 } 1286 catch(Ice.CommunicatorDestroyedException) 1287 { 1288 // Expected. 1289 } 1290 } 1291 } 1292 output.WriteLine("ok"); 1293 1294 output.Write("testing local exceptions with async tasks... "); 1295 output.Flush(); 1296 { 1297 Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1298 1299 try 1300 { 1301 indirect.opAsync().Wait(); 1302 test(false); 1303 } 1304 catch(AggregateException ae) 1305 { 1306 ae.Handle((ex) => 1307 { 1308 return ex is Ice.NoEndpointException; 1309 }); 1310 } 1311 1312 try 1313 { 1314 ((Test.TestIntfPrx)p.ice_oneway()).opWithResultAsync(); 1315 test(false); 1316 } 1317 catch(Ice.TwowayOnlyException) 1318 { 1319 } 1320 1321 // 1322 // Check that CommunicatorDestroyedException is raised directly. 1323 // 1324 if(p.ice_getConnection() != null) 1325 { 1326 Ice.InitializationData initData = new Ice.InitializationData(); 1327 initData.properties = communicator.getProperties().ice_clone_(); 1328 Ice.Communicator ic = helper.initialize(initData); 1329 Ice.ObjectPrx o = ic.stringToProxy(p.ToString()); 1330 Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o); 1331 ic.destroy(); 1332 1333 try 1334 { 1335 p2.opAsync(); 1336 test(false); 1337 } 1338 catch(Ice.CommunicatorDestroyedException) 1339 { 1340 // Expected. 1341 } 1342 } 1343 } 1344 output.WriteLine("ok"); 1345 1346 output.Write("testing local exceptions with async callback... "); 1347 output.Flush(); 1348 { 1349 Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1350 AsyncCallback cb = new AsyncCallback(); 1351 Cookie cookie = new Cookie(5); 1352 AsyncCallback cbWC = new AsyncCallback(cookie); 1353 1354 i.begin_ice_isA("::Test::TestIntf", cb.isAEx, null); 1355 cb.check(); 1356 i.begin_ice_isA("::Test::TestIntf", cbWC.isAEx, cookie); 1357 cbWC.check(); 1358 1359 i.begin_ice_ping(cb.pingEx, null); 1360 cb.check(); 1361 i.begin_ice_ping(cbWC.pingEx, cookie); 1362 cbWC.check(); 1363 1364 i.begin_ice_id(cb.idEx, null); 1365 cb.check(); 1366 i.begin_ice_id(cbWC.idEx, cookie); 1367 cbWC.check(); 1368 1369 i.begin_ice_ids(cb.idsEx, null); 1370 cb.check(); 1371 i.begin_ice_ids(cbWC.idsEx, cookie); 1372 cbWC.check(); 1373 1374 if(!collocated) 1375 { 1376 i.begin_ice_getConnection(cb.connectionEx, null); 1377 cb.check(); 1378 i.begin_ice_getConnection(cbWC.connectionEx, cookie); 1379 cbWC.check(); 1380 } 1381 1382 i.begin_op(cb.opEx, null); 1383 cb.check(); 1384 i.begin_op(cbWC.opEx, cookie); 1385 cbWC.check(); 1386 } 1387 output.WriteLine("ok"); 1388 1389 output.Write("testing local exceptions with response callback... "); 1390 output.Flush(); 1391 { 1392 Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1393 ExceptionCallback cb = new ExceptionCallback(); 1394 1395 i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, cb.ex); 1396 cb.check(); 1397 1398 i.begin_ice_ping().whenCompleted(cb.ping, cb.ex); 1399 cb.check(); 1400 1401 i.begin_ice_id().whenCompleted(cb.id, cb.ex); 1402 cb.check(); 1403 1404 i.begin_ice_ids().whenCompleted(cb.ids, cb.ex); 1405 cb.check(); 1406 1407 if(!collocated) 1408 { 1409 i.begin_ice_getConnection().whenCompleted(cb.connection, cb.ex); 1410 cb.check(); 1411 } 1412 1413 i.begin_op().whenCompleted(cb.op, cb.ex); 1414 cb.check(); 1415 } 1416 output.WriteLine("ok"); 1417 1418 output.Write("testing local exceptions with lambda callback... "); 1419 output.Flush(); 1420 { 1421 Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1422 ExceptionCallback cb = new ExceptionCallback(); 1423 1424 i.begin_ice_isA("::Test::TestIntf").whenCompleted( 1425 (bool r) => 1426 { 1427 cb.isA(r); 1428 }, 1429 (Ice.Exception ex) => 1430 { 1431 cb.ex(ex); 1432 }); 1433 cb.check(); 1434 1435 i.begin_ice_ping().whenCompleted( 1436 () => 1437 { 1438 cb.ping(); 1439 }, 1440 (Ice.Exception ex) => 1441 { 1442 cb.ex(ex); 1443 }); 1444 cb.check(); 1445 1446 i.begin_ice_id().whenCompleted( 1447 (string id) => 1448 { 1449 cb.id(id); 1450 }, 1451 (Ice.Exception ex) => 1452 { 1453 cb.ex(ex); 1454 }); 1455 cb.check(); 1456 1457 i.begin_ice_ids().whenCompleted( 1458 (string[] ids) => 1459 { 1460 cb.ids(ids); 1461 }, 1462 (Ice.Exception ex) => 1463 { 1464 cb.ex(ex); 1465 }); 1466 cb.check(); 1467 1468 if(!collocated) 1469 { 1470 i.begin_ice_getConnection().whenCompleted( 1471 (Ice.Connection conn) => 1472 { 1473 cb.connection(conn); 1474 }, 1475 (Ice.Exception ex) => 1476 { 1477 cb.ex(ex); 1478 }); 1479 cb.check(); 1480 } 1481 1482 i.begin_op().whenCompleted( 1483 () => 1484 { 1485 cb.op(); 1486 }, 1487 (Ice.Exception ex) => 1488 { 1489 cb.ex(ex); 1490 }); 1491 cb.check(); 1492 } 1493 output.WriteLine("ok"); 1494 1495 output.Write("testing exception callback... "); 1496 output.Flush(); 1497 { 1498 Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1499 ExceptionCallback cb = new ExceptionCallback(); 1500 1501 i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.ex); 1502 cb.check(); 1503 1504 i.begin_op().whenCompleted(cb.ex); 1505 cb.check(); 1506 1507 i.begin_opWithResult().whenCompleted(cb.ex); 1508 cb.check(); 1509 1510 i.begin_opWithUE().whenCompleted(cb.ex); 1511 cb.check(); 1512 1513 // Ensures no exception is called when response is received 1514 p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.noEx); 1515 p.begin_op().whenCompleted(cb.noEx); 1516 p.begin_opWithResult().whenCompleted(cb.noEx); 1517 1518 // If response is a user exception, it should be received. 1519 p.begin_opWithUE().whenCompleted(cb.opWithUE); 1520 cb.check(); 1521 } 1522 output.WriteLine("ok"); 1523 1524 output.Write("testing exception with async task... "); 1525 output.Flush(); 1526 { 1527 Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1528 ExceptionCallback cb = new ExceptionCallback(); 1529 1530 try 1531 { 1532 i.ice_isAAsync("::Test::TestIntf").Wait(); 1533 test(false); 1534 } 1535 catch(AggregateException) 1536 { 1537 } 1538 1539 try 1540 { 1541 i.opAsync().Wait(); 1542 test(false); 1543 } 1544 catch(AggregateException) 1545 { 1546 } 1547 1548 try 1549 { 1550 i.opWithResultAsync().Wait(); 1551 test(false); 1552 } 1553 catch(AggregateException) 1554 { 1555 } 1556 1557 try 1558 { 1559 i.opWithUEAsync().Wait(); 1560 test(false); 1561 } 1562 catch(AggregateException) 1563 { 1564 } 1565 1566 // Ensures no exception is called when response is received 1567 test(p.ice_isAAsync("::Test::TestIntf").Result); 1568 p.opAsync().Wait(); 1569 p.opWithResultAsync().Wait(); 1570 1571 // If response is a user exception, it should be received. 1572 try 1573 { 1574 p.opWithUEAsync().Wait(); 1575 test(false); 1576 } 1577 catch(AggregateException ae) 1578 { 1579 ae.Handle((ex) => 1580 { 1581 return ex is Test.TestIntfException; 1582 }); 1583 } 1584 } 1585 output.WriteLine("ok"); 1586 1587 output.Write("testing lambda exception callback... "); 1588 output.Flush(); 1589 { 1590 Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1591 ExceptionCallback cb = new ExceptionCallback(); 1592 1593 i.begin_ice_isA("::Test::TestIntf").whenCompleted( 1594 (Ice.Exception ex) => 1595 { 1596 cb.ex(ex); 1597 }); 1598 cb.check(); 1599 1600 i.begin_op().whenCompleted( 1601 (Ice.Exception ex) => 1602 { 1603 cb.ex(ex); 1604 }); 1605 1606 cb.check(); 1607 1608 i.begin_opWithResult().whenCompleted( 1609 (Ice.Exception ex) => 1610 { 1611 cb.ex(ex); 1612 }); 1613 cb.check(); 1614 1615 i.begin_opWithUE().whenCompleted( 1616 (Ice.Exception ex) => 1617 { 1618 cb.ex(ex); 1619 }); 1620 cb.check(); 1621 1622 // Ensures no exception is called when response is received 1623 p.begin_ice_isA("::Test::TestIntf").whenCompleted( 1624 (Ice.Exception ex) => 1625 { 1626 cb.noEx(ex); 1627 }); 1628 p.begin_op().whenCompleted( 1629 (Ice.Exception ex) => 1630 { 1631 cb.noEx(ex); 1632 }); 1633 p.begin_opWithResult().whenCompleted( 1634 (Ice.Exception ex) => 1635 { 1636 cb.noEx(ex); 1637 }); 1638 1639 // If response is a user exception, it should be received. 1640 p.begin_opWithUE().whenCompleted( 1641 (Ice.Exception ex) => 1642 { 1643 cb.opWithUE(ex); 1644 }); 1645 cb.check(); 1646 } 1647 output.WriteLine("ok"); 1648 1649 output.Write("testing sent callback... "); 1650 output.Flush(); 1651 { 1652 SentCallback cb = new SentCallback(); 1653 1654 p.begin_ice_isA("").whenCompleted(cb.isA, cb.ex).whenSent(cb.sent); 1655 cb.check(); 1656 1657 p.begin_ice_ping().whenCompleted(cb.ping, cb.ex).whenSent(cb.sent); 1658 cb.check(); 1659 1660 p.begin_ice_id().whenCompleted(cb.id, cb.ex).whenSent(cb.sent); 1661 cb.check(); 1662 1663 p.begin_ice_ids().whenCompleted(cb.ids, cb.ex).whenSent(cb.sent); 1664 cb.check(); 1665 1666 p.begin_op().whenCompleted(cb.op, cb.ex).whenSent(cb.sent); 1667 cb.check(); 1668 1669 p.begin_op(cb.opAsync, null).whenSent(cb.sentAsync); 1670 cb.check(); 1671 1672 p.begin_op().whenCompleted(cb.ex).whenSent(cb.sent); 1673 cb.check(); 1674 1675 List<SentCallback> cbs = new List<SentCallback>(); 1676 byte[] seq = new byte[10024]; 1677 (new Random()).NextBytes(seq); 1678 testController.holdAdapter(); 1679 try 1680 { 1681 Ice.AsyncResult r; 1682 do 1683 { 1684 SentCallback cb2 = new SentCallback(); 1685 r = p.begin_opWithPayload(seq).whenCompleted(cb2.ex).whenSent(cb2.sent); 1686 cbs.Add(cb2); 1687 } 1688 while(r.sentSynchronously()); 1689 } 1690 finally 1691 { 1692 testController.resumeAdapter(); 1693 } 1694 foreach(SentCallback cb3 in cbs) 1695 { 1696 cb3.check(); 1697 } 1698 } 1699 output.WriteLine("ok"); 1700 1701 output.Write("testing progress callback... "); 1702 output.Flush(); 1703 { 1704 { 1705 SentCallback cb = new SentCallback(); 1706 1707 Task t = p.ice_isAAsync("", 1708 progress: new Progress(sentSynchronously => 1709 { 1710 cb.sent(sentSynchronously); 1711 })); 1712 cb.check(); 1713 t.Wait(); 1714 1715 t = p.ice_pingAsync( 1716 progress: new Progress(sentSynchronously => 1717 { 1718 cb.sent(sentSynchronously); 1719 })); 1720 cb.check(); 1721 t.Wait(); 1722 1723 t = p.ice_idAsync( 1724 progress: new Progress(sentSynchronously => 1725 { 1726 cb.sent(sentSynchronously); 1727 })); 1728 cb.check(); 1729 t.Wait(); 1730 1731 t = p.ice_idsAsync( 1732 progress: new Progress(sentSynchronously => 1733 { 1734 cb.sent(sentSynchronously); 1735 })); 1736 cb.check(); 1737 t.Wait(); 1738 1739 t = p.opAsync( 1740 progress: new Progress(sentSynchronously => 1741 { 1742 cb.sent(sentSynchronously); 1743 })); 1744 cb.check(); 1745 t.Wait(); 1746 } 1747 1748 List<Task> tasks = new List<Task>(); 1749 byte[] seq = new byte[10024]; 1750 (new Random()).NextBytes(seq); 1751 testController.holdAdapter(); 1752 try 1753 { 1754 Task t = null; 1755 ProgresCallback cb; 1756 do 1757 { 1758 cb = new ProgresCallback(); 1759 t = p.opWithPayloadAsync(seq, progress: cb); 1760 tasks.Add(t); 1761 } 1762 while(cb.SentSynchronously); 1763 } 1764 finally 1765 { 1766 testController.resumeAdapter(); 1767 } 1768 foreach(Task t in tasks) 1769 { 1770 t.Wait(); 1771 } 1772 } 1773 output.WriteLine("ok"); 1774 1775 output.Write("testing lambda sent callback... "); 1776 output.Flush(); 1777 { 1778 SentCallback cb = new SentCallback(); 1779 1780 p.begin_ice_isA("").whenCompleted( 1781 (bool r) => 1782 { 1783 cb.isA(r); 1784 }, 1785 (Ice.Exception ex) => 1786 { 1787 cb.ex(ex); 1788 } 1789 ).whenSent( 1790 (bool sentSynchronously) => 1791 { 1792 cb.sent(sentSynchronously); 1793 }); 1794 cb.check(); 1795 1796 p.begin_ice_ping().whenCompleted( 1797 () => 1798 { 1799 cb.ping(); 1800 }, 1801 (Ice.Exception ex) => 1802 { 1803 cb.ex(ex); 1804 } 1805 ).whenSent( 1806 (bool sentSynchronously) => 1807 { 1808 cb.sent(sentSynchronously); 1809 }); 1810 cb.check(); 1811 1812 p.begin_ice_id().whenCompleted( 1813 (string id) => 1814 { 1815 cb.id(id); 1816 }, 1817 (Ice.Exception ex) => 1818 { 1819 cb.ex(ex); 1820 } 1821 ).whenSent( 1822 (bool sentSynchronously) => 1823 { 1824 cb.sent(sentSynchronously); 1825 }); 1826 cb.check(); 1827 1828 p.begin_ice_ids().whenCompleted( 1829 (string[] ids) => 1830 { 1831 cb.ids(ids); 1832 }, 1833 (Ice.Exception ex) => 1834 { 1835 cb.ex(ex); 1836 } 1837 ).whenSent( 1838 (bool sentSynchronously) => 1839 { 1840 cb.sent(sentSynchronously); 1841 }); 1842 cb.check(); 1843 1844 p.begin_op().whenCompleted( 1845 () => 1846 { 1847 cb.op(); 1848 }, 1849 (Ice.Exception ex) => 1850 { 1851 cb.ex(ex); 1852 } 1853 ).whenSent( 1854 (bool sentSynchronously) => 1855 { 1856 cb.sent(sentSynchronously); 1857 }); 1858 cb.check(); 1859 1860 p.begin_op(cb.opAsync, null).whenSent( 1861 (Ice.AsyncResult r) => 1862 { 1863 cb.sentAsync(r); 1864 }); 1865 cb.check(); 1866 1867 p.begin_op().whenCompleted( 1868 (Ice.Exception ex) => 1869 { 1870 cb.ex(ex); 1871 } 1872 ).whenSent( 1873 (bool sentSynchronously) => 1874 { 1875 cb.sent(sentSynchronously); 1876 }); 1877 cb.check(); 1878 1879 List<SentCallback> cbs = new List<SentCallback>(); 1880 byte[] seq = new byte[10024]; 1881 (new System.Random()).NextBytes(seq); 1882 testController.holdAdapter(); 1883 try 1884 { 1885 Ice.AsyncResult r; 1886 do 1887 { 1888 SentCallback cb2 = new SentCallback(); 1889 r = p.begin_opWithPayload(seq).whenCompleted( 1890 (Ice.Exception ex) => 1891 { 1892 cb2.ex(ex); 1893 } 1894 ).whenSent( 1895 (bool sentSynchronously) => 1896 { 1897 cb2.sent(sentSynchronously); 1898 }); 1899 cbs.Add(cb2); 1900 } 1901 while(r.sentSynchronously()); 1902 } 1903 finally 1904 { 1905 testController.resumeAdapter(); 1906 } 1907 foreach(SentCallback cb3 in cbs) 1908 { 1909 cb3.check(); 1910 } 1911 } 1912 output.WriteLine("ok"); 1913 1914 output.Write("testing illegal arguments... "); 1915 output.Flush(); 1916 { 1917 Ice.AsyncResult result; 1918 1919 result = p.begin_op(); 1920 p.end_op(result); 1921 try 1922 { 1923 p.end_op(result); 1924 test(false); 1925 } 1926 catch(System.ArgumentException) 1927 { 1928 } 1929 1930 result = p.begin_op(); 1931 try 1932 { 1933 p.end_opWithResult(result); 1934 test(false); 1935 } 1936 catch(System.ArgumentException) 1937 { 1938 } 1939 1940 try 1941 { 1942 p.end_op(null); 1943 test(false); 1944 } 1945 catch(System.ArgumentException) 1946 { 1947 } 1948 } 1949 output.WriteLine("ok"); 1950 1951 output.Write("testing unexpected exceptions... "); 1952 output.Flush(); 1953 { 1954 Test.TestIntfPrx q = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); 1955 ThrowType[] throwEx = new ThrowType[]{ ThrowType.LocalException, 1956 ThrowType.UserException, 1957 ThrowType.OtherException }; 1958 1959 for(int i = 0; i < 3; ++i) 1960 { 1961 Thrower cb = new Thrower(throwEx[i]); 1962 1963 p.begin_op(cb.opAsync, null); 1964 cb.check(); 1965 1966 p.begin_op().whenCompleted(cb.op, null); 1967 cb.check(); 1968 1969 p.begin_op().whenCompleted( 1970 () => 1971 { 1972 cb.op(); 1973 }, null); 1974 cb.check(); 1975 1976 try 1977 { 1978 p.opAsync().ContinueWith( 1979 (t) => 1980 { 1981 cb.op(); 1982 }).Wait(); 1983 test(false); 1984 } 1985 catch(AggregateException) 1986 { 1987 } 1988 cb.check(); 1989 1990 q.begin_op().whenCompleted(cb.op, cb.ex); 1991 cb.check(); 1992 1993 q.begin_op().whenCompleted( 1994 () => 1995 { 1996 cb.op(); 1997 }, 1998 (Ice.Exception ex) => 1999 { 2000 cb.ex(ex); 2001 }); 2002 cb.check(); 2003 2004 q.begin_op().whenCompleted(cb.ex); 2005 cb.check(); 2006 2007 q.begin_op().whenCompleted( 2008 (Ice.Exception ex) => 2009 { 2010 cb.ex(ex); 2011 }); 2012 cb.check(); 2013 2014 try 2015 { 2016 q.opAsync().ContinueWith( 2017 (t) => 2018 { 2019 try 2020 { 2021 t.Wait(); 2022 test(false); 2023 } 2024 catch(AggregateException ex) 2025 { 2026 cb.ex((Ice.Exception)ex.InnerException); 2027 } 2028 }).Wait(); 2029 test(false); 2030 } 2031 catch(AggregateException) 2032 { 2033 } 2034 cb.check(); 2035 2036 p.begin_op().whenCompleted(cb.noOp, cb.ex).whenSent(cb.sent); 2037 cb.check(); 2038 2039 p.begin_op().whenCompleted( 2040 () => 2041 { 2042 cb.noOp(); 2043 }, 2044 (Ice.Exception ex) => 2045 { 2046 cb.ex(ex); 2047 } 2048 ).whenSent( 2049 (bool sentSynchronously) => 2050 { 2051 cb.sent(sentSynchronously); 2052 }); 2053 cb.check(); 2054 2055 p.opAsync(progress: new Progress(sentSynchronously => 2056 { 2057 cb.sent(sentSynchronously); 2058 })).Wait(); 2059 cb.check(); 2060 } 2061 } 2062 output.WriteLine("ok"); 2063 2064 output.Write("testing batch requests with proxy... "); 2065 output.Flush(); 2066 { 2067 test(p.ice_batchOneway().begin_ice_flushBatchRequests().sentSynchronously()); 2068 2069 Cookie cookie = new Cookie(5); 2070 2071 { 2072 // 2073 // AsyncResult. 2074 // 2075 test(p.opBatchCount() == 0); 2076 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2077 Ice.AsyncResult r = b1.begin_opBatch(); 2078 test(r.IsCompleted); 2079 test(!r.isSent()); 2080 b1.opBatch(); 2081 FlushCallback cb = new FlushCallback(cookie); 2082 r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie); 2083 r.whenSent(cb.sentAsync); 2084 cb.check(); 2085 test(r.isSent()); 2086 test(r.IsCompleted); 2087 test(p.waitForBatch(2)); 2088 } 2089 2090 if(p.ice_getConnection() != null) 2091 { 2092 // 2093 // AsyncResult exception. 2094 // 2095 test(p.opBatchCount() == 0); 2096 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2097 b1.opBatch(); 2098 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2099 FlushCallback cb = new FlushCallback(cookie); 2100 Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie); 2101 r.whenSent(cb.sentAsync); 2102 cb.check(); 2103 test(r.isSent()); 2104 test(r.IsCompleted); 2105 test(p.waitForBatch(1)); 2106 } 2107 2108 { 2109 // 2110 // Type-safe. 2111 // 2112 test(p.opBatchCount() == 0); 2113 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2114 b1.opBatch(); 2115 b1.opBatch(); 2116 FlushCallback cb = new FlushCallback(); 2117 Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); 2118 r.whenCompleted(cb.exception); 2119 r.whenSent(cb.sent); 2120 cb.check(); 2121 test(r.isSent()); 2122 test(r.IsCompleted); 2123 test(p.waitForBatch(2)); 2124 } 2125 2126 if(p.ice_getConnection() != null) 2127 { 2128 // 2129 // Type-safe exception. 2130 // 2131 test(p.opBatchCount() == 0); 2132 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2133 b1.opBatch(); 2134 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2135 FlushCallback cb = new FlushCallback(); 2136 Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); 2137 r.whenCompleted(cb.exception); 2138 r.whenSent(cb.sent); 2139 cb.check(); 2140 test(r.isSent()); 2141 test(r.IsCompleted); 2142 test(p.waitForBatch(1)); 2143 } 2144 } 2145 output.WriteLine("ok"); 2146 2147 output.Write("testing batch requests with proxy and async tasks... "); 2148 output.Flush(); 2149 { 2150 { 2151 FlushCallback cb = new FlushCallback(); 2152 Task t = p.ice_batchOneway().ice_flushBatchRequestsAsync( 2153 progress: new Progress(sentSynchronously => 2154 { 2155 cb.sent(sentSynchronously); 2156 })); 2157 cb.check(); 2158 t.Wait(); 2159 } 2160 2161 { 2162 test(p.opBatchCount() == 0); 2163 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2164 b1.opBatch(); 2165 var bf = b1.opBatchAsync(); 2166 test(bf.IsCompleted); 2167 FlushCallback cb = new FlushCallback(); 2168 Task t = b1.ice_flushBatchRequestsAsync( 2169 progress: new Progress(sentSynchronously => 2170 { 2171 cb.sent(sentSynchronously); 2172 })); 2173 2174 cb.check(); 2175 t.Wait(); 2176 test(p.waitForBatch(2)); 2177 } 2178 2179 if(p.ice_getConnection() != null) 2180 { 2181 test(p.opBatchCount() == 0); 2182 Test.TestIntfPrx b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2183 b1.opBatch(); 2184 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2185 FlushCallback cb = new FlushCallback(); 2186 Task t = b1.ice_flushBatchRequestsAsync( 2187 progress: new Progress(sentSynchronously => 2188 { 2189 cb.sent(sentSynchronously); 2190 })); 2191 cb.check(); 2192 t.Wait(); 2193 test(p.waitForBatch(1)); 2194 } 2195 } 2196 output.WriteLine("ok"); 2197 2198 output.Write("testing batch requests with proxy and lambda... "); 2199 output.Flush(); 2200 { 2201 test(p.ice_batchOneway().begin_ice_flushBatchRequests().sentSynchronously()); 2202 2203 Cookie cookie = new Cookie(5); 2204 2205 { 2206 // 2207 // AsyncResult. 2208 // 2209 test(p.opBatchCount() == 0); 2210 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2211 b1.opBatch(); 2212 b1.opBatch(); 2213 FlushCallback cb = new FlushCallback(cookie); 2214 Ice.AsyncResult r = b1.begin_ice_flushBatchRequests( 2215 (Ice.AsyncResult result) => 2216 { 2217 cb.completedAsync(result); 2218 }, cookie); 2219 r.whenSent( 2220 (Ice.AsyncResult result) => 2221 { 2222 cb.sentAsync(result); 2223 }); 2224 cb.check(); 2225 test(r.isSent()); 2226 test(r.IsCompleted); 2227 test(p.waitForBatch(2)); 2228 2229 FlushCallback cb2 = new FlushCallback(cookie); 2230 Ice.AsyncResult r2 = b1.begin_ice_flushBatchRequests( 2231 (Ice.AsyncResult result) => 2232 { 2233 cb2.completedAsync(result); 2234 }, cookie); 2235 r2.whenSent( 2236 (Ice.AsyncResult result) => 2237 { 2238 cb2.sentAsync(result); 2239 }); 2240 cb2.check(); 2241 test(r2.isSent()); 2242 test(r2.IsCompleted); 2243 } 2244 2245 if(p.ice_getConnection() != null) 2246 { 2247 // 2248 // AsyncResult exception. 2249 // 2250 test(p.opBatchCount() == 0); 2251 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2252 b1.opBatch(); 2253 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2254 FlushCallback cb = new FlushCallback(cookie); 2255 Ice.AsyncResult r = b1.begin_ice_flushBatchRequests( 2256 (Ice.AsyncResult result) => 2257 { 2258 cb.completedAsync(result); 2259 }, cookie); 2260 r.whenSent( 2261 (Ice.AsyncResult result) => 2262 { 2263 cb.sentAsync(result); 2264 }); 2265 cb.check(); 2266 test(r.isSent()); 2267 test(r.IsCompleted); 2268 test(p.waitForBatch(1)); 2269 } 2270 2271 { 2272 // 2273 // Type-safe. 2274 // 2275 test(p.opBatchCount() == 0); 2276 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2277 b1.opBatch(); 2278 b1.opBatch(); 2279 FlushCallback cb = new FlushCallback(); 2280 Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); 2281 r.whenCompleted( 2282 (Ice.Exception ex) => 2283 { 2284 cb.exception(ex); 2285 }); 2286 r.whenSent( 2287 (bool sentSynchronously) => 2288 { 2289 cb.sent(sentSynchronously); 2290 }); 2291 cb.check(); 2292 test(r.isSent()); 2293 test(r.IsCompleted); 2294 test(p.waitForBatch(2)); 2295 } 2296 2297 if(p.ice_getConnection() != null) 2298 { 2299 // 2300 // Type-safe exception. 2301 // 2302 test(p.opBatchCount() == 0); 2303 var b1 =(Test.TestIntfPrx)p.ice_batchOneway(); 2304 b1.opBatch(); 2305 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2306 FlushCallback cb = new FlushCallback(); 2307 Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); 2308 r.whenCompleted( 2309 (Ice.Exception ex) => 2310 { 2311 cb.exception(ex); 2312 }); 2313 r.whenSent( 2314 (bool sentSynchronously) => 2315 { 2316 cb.sent(sentSynchronously); 2317 }); 2318 cb.check(); 2319 test(r.isSent()); 2320 test(r.IsCompleted); 2321 test(p.waitForBatch(1)); 2322 } 2323 } 2324 output.WriteLine("ok"); 2325 2326 if(p.ice_getConnection() != null) 2327 { 2328 output.Write("testing batch requests with connection... "); 2329 output.Flush(); 2330 { 2331 { 2332 // 2333 // Async task. 2334 // 2335 test(p.opBatchCount() == 0); 2336 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2337 p.ice_getIdentity()).ice_batchOneway()); 2338 b1.opBatch(); 2339 b1.opBatch(); 2340 SentCallback cb = new SentCallback(); 2341 Task t = b1.ice_getConnection().flushBatchRequestsAsync( 2342 Ice.CompressBatch.BasedOnProxy, 2343 progress: new Progress( 2344 sentSyncrhonously => 2345 { 2346 cb.sent(sentSyncrhonously); 2347 })); 2348 2349 cb.check(); 2350 t.Wait(); 2351 test(t.IsCompleted); 2352 test(p.waitForBatch(2)); 2353 } 2354 2355 { 2356 // 2357 // Async task exception. 2358 // 2359 test(p.opBatchCount() == 0); 2360 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2361 p.ice_getIdentity()).ice_batchOneway()); 2362 b1.opBatch(); 2363 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2364 Task t = b1.ice_getConnection().flushBatchRequestsAsync( 2365 Ice.CompressBatch.BasedOnProxy, 2366 progress: new Progress( 2367 sentSynchronously => 2368 { 2369 test(false); 2370 })); 2371 try 2372 { 2373 t.Wait(); 2374 test(false); 2375 } 2376 catch(System.AggregateException) 2377 { 2378 } 2379 test(p.opBatchCount() == 0); 2380 } 2381 2382 Cookie cookie = new Cookie(5); 2383 2384 { 2385 // 2386 // AsyncResult. 2387 // 2388 test(p.opBatchCount() == 0); 2389 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2390 p.ice_getIdentity()).ice_batchOneway()); 2391 b1.opBatch(); 2392 b1.opBatch(); 2393 FlushCallback cb = new FlushCallback(cookie); 2394 Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests( 2395 Ice.CompressBatch.BasedOnProxy, 2396 cb.completedAsync, 2397 cookie); 2398 r.whenSent(cb.sentAsync); 2399 cb.check(); 2400 test(r.isSent()); 2401 test(r.IsCompleted); 2402 test(p.waitForBatch(2)); 2403 } 2404 2405 { 2406 // 2407 // AsyncResult exception. 2408 // 2409 test(p.opBatchCount() == 0); 2410 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2411 p.ice_getIdentity()).ice_batchOneway()); 2412 b1.opBatch(); 2413 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2414 FlushExCallback cb = new FlushExCallback(cookie); 2415 Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests( 2416 Ice.CompressBatch.BasedOnProxy, 2417 cb.completedAsync, 2418 cookie); 2419 r.whenSent(cb.sentAsync); 2420 cb.check(); 2421 test(!r.isSent()); 2422 test(r.IsCompleted); 2423 test(p.opBatchCount() == 0); 2424 } 2425 2426 { 2427 // 2428 // Type-safe. 2429 // 2430 test(p.opBatchCount() == 0); 2431 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2432 p.ice_getIdentity()).ice_batchOneway()); 2433 b1.opBatch(); 2434 b1.opBatch(); 2435 FlushCallback cb = new FlushCallback(); 2436 Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2437 r.whenCompleted(cb.exception); 2438 r.whenSent(cb.sent); 2439 cb.check(); 2440 test(r.isSent()); 2441 test(r.IsCompleted); 2442 test(p.waitForBatch(2)); 2443 } 2444 2445 { 2446 // 2447 // Type-safe exception. 2448 // 2449 test(p.opBatchCount() == 0); 2450 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2451 p.ice_getIdentity()).ice_batchOneway()); 2452 b1.opBatch(); 2453 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2454 FlushExCallback cb = new FlushExCallback(); 2455 Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2456 r.whenCompleted(cb.exception); 2457 r.whenSent(cb.sent); 2458 cb.check(); 2459 test(!r.isSent()); 2460 test(r.IsCompleted); 2461 test(p.opBatchCount() == 0); 2462 } 2463 } 2464 output.WriteLine("ok"); 2465 } 2466 2467 if(p.ice_getConnection() != null) 2468 { 2469 output.Write("testing batch requests with connection and lambda... "); 2470 output.Flush(); 2471 { 2472 Cookie cookie = new Cookie(5); 2473 2474 { 2475 // 2476 // AsyncResult. 2477 // 2478 test(p.opBatchCount() == 0); 2479 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2480 p.ice_getIdentity()).ice_batchOneway()); 2481 b1.opBatch(); 2482 b1.opBatch(); 2483 FlushCallback cb = new FlushCallback(cookie); 2484 Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests( 2485 Ice.CompressBatch.BasedOnProxy, 2486 (Ice.AsyncResult result) => 2487 { 2488 cb.completedAsync(result); 2489 }, cookie); 2490 r.whenSent( 2491 (Ice.AsyncResult result) => 2492 { 2493 cb.sentAsync(result); 2494 }); 2495 cb.check(); 2496 test(r.isSent()); 2497 test(r.IsCompleted); 2498 test(p.waitForBatch(2)); 2499 } 2500 2501 { 2502 // 2503 // AsyncResult exception. 2504 // 2505 test(p.opBatchCount() == 0); 2506 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2507 p.ice_getIdentity()).ice_batchOneway()); 2508 b1.opBatch(); 2509 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2510 FlushExCallback cb = new FlushExCallback(cookie); 2511 Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests( 2512 Ice.CompressBatch.BasedOnProxy, 2513 (Ice.AsyncResult result) => 2514 { 2515 cb.completedAsync(result); 2516 }, cookie); 2517 r.whenSent( 2518 (Ice.AsyncResult result) => 2519 { 2520 cb.sentAsync(result); 2521 }); 2522 cb.check(); 2523 test(!r.isSent()); 2524 test(r.IsCompleted); 2525 test(p.opBatchCount() == 0); 2526 } 2527 2528 { 2529 // 2530 // Type-safe. 2531 // 2532 test(p.opBatchCount() == 0); 2533 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2534 p.ice_getIdentity()).ice_batchOneway()); 2535 b1.opBatch(); 2536 b1.opBatch(); 2537 FlushCallback cb = new FlushCallback(); 2538 Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2539 r.whenCompleted( 2540 (Ice.Exception ex) => 2541 { 2542 cb.exception(ex); 2543 }); 2544 r.whenSent( 2545 (bool sentSynchronously) => 2546 { 2547 cb.sent(sentSynchronously); 2548 }); 2549 cb.check(); 2550 test(r.isSent()); 2551 test(r.IsCompleted); 2552 test(p.waitForBatch(2)); 2553 } 2554 2555 { 2556 // 2557 // Type-safe exception. 2558 // 2559 test(p.opBatchCount() == 0); 2560 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2561 p.ice_getIdentity()).ice_batchOneway()); 2562 b1.opBatch(); 2563 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2564 FlushExCallback cb = new FlushExCallback(); 2565 Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2566 r.whenCompleted( 2567 (Ice.Exception ex) => 2568 { 2569 cb.exception(ex); 2570 }); 2571 r.whenSent( 2572 (bool sentSynchronously) => 2573 { 2574 cb.sent(sentSynchronously); 2575 }); 2576 cb.check(); 2577 test(!r.isSent()); 2578 test(r.IsCompleted); 2579 test(p.opBatchCount() == 0); 2580 } 2581 } 2582 output.WriteLine("ok"); 2583 2584 output.Write("testing batch requests with communicator... "); 2585 output.Flush(); 2586 { 2587 { 2588 // 2589 // Async task - 1 connection. 2590 // 2591 test(p.opBatchCount() == 0); 2592 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2593 p.ice_getIdentity()).ice_batchOneway()); 2594 b1.opBatch(); 2595 b1.opBatch(); 2596 2597 SentCallback cb = new SentCallback(); 2598 Task t = communicator.flushBatchRequestsAsync( 2599 Ice.CompressBatch.BasedOnProxy, 2600 progress: new Progress( 2601 sentSynchronously => 2602 { 2603 cb.sent(sentSynchronously); 2604 })); 2605 cb.check(); 2606 t.Wait(); 2607 test(t.IsCompleted); 2608 test(p.waitForBatch(2)); 2609 } 2610 2611 { 2612 // 2613 // Async task exception - 1 connection. 2614 // 2615 test(p.opBatchCount() == 0); 2616 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2617 p.ice_getIdentity()).ice_batchOneway()); 2618 b1.opBatch(); 2619 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2620 SentCallback cb = new SentCallback(); 2621 Task t = communicator.flushBatchRequestsAsync( 2622 Ice.CompressBatch.BasedOnProxy, 2623 progress: new Progress( 2624 sentSynchronously => 2625 { 2626 cb.sent(sentSynchronously); 2627 })); 2628 cb.check(); // Exceptions are ignored! 2629 t.Wait(); 2630 test(t.IsCompleted); 2631 test(p.opBatchCount() == 0); 2632 } 2633 2634 { 2635 // 2636 // Async task - 2 connections. 2637 // 2638 test(p.opBatchCount() == 0); 2639 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2640 p.ice_getIdentity()).ice_batchOneway()); 2641 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2642 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2643 2644 b2.ice_getConnection(); // Ensure connection is established. 2645 b1.opBatch(); 2646 b1.opBatch(); 2647 b2.opBatch(); 2648 b2.opBatch(); 2649 2650 SentCallback cb = new SentCallback(); 2651 Task t = communicator.flushBatchRequestsAsync( 2652 Ice.CompressBatch.BasedOnProxy, 2653 new Progress(sentSynchronously => 2654 { 2655 cb.sent(sentSynchronously); 2656 })); 2657 cb.check(); 2658 t.Wait(); 2659 test(t.IsCompleted); 2660 test(p.waitForBatch(4)); 2661 } 2662 2663 { 2664 // 2665 // AsyncResult exception - 2 connections - 1 failure. 2666 // 2667 // All connections should be flushed even if there are failures on some connections. 2668 // Exceptions should not be reported. 2669 // 2670 test(p.opBatchCount() == 0); 2671 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2672 p.ice_getIdentity()).ice_batchOneway()); 2673 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2674 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2675 b2.ice_getConnection(); // Ensure connection is established. 2676 b1.opBatch(); 2677 b2.opBatch(); 2678 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2679 SentCallback cb = new SentCallback(); 2680 Task t = communicator.flushBatchRequestsAsync( 2681 Ice.CompressBatch.BasedOnProxy, 2682 new Progress( 2683 sentSynchronously => 2684 { 2685 cb.sent(sentSynchronously); 2686 })); 2687 cb.check(); // Exceptions are ignored! 2688 t.Wait(); 2689 test(t.IsCompleted); 2690 test(p.waitForBatch(1)); 2691 } 2692 2693 { 2694 // 2695 // Async task exception - 2 connections - 2 failures. 2696 // 2697 // The sent callback should be invoked even if all connections fail. 2698 // 2699 test(p.opBatchCount() == 0); 2700 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2701 p.ice_getIdentity()).ice_batchOneway()); 2702 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2703 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2704 b2.ice_getConnection(); // Ensure connection is established. 2705 b1.opBatch(); 2706 b2.opBatch(); 2707 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2708 b2.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2709 SentCallback cb = new SentCallback(); 2710 Task t = communicator.flushBatchRequestsAsync( 2711 Ice.CompressBatch.BasedOnProxy, 2712 new Progress( 2713 sentSynchronously => 2714 { 2715 cb.sent(sentSynchronously); 2716 })); 2717 cb.check(); // Exceptions are ignored! 2718 t.Wait(); 2719 test(t.IsCompleted); 2720 test(p.opBatchCount() == 0); 2721 } 2722 2723 Cookie cookie = new Cookie(5); 2724 2725 { 2726 // 2727 // AsyncResult - 1 connection. 2728 // 2729 test(p.opBatchCount() == 0); 2730 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2731 p.ice_getIdentity()).ice_batchOneway()); 2732 b1.opBatch(); 2733 b1.opBatch(); 2734 FlushCallback cb = new FlushCallback(cookie); 2735 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy, 2736 cb.completedAsync, 2737 cookie); 2738 r.whenSent(cb.sentAsync); 2739 cb.check(); 2740 test(r.isSent()); 2741 test(r.IsCompleted); 2742 test(p.waitForBatch(2)); 2743 } 2744 2745 { 2746 // 2747 // AsyncResult exception - 1 connection. 2748 // 2749 test(p.opBatchCount() == 0); 2750 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2751 p.ice_getIdentity()).ice_batchOneway()); 2752 b1.opBatch(); 2753 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2754 FlushCallback cb = new FlushCallback(cookie); 2755 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy, 2756 cb.completedAsync, 2757 cookie); 2758 r.whenSent(cb.sentAsync); 2759 cb.check(); 2760 test(r.isSent()); // Exceptions are ignored! 2761 test(r.IsCompleted); 2762 test(p.opBatchCount() == 0); 2763 } 2764 2765 { 2766 // 2767 // AsyncResult - 2 connections. 2768 // 2769 test(p.opBatchCount() == 0); 2770 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2771 p.ice_getIdentity()).ice_batchOneway()); 2772 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2773 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2774 2775 b2.ice_getConnection(); // Ensure connection is established. 2776 b1.opBatch(); 2777 b1.opBatch(); 2778 b2.opBatch(); 2779 b2.opBatch(); 2780 FlushCallback cb = new FlushCallback(cookie); 2781 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy, 2782 cb.completedAsync, 2783 cookie); 2784 r.whenSent(cb.sentAsync); 2785 cb.check(); 2786 test(r.isSent()); 2787 test(r.IsCompleted); 2788 test(p.waitForBatch(4)); 2789 } 2790 2791 { 2792 // 2793 // AsyncResult exception - 2 connections - 1 failure. 2794 // 2795 // All connections should be flushed even if there are failures on some connections. 2796 // Exceptions should not be reported. 2797 // 2798 test(p.opBatchCount() == 0); 2799 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2800 p.ice_getIdentity()).ice_batchOneway()); 2801 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2802 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2803 b2.ice_getConnection(); // Ensure connection is established. 2804 b1.opBatch(); 2805 b2.opBatch(); 2806 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2807 var cb = new FlushCallback(cookie); 2808 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy, 2809 cb.completedAsync, 2810 cookie); 2811 r.whenSent(cb.sentAsync); 2812 cb.check(); 2813 test(r.isSent()); // Exceptions are ignored! 2814 test(r.IsCompleted); 2815 test(p.waitForBatch(1)); 2816 } 2817 2818 { 2819 // 2820 // AsyncResult exception - 2 connections - 2 failures. 2821 // 2822 // The sent callback should be invoked even if all connections fail. 2823 // 2824 test(p.opBatchCount() == 0); 2825 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2826 p.ice_getIdentity()).ice_batchOneway()); 2827 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2828 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2829 b2.ice_getConnection(); // Ensure connection is established. 2830 b1.opBatch(); 2831 b2.opBatch(); 2832 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2833 b2.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2834 FlushCallback cb = new FlushCallback(cookie); 2835 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy, 2836 cb.completedAsync, 2837 cookie); 2838 r.whenSent(cb.sentAsync); 2839 cb.check(); 2840 test(r.isSent()); // Exceptions are ignored! 2841 test(r.IsCompleted); 2842 test(p.opBatchCount() == 0); 2843 } 2844 2845 { 2846 // 2847 // Type-safe - 1 connection. 2848 // 2849 test(p.opBatchCount() == 0); 2850 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2851 p.ice_getIdentity()).ice_batchOneway()); 2852 b1.opBatch(); 2853 b1.opBatch(); 2854 FlushCallback cb = new FlushCallback(); 2855 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2856 r.whenCompleted(cb.exception); 2857 r.whenSent(cb.sent); 2858 cb.check(); 2859 test(r.isSent()); 2860 test(r.IsCompleted); 2861 test(p.waitForBatch(2)); 2862 } 2863 2864 { 2865 // 2866 // Type-safe exception - 1 connection. 2867 // 2868 test(p.opBatchCount() == 0); 2869 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2870 p.ice_getIdentity()).ice_batchOneway()); 2871 b1.opBatch(); 2872 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2873 FlushCallback cb = new FlushCallback(); 2874 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2875 r.whenCompleted(cb.exception); 2876 r.whenSent(cb.sent); 2877 cb.check(); 2878 test(r.isSent()); // Exceptions are ignored! 2879 test(r.IsCompleted); 2880 test(p.opBatchCount() == 0); 2881 } 2882 2883 { 2884 // 2885 // 2 connections. 2886 // 2887 test(p.opBatchCount() == 0); 2888 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2889 p.ice_getIdentity()).ice_batchOneway()); 2890 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2891 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2892 b2.ice_getConnection(); // Ensure connection is established. 2893 b1.opBatch(); 2894 b1.opBatch(); 2895 b2.opBatch(); 2896 b2.opBatch(); 2897 FlushCallback cb = new FlushCallback(); 2898 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2899 r.whenCompleted(cb.exception); 2900 r.whenSent(cb.sent); 2901 cb.check(); 2902 test(r.isSent()); 2903 test(r.IsCompleted); 2904 test(p.waitForBatch(4)); 2905 } 2906 2907 { 2908 // 2909 // Exception - 2 connections - 1 failure. 2910 // 2911 // All connections should be flushed even if there are failures on some connections. 2912 // Exceptions should not be reported. 2913 // 2914 test(p.opBatchCount() == 0); 2915 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2916 p.ice_getIdentity()).ice_batchOneway()); 2917 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2918 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2919 b2.ice_getConnection(); // Ensure connection is established. 2920 b1.opBatch(); 2921 b2.opBatch(); 2922 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2923 FlushCallback cb = new FlushCallback(); 2924 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2925 r.whenCompleted(cb.exception); 2926 r.whenSent(cb.sent); 2927 cb.check(); 2928 test(r.isSent()); // Exceptions are ignored! 2929 test(r.IsCompleted); 2930 test(p.waitForBatch(1)); 2931 } 2932 2933 { 2934 // 2935 // Exception - 2 connections - 2 failures. 2936 // 2937 // The sent callback should be invoked even if all connections fail. 2938 // 2939 test(p.opBatchCount() == 0); 2940 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2941 p.ice_getIdentity()).ice_batchOneway()); 2942 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 2943 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 2944 b2.ice_getConnection(); // Ensure connection is established. 2945 b1.opBatch(); 2946 b2.opBatch(); 2947 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2948 b2.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 2949 FlushCallback cb = new FlushCallback(); 2950 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 2951 r.whenCompleted(cb.exception); 2952 r.whenSent(cb.sent); 2953 cb.check(); 2954 test(r.isSent()); // Exceptions are ignored! 2955 test(r.IsCompleted); 2956 test(p.opBatchCount() == 0); 2957 } 2958 } 2959 output.WriteLine("ok"); 2960 2961 output.Write("testing batch requests with communicator with lambda... "); 2962 output.Flush(); 2963 { 2964 Cookie cookie = new Cookie(5); 2965 2966 { 2967 // 2968 // AsyncResult - 1 connection. 2969 // 2970 test(p.opBatchCount() == 0); 2971 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2972 p.ice_getIdentity()).ice_batchOneway()); 2973 b1.opBatch(); 2974 b1.opBatch(); 2975 FlushCallback cb = new FlushCallback(cookie); 2976 Ice.AsyncResult r = communicator.begin_flushBatchRequests( 2977 Ice.CompressBatch.BasedOnProxy, 2978 (Ice.AsyncResult result) => 2979 { 2980 cb.completedAsync(result); 2981 }, cookie); 2982 r.whenSent( 2983 (Ice.AsyncResult result) => 2984 { 2985 cb.sentAsync(result); 2986 }); 2987 cb.check(); 2988 test(r.isSent()); 2989 test(r.IsCompleted); 2990 test(p.waitForBatch(2)); 2991 } 2992 2993 { 2994 // 2995 // AsyncResult exception - 1 connection. 2996 // 2997 test(p.opBatchCount() == 0); 2998 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 2999 p.ice_getIdentity()).ice_batchOneway()); 3000 b1.opBatch(); 3001 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 3002 FlushCallback cb = new FlushCallback(cookie); 3003 Ice.AsyncResult r = communicator.begin_flushBatchRequests( 3004 Ice.CompressBatch.BasedOnProxy, 3005 (Ice.AsyncResult result) => 3006 { 3007 cb.completedAsync(result); 3008 }, cookie); 3009 r.whenSent( 3010 (Ice.AsyncResult result) => 3011 { 3012 cb.sentAsync(result); 3013 }); 3014 cb.check(); 3015 test(r.isSent()); // Exceptions are ignored! 3016 test(r.IsCompleted); 3017 test(p.opBatchCount() == 0); 3018 } 3019 3020 { 3021 // 3022 // AsyncResult - 2 connections. 3023 // 3024 test(p.opBatchCount() == 0); 3025 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 3026 p.ice_getIdentity()).ice_batchOneway()); 3027 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 3028 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3029 b2.ice_getConnection(); // Ensure connection is established. 3030 b1.opBatch(); 3031 b1.opBatch(); 3032 b2.opBatch(); 3033 b2.opBatch(); 3034 FlushCallback cb = new FlushCallback(cookie); 3035 Ice.AsyncResult r = communicator.begin_flushBatchRequests( 3036 Ice.CompressBatch.BasedOnProxy, 3037 (Ice.AsyncResult result) => 3038 { 3039 cb.completedAsync(result); 3040 }, cookie); 3041 r.whenSent( 3042 (Ice.AsyncResult result) => 3043 { 3044 cb.sentAsync(result); 3045 }); 3046 cb.check(); 3047 test(r.isSent()); 3048 test(r.IsCompleted); 3049 test(p.waitForBatch(4)); 3050 } 3051 3052 { 3053 // 3054 // AsyncResult exception - 2 connections - 1 failure. 3055 // 3056 // All connections should be flushed even if there are failures on some connections. 3057 // Exceptions should not be reported. 3058 // 3059 test(p.opBatchCount() == 0); 3060 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 3061 p.ice_getIdentity()).ice_batchOneway()); 3062 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 3063 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3064 b2.ice_getConnection(); // Ensure connection is established. 3065 b1.opBatch(); 3066 b2.opBatch(); 3067 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 3068 FlushCallback cb = new FlushCallback(cookie); 3069 Ice.AsyncResult r = communicator.begin_flushBatchRequests( 3070 Ice.CompressBatch.BasedOnProxy, 3071 (Ice.AsyncResult result) => 3072 { 3073 cb.completedAsync(result); 3074 }, cookie); 3075 r.whenSent( 3076 (Ice.AsyncResult result) => 3077 { 3078 cb.sentAsync(result); 3079 }); 3080 cb.check(); 3081 test(r.isSent()); // Exceptions are ignored! 3082 test(r.IsCompleted); 3083 test(p.waitForBatch(1)); 3084 } 3085 3086 { 3087 // 3088 // AsyncResult exception - 2 connections - 2 failures. 3089 // 3090 // The sent callback should be invoked even if all connections fail. 3091 // 3092 test(p.opBatchCount() == 0); 3093 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 3094 p.ice_getIdentity()).ice_batchOneway()); 3095 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 3096 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3097 b2.ice_getConnection(); // Ensure connection is established. 3098 b1.opBatch(); 3099 b2.opBatch(); 3100 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 3101 b2.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 3102 FlushCallback cb = new FlushCallback(cookie); 3103 Ice.AsyncResult r = communicator.begin_flushBatchRequests( 3104 Ice.CompressBatch.BasedOnProxy, 3105 (Ice.AsyncResult result) => 3106 { 3107 cb.completedAsync(result); 3108 }, cookie); 3109 r.whenSent( 3110 (Ice.AsyncResult result) => 3111 { 3112 cb.sentAsync(result); 3113 }); 3114 cb.check(); 3115 test(r.isSent()); // Exceptions are ignored! 3116 test(r.IsCompleted); 3117 test(p.opBatchCount() == 0); 3118 } 3119 3120 { 3121 // 3122 // Type-safe - 1 connection. 3123 // 3124 test(p.opBatchCount() == 0); 3125 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 3126 p.ice_getIdentity()).ice_batchOneway()); 3127 b1.opBatch(); 3128 b1.opBatch(); 3129 FlushCallback cb = new FlushCallback(); 3130 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 3131 r.whenCompleted( 3132 (Ice.Exception ex) => 3133 { 3134 cb.exception(ex); 3135 }); 3136 r.whenSent( 3137 (bool sentSynchronously) => 3138 { 3139 cb.sent(sentSynchronously); 3140 }); 3141 cb.check(); 3142 test(r.isSent()); 3143 test(r.IsCompleted); 3144 test(p.waitForBatch(2)); 3145 } 3146 3147 { 3148 // 3149 // Type-safe exception - 1 connection. 3150 // 3151 test(p.opBatchCount() == 0); 3152 var b1 = Test.TestIntfPrxHelper.uncheckedCast(p.ice_getConnection().createProxy( 3153 p.ice_getIdentity()).ice_batchOneway()); 3154 b1.opBatch(); 3155 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 3156 FlushCallback cb = new FlushCallback(); 3157 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 3158 r.whenCompleted( 3159 (Ice.Exception ex) => 3160 { 3161 cb.exception(ex); 3162 }); 3163 r.whenSent( 3164 (bool sentSynchronously) => 3165 { 3166 cb.sent(sentSynchronously); 3167 }); 3168 cb.check(); 3169 test(r.isSent()); // Exceptions are ignored! 3170 test(r.IsCompleted); 3171 test(p.opBatchCount() == 0); 3172 } 3173 3174 { 3175 // 3176 // 2 connections. 3177 // 3178 test(p.opBatchCount() == 0); 3179 var b1 = Test.TestIntfPrxHelper.uncheckedCast( 3180 p.ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3181 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 3182 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3183 b2.ice_getConnection(); // Ensure connection is established. 3184 b1.opBatch(); 3185 b1.opBatch(); 3186 b2.opBatch(); 3187 b2.opBatch(); 3188 FlushCallback cb = new FlushCallback(); 3189 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 3190 r.whenCompleted( 3191 (Ice.Exception ex) => 3192 { 3193 cb.exception(ex); 3194 }); 3195 r.whenSent( 3196 (bool sentSynchronously) => 3197 { 3198 cb.sent(sentSynchronously); 3199 }); 3200 cb.check(); 3201 test(r.isSent()); 3202 test(r.IsCompleted); 3203 test(p.waitForBatch(4)); 3204 } 3205 3206 { 3207 // 3208 // Exception - 2 connections - 1 failure. 3209 // 3210 // All connections should be flushed even if there are failures on some connections. 3211 // Exceptions should not be reported. 3212 // 3213 test(p.opBatchCount() == 0); 3214 var b1 = Test.TestIntfPrxHelper.uncheckedCast( 3215 p.ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3216 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 3217 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3218 b2.ice_getConnection(); // Ensure connection is established. 3219 b1.opBatch(); 3220 b2.opBatch(); 3221 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 3222 FlushCallback cb = new FlushCallback(); 3223 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 3224 r.whenCompleted( 3225 (Ice.Exception ex) => 3226 { 3227 cb.exception(ex); 3228 }); 3229 r.whenSent( 3230 (bool sentSynchronously) => 3231 { 3232 cb.sent(sentSynchronously); 3233 }); 3234 cb.check(); 3235 test(r.isSent()); // Exceptions are ignored! 3236 test(r.IsCompleted); 3237 test(p.waitForBatch(1)); 3238 } 3239 3240 { 3241 // 3242 // Exception - 2 connections - 2 failures. 3243 // 3244 // The sent callback should be invoked even if all connections fail. 3245 // 3246 test(p.opBatchCount() == 0); 3247 var b1 = Test.TestIntfPrxHelper.uncheckedCast( 3248 p.ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3249 var b2 = Test.TestIntfPrxHelper.uncheckedCast( 3250 p.ice_connectionId("2").ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway()); 3251 b2.ice_getConnection(); // Ensure connection is established. 3252 b1.opBatch(); 3253 b2.opBatch(); 3254 b1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 3255 b2.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); 3256 FlushCallback cb = new FlushCallback(); 3257 Ice.AsyncResult r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 3258 r.whenCompleted( 3259 (Ice.Exception ex) => 3260 { 3261 cb.exception(ex); 3262 }); 3263 r.whenSent( 3264 (bool sentSynchronously) => 3265 { 3266 cb.sent(sentSynchronously); 3267 }); 3268 cb.check(); 3269 test(r.isSent()); // Exceptions are ignored! 3270 test(r.IsCompleted); 3271 test(p.opBatchCount() == 0); 3272 } 3273 } 3274 output.WriteLine("ok"); 3275 } 3276 3277 output.Write("testing async/await... "); 3278 output.Flush(); 3279 Func<Task> task = async() => 3280 { 3281 try 3282 { 3283 await p.opAsync(); 3284 3285 var r = await p.opWithResultAsync(); 3286 test(r == 15); 3287 3288 try 3289 { 3290 await p.opWithUEAsync(); 3291 } 3292 catch(Test.TestIntfException) 3293 { 3294 } 3295 3296 // Operations implemented with amd and async. 3297 await p.opAsyncDispatchAsync(); 3298 3299 r = await p.opWithResultAsyncDispatchAsync(); 3300 test(r == 15); 3301 3302 try 3303 { 3304 await p.opWithUEAsyncDispatchAsync(); 3305 test(false); 3306 } 3307 catch(Test.TestIntfException) 3308 { 3309 } 3310 } 3311 catch(Ice.OperationNotExistException) 3312 { 3313 // Expected with cross testing, this opXxxAsyncDispatch methods are C# only. 3314 } 3315 }; 3316 task().Wait(); 3317 output.WriteLine("ok"); 3318 3319 if(p.ice_getConnection() != null) 3320 { 3321 output.Write("testing async Task cancellation... "); 3322 output.Flush(); 3323 { 3324 var cs1 = new CancellationTokenSource(); 3325 var cs2 = new CancellationTokenSource(); 3326 var cs3 = new CancellationTokenSource(); 3327 Task t1; 3328 Task t2; 3329 Task t3; 3330 try 3331 { 3332 testController.holdAdapter(); 3333 ProgresCallback cb = null; 3334 byte[] seq = new byte[10024]; 3335 for(int i = 0; i < 200; ++i) // 2MB 3336 { 3337 cb = new ProgresCallback(); 3338 p.opWithPayloadAsync(seq, progress: cb); 3339 } 3340 3341 test(!cb.Sent); 3342 3343 t1 = p.ice_pingAsync(cancel: cs1.Token); 3344 t2 = p.ice_pingAsync(cancel: cs2.Token); 3345 cs3.Cancel(); 3346 t3 = p.ice_pingAsync(cancel: cs3.Token); 3347 cs1.Cancel(); 3348 cs2.Cancel(); 3349 try 3350 { 3351 t1.Wait(); 3352 test(false); 3353 } 3354 catch(AggregateException ae) 3355 { 3356 ae.Handle(ex => 3357 { 3358 return ex is Ice.InvocationCanceledException; 3359 }); 3360 } 3361 try 3362 { 3363 t2.Wait(); 3364 test(false); 3365 } 3366 catch(AggregateException ae) 3367 { 3368 ae.Handle(ex => 3369 { 3370 return ex is Ice.InvocationCanceledException; 3371 }); 3372 } 3373 3374 try 3375 { 3376 t3.Wait(); 3377 test(false); 3378 } 3379 catch(AggregateException ae) 3380 { 3381 ae.Handle(ex => 3382 { 3383 return ex is Ice.InvocationCanceledException; 3384 }); 3385 } 3386 3387 } 3388 finally 3389 { 3390 testController.resumeAdapter(); 3391 p.ice_ping(); 3392 } 3393 } 3394 output.WriteLine("ok"); 3395 } 3396 3397 output.Write("testing AsyncResult operations... "); 3398 output.Flush(); 3399 { 3400 { 3401 testController.holdAdapter(); 3402 Ice.AsyncResult r1; 3403 Ice.AsyncResult r2; 3404 try 3405 { 3406 r1 = p.begin_op(); 3407 byte[] seq = new byte[10024]; 3408 (new System.Random()).NextBytes(seq); 3409 while((r2 = p.begin_opWithPayload(seq)).sentSynchronously()) ; 3410 3411 if(p.ice_getConnection() != null) 3412 { 3413 test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted_() || 3414 !r1.sentSynchronously() && !r1.isCompleted_()); 3415 3416 test(!r2.sentSynchronously() && !r2.isCompleted_()); 3417 3418 test(!r1.IsCompleted && !r1.CompletedSynchronously); 3419 test(!r2.IsCompleted && !r2.CompletedSynchronously); 3420 } 3421 } 3422 finally 3423 { 3424 testController.resumeAdapter(); 3425 } 3426 3427 WaitHandle w1 = r1.AsyncWaitHandle; 3428 WaitHandle w2 = r2.AsyncWaitHandle; 3429 3430 r1.waitForSent(); 3431 test(r1.isSent()); 3432 3433 r2.waitForSent(); 3434 test(r2.isSent()); 3435 3436 r1.waitForCompleted(); 3437 test(r1.isCompleted_()); 3438 w1.WaitOne(); 3439 3440 r2.waitForCompleted(); 3441 test(r2.isCompleted_()); 3442 w2.WaitOne(); 3443 3444 test(r1.getOperation().Equals("op")); 3445 test(r2.getOperation().Equals("opWithPayload")); 3446 } 3447 3448 { 3449 Ice.AsyncResult r; 3450 3451 // 3452 // Twoway 3453 // 3454 r = p.begin_ice_ping(); 3455 test(r.getOperation().Equals("ice_ping")); 3456 test(r.getConnection() == null); // Expected 3457 test(r.getCommunicator() == communicator); 3458 test(r.getProxy() == p); 3459 p.end_ice_ping(r); 3460 3461 Test.TestIntfPrx p2; 3462 3463 // 3464 // Oneway 3465 // 3466 p2 = p.ice_oneway() as Test.TestIntfPrx; 3467 r = p2.begin_ice_ping(); 3468 test(r.getOperation().Equals("ice_ping")); 3469 test(r.getConnection() == null); // Expected 3470 test(r.getCommunicator() == communicator); 3471 test(r.getProxy() == p2); 3472 3473 // 3474 // Batch request via proxy 3475 // 3476 p2 = p.ice_batchOneway() as Test.TestIntfPrx; 3477 p2.ice_ping(); 3478 r = p2.begin_ice_flushBatchRequests(); 3479 test(r.getConnection() == null); // Expected 3480 test(r.getCommunicator() == communicator); 3481 test(r.getProxy() == p2); 3482 p2.end_ice_flushBatchRequests(r); 3483 3484 if(p.ice_getConnection() != null) 3485 { 3486 // 3487 // Batch request via connection 3488 // 3489 Ice.Connection con = p.ice_getConnection(); 3490 p2 = p.ice_batchOneway() as Test.TestIntfPrx; 3491 p2.ice_ping(); 3492 r = con.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 3493 test(r.getConnection() == con); 3494 test(r.getCommunicator() == communicator); 3495 test(r.getProxy() == null); // Expected 3496 con.end_flushBatchRequests(r); 3497 3498 // 3499 // Batch request via communicator 3500 // 3501 p2 = p.ice_batchOneway() as Test.TestIntfPrx; 3502 p2.ice_ping(); 3503 r = communicator.begin_flushBatchRequests(Ice.CompressBatch.BasedOnProxy); 3504 test(r.getConnection() == null); // Expected 3505 test(r.getCommunicator() == communicator); 3506 test(r.getProxy() == null); // Expected 3507 communicator.end_flushBatchRequests(r); 3508 } 3509 } 3510 3511 if(p.ice_getConnection() != null) 3512 { 3513 Ice.AsyncResult r1 = null; 3514 Ice.AsyncResult r2 = null; 3515 testController.holdAdapter(); 3516 try 3517 { 3518 Ice.AsyncResult r = null; 3519 byte[] seq = new byte[10024]; 3520 for(int i = 0; i < 200; ++i) // 2MB 3521 { 3522 r = p.begin_opWithPayload(seq); 3523 } 3524 3525 test(!r.isSent()); 3526 3527 r1 = p.begin_ice_ping(); 3528 r2 = p.begin_ice_id(); 3529 r1.cancel(); 3530 r2.cancel(); 3531 try 3532 { 3533 p.end_ice_ping(r1); 3534 test(false); 3535 } 3536 catch(Ice.InvocationCanceledException) 3537 { 3538 } 3539 try 3540 { 3541 p.end_ice_id(r2); 3542 test(false); 3543 } 3544 catch(Ice.InvocationCanceledException) 3545 { 3546 } 3547 3548 } 3549 finally 3550 { 3551 testController.resumeAdapter(); 3552 p.ice_ping(); 3553 test(!r1.isSent() && r1.isCompleted_()); 3554 test(!r2.isSent() && r2.isCompleted_()); 3555 } 3556 3557 testController.holdAdapter(); 3558 try 3559 { 3560 r1 = p.begin_op(); 3561 r2 = p.begin_ice_id(); 3562 r1.waitForSent(); 3563 r2.waitForSent(); 3564 r1.cancel(); 3565 r2.cancel(); 3566 try 3567 { 3568 p.end_op(r1); 3569 test(false); 3570 } 3571 catch(Ice.InvocationCanceledException) 3572 { 3573 } 3574 try 3575 { 3576 p.end_ice_id(r2); 3577 test(false); 3578 } 3579 catch(Ice.InvocationCanceledException) 3580 { 3581 } 3582 } 3583 finally 3584 { 3585 testController.resumeAdapter(); 3586 } 3587 } 3588 } 3589 output.WriteLine("ok"); 3590 3591 if(p.ice_getConnection() != null && p.supportsAMD()) 3592 { 3593 output.Write("testing graceful close connection with wait... "); 3594 output.Flush(); 3595 { 3596 // 3597 // Local case: begin a request, close the connection gracefully, and make sure it waits 3598 // for the request to complete. 3599 // 3600 Ice.Connection con = p.ice_getConnection(); 3601 CallbackBase cb = new CallbackBase(); 3602 con.setCloseCallback(_ => 3603 { 3604 cb.called(); 3605 }); 3606 Task t = p.sleepAsync(100); 3607 con.close(Ice.ConnectionClose.GracefullyWithWait); 3608 t.Wait(); // Should complete successfully. 3609 cb.check(); 3610 } 3611 { 3612 // 3613 // Remote case. 3614 // 3615 byte[] seq = new byte[1024 * 10]; 3616 3617 // 3618 // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod. 3619 // The goal is to make sure that none of the opWithPayload fail even if the server closes 3620 // the connection gracefully in between. 3621 // 3622 int maxQueue = 2; 3623 bool done = false; 3624 while(!done && maxQueue < 50) 3625 { 3626 done = true; 3627 p.ice_ping(); 3628 List<Task> results = new List<Task>(); 3629 for(int i = 0; i < maxQueue; ++i) 3630 { 3631 results.Add(p.opWithPayloadAsync(seq)); 3632 } 3633 3634 ProgresCallback cb = new ProgresCallback(); 3635 p.closeAsync(Test.CloseMode.GracefullyWithWait, progress: cb); 3636 3637 if(!cb.SentSynchronously) 3638 { 3639 for(int i = 0; i < maxQueue; i++) 3640 { 3641 cb = new ProgresCallback(); 3642 Task t = p.opWithPayloadAsync(seq, progress: cb); 3643 results.Add(t); 3644 if(cb.SentSynchronously) 3645 { 3646 done = false; 3647 maxQueue *= 2; 3648 break; 3649 } 3650 } 3651 } 3652 else 3653 { 3654 maxQueue *= 2; 3655 done = false; 3656 } 3657 foreach(Task q in results) 3658 { 3659 q.Wait(); 3660 } 3661 } 3662 } 3663 output.WriteLine("ok"); 3664 3665 output.Write("testing graceful close connection without wait... "); 3666 output.Flush(); 3667 { 3668 // 3669 // Local case: start an operation and then close the connection gracefully on the client side 3670 // without waiting for the pending invocation to complete. There will be no retry and we expect the 3671 // invocation to fail with ConnectionManuallyClosedException. 3672 // 3673 p =(Test.TestIntfPrx)p.ice_connectionId("CloseGracefully"); // Start with a new connection. 3674 Ice.Connection con = p.ice_getConnection(); 3675 CallbackBase cb = new CallbackBase(); 3676 Task t = p.startDispatchAsync( 3677 progress: new Progress(sentSynchronously => 3678 { 3679 cb.called(); 3680 })); 3681 cb.check(); // Ensure the request was sent before we close the connection. 3682 con.close(Ice.ConnectionClose.Gracefully); 3683 try 3684 { 3685 t.Wait(); 3686 test(false); 3687 } 3688 catch(System.AggregateException ex) 3689 { 3690 test(ex.InnerException is Ice.ConnectionManuallyClosedException); 3691 test((ex.InnerException as Ice.ConnectionManuallyClosedException).graceful); 3692 } 3693 p.finishDispatch(); 3694 3695 // 3696 // Remote case: the server closes the connection gracefully, which means the connection 3697 // will not be closed until all pending dispatched requests have completed. 3698 // 3699 con = p.ice_getConnection(); 3700 cb = new CallbackBase(); 3701 con.setCloseCallback(_ => 3702 { 3703 cb.called(); 3704 }); 3705 t = p.sleepAsync(100); 3706 p.close(Test.CloseMode.Gracefully); // Close is delayed until sleep completes. 3707 cb.check(); 3708 t.Wait(); 3709 } 3710 output.WriteLine("ok"); 3711 3712 output.Write("testing forceful close connection... "); 3713 output.Flush(); 3714 { 3715 // 3716 // Local case: start an operation and then close the connection forcefully on the client side. 3717 // There will be no retry and we expect the invocation to fail with ConnectionManuallyClosedException. 3718 // 3719 p.ice_ping(); 3720 Ice.Connection con = p.ice_getConnection(); 3721 CallbackBase cb = new CallbackBase(); 3722 Task t = p.startDispatchAsync( 3723 progress: new Progress(sentSynchronously => 3724 { 3725 cb.called(); 3726 })); 3727 cb.check(); // Ensure the request was sent before we close the connection. 3728 con.close(Ice.ConnectionClose.Forcefully); 3729 try 3730 { 3731 t.Wait(); 3732 test(false); 3733 } 3734 catch(AggregateException ex) 3735 { 3736 test(ex.InnerException is Ice.ConnectionManuallyClosedException); 3737 test(!(ex.InnerException as Ice.ConnectionManuallyClosedException).graceful); 3738 } 3739 p.finishDispatch(); 3740 3741 // 3742 // Remote case: the server closes the connection forcefully. This causes the request to fail 3743 // with a ConnectionLostException. Since the close() operation is not idempotent, the client 3744 // will not retry. 3745 // 3746 try 3747 { 3748 p.close(Test.CloseMode.Forcefully); 3749 test(false); 3750 } 3751 catch(Ice.ConnectionLostException) 3752 { 3753 // Expected. 3754 } 3755 } 3756 output.WriteLine("ok"); 3757 } 3758 3759 output.Write("testing ice_scheduler... "); 3760 output.Flush(); 3761 { 3762 p.ice_pingAsync().ContinueWith( 3763 (t) => 3764 { 3765 test(Thread.CurrentThread.Name == null || 3766 !Thread.CurrentThread.Name.Contains("Ice.ThreadPool.Client")); 3767 }).Wait(); 3768 3769 p.ice_pingAsync().ContinueWith( 3770 (t) => 3771 { 3772 test(Thread.CurrentThread.Name.Contains("Ice.ThreadPool.Client")); 3773 }, p.ice_scheduler()).Wait(); 3774 3775 { 3776 TaskCompletionSource<int> s1 = new TaskCompletionSource<int>(); 3777 TaskCompletionSource<int> s2 = new TaskCompletionSource<int>(); 3778 Task t1 = s1.Task; 3779 Task t2 = s2.Task; 3780 Task t3 = null; 3781 Task t4 = null; 3782 p.ice_pingAsync().ContinueWith( 3783 (t) => 3784 { 3785 test(Thread.CurrentThread.Name.Contains("Ice.ThreadPool.Client")); 3786 // 3787 // t1 Continuation run in the thread that completes it. 3788 // 3789 var id = Thread.CurrentThread.ManagedThreadId; 3790 t3 = t1.ContinueWith(prev => 3791 { 3792 test(id == Thread.CurrentThread.ManagedThreadId); 3793 }, 3794 CancellationToken.None, 3795 TaskContinuationOptions.ExecuteSynchronously, 3796 p.ice_scheduler()); 3797 s1.SetResult(1); 3798 3799 // 3800 // t2 completed from the main thread 3801 // 3802 t4 = t2.ContinueWith(prev => 3803 { 3804 test(id != Thread.CurrentThread.ManagedThreadId); 3805 test(Thread.CurrentThread.Name == null || 3806 !Thread.CurrentThread.Name.Contains("Ice.ThreadPool.Client")); 3807 }, 3808 CancellationToken.None, 3809 TaskContinuationOptions.ExecuteSynchronously, 3810 p.ice_scheduler()); 3811 }, p.ice_scheduler()).Wait(); 3812 s2.SetResult(1); 3813 Task.WaitAll(t1, t2, t3, t4); 3814 } 3815 3816 if(!collocated) 3817 { 3818 Ice.ObjectAdapter adapter = communicator.createObjectAdapter(""); 3819 PingReplyI replyI = new PingReplyI(); 3820 var reply = Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)); 3821 adapter.activate(); 3822 3823 p.ice_getConnection().setAdapter(adapter); 3824 p.pingBiDir(reply); 3825 test(replyI.checkReceived()); 3826 adapter.destroy(); 3827 } 3828 } 3829 output.WriteLine("ok"); 3830 3831 output.Write("testing result struct... "); 3832 output.Flush(); 3833 { 3834 var q = Test.Outer.Inner.TestIntfPrxHelper.uncheckedCast( 3835 communicator.stringToProxy("test2:" + helper.getTestEndpoint(0))); 3836 q.opAsync(1).ContinueWith(t => 3837 { 3838 var r = t.Result; 3839 test(r.returnValue == 1); 3840 test(r.j == 1); 3841 }).Wait(); 3842 } 3843 output.WriteLine("ok"); 3844 3845 p.shutdown(); 3846 } 3847 } 3848 } 3849 } 3850