public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var manager = ServerManagerPrx.Parse($"ServerManager :{helper.getTestEndpoint(0)}", communicator); var locator = TestLocatorPrx.UncheckedCast(communicator.getDefaultLocator()); Console.WriteLine("registry checkedcast"); var registry = TestLocatorRegistryPrx.CheckedCast(locator.getRegistry()); test(registry != null); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); var @base = IObjectPrx.Parse("test @ TestAdapter", communicator); var base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); var base3 = IObjectPrx.Parse("test", communicator); var base4 = IObjectPrx.Parse("ServerManager", communicator); var base5 = IObjectPrx.Parse("test2", communicator); var base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); test(default(ProxyIdentityComparer).Compare(@base.Locator, communicator.getDefaultLocator()) == 0); var anotherLocator = LocatorPrx.Parse("anotherLocator", communicator); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Compare(@base.Locator, anotherLocator) == 0); communicator.setDefaultLocator(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Locator == null); @base = @base.Clone(locator: anotherLocator); test(default(ProxyIdentityComparer).Compare(@base.Locator, anotherLocator) == 0); communicator.setDefaultLocator(locator); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Compare(@base.Locator, communicator.getDefaultLocator()) == 0); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // test(@base.Router == null); var anotherRouter = RouterPrx.Parse("anotherRouter", communicator); @base = @base.Clone(router: anotherRouter); test(default(ProxyIdentityComparer).Compare(@base.Router, anotherRouter) == 0); var router = RouterPrx.Parse("dummyrouter", communicator); communicator.setDefaultRouter(router); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(default(ProxyIdentityComparer).Compare(@base.Router, communicator.getDefaultRouter()) == 0); communicator.setDefaultRouter(null); @base = IObjectPrx.Parse("test @ TestAdapter", communicator); test(@base.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.startServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrx.CheckedCast(@base); test(obj != null); var obj2 = Test.TestIntfPrx.CheckedCast(base2); test(obj2 != null); var obj3 = Test.TestIntfPrx.CheckedCast(base3); test(obj3 != null); var obj4 = Test.ServerManagerPrx.CheckedCast(base4); test(obj4 != null); var obj5 = Test.TestIntfPrx.CheckedCast(base5); test(obj5 != null); var obj6 = Test.TestIntfPrx.CheckedCast(base6); test(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj6.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = Test.TestIntfPrx.CheckedCast(base5); obj5.IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { @base = IObjectPrx.Parse("unknown/unknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject.Equals("object")); test(ex.id.Equals("unknown/unknown")); } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { @base = IObjectPrx.Parse("test @ TestAdapterUnknown", communicator); @base.IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject.Equals("object adapter")); test(ex.id.Equals("TestAdapterUnknown")); } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); var basencc = IObjectPrx.Parse("test@TestAdapter", communicator).Clone(connectionCached: false); int count = locator.getRequestCount(); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. test(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. test(++count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 2).IcePing(); // 2s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout count += 2; test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: -1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).IcePing(); test(count == locator.getRequestCount()); test(IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: 99).LocatorCacheTimeout == 99); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj = TestIntfPrx.Parse("test@TestAdapter", communicator); var hello = obj.getHello(); test(hello.AdapterId.Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.AdapterId.Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj.getReplicatedHello().Clone(locatorCacheTimeout: 0, connectionCached: false); count = locator.getRequestCount(); hello.IcePing(); test(++count == locator.getRequestCount()); List <Task> results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } count = locator.getRequestCount(); hello = hello.Clone(adapterId: "unknown"); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync().ContinueWith((Task t) => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is Ice.NotRegisteredException) { } })); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } output.WriteLine("ok"); output.Write("testing adapter locator cache... "); output.Flush(); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestAdapter3")); } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); registry.setAdapterDirectProxy("TestAdapter3", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter3", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.addObject(IObjectPrx.Parse("test3@TestUnknown", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestUnknown")); } registry.addObject(IObjectPrx.Parse("test3@TestAdapter4", communicator)); // Update registry.setAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter")); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.setAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.getTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } try { IObjectPrx.Parse("test@TestAdapter4", communicator).Clone(locatorCacheTimeout: 0).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test@TestAdapter4", communicator).IcePing(); test(false); } catch (LocalException) { } try { IObjectPrx.Parse("test3", communicator).IcePing(); test(false); } catch (LocalException) { } registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (LocalException) { test(false); } registry.addObject(IObjectPrx.Parse("test4", communicator)); try { IObjectPrx.Parse("test4", communicator).IcePing(); test(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { Dictionary <string, string> properties = communicator.GetProperties(); properties["Ice.BackgroundLocatorCacheUpdates"] = "1"; Communicator ic = helper.initialize(properties); registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter")); registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 0).IcePing(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.setAdapterDirectProxy("TestAdapter5", null); registry.addObject(IObjectPrx.Parse($"test3:{helper.getTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 10).IcePing(); // 10s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse("test@TestAdapter5", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: 1).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (LocalException) { // Expected to fail once they endpoints have been updated in the background. } ic.destroy(); } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); hello = HelloPrx.Parse("hello", communicator); obj.migrateHello(); hello.GetConnection().close(ConnectionClose.GracefullyWithWait); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.migrateHello(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator encoding resolution... "); output.Flush(); hello = HelloPrx.Parse("hello", communicator); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(encodingVersion: Util.Encoding_1_1).IcePing(); test(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter10", communicator).Clone(encodingVersion: Util.Encoding_1_0).IcePing(); test(++count == locator.getRequestCount()); IObjectPrx.Parse("test -e 1.0@TestAdapter10-2", communicator).IcePing(); test(++count == locator.getRequestCount()); output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj.shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); test(false); } catch (LocalException) { } try { obj3.IcePing(); test(false); } catch (LocalException) { } try { obj5.IcePing(); test(false); } catch (LocalException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to collocated objects... "); output.Flush(); communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default"); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(new HelloI(), id); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. HelloPrx?helloPrx = HelloPrx.Parse("\"" + id.ToString(communicator.ToStringMode) + "\"", communicator); test(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = HelloPrx.CheckedCast(adapter.CreateIndirectProxy(id)); test(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = HelloPrx.CheckedCast(adapter.CreateDirectProxy(id)); test(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }
public static void allTests(global::Test.TestHelper helper, bool collocated) { Communicator communicator = helper.communicator(); var p = TestIntfPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator); var testController = TestIntfControllerPrx.Parse($"testController:{helper.getTestEndpoint(1)}", communicator); var output = helper.getWriter(); output.Write("testing async invocation..."); output.Flush(); { Dictionary <string, string> ctx = new Dictionary <string, string>(); test(p.IceIsAAsync("::Test::TestIntf").Result); test(p.IceIsAAsync("::Test::TestIntf", ctx).Result); p.IcePingAsync().Wait(); p.IcePingAsync(ctx).Wait(); test(p.IceIdAsync().Result.Equals("::Test::TestIntf")); test(p.IceIdAsync(ctx).Result.Equals("::Test::TestIntf")); test(p.IceIdsAsync().Result.Length == 2); test(p.IceIdsAsync(ctx).Result.Length == 2); if (!collocated) { test(p.GetConnectionAsync().Result != null); } p.opAsync().Wait(); p.opAsync(ctx).Wait(); test(p.opWithResultAsync().Result == 15); test(p.opWithResultAsync(ctx).Result == 15); try { p.opWithUEAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } try { p.opWithUEAsync(ctx).Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } } output.WriteLine("ok"); output.Write("testing async/await..."); output.Flush(); { Task.Run(async() => { Dictionary <string, string> ctx = new Dictionary <string, string>(); test(await p.IceIsAAsync("::Test::TestIntf")); test(await p.IceIsAAsync("::Test::TestIntf", ctx)); await p.IcePingAsync(); await p.IcePingAsync(ctx); var id = await p.IceIdAsync(); test(id.Equals("::Test::TestIntf")); id = await p.IceIdAsync(ctx); test(id.Equals("::Test::TestIntf")); var ids = await p.IceIdsAsync(); test(ids.Length == 2); ids = await p.IceIdsAsync(ctx); test(ids.Length == 2); if (!collocated) { var conn = await p.GetConnectionAsync(); test(conn != null); } await p.opAsync(); await p.opAsync(ctx); var result = await p.opWithResultAsync(); test(result == 15); result = await p.opWithResultAsync(ctx); test(result == 15); try { await p.opWithUEAsync(); test(false); } catch (System.Exception ex) { test(ex is Test.TestIntfException); } try { await p.opWithUEAsync(ctx); test(false); } catch (System.Exception ex) { test(ex is Test.TestIntfException); } }).Wait(); } output.WriteLine("ok"); output.Write("testing async continuations..."); output.Flush(); { Dictionary <string, string> ctx = new Dictionary <string, string>(); p.IceIsAAsync("::Test::TestIntf").ContinueWith(previous => { test(previous.Result); }).Wait(); p.IceIsAAsync("::Test::TestIntf", ctx).ContinueWith(previous => { test(previous.Result); }).Wait(); p.IcePingAsync().ContinueWith(previous => { previous.Wait(); }).Wait(); p.IcePingAsync(ctx).ContinueWith(previous => { previous.Wait(); }).Wait(); p.IceIdAsync().ContinueWith(previous => { test(previous.Result.Equals("::Test::TestIntf")); }).Wait(); p.IceIdAsync(ctx).ContinueWith(previous => { test(previous.Result.Equals("::Test::TestIntf")); }).Wait(); p.IceIdsAsync().ContinueWith(previous => { test(previous.Result.Length == 2); }).Wait(); p.IceIdsAsync(ctx).ContinueWith(previous => { test(previous.Result.Length == 2); }).Wait(); if (!collocated) { p.GetConnectionAsync().ContinueWith(previous => { test(previous.Result != null); }).Wait(); } p.opAsync().ContinueWith(previous => previous.Wait()).Wait(); p.opAsync(ctx).ContinueWith(previous => previous.Wait()).Wait(); p.opWithResultAsync().ContinueWith(previous => { test(previous.Result == 15); }).Wait(); p.opWithResultAsync(ctx).ContinueWith(previous => { test(previous.Result == 15); }).Wait(); p.opWithUEAsync().ContinueWith(previous => { try { previous.Wait(); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } }).Wait(); p.opWithUEAsync(ctx).ContinueWith(previous => { try { previous.Wait(); } catch (AggregateException ae) { ae.Handle(ex => ex is Test.TestIntfException); } }).Wait(); } output.WriteLine("ok"); output.Write("testing local exceptions with async tasks... "); output.Flush(); { TestIntfPrx indirect = p.Clone(adapterId: "dummy"); try { indirect.opAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle((ex) => { return(ex is NoEndpointException); }); } try { p.Clone(oneway: true).opWithResultAsync(); test(false); } catch (TwowayOnlyException) { } // // Check that CommunicatorDestroyedException is raised directly. // if (p.GetConnection() != null) { Communicator ic = helper.initialize(communicator.GetProperties()); IObjectPrx o = IObjectPrx.Parse(p.ToString(), ic); TestIntfPrx p2 = Test.TestIntfPrx.CheckedCast(o); ic.destroy(); try { p2.opAsync(); test(false); } catch (CommunicatorDestroyedException) { // Expected. } } } output.WriteLine("ok"); output.Write("testing exception with async task... "); output.Flush(); { TestIntfPrx i = p.Clone(adapterId: "dummy"); try { i.IceIsAAsync("::Test::TestIntf").Wait(); test(false); } catch (AggregateException) { } try { i.opAsync().Wait(); test(false); } catch (AggregateException) { } try { i.opWithResultAsync().Wait(); test(false); } catch (AggregateException) { } try { i.opWithUEAsync().Wait(); test(false); } catch (AggregateException) { } // Ensures no exception is called when response is received test(p.IceIsAAsync("::Test::TestIntf").Result); p.opAsync().Wait(); p.opWithResultAsync().Wait(); // If response is a user exception, it should be received. try { p.opWithUEAsync().Wait(); test(false); } catch (AggregateException ae) { ae.Handle((ex) => { return(ex is Test.TestIntfException); }); } } output.WriteLine("ok"); output.Write("testing progress callback... "); output.Flush(); { { SentCallback cb = new SentCallback(); Task t = p.IceIsAAsync("", progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.IcePingAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.IceIdAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.IceIdsAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); t = p.opAsync( progress: new Progress(sentSynchronously => { cb.sent(sentSynchronously); })); cb.check(); t.Wait(); } List <Task> tasks = new List <Task>(); byte[] seq = new byte[10024]; (new Random()).NextBytes(seq); testController.holdAdapter(); try { Task t = null; ProgresCallback cb; do { cb = new ProgresCallback(); t = p.opWithPayloadAsync(seq, progress: cb); tasks.Add(t); }while (cb.SentSynchronously); } finally { testController.resumeAdapter(); } foreach (Task t in tasks) { t.Wait(); } } output.WriteLine("ok"); output.Write("testing async/await... "); output.Flush(); Func <Task> task = async() => { try { await p.opAsync(); var r = await p.opWithResultAsync(); test(r == 15); try { await p.opWithUEAsync(); } catch (Test.TestIntfException) { } // Operations implemented with amd and async. await p.opAsyncDispatchAsync(); r = await p.opWithResultAsyncDispatchAsync(); test(r == 15); try { await p.opWithUEAsyncDispatchAsync(); test(false); } catch (Test.TestIntfException) { } } catch (OperationNotExistException) { // Expected with cross testing, this opXxxAsyncDispatch methods are C# only. } }; task().Wait(); output.WriteLine("ok"); if (p.GetConnection() != null) { output.Write("testing async Task cancellation... "); output.Flush(); { var cs1 = new CancellationTokenSource(); var cs2 = new CancellationTokenSource(); var cs3 = new CancellationTokenSource(); Task t1; Task t2; Task t3; try { testController.holdAdapter(); ProgresCallback cb = null; byte[] seq = new byte[10024]; for (int i = 0; i < 200; ++i) // 2MB { cb = new ProgresCallback(); p.opWithPayloadAsync(seq, progress: cb); } test(!cb.Sent); t1 = p.IcePingAsync(cancel: cs1.Token); t2 = p.IcePingAsync(cancel: cs2.Token); cs3.Cancel(); t3 = p.IcePingAsync(cancel: cs3.Token); cs1.Cancel(); cs2.Cancel(); try { t1.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } try { t2.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } try { t3.Wait(); test(false); } catch (AggregateException ae) { ae.Handle(ex => { return(ex is InvocationCanceledException); }); } } finally { testController.resumeAdapter(); p.IcePing(); } } output.WriteLine("ok"); } if (p.GetConnection() != null && p.supportsAMD()) { output.Write("testing graceful close connection with wait... "); output.Flush(); { // // Local case: begin a request, close the connection gracefully, and make sure it waits // for the request to complete. // Connection con = p.GetConnection(); CallbackBase cb = new CallbackBase(); con.setCloseCallback(_ => { cb.called(); }); Task t = p.sleepAsync(100); con.close(ConnectionClose.GracefullyWithWait); t.Wait(); // Should complete successfully. cb.check(); } { // // Remote case. // byte[] seq = new byte[1024 * 10]; // // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod. // The goal is to make sure that none of the opWithPayload fail even if the server closes // the connection gracefully in between. // int maxQueue = 2; bool done = false; while (!done && maxQueue < 50) { done = true; p.IcePing(); List <Task> results = new List <Task>(); for (int i = 0; i < maxQueue; ++i) { results.Add(p.opWithPayloadAsync(seq)); } ProgresCallback cb = new ProgresCallback(); p.closeAsync(Test.CloseMode.GracefullyWithWait, progress: cb); if (!cb.SentSynchronously) { for (int i = 0; i < maxQueue; i++) { cb = new ProgresCallback(); Task t = p.opWithPayloadAsync(seq, progress: cb); results.Add(t); if (cb.SentSynchronously) { done = false; maxQueue *= 2; break; } } } else { maxQueue *= 2; done = false; } foreach (Task q in results) { q.Wait(); } } } output.WriteLine("ok"); output.Write("testing graceful close connection without wait... "); output.Flush(); { // // Local case: start an operation and then close the connection gracefully on the client side // without waiting for the pending invocation to complete. There will be no retry and we expect the // invocation to fail with ConnectionManuallyClosedException. // p = p.Clone(connectionId: "CloseGracefully"); // Start with a new connection. Connection con = p.GetConnection(); CallbackBase cb = new CallbackBase(); Task t = p.startDispatchAsync( progress: new Progress(sentSynchronously => { cb.called(); })); cb.check(); // Ensure the request was sent before we close the connection. con.close(ConnectionClose.Gracefully); try { t.Wait(); test(false); } catch (System.AggregateException ex) { test(ex.InnerException is ConnectionManuallyClosedException); test((ex.InnerException as ConnectionManuallyClosedException).graceful); } p.finishDispatch(); // // Remote case: the server closes the connection gracefully, which means the connection // will not be closed until all pending dispatched requests have completed. // con = p.GetConnection(); cb = new CallbackBase(); con.setCloseCallback(_ => { cb.called(); }); t = p.sleepAsync(100); p.close(Test.CloseMode.Gracefully); // Close is delayed until sleep completes. cb.check(); t.Wait(); } output.WriteLine("ok"); output.Write("testing forceful close connection... "); output.Flush(); { // // Local case: start an operation and then close the connection forcefully on the client side. // There will be no retry and we expect the invocation to fail with ConnectionManuallyClosedException. // p.IcePing(); Connection con = p.GetConnection(); CallbackBase cb = new CallbackBase(); Task t = p.startDispatchAsync( progress: new Progress(sentSynchronously => { cb.called(); })); cb.check(); // Ensure the request was sent before we close the connection. con.close(ConnectionClose.Forcefully); try { t.Wait(); test(false); } catch (AggregateException ex) { test(ex.InnerException is ConnectionManuallyClosedException); test(!(ex.InnerException as ConnectionManuallyClosedException).graceful); } p.finishDispatch(); // // Remote case: the server closes the connection forcefully. This causes the request to fail // with a ConnectionLostException. Since the close() operation is not idempotent, the client // will not retry. // try { p.close(Test.CloseMode.Forcefully); test(false); } catch (ConnectionLostException) { // Expected. } } output.WriteLine("ok"); } output.Write("testing ice_scheduler... "); output.Flush(); { p.IcePingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name == null || !Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }).Wait(); p.IcePingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }, p.Scheduler).Wait(); { TaskCompletionSource <int> s1 = new TaskCompletionSource <int>(); TaskCompletionSource <int> s2 = new TaskCompletionSource <int>(); Task t1 = s1.Task; Task t2 = s2.Task; Task t3 = null; Task t4 = null; p.IcePingAsync().ContinueWith( (t) => { test(Thread.CurrentThread.Name.Contains("ThreadPool.Client")); // // t1 Continuation run in the thread that completes it. // var id = Thread.CurrentThread.ManagedThreadId; t3 = t1.ContinueWith(prev => { test(id == Thread.CurrentThread.ManagedThreadId); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, p.Scheduler); s1.SetResult(1); // // t2 completed from the main thread // t4 = t2.ContinueWith(prev => { test(id != Thread.CurrentThread.ManagedThreadId); test(Thread.CurrentThread.Name == null || !Thread.CurrentThread.Name.Contains("ThreadPool.Client")); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, p.Scheduler); }, p.Scheduler).Wait(); s2.SetResult(1); Task.WaitAll(t1, t2, t3, t4); } if (!collocated) { ObjectAdapter adapter = communicator.createObjectAdapter(""); PingReplyI replyI = new PingReplyI(); var reply = adapter.Add(replyI); adapter.Activate(); p.GetConnection().setAdapter(adapter); p.pingBiDir(reply); test(replyI.checkReceived()); adapter.Destroy(); } } output.WriteLine("ok"); output.Write("testing result struct... "); output.Flush(); { var q = Test.Outer.Inner.TestIntfPrx.Parse($"test2:{helper.getTestEndpoint(0)}", communicator); q.opAsync(1).ContinueWith(t => { var r = t.Result; test(r.returnValue == 1); test(r.j == 1); }).Wait(); } output.WriteLine("ok"); p.shutdown(); }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp"); ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter"); PingReplyI replyI = new PingReplyI(); PingReplyPrx reply = adapter.Add(replyI).Clone(invocationMode: InvocationMode.Datagram); adapter.Activate(); Console.Out.Write("testing udp... "); Console.Out.Flush(); var obj = TestIntfPrx.Parse("test:" + helper.getTestEndpoint(0, "udp"), communicator).Clone(invocationMode: InvocationMode.Datagram); int nRetry = 5; bool ret = false; while (nRetry-- > 0) { replyI.reset(); obj.ping(reply); obj.ping(reply); obj.ping(reply); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } // If the 3 datagrams were not received within the 2 seconds, we try again to // receive 3 new datagrams using a new object. We give up after 5 retries. replyI = new PingReplyI(); reply = adapter.Add(replyI).Clone(invocationMode: InvocationMode.Datagram); } test(ret == true); if (communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0) { // // Only run this test if compression is disabled, the test expect fixed message size // to be sent over the wire. // byte[] seq = null; try { seq = new byte[1024]; while (true) { seq = new byte[seq.Length * 2 + 10]; replyI.reset(); obj.sendByteSeq(seq, reply); replyI.waitReply(1, 10000); } } catch (Ice.DatagramLimitException) { // // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException // will be throw when try to send a packet bigger than that. // test(seq.Length > 16384); } obj.GetConnection().close(Ice.ConnectionClose.GracefullyWithWait); communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000"); seq = new byte[50000]; try { replyI.reset(); obj.sendByteSeq(seq, reply); bool b = replyI.waitReply(1, 500); // // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet // should not be delivered. // test(!b); } catch (Ice.DatagramLimitException) { } catch (Ice.LocalException ex) { Console.Out.WriteLine(ex); test(false); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing udp multicast... "); Console.Out.Flush(); StringBuilder endpoint = new StringBuilder(); // // Use loopback to prevent other machines to answer. // if (communicator.getProperties().getProperty("Ice.IPv6").Equals("1")) { endpoint.Append("udp -h \"ff15::1:1\""); if (IceInternal.AssemblyUtil.isWindows || IceInternal.AssemblyUtil.isMacOS) { endpoint.Append(" --interface \"::1\""); } } else { endpoint.Append("udp -h 239.255.1.1"); if (IceInternal.AssemblyUtil.isWindows || IceInternal.AssemblyUtil.isMacOS) { endpoint.Append(" --interface 127.0.0.1"); } } endpoint.Append(" -p "); endpoint.Append(helper.getTestPort(10)); var objMcast = TestIntfPrx.Parse($"test -d:{endpoint}", communicator); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); objMcast.ping(reply); ret = replyI.waitReply(5, 5000); if (ret) { break; } replyI = new PingReplyI(); reply = adapter.Add(replyI).Clone(invocationMode: InvocationMode.Datagram); } if (!ret) { Console.Out.WriteLine("failed(is a firewall enabled?)"); } else { Console.Out.WriteLine("ok"); } Console.Out.Write("testing udp bi-dir connection... "); Console.Out.Flush(); obj.GetConnection().setAdapter(adapter); objMcast.GetConnection().setAdapter(adapter); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); obj.pingBiDir(reply.Identity); obj.pingBiDir(reply.Identity); obj.pingBiDir(reply.Identity); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } replyI = new PingReplyI(); reply = adapter.Add(replyI).Clone(invocationMode: InvocationMode.Datagram); } test(ret); Console.Out.WriteLine("ok"); // // Sending the replies back on the multicast UDP connection doesn't work for most // platform(it works for macOS Leopard but not Snow Leopard, doesn't work on SLES, // Windows...). For Windows, see UdpTransceiver constructor for the details. So // we don't run this test. // // Console.Out.Write("testing udp bi-dir connection... "); // nRetry = 5; // while(nRetry-- > 0) // { // replyI.reset(); // objMcast.pingBiDir(reply.Identity); // ret = replyI.waitReply(5, 2000); // if(ret) // { // break; // Success // } // replyI = new PingReplyI(); // reply =(PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); // } // if(!ret) // { // Console.Out.WriteLine("failed(is a firewall enabled?)"); // } // else // { // Console.Out.WriteLine("ok"); // } }
public static void allTests(Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var service1 = TestIntfPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator); var service2 = TestIntfPrx.Parse($"test:{helper.getTestEndpoint(1)}", communicator); var service3 = TestIntfPrx.Parse($"test:{helper.getTestEndpoint(2)}", communicator); var service4 = TestIntfPrx.Parse($"test:{helper.getTestEndpoint(3)}", communicator); if (service1.getProperty("IceBox.InheritProperties").Equals("")) { Console.Out.Write("testing service properties... "); Console.Out.Flush(); test(service1.getProperty("Ice.ProgramName").Equals("IceBox-Service1")); test(service1.getProperty("Service").Equals("1")); test(service1.getProperty("Service1.Ovrd").Equals("2")); test(service1.getProperty("Service1.Unset").Equals("")); test(service1.getProperty("Arg").Equals("1")); string[] args1 = { "-a", "--Arg=2" }; test(IceUtilInternal.Arrays.Equals(service1.getArgs(), args1)); test(service2.getProperty("Ice.ProgramName").Equals("Test")); test(service2.getProperty("Service").Equals("2")); test(service2.getProperty("Service1.ArgProp").Equals("")); test(service2.getProperty("IceBox.InheritProperties").Equals("1")); string[] args2 = { "--Service1.ArgProp=1" }; test(IceUtilInternal.Arrays.Equals(service2.getArgs(), args2)); Console.Out.WriteLine("ok"); Console.Out.Write("testing with shared communicator... "); Console.Out.Flush(); test(service3.getProperty("Ice.ProgramName").Equals("IceBox-SharedCommunicator")); test(service3.getProperty("Service").Equals("4")); test(service3.getProperty("Prop").Equals("")); test(service3.getProperty("Service3.Prop").Equals("1")); test(service3.getProperty("Ice.Trace.Slicing").Equals("3")); test(service4.getProperty("Ice.ProgramName").Equals("IceBox-SharedCommunicator")); test(service4.getProperty("Service").Equals("4")); test(service4.getProperty("Prop").Equals("")); test(service4.getProperty("Service3.Prop").Equals("1")); test(service4.getProperty("Ice.Trace.Slicing").Equals("3")); string[] args4 = { "--Service3.Prop=2" }; test(IceUtilInternal.Arrays.Equals(service4.getArgs(), args4)); Console.Out.WriteLine("ok"); } else { Console.Out.Write("testing property inheritance... "); Console.Out.Flush(); test(service1.getProperty("Ice.ProgramName").Equals("IceBox2-Service1")); test(service1.getProperty("ServerProp").Equals("1")); test(service1.getProperty("OverrideMe").Equals("2")); test(service1.getProperty("UnsetMe").Equals("")); test(service1.getProperty("Service1.Prop").Equals("1")); test(service1.getProperty("Service1.ArgProp").Equals("2")); test(service2.getProperty("Ice.ProgramName").Equals("IceBox2-SharedCommunicator")); test(service2.getProperty("ServerProp").Equals("1")); test(service2.getProperty("OverrideMe").Equals("3")); test(service2.getProperty("UnsetMe").Equals("")); test(service2.getProperty("Service2.Prop").Equals("1")); Console.Out.WriteLine("ok"); } }
allTests(Test.TestHelper helper, int num) { var output = helper.getWriter(); Ice.Communicator communicator = helper.communicator(); List <ControllerPrx> proxies = new List <ControllerPrx>(); List <ControllerPrx> indirectProxies = new List <ControllerPrx>(); for (int i = 0; i < num; ++i) { string id = "controller" + i; proxies.Add(ControllerPrx.Parse(id, communicator)); indirectProxies.Add(ControllerPrx.Parse($"{id}@control{i}", communicator)); } output.Write("testing indirect proxies... "); output.Flush(); { foreach (ControllerPrx prx in indirectProxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing well-known proxies... "); output.Flush(); { foreach (ControllerPrx prx in proxies) { prx.IcePing(); } } output.WriteLine("ok"); output.Write("testing object adapter registration... "); output.Flush(); { try { IObjectPrx.Parse("object @ oa1", communicator).IcePing(); test(false); } catch (NoEndpointException) { } proxies[0].activateObjectAdapter("oa", "oa1", ""); try { IObjectPrx.Parse("object @ oa1", communicator).IcePing(); test(false); } catch (ObjectNotExistException) { } proxies[0].deactivateObjectAdapter("oa"); try { IObjectPrx.Parse("object @ oa1", communicator).IcePing(); test(false); } catch (NoEndpointException) { } } output.WriteLine("ok"); output.Write("testing object adapter migration..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", ""); proxies[0].addObject("oa", "object"); IObjectPrx.Parse("object @ oa1", communicator).IcePing(); proxies[0].removeObject("oa", "object"); proxies[0].deactivateObjectAdapter("oa"); proxies[1].activateObjectAdapter("oa", "oa1", ""); proxies[1].addObject("oa", "object"); IObjectPrx.Parse("object @ oa1", communicator).IcePing(); proxies[1].removeObject("oa", "object"); proxies[1].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing object migration..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", ""); proxies[1].activateObjectAdapter("oa", "oa2", ""); proxies[0].addObject("oa", "object"); IObjectPrx.Parse("object @ oa1", communicator).IcePing(); IObjectPrx.Parse("object", communicator).IcePing(); proxies[0].removeObject("oa", "object"); proxies[1].addObject("oa", "object"); IObjectPrx.Parse("object @ oa2", communicator).IcePing(); IObjectPrx.Parse("object", communicator).IcePing(); proxies[1].removeObject("oa", "object"); try { IObjectPrx.Parse("object @ oa1", communicator).IcePing(); } catch (ObjectNotExistException) { } try { IObjectPrx.Parse("object @ oa2", communicator).IcePing(); } catch (ObjectNotExistException) { } proxies[0].deactivateObjectAdapter("oa"); proxies[1].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing replica groups..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", "rg"); proxies[1].activateObjectAdapter("oa", "oa2", "rg"); proxies[2].activateObjectAdapter("oa", "oa3", "rg"); proxies[0].addObject("oa", "object"); proxies[1].addObject("oa", "object"); proxies[2].addObject("oa", "object"); IObjectPrx.Parse("object @ oa1", communicator).IcePing(); IObjectPrx.Parse("object @ oa2", communicator).IcePing(); IObjectPrx.Parse("object @ oa3", communicator).IcePing(); IObjectPrx.Parse("object @ rg", communicator).IcePing(); List <string> adapterIds = new List <string>(); adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); TestIntfPrx intf = TestIntfPrx.Parse("object", communicator).Clone( connectionCached: false, locatorCacheTimeout: 0); while (adapterIds.Count > 0) { adapterIds.Remove(intf.getAdapterId()); } while (true) { adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); intf = TestIntfPrx.Parse("object @ rg", communicator).Clone(connectionCached: false); int nRetry = 100; while (adapterIds.Count > 0 && --nRetry > 0) { adapterIds.Remove(intf.getAdapterId()); } if (nRetry > 0) { break; } // The previous locator lookup probably didn't return all the replicas... try again. IObjectPrx.Parse("object @ rg", communicator).Clone(locatorCacheTimeout: 0).IcePing(); } proxies[0].deactivateObjectAdapter("oa"); proxies[1].deactivateObjectAdapter("oa"); test(TestIntfPrx.Parse("object @ rg", communicator).getAdapterId().Equals("oa3")); proxies[2].deactivateObjectAdapter("oa"); proxies[0].activateObjectAdapter("oa", "oa1", "rg"); proxies[0].addObject("oa", "object"); test(TestIntfPrx.Parse("object @ rg", communicator).getAdapterId().Equals("oa1")); proxies[0].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing invalid lookup endpoints... "); output.Flush(); { string multicast; if (communicator.GetProperty("Ice.IPv6") == "1") { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } { var properties = communicator.GetProperties(); properties["IceDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown"; Communicator comm = new Communicator(properties); test(comm.getDefaultLocator() != null); try { IObjectPrx.Parse("controller0@control0", comm).IcePing(); test(false); } catch (LocalException) { } comm.destroy(); } { var properties = communicator.GetProperties(); string intf = communicator.GetProperty("IceDiscovery.Interface") ?? ""; if (intf != "") { intf = $" --interface \"{intf}\""; } string port = communicator.GetProperty("IceDiscovery.Port") ?? ""; properties["IceDiscovery.Lookup"] = $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}{intf}"; Communicator comm = new Communicator(properties); test(comm.getDefaultLocator() != null); IObjectPrx.Parse("controller0@control0", comm).IcePing(); comm.destroy(); } } output.WriteLine("ok"); output.Write("shutting down... "); output.Flush(); foreach (ControllerPrx prx in proxies) { prx.shutdown(); } output.WriteLine("ok"); }