/// <summary>Creates a new object adapter with the specified router proxy. Calling this method is equivalent /// to setting the name.Router property and then calling <see cref="CreateObjectAdapter(string)"/>.</summary> /// <param name="name">The object adapter name. Cannot be empty.</param> /// <param name="router">The proxy to the router.</param> /// <returns>The new object adapter.</returns> public ObjectAdapter CreateObjectAdapterWithRouter(string name, IRouterPrx router) { if (name.Length == 0) { throw new ArgumentException("The empty string is not a valid object adapter name", nameof(name)); } // We set the proxy properties here, although we still use the proxy supplied. Dictionary <string, string> properties = router.ToProperty($"{name}.Router"); foreach (KeyValuePair <string, string> entry in properties) { SetProperty(entry.Key, entry.Value); } return(AddObjectAdapter(name, router)); }
// // Returns router info for a given router. Automatically creates // the router info if it doesn't exist yet. // public RouterInfo get(IRouterPrx rtr) { // // The router cannot be routed. // IRouterPrx router = rtr.Clone(clearRouter: true); lock (this) { RouterInfo info; if (!_table.TryGetValue(router, out info)) { info = new RouterInfo(router); _table.Add(router, info); } return(info); } }
// // Returns router info for a given router. Automatically creates // the router info if it doesn't exist yet. // public RouterInfo?erase(IRouterPrx?rtr) { RouterInfo?info = null; if (rtr != null) { // // The router cannot be routed. // IRouterPrx router = rtr.Clone(clearRouter: true); lock (this) { if (_table.TryGetValue(router, out info)) { _table.Remove(router); } } } return(info); }
/// <summary>Creates a new object adapter with the specified router proxy. Calling this method is equivalent to /// setting the name.Router property and then calling /// <see cref="CreateObjectAdapterAsync(string, bool, TaskScheduler?, CancellationToken)"/>.</summary> /// <param name="name">The object adapter name. Cannot be empty.</param> /// <param name="router">The proxy to the router.</param> /// <param name="serializeDispatch">Indicates whether or not this object adapter serializes the dispatching of /// of requests received over the same connection.</param> /// <param name="taskScheduler">The optional task scheduler to use for dispatching requests.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>A value task holding the new object adapter.</returns> public ValueTask <ObjectAdapter> CreateObjectAdapterWithRouterAsync( string name, IRouterPrx router, bool serializeDispatch = false, TaskScheduler?taskScheduler = null, CancellationToken cancel = default) { if (name.Length == 0) { throw new ArgumentException("the empty string is not a valid object adapter name", nameof(name)); } // We set the proxy properties here, although we still use the proxy supplied. Dictionary <string, string> properties = router.ToProperty($"{name}.Router"); foreach (KeyValuePair <string, string> entry in properties) { SetProperty(entry.Key, entry.Value); } return(CreateObjectAdapterAsync(name, serializeDispatch, taskScheduler, router, cancel)); }
public static Test.IBackgroundPrx allTests(Test.TestHelper helper) { Communicator communicator = helper.communicator(); var background = IBackgroundPrx.Parse($"background:{helper.getTestEndpoint(0)}", communicator); var backgroundController = IBackgroundControllerPrx.Parse("backgroundController:" + helper.getTestEndpoint(1, "tcp"), communicator); Configuration configuration = Configuration.getInstance(); Console.Write("testing connect... "); Console.Out.Flush(); { connectTests(configuration, background); } Console.Out.WriteLine("ok"); Console.Write("testing initialization... "); Console.Out.Flush(); { initializeTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing connection validation... "); Console.Out.Flush(); { validationTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing read/write... "); Console.Out.Flush(); { readWriteTests(configuration, background, backgroundController); } Console.Out.WriteLine("ok"); Console.Write("testing locator... "); Console.Out.Flush(); { var locator = ILocatorPrx.Parse($"locator:{helper.getTestEndpoint(0)}", communicator).Clone( invocationTimeout: 250); var obj = IObjectPrx.Parse("background@Test", communicator).Clone(locator: locator, oneway: true); backgroundController.pauseCall("findAdapterById"); try { obj.IcePing(); test(false); } catch (Ice.TimeoutException) { } backgroundController.resumeCall("findAdapterById"); locator = ILocatorPrx.Parse($"locator:{helper.getTestEndpoint(0)}", communicator).Clone(locator: locator); locator.IcePing(); var bg = IBackgroundPrx.Parse("background@Test", communicator).Clone(locator: locator); backgroundController.pauseCall("findAdapterById"); var t1 = bg.opAsync(); var t2 = bg.opAsync(); test(!t1.IsCompleted); test(!t2.IsCompleted); backgroundController.resumeCall("findAdapterById"); t1.Wait(); t2.Wait(); test(t1.IsCompleted); test(t2.IsCompleted); } Console.Out.WriteLine("ok"); Console.Write("testing router... "); Console.Out.Flush(); { var router = IRouterPrx.Parse($"router:{helper.getTestEndpoint(0)}", communicator).Clone( invocationTimeout: 250); var obj = IObjectPrx.Parse("background@Test", communicator).Clone(router: router, oneway: true); backgroundController.pauseCall("getClientProxy"); try { obj.IcePing(); test(false); } catch (Ice.TimeoutException) { } backgroundController.resumeCall("getClientProxy"); router = IRouterPrx.Parse($"router:{helper.getTestEndpoint(0)}", communicator); var bg = IBackgroundPrx.Parse("background@Test", communicator).Clone(router: router); test(bg.Router != null); backgroundController.pauseCall("getClientProxy"); var t1 = bg.opAsync(); var t2 = bg.opAsync(); test(!t1.IsCompleted); test(!t2.IsCompleted); backgroundController.resumeCall("getClientProxy"); t1.Wait(); t2.Wait(); test(t1.IsCompleted); test(t2.IsCompleted); } Console.Out.WriteLine("ok"); bool ws = communicator.GetProperty("Ice.Default.Protocol") == "test-ws"; bool wss = communicator.GetProperty("Ice.Default.Protocol") == "test-wss"; if (!ws && !wss) { Console.Write("testing buffered transport... "); Console.Out.Flush(); configuration.buffered(true); backgroundController.buffered(true); background.opAsync(); background.GetCachedConnection() !.close(ConnectionClose.Forcefully); background.opAsync(); OpAMICallback cb = new OpAMICallback(); var results = new List <Task>(); for (int i = 0; i < 10000; ++i) { var t = background.opAsync().ContinueWith((Task p) => { try { p.Wait(); cb.responseNoOp(); } catch (Ice.Exception ex) { cb.noException(ex); } }); results.Add(t); if (i % 50 == 0) { backgroundController.holdAdapter(); backgroundController.resumeAdapter(); } if (i % 100 == 0) { t.Wait(); } } Task.WaitAll(results.ToArray()); Console.Out.WriteLine("ok"); } return(background); }
public static void Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); bool ice1 = helper.Protocol == Protocol.Ice1; var manager = IServerManagerPrx.Parse(helper.GetTestProxy("ServerManager", 0), communicator); var locator = communicator.DefaultLocator !.Clone(ITestLocatorPrx.Factory); Console.WriteLine("registry checkedcast"); var registry = locator.GetRegistry() !.Clone(ITestLocatorRegistryPrx.Factory); TestHelper.Assert(registry != null); System.IO.TextWriter output = helper.Output; output.Write("testing stringToProxy... "); output.Flush(); IObjectPrx base1, base2, base3, base4, base5, base6; if (ice1) { base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); base3 = IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator); base4 = IObjectPrx.Parse("ServerManager", communicator); base5 = IObjectPrx.Parse("test2", communicator); base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); } else { base1 = IObjectPrx.Parse("ice:TestAdapter//test", communicator); base2 = IObjectPrx.Parse("ice:TestAdapter//test", communicator); base3 = IObjectPrx.Parse("ice:test", communicator); base4 = IObjectPrx.Parse("ice:ServerManager", communicator); base5 = IObjectPrx.Parse("ice:test2", communicator); base6 = IObjectPrx.Parse("ice:ReplicatedAdapter//test", communicator); } output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); var anotherLocator = ILocatorPrx.Parse(ice1 ? "anotherLocator" : "ice:anotherLocator", communicator); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = null; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(base1.Locator == null); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = locator; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // TestHelper.Assert(base1.Router == null); var anotherRouter = IRouterPrx.Parse(ice1 ? "anotherRouter" : "ice:anotherRouter", communicator); base1 = base1.Clone(router: anotherRouter); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, anotherRouter)); var router = IRouterPrx.Parse(ice1 ? "dummyrouter" : "ice:dummyrouter", communicator); communicator.DefaultRouter = router; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, communicator.DefaultRouter !)); communicator.DefaultRouter = null; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(base1.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.StartServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj1 = base1.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj1 != null); var obj2 = base2.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj2 != null); var obj3 = base3.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj3 != null); var obj4 = base4.CheckedCast(IServerManagerPrx.Factory); TestHelper.Assert(obj4 != null); var obj5 = base5.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj5 != null); var obj6 = base6.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj6 != null); output.WriteLine("ok"); output.Write("testing AdapterId//id indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing ReplicaGroupId//id indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj6.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj3.IcePing(); } catch { TestHelper.Assert(false); } try { obj2.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } try { obj3.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj3.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj5 = base5.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj5 != null); obj5.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { base1 = IObjectPrx.Parse(ice1 ? "unknown/unknown" : "ice:unknown/unknown", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (ObjectNotFoundException) { } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { base1 = IObjectPrx.Parse( ice1 ? "test @ TestAdapterUnknown" : "ice:TestAdapterUnknown//test", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); IObjectPrx basencc = IObjectPrx.Parse( ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).Clone(cacheConnection: false); int count = locator.GetRequestCount(); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.GetRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.GetRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout. TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. TestHelper.Assert(++count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 2; TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout TestHelper.Assert(count == locator.GetRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout count += 2; TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator) .Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); TestHelper.Assert(IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(99)).LocatorCacheTimeout == TimeSpan.FromSeconds(99)); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj1 = ITestIntfPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator); IHelloPrx?hello = obj1.GetHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.AdapterId.Equals("TestAdapter")); hello.SayHello(); hello = obj1.GetReplicatedHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.AdapterId.Equals("ReplicatedAdapter")); hello.SayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj1.GetReplicatedHello() !.Clone(locatorCacheTimeout: TimeSpan.Zero, cacheConnection: false); TestHelper.Assert(hello != null); count = locator.GetRequestCount(); hello.IcePing(); TestHelper.Assert(++count == locator.GetRequestCount()); var results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.SayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); if (locator.GetRequestCount() > count + 800) { output.Write("queuing = " + (locator.GetRequestCount() - count)); } TestHelper.Assert(locator.GetRequestCount() > count && locator.GetRequestCount() < count + 999); count = locator.GetRequestCount(); hello = hello.Clone(adapterId: "unknown"); for (int i = 0; i < 1000; i++) { results.Add(hello.SayHelloAsync().ContinueWith( t => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is AdapterNotFoundException) { } }, TaskScheduler.Default)); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. TestHelper.Assert(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(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); registry.SetAdapterDirectProxy( "TestAdapter3", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch { TestHelper.Assert(false); } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).Clone( locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch (ConnectionRefusedException) { } registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestUnknown" : "ice:TestUnknown//test3", communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter4" : "ice:TestAdapter4//test3", communicator)); // Update registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } registry.SetAdapterDirectProxy("TestAdapter4", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).Clone( locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } registry.AddObject(IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator)); try { IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator).IcePing(); TestHelper.Assert(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"; using Communicator ic = helper.Initialize(properties); registry.SetAdapterDirectProxy("TestAdapter5", locator.FindAdapterById("TestAdapter")); registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator)); count = locator.GetRequestCount(); IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 3; TestHelper.Assert(count == locator.GetRequestCount()); registry.SetAdapterDirectProxy("TestAdapter5", null); registry.AddObject(IObjectPrx.Parse(helper.GetTestProxy("test3", 99), communicator)); IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. Thread.Sleep(10); } } catch { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. Thread.Sleep(10); } } catch { // Expected to fail once they endpoints have been updated in the background. } } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj1.GetReplicatedHello(); TestHelper.Assert(hello != null); obj1.Shutdown(); manager.StartServer(); hello.SayHello(); output.WriteLine("ok"); // TODO: this does not work with ice2 because we currently don't retry on any remote exception, including // ONE. if (ice1) { output.Write("testing object migration... "); output.Flush(); hello = IHelloPrx.Parse(ice1 ? "hello" : "ice:hello", communicator); obj1.MigrateHello(); hello.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); hello.SayHello(); obj1.MigrateHello(); hello.SayHello(); obj1.MigrateHello(); hello.SayHello(); output.WriteLine("ok"); } output.Write("testing locator encoding resolution... "); output.Flush(); hello = IHelloPrx.Parse(ice1 ? "hello" : "ice:hello", communicator); count = locator.GetRequestCount(); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).Clone(encoding: Encoding.V1_1).IcePing(); // TODO: the count is apparently tied to whether or not we skip the if (ice1) block above. Would be nice to // add a comment. if (ice1) { TestHelper.Assert(count == locator.GetRequestCount()); } else { TestHelper.Assert(count + 1 == locator.GetRequestCount()); } output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj1.Shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } try { obj3.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } try { TestHelper.Assert(obj5 != null); obj5.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } 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", ice1 ? "tcp -h localhost" : "ice+tcp://localhost:0"); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(id, new Hello()); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. IHelloPrx?helloPrx; if (ice1) { helloPrx = IHelloPrx.Parse($"{id}", communicator); } else { helloPrx = IHelloPrx.Parse($"ice:{id}", communicator); } TestHelper.Assert(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = adapter.CreateIndirectProxy(id, IObjectPrx.Factory).CheckedCast(IHelloPrx.Factory); TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = adapter.CreateDirectProxy(id, IObjectPrx.Factory).CheckedCast(IHelloPrx.Factory); TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.Shutdown(); output.WriteLine("ok"); }
public static ITestIntfPrx Run(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); bool ice1 = communicator.DefaultProtocol == Protocol.Ice1; TextWriter output = helper.GetWriter(); output.Write("testing stringToProxy... "); output.Flush(); var baseprx = IObjectPrx.Parse(helper.GetTestProxy("test", 0), communicator); TestHelper.Assert(baseprx != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = ITestIntfPrx.CheckedCast(baseprx); TestHelper.Assert(obj != null); TestHelper.Assert(obj.Equals(baseprx)); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", helper.GetTestEndpoint(1)); try { communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", helper.GetTestEndpoint(2)); TestHelper.Assert(false); } catch (ArgumentException) { } adapter.Dispose(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", helper.GetTestEndpoint(2)); adapter.Dispose(); output.WriteLine("ok"); } output.Write("creating/activating/deactivating object adapter in one operation... "); output.Flush(); obj.Transient(); obj.TransientAsync().Wait(); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { using var comm = new Communicator(communicator.GetProperties()); IObjectPrx.Parse(helper.GetTestProxy("test", 0), communicator).IcePingAsync(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.SetProperty("PAdapter.PublishedEndpoints", ice1 ? "tcp -h localhost -p 12345 -t 30000" : "ice+tcp://localhost:12345"); ObjectAdapter adapter = communicator.CreateObjectAdapter("PAdapter"); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); Endpoint?endpt = adapter.GetPublishedEndpoints()[0]; TestHelper.Assert(endpt != null); if (ice1) { TestHelper.Assert(endpt.ToString() !.Equals("tcp -h localhost -p 12345 -t 30000")); } else { TestHelper.Assert(endpt.ToString() !.Equals("ice+tcp://localhost:12345")); } var prx = IObjectPrx.Parse(ice1 ? "dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000" : "ice+tcp://localhost:12346/dummy?alt-endpoint=localhost:12347", communicator); adapter.SetPublishedEndpoints(prx.Endpoints); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 2); TestHelper.Assert(adapter.CreateProxy(new Identity("dummy", ""), IObjectPrx.Factory).Endpoints. SequenceEqual(prx.Endpoints)); TestHelper.Assert(adapter.GetPublishedEndpoints().SequenceEqual(prx.Endpoints)); adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); TestHelper.Assert(adapter.GetPublishedEndpoints()[0].Equals(endpt)); communicator.SetProperty("PAdapter.PublishedEndpoints", ice1 ? "tcp -h localhost -p 12345 -t 20000" : "ice+tcp://localhost:12345"); adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); if (ice1) { TestHelper.Assert( adapter.GetPublishedEndpoints()[0].ToString() == "tcp -h localhost -p 12345 -t 20000"); } else { TestHelper.Assert(adapter.GetPublishedEndpoints()[0].ToString() == "ice+tcp://localhost:12345"); } adapter.Dispose(); } output.WriteLine("ok"); Connection?connection = obj.GetConnection(); if (connection != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); ObjectAdapter adapter = communicator.CreateObjectAdapter(); connection.Adapter = adapter; connection.Adapter = null; adapter.Dispose(); // Setting a deactivated adapter on a connection no longer raise ObjectAdapterDeactivatedException connection.Adapter = adapter; output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); { var routerId = new Identity("router", ""); IRouterPrx router = baseprx.Clone(routerId, IRouterPrx.Factory, connectionId: "rc"); ObjectAdapter adapter = communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); string endpointsStr = adapter.GetPublishedEndpoints()[0].ToString(); if (ice1) { TestHelper.Assert(endpointsStr == "tcp -h localhost -p 23456 -t 60000"); } else { TestHelper.Assert(endpointsStr == "ice+tcp://localhost:23456"); } adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); if (ice1) { TestHelper.Assert( adapter.GetPublishedEndpoints()[0].ToString() == "tcp -h localhost -p 23457 -t 60000"); } else { TestHelper.Assert(adapter.GetPublishedEndpoints()[0].ToString() == "ice+tcp://localhost:23457"); } try { adapter.SetPublishedEndpoints(router.Endpoints); TestHelper.Assert(false); } catch (InvalidOperationException) { // Expected. } adapter.Dispose(); try { routerId = new Identity("test", ""); router = baseprx.Clone(routerId, IRouterPrx.Factory); communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = IRouterPrx.Parse(helper.GetTestProxy("test", 1), communicator); communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { ObjectAdapter adapter1 = communicator.CreateObjectAdapterWithEndpoints("Adpt1", helper.GetTestEndpoint(10)); try { communicator.CreateObjectAdapterWithEndpoints("Adpt2", helper.GetTestEndpoint(10)); TestHelper.Assert(false); } catch { // Expected can't re-use the same endpoint. } adapter1.Dispose(); } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.Deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.IcePing(); TestHelper.Assert(false); } catch { output.WriteLine("ok"); } return(obj); }
public static void allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); var manager = IServerManagerPrx.Parse($"ServerManager :{helper.GetTestEndpoint(0)}", communicator); var locator = ITestLocatorPrx.UncheckedCast(communicator.DefaultLocator !); Console.WriteLine("registry checkedcast"); var registry = ITestLocatorRegistryPrx.CheckedCast(locator.GetRegistry() !); TestHelper.Assert(registry != null); System.IO.TextWriter output = helper.GetWriter(); output.Write("testing stringToProxy... "); output.Flush(); var base1 = 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... "); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); var anotherLocator = ILocatorPrx.Parse("anotherLocator", communicator); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = null; base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); TestHelper.Assert(base1.Locator == null); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = locator; base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // TestHelper.Assert(base1.Router == null); var anotherRouter = IRouterPrx.Parse("anotherRouter", communicator); base1 = base1.Clone(router: anotherRouter); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, anotherRouter)); var router = IRouterPrx.Parse("dummyrouter", communicator); communicator.DefaultRouter = router; base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, communicator.DefaultRouter !)); communicator.DefaultRouter = null; base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); TestHelper.Assert(base1.Router == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.startServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj1 = ITestIntfPrx.CheckedCast(base1); TestHelper.Assert(obj1 != null); var obj2 = ITestIntfPrx.CheckedCast(base2); TestHelper.Assert(obj2 != null); var obj3 = ITestIntfPrx.CheckedCast(base3); TestHelper.Assert(obj3 != null); var obj4 = IServerManagerPrx.CheckedCast(base4); TestHelper.Assert(obj4 != null); var obj5 = ITestIntfPrx.CheckedCast(base5); TestHelper.Assert(obj5 != null); var obj6 = ITestIntfPrx.CheckedCast(base6); TestHelper.Assert(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj1.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (Exception) { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj1.shutdown(); manager.startServer(); try { obj6.IcePing(); } catch (Exception) { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj1.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (Exception) { TestHelper.Assert(false); } try { obj2.IcePing(); } catch (Exception) { TestHelper.Assert(false); } obj1.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (Exception) { TestHelper.Assert(false); } try { obj3.IcePing(); } catch (Exception) { TestHelper.Assert(false); } obj1.shutdown(); manager.startServer(); try { obj2.IcePing(); } catch (Exception) { TestHelper.Assert(false); } obj1.shutdown(); manager.startServer(); try { obj3.IcePing(); } catch (Exception) { TestHelper.Assert(false); } obj1.shutdown(); manager.startServer(); try { obj5 = ITestIntfPrx.CheckedCast(base5); TestHelper.Assert(obj5 != null); obj5.IcePing(); } catch (Exception) { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { base1 = IObjectPrx.Parse("unknown/unknown", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (ObjectNotFoundException) { } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { base1 = IObjectPrx.Parse("test @ TestAdapterUnknown", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); IObjectPrx basencc = IObjectPrx.Parse("test@TestAdapter", communicator).Clone(cacheConnection: false); int count = locator.getRequestCount(); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.getRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout. TestHelper.Assert(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. TestHelper.Assert(++count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 2; TestHelper.Assert(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout TestHelper.Assert(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms IObjectPrx.Parse("test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout count += 2; TestHelper.Assert(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator) .Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.getRequestCount()); IObjectPrx.Parse("test@TestAdapter", communicator).IcePing(); TestHelper.Assert(count == locator.getRequestCount()); IObjectPrx.Parse("test", communicator).IcePing(); TestHelper.Assert(count == locator.getRequestCount()); TestHelper.Assert(IObjectPrx.Parse("test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(99)).LocatorCacheTimeout == TimeSpan.FromSeconds(99)); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj1 = ITestIntfPrx.Parse("test@TestAdapter", communicator); IHelloPrx?hello = obj1.getHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.AdapterId.Equals("TestAdapter")); hello.sayHello(); hello = obj1.getReplicatedHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.AdapterId.Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj1.getReplicatedHello() !.Clone(locatorCacheTimeout: TimeSpan.Zero, cacheConnection: false); TestHelper.Assert(hello != null); count = locator.getRequestCount(); hello.IcePing(); TestHelper.Assert(++count == locator.getRequestCount()); var results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.sayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } TestHelper.Assert(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); 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 AdapterNotFoundException) { } })); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. TestHelper.Assert(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(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } 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 (System.Exception) { TestHelper.Assert(false); } try { IObjectPrx.Parse("test@TestAdapter3", communicator).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (ConnectionRefusedException) { } registry.SetAdapterDirectProxy("TestAdapter3", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse("test@TestAdapter3", communicator).IcePing(); } catch (System.Exception) { TestHelper.Assert(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(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } registry.addObject(IObjectPrx.Parse("test3@TestAdapter4", communicator)); // Update registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.GetTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } registry.SetAdapterDirectProxy("TestAdapter4", locator.FindAdapterById("TestAdapter")); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (System.Exception) { TestHelper.Assert(false); } registry.SetAdapterDirectProxy("TestAdapter4", IObjectPrx.Parse($"dummy:{helper.GetTestEndpoint(99)}", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (System.Exception) { TestHelper.Assert(false); } try { IObjectPrx.Parse("test@TestAdapter4", communicator).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse("test@TestAdapter4", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse("test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } registry.addObject(IObjectPrx.Parse("test3@TestAdapter", communicator)); try { IObjectPrx.Parse("test3", communicator).IcePing(); } catch (System.Exception) { TestHelper.Assert(false); } registry.addObject(IObjectPrx.Parse("test4", communicator)); try { IObjectPrx.Parse("test4", communicator).IcePing(); TestHelper.Assert(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: TimeSpan.Zero).IcePing(); // No locator cache. IObjectPrx.Parse("test3", ic).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 3; TestHelper.Assert(count == locator.getRequestCount()); registry.SetAdapterDirectProxy("TestAdapter5", null); registry.addObject(IObjectPrx.Parse($"test3:{helper.GetTestEndpoint(99)}", communicator)); IObjectPrx.Parse("test@TestAdapter5", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. IObjectPrx.Parse("test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. TestHelper.Assert(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: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. IObjectPrx.Parse("test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse("test@TestAdapter5", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (System.Exception) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse("test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (System.Exception) { // 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 = obj1.getReplicatedHello(); TestHelper.Assert(hello != null); obj1.shutdown(); manager.startServer(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); hello = IHelloPrx.Parse("hello", communicator); obj1.migrateHello(); hello.GetConnection() !.Close(ConnectionClose.GracefullyWithWait); hello.sayHello(); obj1.migrateHello(); hello.sayHello(); obj1.migrateHello(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator encoding resolution... "); output.Flush(); hello = IHelloPrx.Parse("hello", communicator); count = locator.getRequestCount(); IObjectPrx.Parse("test@TestAdapter", communicator).Clone(encoding: Encoding.V1_1).IcePing(); TestHelper.Assert(count == locator.getRequestCount()); output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj1.shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } try { obj3.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } try { TestHelper.Assert(obj5 != null); obj5.IcePing(); TestHelper.Assert(false); } catch (AdapterNotFoundException) { } 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(id, new Hello()); adapter.Activate(); // Ensure that calls on the well-known proxy is collocated. IHelloPrx?helloPrx; helloPrx = IHelloPrx.Parse($"\"{id.ToString(communicator.ToStringMode)}\"", communicator); TestHelper.Assert(helloPrx.GetConnection() == null); // Ensure that calls on the indirect proxy (with adapter ID) is collocated helloPrx = IHelloPrx.CheckedCast(adapter.CreateIndirectProxy(id, IObjectPrx.Factory)); TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null); // Ensure that calls on the direct proxy is collocated helloPrx = IHelloPrx.CheckedCast(adapter.CreateDirectProxy(id, IObjectPrx.Factory)); TestHelper.Assert(helloPrx != null && helloPrx.GetConnection() == null); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }
Connected(IRouterPrx router, ISessionPrx session) { // // Remote invocation should be done without acquiring a mutex lock. // Debug.Assert(router != null); Debug.Assert(_communicator != null); Connection?conn = router.GetCachedConnection(); string category = router.GetCategoryForClient(); int acmTimeout = 0; try { acmTimeout = router.GetACMTimeout(); } catch (OperationNotExistException) { } if (acmTimeout <= 0) { acmTimeout = (int)router.GetSessionTimeout(); } // // We create the callback object adapter here because createObjectAdapter internally // makes synchronous RPCs to the router. We can't create the OA on-demand when the // client calls objectAdapter() or addWithUUID() because they can be called from the // GUI thread. // if (_useCallbacks) { Debug.Assert(_adapter == null); _adapter = _communicator.CreateObjectAdapterWithRouter(router); _adapter.Activate(); } lock (_mutex) { _router = router; if (_destroy) { // // Run destroyInternal in a thread because it makes remote invocations. // var t = new Thread(new ThreadStart(DestroyInternal)); t.Start(); return; } // // Cache the category. // _category = category; // // Assign the session after _destroy is checked. // _session = session; _connected = true; if (acmTimeout > 0) { Connection?connection = _router.GetCachedConnection(); Debug.Assert(connection != null); connection.SetACM(acmTimeout, null, ACMHeartbeat.HeartbeatAlways); connection.SetCloseCallback(_ => Destroy()); } } try { _callback.Connected(this); } catch (SessionNotExistException) { Destroy(); } }
private void Connected(IRouterPrx router, ISessionPrx session) { // Remote invocation should be done without acquiring a mutex lock. Debug.Assert(router != null); Debug.Assert(_communicator != null); // We create the callback object adapter here because createObjectAdapter internally makes synchronous // RPCs to the router. We can't create the OA on-demand when the client calls ObjectAdapter() or // AddWithUUID() because they can be called from the GUI thread. if (_useCallbacks) { Debug.Assert(_adapter == null); _adapter = _communicator.CreateObjectAdapterWithRouter(router); _adapter.Activate(); } string category = router.GetCategoryForClient(); lock (_mutex) { _router = router; if (_destroy) { // Run destroyInternal in a thread because it makes remote invocations. var t = new Thread(new ThreadStart(DestroyInternal)); t.Start(); return; } // Cache the category. _category = category; // Assign the session after _destroy is checked. _session = session; _connected = true; } // When using Ice1, we need to figure out the router's acm/session timeout and configure the connection // accordingly. With Ice2, this is no longer necessary, the idle timeout is negotiated on connection // establishment. Connection connection = router.GetConnection(); if (router.Protocol == Protocol.Ice1) { TimeSpan idleTimeout = TimeSpan.Zero; try { idleTimeout = TimeSpan.FromSeconds(router.GetACMTimeout()); } catch (OperationNotExistException) { } if (idleTimeout == TimeSpan.Zero) { idleTimeout = TimeSpan.FromSeconds(router.GetSessionTimeout()); } if (idleTimeout != TimeSpan.Zero) { connection.IdleTimeout = idleTimeout; } } connection.Closed += (sender, args) => Destroy(); try { _callback.Connected(this); } catch (SessionNotExistException) { Destroy(); } }
public static ITestIntfPrx allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); var output = helper.GetWriter(); output.Write("testing stringToProxy... "); output.Flush(); var baseprx = IObjectPrx.Parse($"test:{helper.GetTestEndpoint(0)}", communicator); TestHelper.Assert(baseprx != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = ITestIntfPrx.CheckedCast(baseprx); TestHelper.Assert(obj != null); TestHelper.Assert(obj.Equals(baseprx)); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", "default"); TestHelper.Assert(false); } catch (ArgumentException) { } adapter.Destroy(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", "default"); adapter.Destroy(); output.WriteLine("ok"); } output.Write("creating/activating/deactivating object adapter in one operation... "); output.Flush(); obj.transient(); obj.transientAsync().Wait(); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { var comm = new Communicator(communicator.GetProperties()); IObjectPrx.Parse($"test:{helper.GetTestEndpoint(0)}", communicator).IcePingAsync(); comm.Destroy(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.SetProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000"); var adapter = communicator.CreateObjectAdapter("PAdapter"); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); var endpt = adapter.GetPublishedEndpoints()[0]; TestHelper.Assert(endpt != null); TestHelper.Assert(endpt.ToString() !.Equals("tcp -h localhost -p 12345 -t 30000")); var prx = IObjectPrx.Parse("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000", communicator); adapter.SetPublishedEndpoints(prx.Endpoints); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 2); TestHelper.Assert(adapter.CreateProxy(new Identity("dummy", ""), IObjectPrx.Factory).Endpoints. SequenceEqual(prx.Endpoints)); TestHelper.Assert(adapter.GetPublishedEndpoints().SequenceEqual(prx.Endpoints)); adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); TestHelper.Assert(adapter.GetPublishedEndpoints()[0].Equals(endpt)); communicator.SetProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000"); adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); TestHelper.Assert(adapter.GetPublishedEndpoints()[0].ToString() !.Equals("tcp -h localhost -p 12345 -t 20000")); adapter.Destroy(); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 0); } output.WriteLine("ok"); if (obj.GetConnection() != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); var adapter = communicator.CreateObjectAdapter(); obj.GetConnection().Adapter = adapter; obj.GetConnection().Adapter = null; adapter.Deactivate(); // Setting a deactivated adapter on a connection no longer raise ObjectAdapterDeactivatedException obj.GetConnection().Adapter = adapter; output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); { var routerId = new Identity("router", ""); var router = baseprx.Clone(routerId, IRouterPrx.Factory, connectionId: "rc"); var adapter = communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); var endpointsStr = adapter.GetPublishedEndpoints()[0].ToString(); TestHelper.Assert(endpointsStr !.Equals("tcp -h localhost -p 23456 -t 30000")); adapter.RefreshPublishedEndpoints(); TestHelper.Assert(adapter.GetPublishedEndpoints().Count == 1); TestHelper.Assert(adapter.GetPublishedEndpoints()[0].ToString() !.Equals("tcp -h localhost -p 23457 -t 30000")); try { adapter.SetPublishedEndpoints(router.Endpoints); TestHelper.Assert(false); } catch (InvalidOperationException) { // Expected. } adapter.Destroy(); try { routerId = new Identity("test", ""); router = baseprx.Clone(routerId, IRouterPrx.Factory); communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = IRouterPrx.Parse($"test:{helper.GetTestEndpoint(1)}", communicator); communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { var adapter1 = communicator.CreateObjectAdapterWithEndpoints("Adpt1", helper.GetTestEndpoint(10)); try { communicator.CreateObjectAdapterWithEndpoints("Adpt2", helper.GetTestEndpoint(10)); TestHelper.Assert(false); } catch (System.Exception) { // Expected can't re-use the same endpoint. } adapter1.Destroy(); } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.Clone(connectionTimeout: 100).IcePing(); // Use timeout to speed up testing on Windows TestHelper.Assert(false); } catch (Exception) { output.WriteLine("ok"); } return(obj); }
internal RouterInfo(IRouterPrx router) { _router = router; Debug.Assert(_router != null); }
public static async Task RunAsync(TestHelper helper) { Communicator communicator = helper.Communicator; TextWriter output = helper.Output; bool ice1 = helper.Protocol == Protocol.Ice1; var manager = IServerManagerPrx.Parse(helper.GetTestProxy("ServerManager", 0), communicator); var locator = communicator.DefaultLocator !.Clone(ITestLocatorPrx.Factory); var registry = locator.GetRegistry() !.Clone(ITestLocatorRegistryPrx.Factory); TestHelper.Assert(registry != null); output.Write("testing ice1 string/URI parsing... "); output.Flush(); IObjectPrx base1, base2, base3, base4, base5, base6, base7; if (ice1) { base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); base2 = IObjectPrx.Parse("test @ TestAdapter", communicator); base3 = IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator); base4 = IObjectPrx.Parse("ServerManager", communicator); base5 = IObjectPrx.Parse("test2", communicator); base6 = IObjectPrx.Parse("test @ ReplicatedAdapter", communicator); base7 = IObjectPrx.Parse("test3 -f facet", communicator); } else { base1 = IObjectPrx.Parse("ice:TestAdapter//test", communicator); base2 = IObjectPrx.Parse("ice:TestAdapter//test", communicator); base3 = IObjectPrx.Parse("ice:test", communicator); base4 = IObjectPrx.Parse("ice:ServerManager", communicator); base5 = IObjectPrx.Parse("ice:test2", communicator); base6 = IObjectPrx.Parse("ice:ReplicatedAdapter//test", communicator); base7 = IObjectPrx.Parse("ice:test3#facet", communicator); } output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); var anotherLocator = ILocatorPrx.Parse(ice1 ? "anotherLocator" : "ice:anotherLocator", communicator); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = null; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(base1.Locator == null); base1 = base1.Clone(locator: anotherLocator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, anotherLocator)); communicator.DefaultLocator = locator; base1 = IObjectPrx.Parse(ice1 ? "test @ TestAdapter" : "ice:TestAdapter//test", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Locator !, communicator.DefaultLocator !)); if (ice1) { // TODO: We also test ice_router/ice_getRouter(perhaps we should add a test/Ice/router test?) TestHelper.Assert(base1.Router == null); var anotherRouter = IRouterPrx.Parse("anotherRouter", communicator); base1 = base1.Clone(router: anotherRouter); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, anotherRouter)); var router = IRouterPrx.Parse("dummyrouter", communicator); communicator.DefaultRouter = router; base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); TestHelper.Assert(ProxyComparer.Identity.Equals(base1.Router !, communicator.DefaultRouter !)); communicator.DefaultRouter = null; base1 = IObjectPrx.Parse("test @ TestAdapter", communicator); TestHelper.Assert(base1.Router == null); } output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.StartServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj1 = base1.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj1 != null); var obj2 = base2.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj2 != null); var obj3 = base3.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj3 != null); var obj4 = base4.CheckedCast(IServerManagerPrx.Factory); TestHelper.Assert(obj4 != null); var obj5 = base5.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj5 != null); var obj6 = base6.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj6 != null); output.WriteLine("ok"); output.Write("testing AdapterId//id indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing ReplicaGroupId//id indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj6.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj1.Shutdown(); manager.StartServer(); try { obj3.IcePing(); } catch { TestHelper.Assert(false); } try { obj2.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } try { obj3.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj2.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj3.IcePing(); } catch { TestHelper.Assert(false); } obj1.Shutdown(); manager.StartServer(); try { obj5 = base5.CheckedCast(ITestIntfPrx.Factory); TestHelper.Assert(obj5 != null); obj5.IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { base1 = IObjectPrx.Parse(ice1 ? "unknown/unknown" : "ice:unknown/unknown", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { base1 = IObjectPrx.Parse( ice1 ? "test @ TestAdapterUnknown" : "ice:TestAdapterUnknown//test", communicator); base1.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); IObjectPrx basencc = IObjectPrx.Parse( ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).Clone(cacheConnection: false); int count = locator.GetRequestCount(); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.GetRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. TestHelper.Assert(++count == locator.GetRequestCount()); basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout. TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1300); // 1300ms basencc.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. TestHelper.Assert(++count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 2; TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(2)).IcePing(); // 2s timeout TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1300); // 1300ms IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout count += 2; TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator) .Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator).IcePing(); TestHelper.Assert(count == locator.GetRequestCount()); TestHelper.Assert(IObjectPrx.Parse(ice1 ? "test" : "ice:test", communicator) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(99)).LocatorCacheTimeout == TimeSpan.FromSeconds(99)); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj1 = ITestIntfPrx.Parse(ice1 ? "test@TestAdapter" : "ice:TestAdapter//test", communicator); IHelloPrx?hello = obj1.GetHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.Location.Count == 1 && hello.Location[0] == "TestAdapter"); hello.SayHello(); hello = obj1.GetReplicatedHello(); TestHelper.Assert(hello != null); TestHelper.Assert(hello.Location.Count == 1 && hello.Location[0] == "ReplicatedAdapter"); hello.SayHello(); output.WriteLine("ok"); output.Write("testing well-known proxy with facet... "); output.Flush(); hello = IHelloPrx.Parse(ice1 ? "bonjour -f abc" : "ice:bonjour#abc", communicator); hello.SayHello(); hello = IHelloPrx.Parse(ice1 ? "hello -f abc" : "ice:hello#abc", communicator); try { hello.SayHello(); TestHelper.Assert(false); } catch (NoEndpointException) // hello does not have an abc facet { } output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = obj1.GetReplicatedHello() !.Clone(locatorCacheTimeout: TimeSpan.Zero, cacheConnection: false); TestHelper.Assert(hello != null); count = locator.GetRequestCount(); hello.IcePing(); TestHelper.Assert(++count == locator.GetRequestCount()); var results = new List <Task>(); for (int i = 0; i < 1000; i++) { results.Add(hello.SayHelloAsync()); } Task.WaitAll(results.ToArray()); results.Clear(); if (locator.GetRequestCount() > count + 800) { output.Write("queuing = " + (locator.GetRequestCount() - count)); } TestHelper.Assert(locator.GetRequestCount() > count && locator.GetRequestCount() < count + 999); count = locator.GetRequestCount(); hello = hello.Clone(location: ImmutableArray.Create("unknown")); for (int i = 0; i < 1000; i++) { results.Add(hello.SayHelloAsync().ContinueWith( t => { try { t.Wait(); } catch (AggregateException ex) when(ex.InnerException is NoEndpointException) { } }, TaskScheduler.Default)); } Task.WaitAll(results.ToArray()); results.Clear(); // XXX: // Take into account the retries. TestHelper.Assert(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(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } RegisterAdapterEndpoints( registry, "TestAdapter3", replicaGroupId: "", ResolveLocation(locator, "TestAdapter") !); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); RegisterAdapterEndpoints( registry, "TestAdapter3", replicaGroupId: "", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch { TestHelper.Assert(false); } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).Clone( locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch (ConnectionRefusedException) { } RegisterAdapterEndpoints( registry, "TestAdapter3", "", ResolveLocation(locator, "TestAdapter") !); try { IObjectPrx.Parse(ice1 ? "test@TestAdapter3" : "ice:TestAdapter3//test", communicator).IcePing(); } catch { TestHelper.Assert(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestUnknown" : "ice:TestUnknown//test3", communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter4" : "ice:TestAdapter4//test3", communicator)); // Update RegisterAdapterEndpoints( registry, "TestAdapter4", "", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } RegisterAdapterEndpoints( registry, "TestAdapter4", "", ResolveLocation(locator, "TestAdapter") !); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } RegisterAdapterEndpoints( registry, "TestAdapter4", "", IObjectPrx.Parse(helper.GetTestProxy("dummy", 99), communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).Clone( locatorCacheTimeout: TimeSpan.Zero).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test@TestAdapter4" : "ice:TestAdapter4//test", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); TestHelper.Assert(false); } catch (ConnectionRefusedException) { } registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator)); try { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", communicator).IcePing(); } catch { TestHelper.Assert(false); } registry.AddObject(IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator)); try { IObjectPrx.Parse(ice1 ? "test4" : "ice:test4", communicator).IcePing(); TestHelper.Assert(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"; await using Communicator ic = TestHelper.CreateCommunicator(properties); RegisterAdapterEndpoints( registry, "TestAdapter5", "", ResolveLocation(locator, "TestAdapter") !); registry.AddObject(IObjectPrx.Parse( ice1 ? "test3@TestAdapter" : "ice:TestAdapter//test3", communicator)); count = locator.GetRequestCount(); IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic).Clone(locatorCacheTimeout: TimeSpan.Zero).IcePing(); // No locator cache. count += 3; TestHelper.Assert(count == locator.GetRequestCount()); UnregisterAdapterEndpoints(registry, "TestAdapter5", ""); registry.AddObject(IObjectPrx.Parse(helper.GetTestProxy("test3", 99), communicator)); IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)).IcePing(); // 10s timeout. TestHelper.Assert(count == locator.GetRequestCount()); Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. try { while (true) { IObjectPrx.Parse(ice1 ? "test@TestAdapter5" : "ice:TestAdapter5//test", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. Thread.Sleep(10); } } catch { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { IObjectPrx.Parse(ice1 ? "test3" : "ice:test3", ic) .Clone(locatorCacheTimeout: TimeSpan.FromSeconds(1)).IcePing(); // 1s timeout. Thread.Sleep(10); } } catch { // Expected to fail once they endpoints have been updated in the background. } } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj1.GetReplicatedHello(); TestHelper.Assert(hello != null); obj1.Shutdown(); manager.StartServer(); hello.SayHello(); output.WriteLine("ok"); // TODO: this does not work with ice2 because we currently don't retry on any remote exception, including // ONE. if (ice1) { output.Write("testing object migration... "); output.Flush(); hello = IHelloPrx.Parse(ice1 ? "hello" : "ice:hello", communicator); obj1.MigrateHello(); _ = (await hello.GetConnectionAsync()).GoAwayAsync(); hello.SayHello(); obj1.MigrateHello(); hello.SayHello(); obj1.MigrateHello(); hello.SayHello(); output.WriteLine("ok"); } output.Write("shutdown server... "); output.Flush(); obj1.Shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } try { obj3.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } try { TestHelper.Assert(obj5 != null); obj5.IcePing(); TestHelper.Assert(false); } catch (NoEndpointException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to colocated objects... "); output.Flush(); communicator.SetProperty("Hello.AdapterId", Guid.NewGuid().ToString()); ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints(helper.GetTestEndpoint(ephemeral: true)); var id = new Identity(Guid.NewGuid().ToString(), ""); adapter.Add(id, new Hello()); await adapter.ActivateAsync(); // Ensure that calls on the well-known proxy is collocated. IHelloPrx?helloPrx; if (ice1) { helloPrx = IHelloPrx.Parse($"{id}", communicator); } else { helloPrx = IHelloPrx.Parse($"ice:{id}", communicator); } TestHelper.Assert(await helloPrx.GetConnectionAsync() is ColocatedConnection); // Ensure that calls on the indirect proxy (with adapter ID) is colocated helloPrx = adapter.CreateProxy(id, IObjectPrx.Factory).CheckedCast(IHelloPrx.Factory); TestHelper.Assert(helloPrx != null && await helloPrx.GetConnectionAsync() is ColocatedConnection); // Ensure that calls on the direct proxy is colocated helloPrx = adapter.CreateProxy(id, IObjectPrx.Factory).Clone( endpoints: adapter.PublishedEndpoints, location: ImmutableArray <string> .Empty).CheckedCast(IHelloPrx.Factory); TestHelper.Assert(helloPrx != null && await helloPrx.GetConnectionAsync() is ColocatedConnection); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.Shutdown(); output.WriteLine("ok"); }
private void Connected(IRouterPrx router, ISessionPrx session) { // Remote invocation should be done without acquiring a mutex lock. Debug.Assert(router != null); Debug.Assert(_communicator != null); Connection?conn = router.GetCachedConnection(); string category = router.GetCategoryForClient(); TimeSpan acmTimeout = TimeSpan.Zero; try { acmTimeout = TimeSpan.FromSeconds(router.GetACMTimeout()); } catch (OperationNotExistException) { } if (acmTimeout == TimeSpan.Zero) { acmTimeout = TimeSpan.FromSeconds(router.GetSessionTimeout()); } // We create the callback object adapter here because createObjectAdapter internally makes synchronous // RPCs to the router. We can't create the OA on-demand when the client calls ObjectAdapter() or // AddWithUUID() because they can be called from the GUI thread. if (_useCallbacks) { Debug.Assert(_adapter == null); _adapter = _communicator.CreateObjectAdapterWithRouter(router); _adapter.Activate(); } lock (_mutex) { _router = router; if (_destroy) { // Run destroyInternal in a thread because it makes remote invocations. var t = new Thread(new ThreadStart(DestroyInternal)); t.Start(); return; } // Cache the category. _category = category; // Assign the session after _destroy is checked. _session = session; _connected = true; if (acmTimeout != TimeSpan.Zero) { Connection?connection = _router.GetCachedConnection(); Debug.Assert(connection != null); connection.Acm = new Acm(acmTimeout, connection.Acm.Close, AcmHeartbeat.Always); connection.Closed += (sender, args) => Destroy(); } } try { _callback.Connected(this); } catch (SessionNotExistException) { Destroy(); } }
ConnectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); new Thread(new ThreadStart(() => { try { lock (_mutex) { _communicator = new Communicator( properties: _properties, compactIdResolver: _compactIdResolver, logger: _logger, observer: _observer, threadStart: _threadStart, threadStop: _threadStop, typeIdNamespaces: _typeIdNamespaces); } } catch (System.Exception ex) { lock (_mutex) { _destroy = true; } _callback.connectFailed(this, ex); return; } if (_communicator.GetDefaultRouter() == null) { var finder = IRouterFinderPrx.Parse(_finderStr, _communicator); try { _communicator.SetDefaultRouter(finder.GetRouter()); } catch (CommunicatorDestroyedException ex) { _callback.connectFailed(this, ex); return; } catch (System.Exception) { // // In case of error getting router identity from RouterFinder use default identity. // _communicator.SetDefaultRouter( Ice.IRouterPrx.UncheckedCast(finder.Clone(new Identity("router", "Glacier2")))); } } try { _callback.createdCommunicator(this); Ice.IRouterPrx?defaultRouter = _communicator.GetDefaultRouter(); Debug.Assert(defaultRouter != null); var routerPrx = IRouterPrx.UncheckedCast(defaultRouter); ISessionPrx session = factory(routerPrx); Connected(routerPrx, session); } catch (System.Exception ex) { _communicator.Destroy(); _callback.connectFailed(this, ex); } })).Start(); }
public static Test.IMyClassPrx allTests(global::Test.TestHelper helper) { var communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string rf = "test:" + helper.getTestEndpoint(0); var baseProxy = IObjectPrx.Parse(rf, communicator); test(baseProxy != null); var b1 = IObjectPrx.Parse("test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("test ", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test ", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("'test -f facet'", communicator); test(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("\"test -f facet'", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("\"test -f facet\"", communicator); test(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test\"", communicator); test(b1.Identity.Name.Equals("test -f facet@test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test @test\"", communicator); test(b1.Identity.Name.Equals("test -f facet@test @test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("test test", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\040test", communicator); test(b1.Identity.Name.Equals("test test") && b1.Identity.Category.Length == 0); try { b1 = IObjectPrx.Parse("test\\777", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\40test", communicator); test(b1.Identity.Name.Equals("test test")); // Test some octal and hex corner cases. b1 = IObjectPrx.Parse("test\\4test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\04test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\004test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\1114test", communicator); test(b1.Identity.Name.Equals("test\u00494test")); b1 = IObjectPrx.Parse("test\\b\\f\\n\\r\\t\\'\\\"\\\\test", communicator); test(b1.Identity.Name.Equals("test\b\f\n\r\t\'\"\\test") && b1.Identity.Category.Length == 0); b1 = IObjectPrx.Parse("category/test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test:tcp --sourceAddress \"::1\"", communicator); test(b1.Equals(IObjectPrx.Parse(b1.ToString(), communicator))); b1 = IObjectPrx.Parse("test:udp --sourceAddress \"::1\" --interface \"0:0:0:0:0:0:0:1%lo\"", communicator); test(b1.Equals(IObjectPrx.Parse(b1.ToString(), communicator))); try { b1 = IObjectPrx.Parse("", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("\"\"", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("\"\" test", communicator); // Invalid trailing characters. test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("test:", communicator); // Missing endpoint. test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Equals("adapter")); try { b1 = IObjectPrx.Parse("id@adapter test", communicator); test(false); } catch (ArgumentException) { } b1 = IObjectPrx.Parse("category/test@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("category/test@adapter:tcp", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter:tcp")); b1 = IObjectPrx.Parse("'category 1/test'@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category 1") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test 1'@adapter", communicator); test(b1.Identity.Name.Equals("test 1") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test'@'adapter 1'", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter 1")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@\"adapter:tcp\"", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") && b1.AdapterId.Equals("adapter:tcp")); b1 = IObjectPrx.Parse("id -f facet", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet")); b1 = IObjectPrx.Parse("id -f 'facet x'", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet x")); b1 = IObjectPrx.Parse("id -f \"facet x\"", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet x")); try { b1 = IObjectPrx.Parse("id -f \"facet x", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("id -f \'facet x", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test -f facet:tcp", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f \"facet:tcp\"", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet:tcp") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f facet@test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet") && b1.AdapterId.Equals("test")); b1 = IObjectPrx.Parse("test -f 'facet@test'", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet@test") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f 'facet@test'@test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet@test") && b1.AdapterId.Equals("test")); try { b1 = IObjectPrx.Parse("test -f facet@test @test", communicator); test(false); } catch (ArgumentException) { } b1 = IObjectPrx.Parse("test", communicator); test(b1.IsTwoway); b1 = IObjectPrx.Parse("test -t", communicator); test(b1.IsTwoway); b1 = IObjectPrx.Parse("test -o", communicator); test(b1.IsOneway); b1 = IObjectPrx.Parse("test -O", communicator); test(b1.InvocationMode == InvocationMode.BatchOneway); b1 = IObjectPrx.Parse("test -d", communicator); test(b1.InvocationMode == InvocationMode.Datagram); b1 = IObjectPrx.Parse("test -D", communicator); test(b1.InvocationMode == InvocationMode.BatchDatagram); b1 = IObjectPrx.Parse("test", communicator); test(!b1.IsSecure); b1 = IObjectPrx.Parse("test -s", communicator); test(b1.IsSecure); test(b1.EncodingVersion.Equals(Util.CurrentEncoding)); b1 = IObjectPrx.Parse("test -e 1.0", communicator); test(b1.EncodingVersion.Major == 1 && b1.EncodingVersion.Minor == 0); b1 = IObjectPrx.Parse("test -e 6.5", communicator); test(b1.EncodingVersion.Major == 6 && b1.EncodingVersion.Minor == 5); b1 = IObjectPrx.Parse("test -p 1.0 -e 1.0", communicator); test(b1.ToString().Equals("test -t -e 1.0")); b1 = IObjectPrx.Parse("test -p 6.5 -e 1.0", communicator); test(b1.ToString().Equals("test -t -p 6.5 -e 1.0")); try { IObjectPrx.Parse("test:tcp@adapterId", communicator); test(false); } catch (FormatException) { } // This is an unknown endpoint warning, not a parse exception. // //try //{ // b1 = communicator.stringToProxy("test -f the:facet:tcp"); // test(false); //} //catch(EndpointParseException) //{ //} try { IObjectPrx.Parse("test: :tcp", communicator); test(false); } catch (FormatException) { } // // Test invalid endpoint syntax // try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", " : "); test(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", "tcp: "); test(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", ":tcp"); test(false); } catch (FormatException) { } // // Test for bug ICE-5543: escaped escapes in stringToIdentity // var id = new Identity("test", ",X2QNUAzSBcJ_e$AV;E\\"); var id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); test(id.Equals(id2)); id = new Identity("test", ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\"); id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); test(id.Equals(id2)); id = new Identity("/test", "cat/"); string idStr = id.ToString(communicator.ToStringMode); test(idStr == "cat\\//\\/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); // Input string with various pitfalls id = Identity.Parse("\\342\\x82\\254\\60\\x9\\60\\"); test(id.Name == "€0\t0\\" && id.Category == ""); try { // Illegal character < 32 id = Identity.Parse("xx\01FooBar"); test(false); } catch (FormatException) { } try { // Illegal surrogate id = Identity.Parse("xx\\ud911"); test(false); } catch (FormatException) { } // Testing bytes 127(\x7F, \177) and € id = new Identity("test", "\x7f€"); idStr = id.ToString(ToStringMode.Unicode); test(idStr == "\\u007f€/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); test(id.ToString() == idStr); idStr = id.ToString(ToStringMode.ASCII); test(idStr == "\\u007f\\u20ac/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.Compat); test(idStr == "\\177\\342\\202\\254/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); test(id.Equals(id2)); // More unicode character id = new Identity("banana \x0E-\ud83c\udf4c\u20ac\u00a2\u0024", "greek \ud800\udd6a"); idStr = id.ToString(ToStringMode.Unicode); test(idStr == "greek \ud800\udd6a/banana \\u000e-\ud83c\udf4c\u20ac\u00a2$"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.ASCII); test(idStr == "greek \\U0001016a/banana \\u000e-\\U0001f34c\\u20ac\\u00a2$"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.Compat); id2 = Identity.Parse(idStr); test(idStr == "greek \\360\\220\\205\\252/banana \\016-\\360\\237\\215\\214\\342\\202\\254\\302\\242$"); test(id.Equals(id2)); output.WriteLine("ok"); output.Write("testing proxyToString... "); output.Flush(); b1 = IObjectPrx.Parse(rf, communicator); var b2 = IObjectPrx.Parse(b1.ToString(), communicator); test(b1.Equals(b2)); if (b1.GetConnection() != null) // not colloc-optimized target { b2 = b1.GetConnection().CreateProxy(Identity.Parse("fixed"), IObjectPrx.Factory); string str = b2.ToString(); test(b2.ToString() == str); string str2 = b1.Clone(b2.Identity).Clone(secure: b2.IsSecure).ToString(); // Verify that the stringified fixed proxy is the same as a regular stringified proxy // but without endpoints test(str2.StartsWith(str)); test(str2[str.Length] == ':'); } output.WriteLine("ok"); output.Write("testing propertyToProxy... "); output.Flush(); string propertyPrefix = "Foo.Proxy"; communicator.SetProperty(propertyPrefix, "test:" + helper.getTestEndpoint(0)); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); string property; property = propertyPrefix + ".Locator"; test(b1.Locator == null); communicator.SetProperty(property, "locator:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator")); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; test(b1.LocatorCacheTimeout == -1); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.LocatorCacheTimeout == 1); communicator.SetProperty(property, ""); // Now retest with an indirect proxy. communicator.SetProperty(propertyPrefix, "test"); property = propertyPrefix + ".Locator"; communicator.SetProperty(property, "locator:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator")); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; test(b1.LocatorCacheTimeout == -1); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.LocatorCacheTimeout == 1); communicator.SetProperty(property, ""); // This cannot be tested so easily because the property is cached // on communicator initialization. // //communicator.SetProperty("Default.LocatorCacheTimeout", "60"); //b1 = communicator.propertyToProxy(propertyPrefix); //test(b1.LocatorCacheTimeout == 60); //communicator.SetProperty("Default.LocatorCacheTimeout", ""); communicator.SetProperty(propertyPrefix, "test:" + helper.getTestEndpoint(0)); property = propertyPrefix + ".Router"; test(b1.Router == null); communicator.SetProperty(property, "router:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.Router != null && b1.Router.Identity.Name.Equals("router")); communicator.RemoveProperty(property); property = propertyPrefix + ".PreferSecure"; test(!b1.IsPreferSecure); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.IsPreferSecure); communicator.RemoveProperty(property); property = propertyPrefix + ".ConnectionCached"; test(b1.IsConnectionCached); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(!b1.IsConnectionCached); communicator.RemoveProperty(property); property = propertyPrefix + ".InvocationTimeout"; test(b1.InvocationTimeout == -1); communicator.SetProperty(property, "1000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.InvocationTimeout == 1000); communicator.RemoveProperty(property); property = propertyPrefix + ".EndpointSelection"; test(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Random"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Ordered"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.EndpointSelection == EndpointSelectionType.Ordered); communicator.RemoveProperty(property); property = propertyPrefix + ".CollocationOptimized"; test(b1.IsCollocationOptimized); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(!b1.IsCollocationOptimized); communicator.RemoveProperty(property); property = propertyPrefix + ".Context.c1"; test(!b1.Context.ContainsKey("c1")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.Context["c1"].Equals("TEST")); property = propertyPrefix + ".Context.c2"; test(!b1.Context.ContainsKey("c2")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.Context["c2"].Equals("TEST")); communicator.SetProperty(propertyPrefix + ".Context.c1", ""); communicator.SetProperty(propertyPrefix + ".Context.c2", ""); output.WriteLine("ok"); output.Write("testing proxyToProperty... "); output.Flush(); var router = IRouterPrx.Parse("router", communicator).Clone( collocationOptimized: false, connectionCached: true, preferSecure: true, endpointSelectionType: EndpointSelectionType.Random, locatorCacheTimeout: 200, invocationTimeout: 1500); var locator = ILocatorPrx.Parse("locator", communicator).Clone( collocationOptimized: true, connectionCached: false, preferSecure: true, endpointSelectionType: EndpointSelectionType.Random, locatorCacheTimeout: 300, invocationTimeout: 1500, router: router); b1 = IObjectPrx.Parse("test", communicator).Clone( collocationOptimized: true, connectionCached: true, preferSecure: false, endpointSelectionType: EndpointSelectionType.Ordered, locatorCacheTimeout: 100, invocationTimeout: 1234, encodingVersion: new EncodingVersion(1, 0), locator: locator); Dictionary <string, string> proxyProps = b1.ToProperty("Test"); test(proxyProps.Count == 21); test(proxyProps["Test"].Equals("test -t -e 1.0")); test(proxyProps["Test.CollocationOptimized"].Equals("1")); test(proxyProps["Test.ConnectionCached"].Equals("1")); test(proxyProps["Test.PreferSecure"].Equals("0")); test(proxyProps["Test.EndpointSelection"].Equals("Ordered")); test(proxyProps["Test.LocatorCacheTimeout"].Equals("100")); test(proxyProps["Test.InvocationTimeout"].Equals("1234")); test(proxyProps["Test.Locator"].Equals( "locator -t -e " + Util.EncodingVersionToString(Util.CurrentEncoding))); // Locator collocation optimization is always disabled. //test(proxyProps["Test.Locator.CollocationOptimized"].Equals("1")); test(proxyProps["Test.Locator.ConnectionCached"].Equals("0")); test(proxyProps["Test.Locator.PreferSecure"].Equals("1")); test(proxyProps["Test.Locator.EndpointSelection"].Equals("Random")); test(proxyProps["Test.Locator.LocatorCacheTimeout"].Equals("300")); test(proxyProps["Test.Locator.InvocationTimeout"].Equals("1500")); test(proxyProps["Test.Locator.Router"].Equals( "router -t -e " + Util.EncodingVersionToString(Util.CurrentEncoding))); test(proxyProps["Test.Locator.Router.CollocationOptimized"].Equals("0")); test(proxyProps["Test.Locator.Router.ConnectionCached"].Equals("1")); test(proxyProps["Test.Locator.Router.PreferSecure"].Equals("1")); test(proxyProps["Test.Locator.Router.EndpointSelection"].Equals("Random")); test(proxyProps["Test.Locator.Router.LocatorCacheTimeout"].Equals("200")); test(proxyProps["Test.Locator.Router.InvocationTimeout"].Equals("1500")); output.WriteLine("ok"); output.Write("testing ice_getCommunicator... "); output.Flush(); test(baseProxy.Communicator == communicator); output.WriteLine("ok"); output.Write("testing proxy methods... "); test(baseProxy.Clone(facet: "facet").Facet.Equals("facet")); test(baseProxy.Clone(adapterId: "id").AdapterId.Equals("id")); test(baseProxy.Clone(invocationMode: InvocationMode.Twoway).IsTwoway); test(baseProxy.Clone(invocationMode: InvocationMode.Oneway).IsOneway); test(baseProxy.Clone(invocationMode: InvocationMode.BatchOneway).InvocationMode == InvocationMode.BatchOneway); test(baseProxy.Clone(invocationMode: InvocationMode.Datagram).InvocationMode == InvocationMode.Datagram); test(baseProxy.Clone(invocationMode: InvocationMode.BatchDatagram).InvocationMode == InvocationMode.BatchDatagram); test(baseProxy.Clone(secure: true).IsSecure); test(!baseProxy.Clone(secure: false).IsSecure); test(baseProxy.Clone(collocationOptimized: true).IsCollocationOptimized); test(!baseProxy.Clone(collocationOptimized: false).IsCollocationOptimized); test(baseProxy.Clone(preferSecure: true).IsPreferSecure); test(!baseProxy.Clone(preferSecure: false).IsPreferSecure); try { baseProxy.Clone(connectionTimeout: 0); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(connectionTimeout: -1); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(connectionTimeout: -2); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: 0); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: -1); baseProxy.Clone(invocationTimeout: -2); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(invocationTimeout: -3); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(locatorCacheTimeout: 0); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(locatorCacheTimeout: -1); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(locatorCacheTimeout: -2); test(false); } catch (ArgumentException) { } output.WriteLine("ok"); output.Write("testing proxy comparison... "); output.Flush(); test(object.Equals(IObjectPrx.Parse("foo", communicator), IObjectPrx.Parse("foo", communicator))); test(!IObjectPrx.Parse("foo", communicator).Equals(IObjectPrx.Parse("foo2", communicator))); var compObj = IObjectPrx.Parse("foo", communicator); test(compObj.Clone(facet: "facet").Equals(compObj.Clone(facet: "facet"))); test(!compObj.Clone(facet: "facet").Equals(compObj.Clone(facet: "facet1"))); test(compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Oneway))); test(!compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Twoway))); test(compObj.Clone(secure: true).Equals(compObj.Clone(secure: true))); test(!compObj.Clone(secure: false).Equals(compObj.Clone(secure: true))); test(compObj.Clone(collocationOptimized: true).Equals(compObj.Clone(collocationOptimized: true))); test(!compObj.Clone(collocationOptimized: false).Equals(compObj.Clone(collocationOptimized: true))); test(compObj.Clone(connectionCached: true).Equals(compObj.Clone(connectionCached: true))); test(!compObj.Clone(connectionCached: false).Equals(compObj.Clone(connectionCached: true))); test(compObj.Clone(endpointSelectionType: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelectionType: EndpointSelectionType.Random))); test(!compObj.Clone(endpointSelectionType: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelectionType: EndpointSelectionType.Ordered))); test(compObj.Clone(connectionId: "id2").Equals(compObj.Clone(connectionId: "id2"))); test(!compObj.Clone(connectionId: "id1").Equals(compObj.Clone(connectionId: "id2"))); test(compObj.Clone(connectionId: "id1").ConnectionId.Equals("id1")); test(compObj.Clone(connectionId: "id2").ConnectionId.Equals("id2")); test(compObj.Clone(compress: true).Equals(compObj.Clone(compress: true))); test(!compObj.Clone(compress: false).Equals(compObj.Clone(compress: true))); test(!compObj.Compress.HasValue); test(compObj.Clone(compress: true).Compress.Value == true); test(compObj.Clone(compress: false).Compress.Value == false); test(compObj.Clone(connectionTimeout: 20).Equals(compObj.Clone(connectionTimeout: 20))); test(!compObj.Clone(connectionTimeout: 10).Equals(compObj.Clone(connectionTimeout: 20))); test(!compObj.ConnectionTimeout.HasValue); test(compObj.Clone(connectionTimeout: 10).ConnectionTimeout.Value == 10); test(compObj.Clone(connectionTimeout: 20).ConnectionTimeout.Value == 20); ILocatorPrx loc1 = ILocatorPrx.Parse("loc1:default -p 10000", communicator); ILocatorPrx loc2 = ILocatorPrx.Parse("loc2:default -p 10000", communicator); test(compObj.Clone(clearLocator: true).Equals(compObj.Clone(clearLocator: true))); test(compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc1))); test(!compObj.Clone(locator: loc1).Equals(compObj.Clone(clearLocator: true))); test(!compObj.Clone(clearLocator: true).Equals(compObj.Clone(locator: loc2))); test(!compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc2))); IRouterPrx rtr1 = IRouterPrx.Parse("rtr1:default -p 10000", communicator); IRouterPrx rtr2 = IRouterPrx.Parse("rtr2:default -p 10000", communicator); test(compObj.Clone(clearRouter: true).Equals(compObj.Clone(clearRouter: true))); test(compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr1))); test(!compObj.Clone(router: rtr1).Equals(compObj.Clone(clearRouter: true))); test(!compObj.Clone(clearRouter: true).Equals(compObj.Clone(router: rtr2))); test(!compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr2))); Dictionary <string, string> ctx1 = new Dictionary <string, string>(); ctx1["ctx1"] = "v1"; Dictionary <string, string> ctx2 = new Dictionary <string, string>(); ctx2["ctx2"] = "v2"; test(compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: new Dictionary <string, string>()))); test(compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx1))); test(!compObj.Clone(context: ctx1).Equals( compObj.Clone(context: new Dictionary <string, string>()))); test(!compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: ctx2))); test(!compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx2))); test(compObj.Clone(preferSecure: true).Equals(compObj.Clone(preferSecure: true))); test(!compObj.Clone(preferSecure: true).Equals(compObj.Clone(preferSecure: false))); var compObj1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator); var compObj2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator); test(!compObj1.Equals(compObj2)); compObj1 = IObjectPrx.Parse("foo@MyAdapter1", communicator); compObj2 = IObjectPrx.Parse("foo@MyAdapter2", communicator); test(!compObj1.Equals(compObj2)); test(compObj1.Clone(locatorCacheTimeout: 20).Equals(compObj1.Clone(locatorCacheTimeout: 20))); test(!compObj1.Clone(locatorCacheTimeout: 10).Equals(compObj1.Clone(locatorCacheTimeout: 20))); test(compObj1.Clone(invocationTimeout: 20).Equals(compObj1.Clone(invocationTimeout: 20))); test(!compObj1.Clone(invocationTimeout: 10).Equals(compObj1.Clone(invocationTimeout: 20))); compObj1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 1000", communicator); compObj2 = IObjectPrx.Parse("foo@MyAdapter1", communicator); test(!compObj1.Equals(compObj2)); IEndpoint[] endpts1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints; IEndpoint[] endpts2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator).Endpoints; test(!endpts1[0].Equals(endpts2[0])); test(endpts1[0].Equals(IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints[0])); Connection baseConnection = baseProxy.GetConnection(); if (baseConnection != null) { Connection baseConnection2 = baseProxy.Clone(connectionId: "base2").GetConnection(); compObj1 = compObj1.Clone(fixedConnection: baseConnection); compObj2 = compObj2.Clone(fixedConnection: baseConnection2); test(!compObj1.Equals(compObj2)); } output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); Test.IMyClassPrx cl = Test.IMyClassPrx.CheckedCast(baseProxy); test(cl != null); Test.IMyDerivedClassPrx derived = Test.IMyDerivedClassPrx.CheckedCast(cl); test(derived != null); test(cl.Equals(baseProxy)); test(derived.Equals(baseProxy)); test(cl.Equals(derived)); try { Test.IMyDerivedClassPrx.CheckedCast(cl.Clone(facet: "facet")); test(false); } catch (ObjectNotExistException) { } output.WriteLine("ok"); output.Write("testing checked cast with context... "); output.Flush(); Dictionary <string, string> c = cl.getContext(); test(c == null || c.Count == 0); c = new Dictionary <string, string>(); c["one"] = "hello"; c["two"] = "world"; cl = Test.IMyClassPrx.CheckedCast(baseProxy, c); Dictionary <string, string> c2 = cl.getContext(); test(Collections.Equals(c, c2)); output.WriteLine("ok"); output.Write("testing ice_fixed... "); output.Flush(); { Connection connection = cl.GetConnection(); if (connection != null) { test(!cl.IsFixed); Test.IMyClassPrx prx = cl.Clone(fixedConnection: connection); test(prx.IsFixed); prx.IcePing(); try { cl.Clone(secure: true, fixedConnection: connection); test(false); } catch (ArgumentException) { } test(cl.Clone(facet: "facet", fixedConnection: connection).Facet.Equals("facet")); test(cl.Clone(invocationMode: InvocationMode.Oneway, fixedConnection: connection).IsOneway); Dictionary <string, string> ctx = new Dictionary <string, string>(); ctx["one"] = "hello"; ctx["two"] = "world"; test(cl.Clone(fixedConnection: connection).Context.Count == 0); test(cl.Clone(context: ctx, fixedConnection: connection).Context.Count == 2); test(cl.Clone(fixedConnection: connection).InvocationTimeout == -1); test(cl.Clone(invocationTimeout: 10, fixedConnection: connection).InvocationTimeout == 10); test(cl.Clone(fixedConnection: connection).GetConnection() == connection); test(cl.Clone(fixedConnection: connection).Clone(fixedConnection: connection).GetConnection() == connection); test(!cl.Clone(fixedConnection: connection).ConnectionTimeout.HasValue); test(cl.Clone(compress: true, fixedConnection: connection).Compress.Value); Connection fixedConnection = cl.Clone(connectionId: "ice_fixed").GetConnection(); test(cl.Clone(fixedConnection: connection).Clone(fixedConnection: fixedConnection).GetConnection() == fixedConnection); try { cl.Clone(secure: !connection.Endpoint.GetInfo().Secure(), fixedConnection: connection); test(false); } catch (ArgumentException) { } try { cl.Clone(invocationMode: InvocationMode.Datagram, fixedConnection: connection); test(false); } catch (ArgumentException) { } } } output.WriteLine("ok"); output.Write("testing encoding versioning... "); output.Flush(); string ref20 = "test -e 2.0:" + helper.getTestEndpoint(0); Test.IMyClassPrx cl20 = Test.IMyClassPrx.Parse(ref20, communicator); try { cl20.IcePing(); test(false); } catch (UnsupportedEncodingException) { // Server 2.0 endpoint doesn't support 1.1 version. } // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the // call will use the 1.1 encoding string ref13 = "test -e 1.3:" + helper.getTestEndpoint(0); Test.IMyClassPrx cl13 = Test.IMyClassPrx.Parse(ref13, communicator); cl13.IcePing(); cl13.IcePingAsync().Wait(); try { // Send request with bogus 1.2 encoding. EncodingVersion version = new EncodingVersion(1, 2); OutputStream os = new OutputStream(communicator); os.StartEncapsulation(); os.EndEncapsulation(); byte[] inEncaps = os.Finished(); inEncaps[4] = version.Major; inEncaps[5] = version.Minor; byte[] outEncaps; cl.Invoke("ice_ping", OperationMode.Normal, inEncaps, out outEncaps); test(false); } catch (UnknownLocalException ex) { // The server thrown an UnsupportedEncodingException test(ex.Unknown.IndexOf("UnsupportedEncodingException") > 0); } try { // Send request with bogus 2.0 encoding. EncodingVersion version = new EncodingVersion(2, 0); OutputStream os = new OutputStream(communicator); os.StartEncapsulation(); os.EndEncapsulation(); byte[] inEncaps = os.Finished(); inEncaps[4] = version.Major; inEncaps[5] = version.Minor; byte[] outEncaps; cl.Invoke("ice_ping", OperationMode.Normal, inEncaps, out outEncaps); test(false); } catch (UnknownLocalException ex) { // The server thrown an UnsupportedEncodingException test(ex.Unknown.IndexOf("UnsupportedEncodingException") > 0); } output.WriteLine("ok"); output.Write("testing protocol versioning... "); output.Flush(); ref20 = "test -p 2.0:" + helper.getTestEndpoint(0); cl20 = Test.IMyClassPrx.Parse(ref20, communicator); try { cl20.IcePing(); test(false); } catch (UnsupportedProtocolException) { // Server 2.0 proxy doesn't support 1.0 version. } // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the // call will use the 1.1 protocol ref13 = "test -p 1.3:" + helper.getTestEndpoint(0); cl13 = Test.IMyClassPrx.Parse(ref13, communicator); cl13.IcePing(); cl13.IcePingAsync().Wait(); output.WriteLine("ok"); output.Write("testing opaque endpoints... "); output.Flush(); try { // Invalid -x option IObjectPrx.Parse("id:opaque -t 99 -v abcd -x abc", communicator); test(false); } catch (FormatException) { } try { // Missing -t and -v IObjectPrx.Parse("id:opaque", communicator); test(false); } catch (FormatException) { } try { // Repeated -t IObjectPrx.Parse("id:opaque -t 1 -t 1 -v abcd", communicator); test(false); } catch (FormatException) { } try { // Repeated -v IObjectPrx.Parse("id:opaque -t 1 -v abcd -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing -t IObjectPrx.Parse("id:opaque -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing -v IObjectPrx.Parse("id:opaque -t 1", communicator); test(false); } catch (FormatException) { } try { // Missing arg for -t IObjectPrx.Parse("id:opaque -t -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing arg for -v IObjectPrx.Parse("id:opaque -t 1 -v", communicator); test(false); } catch (FormatException) { } try { // Not a number for -t IObjectPrx.Parse("id:opaque -t x -v abcd", communicator); test(false); } catch (FormatException) { } try { // < 0 for -t IObjectPrx.Parse("id:opaque -t -1 -v abcd", communicator); test(false); } catch (FormatException) { } try { // Invalid char for -v IObjectPrx.Parse("id:opaque -t 99 -v x?c", communicator); test(false); } catch (FormatException) { } try { // Invalid lenght for base64 input IObjectPrx.Parse("id:opaque -t 99 -v xc", communicator); test(false); } catch (FormatException) { } // Legal TCP endpoint expressed as opaque endpoint var p1 = IObjectPrx.Parse("test -e 1.1:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==", communicator); string pstr = p1.ToString(); test(pstr.Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000")); // Opaque endpoint encoded with 1.1 encoding. var p2 = IObjectPrx.Parse("test -e 1.1:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==", communicator); test(p2.ToString().Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000")); if ((communicator.GetPropertyAsInt("IPv6") ?? 0) == 0) { // Working? bool ssl = communicator.GetProperty("Default.Protocol") == "ssl"; bool tcp = communicator.GetProperty("Default.Protocol") == "tcp"; // Two legal TCP endpoints expressed as opaque endpoints p1 = IObjectPrx.Parse("test -e 1.1:" + "" + "opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:" + "opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA==", communicator); pstr = p1.ToString(); test(pstr.Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000:tcp -h 127.0.0.2 -p 12011 -t 10000")); // Test that an SSL endpoint and a nonsense endpoint get written back out as an opaque endpoint. p1 = IObjectPrx.Parse("test -e 1.1:opaque -e 1.1 -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -e 1.1 -t 99 -v abch", communicator); pstr = p1.ToString(); if (ssl) { test(pstr.Equals("test -t -e 1.1:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.1 -v abch")); } else if (tcp) { test(pstr.Equals( "test -t -e 1.1:opaque -t 2 -e 1.1 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.1 -v abch")); } } output.WriteLine("ok"); output.Write("testing communicator shutdown/destroy... "); output.Flush(); { Communicator com = new Communicator(); com.Shutdown(); test(com.IsShutdown()); com.WaitForShutdown(); com.Destroy(); com.Shutdown(); test(com.IsShutdown()); com.WaitForShutdown(); com.Destroy(); } output.WriteLine("ok"); return(cl); }
/// <summary>Creates a new object adapter with the specified router proxy. This method generates a UUID for /// the object adapter name and then calls /// <see cref="CreateObjectAdapterWithRouter(string, IRouterPrx, bool, TaskScheduler?)"/>.</summary> /// <param name="router">The proxy to the router.</param> /// <param name="serializeDispatch">Indicates whether or not this object adapter serializes the dispatching of /// of requests received over the same connection.</param> /// <param name="taskScheduler">The optional task scheduler to use for dispatching requests.</param> /// <returns>The new object adapter.</returns> public ObjectAdapter CreateObjectAdapterWithRouter( IRouterPrx router, bool serializeDispatch = false, TaskScheduler?taskScheduler = null) => CreateObjectAdapterWithRouter(Guid.NewGuid().ToString(), router, serializeDispatch, taskScheduler);
private void ConnectImpl(Func <IRouterPrx, ISessionPrx> factory) { Debug.Assert(!_destroy); new Thread(new ThreadStart(() => { try { lock (_mutex) { _communicator = new Communicator(_properties, logger: _logger, observer: _observer, tlsClientOptions: _tlsClientOptions, tlsServerOptions: _tlsServerOptions); } } catch (Exception ex) { lock (_mutex) { _destroy = true; } _callback.ConnectFailed(this, ex); return; } if (_communicator.DefaultRouter == null) { IRouterFinderPrx?finder = null; try { finder = IRouterFinderPrx.Parse(_finderStr, _communicator); _communicator.DefaultRouter = finder.GetRouter(); } catch (CommunicatorDisposedException ex) { _callback.ConnectFailed(this, ex); return; } catch (Exception ex) { if (finder == null) { _callback.ConnectFailed(this, ex); return; } else { // In case of error getting router identity from RouterFinder use default identity. _communicator.DefaultRouter = finder.Clone(Ice.IRouterPrx.Factory, identity: new Identity("router", "Glacier2")); } } } try { _callback.CreatedCommunicator(this); IRouterPrx routerPrx = _communicator.DefaultRouter !.Clone(IRouterPrx.Factory); ISessionPrx session = factory(routerPrx); Connected(routerPrx, session); } catch (Exception ex) { _communicator.Dispose(); _callback.ConnectFailed(this, ex); } })).Start(); }
public static ITestIntfPrx Run(TestHelper helper) { Communicator?communicator = helper.Communicator; TestHelper.Assert(communicator != null); bool ice1 = TestHelper.GetTestProtocol(communicator.GetProperties()) == Protocol.Ice1; TextWriter output = helper.Output; output.Write("testing stringToProxy... "); output.Flush(); var obj = ITestIntfPrx.Parse(helper.GetTestProxy("test", 0), communicator); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); { using var adapter = communicator.CreateObjectAdapterWithEndpoints( "TransientTestAdapter", helper.GetTestEndpoint(1)); try { communicator.CreateObjectAdapterWithEndpoints("TransientTestAdapter", helper.GetTestEndpoint(2)); TestHelper.Assert(false); } catch (ArgumentException) { } } // Use a different port than the first adapter to avoid an "address already in use" error. { using var adapter = communicator.CreateObjectAdapterWithEndpoints( "TransientTestAdapter", helper.GetTestEndpoint(2)); } output.WriteLine("ok"); } output.Write("creating/activating/disposing object adapter in one operation... "); output.Flush(); obj.Transient(); obj.TransientAsync().Wait(); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { using var comm = new Communicator(communicator.GetProperties()); IObjectPrx.Parse(helper.GetTestProxy("test", 0), communicator).IcePingAsync(); } output.WriteLine("ok"); } { output.Write("testing invalid object adapter endpoints... "); output.Flush(); try { communicator.CreateObjectAdapterWithEndpoints( "BadAdapter1", ice1 ? "tcp -h localhost -p 0" : "ice+tcp://localhost:0"); TestHelper.Assert(false); } catch (InvalidConfigurationException) { // expected } try { communicator.CreateObjectAdapterWithEndpoints( "BadAdapter2", ice1 ? "tcp -h 127.0.0.1 -p 0:tcp -h \"::1\" -p 10000" : "ice+tcp://127.0.0.1:0?alt-endpoint=[::1]:10000"); TestHelper.Assert(false); } catch (InvalidConfigurationException) { // expected } output.WriteLine("ok"); } { output.Write("testing object adapter default published endpoints... "); string testHost = "testhost"; communicator.SetProperty("DAdapter.ServerName", testHost); if (ice1) { communicator.SetProperty("DAdapter.AcceptNonSecure", "true"); } { communicator.SetProperty( "DAdapter.Endpoints", ice1 ? "tcp -h \"::0\" -p 0" : "ice+tcp://[::0]:0"); using var adapter = communicator.CreateObjectAdapter("DAdapter"); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); Endpoint publishedEndpoint = adapter.PublishedEndpoints[0]; TestHelper.Assert(publishedEndpoint.Host == testHost); } { communicator.SetProperty( "DAdapter.Endpoints", ice1 ? $"{helper.GetTestEndpoint(1)}:{helper.GetTestEndpoint(2)}" : $"{helper.GetTestEndpoint(1)}?alt-endpoint={helper.GetTestEndpoint(2)}"); using var adapter = communicator.CreateObjectAdapter("DAdapter"); TestHelper.Assert(adapter.PublishedEndpoints.Count == 2); Endpoint publishedEndpoint0 = adapter.PublishedEndpoints[0]; TestHelper.Assert(publishedEndpoint0.Host == testHost); TestHelper.Assert(publishedEndpoint0.Port == helper.BasePort + 1); Endpoint publishedEndpoint1 = adapter.PublishedEndpoints[1]; TestHelper.Assert(publishedEndpoint1.Host == testHost); TestHelper.Assert(publishedEndpoint1.Port == helper.BasePort + 2); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.SetProperty("PAdapter.PublishedEndpoints", ice1 ? "tcp -h localhost -p 12345 -t 30000" : "ice+tcp://localhost:12345"); using var adapter = communicator.CreateObjectAdapter("PAdapter"); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); Endpoint?endpt = adapter.PublishedEndpoints[0]; TestHelper.Assert(endpt != null); if (ice1) { TestHelper.Assert(endpt.ToString() == "tcp -h localhost -p 12345 -t 30000"); } else { TestHelper.Assert(endpt.ToString() == "ice+tcp://localhost:12345"); } var prx = IObjectPrx.Parse(ice1 ? "dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000" : "ice+tcp://localhost:12346/dummy?alt-endpoint=localhost:12347", communicator); adapter.SetPublishedEndpoints(prx.Endpoints); TestHelper.Assert(adapter.PublishedEndpoints.Count == 2); TestHelper.Assert(adapter.CreateProxy(new Identity("dummy", ""), IObjectPrx.Factory).Endpoints. SequenceEqual(prx.Endpoints)); TestHelper.Assert(adapter.PublishedEndpoints.SequenceEqual(prx.Endpoints)); } output.WriteLine("ok"); Connection?connection = obj.GetConnection(); if (connection != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); ObjectAdapter adapter = communicator.CreateObjectAdapter(); connection.Adapter = adapter; connection.Adapter = null; adapter.Dispose(); // Setting a deactivated adapter on a connection no longer raise ObjectAdapterDeactivatedException connection.Adapter = adapter; output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); if (ice1) { var routerId = new Identity("router", ""); IRouterPrx router = obj.Clone(IRouterPrx.Factory, connectionId: "rc", identity: routerId); { using var adapter = communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(adapter.PublishedEndpoints.Count == 1); string endpointsStr = adapter.PublishedEndpoints[0].ToString(); TestHelper.Assert(endpointsStr == "tcp -h localhost -p 23456 -t 60000"); try { adapter.SetPublishedEndpoints(router.Endpoints); TestHelper.Assert(false); } catch (InvalidOperationException) { // Expected. } } try { routerId = new Identity("test", ""); router = obj.Clone(IRouterPrx.Factory, identity: routerId); communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = IRouterPrx.Parse(helper.GetTestProxy("test", 1), communicator); communicator.CreateObjectAdapterWithRouter(router); TestHelper.Assert(false); } catch (ConnectFailedException) { } } else { try { using var adapter = communicator.CreateObjectAdapterWithRouter( obj.Clone(IRouterPrx.Factory, connectionId: "rc", identity: new Identity("router", ""))); TestHelper.Assert(false); } catch (ArgumentException) { // expected. } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { using var adapter1 = communicator.CreateObjectAdapterWithEndpoints("Adpt1", helper.GetTestEndpoint(10)); try { communicator.CreateObjectAdapterWithEndpoints("Adpt2", helper.GetTestEndpoint(10)); TestHelper.Assert(false); } catch { // Expected can't re-use the same endpoint. } } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.Deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.IcePing(); TestHelper.Assert(false); } catch { output.WriteLine("ok"); } return(obj); }
ConnectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); new Thread(new ThreadStart(() => { try { lock (_mutex) { _communicator = new Communicator( properties: _properties, logger: _logger, observer: _observer, certificates: _certificates, caCertificates: _caCertificates, certificateValidationCallback: _certificateValidationCallback, passwordCallback: _passwordCallback); } } catch (System.Exception ex) { lock (_mutex) { _destroy = true; } _callback.ConnectFailed(this, ex); return; } if (_communicator.DefaultRouter == null) { IRouterFinderPrx?finder = null; try { finder = IRouterFinderPrx.Parse(_finderStr, _communicator); _communicator.DefaultRouter = finder.GetRouter(); } catch (CommunicatorDestroyedException ex) { _callback.ConnectFailed(this, ex); return; } catch (System.Exception ex) { if (finder == null) { _callback.ConnectFailed(this, ex); return; } else { // // In case of error getting router identity from RouterFinder use default identity. // _communicator.DefaultRouter = finder.Clone(new Identity("router", "Glacier2"), Ice.IRouterPrx.Factory); } } } try { _callback.CreatedCommunicator(this); Ice.IRouterPrx?defaultRouter = _communicator.DefaultRouter; Debug.Assert(defaultRouter != null); var routerPrx = IRouterPrx.UncheckedCast(defaultRouter); ISessionPrx session = factory(routerPrx); Connected(routerPrx, session); } catch (System.Exception ex) { _communicator.Destroy(); _callback.ConnectFailed(this, ex); } })).Start(); }
public static IMyClassPrx Run(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); System.IO.TextWriter output = helper.GetWriter(); output.Write("testing proxy parsing... "); output.Flush(); // ice1 proxies string[] ice1ProxyArray = { "ice -t:tcp -p 10000", "ice+tcp:ssl -p 10000", }; // ice2 proxies string[] ice2ProxyArray = { "ice+tcp://host.zeroc.com/identity#facet", "ice+tcp://host.zeroc.com:1000/category/name", "ice+tcp://host.zeroc.com/category/name%20with%20space", "ice+ws://host.zeroc.com//identity", "ice+ws://host.zeroc.com//identity?alt-endpoint=host2.zeroc.com", "ice+ws://host.zeroc.com//identity?alt-endpoint=host2.zeroc.com:10000", "ice+tcp://[::1]:10000/identity?alt-endpoint=host1:10000,host2,host3,host4", "ice+ssl://[::1]:10000/identity?alt-endpoint=host1:10000&alt-endpoint=host2,host3&alt-endpoint=[::2]", "ice:location//identity#facet", "ice+tcp://host.zeroc.com//identity", "ice+tcp://host.zeroc.com:/identity", // another syntax for empty port "ice+universal://com.zeroc.ice/identity?transport=iaps&option=a,b%2Cb,c&option=d", "ice+universal://host.zeroc.com/identity?transport=100", "ice+universal://[::ab:cd:ef:00]/identity?transport=bt", // leading :: to make the address IPv6-like "ice+ws://host.zeroc.com/identity?resource=/foo%2Fbar?/xyz", "ice+universal://host.zeroc.com:10000/identity?transport=tcp", "ice+universal://host.zeroc.com/identity?transport=ws&option=/foo%2520/bar", "ice:tcp -p 10000", // a valid URI }; // ice3 proxies string[] ice3ProxyArray = { "ice+universal://host.zeroc.com/identity?transport=ws&option=/foo%2520/bar&protocol=3" }; foreach (string str in ice1ProxyArray) { var prx = IObjectPrx.Parse(str, communicator); TestHelper.Assert(prx.Protocol == Protocol.Ice1); // output.WriteLine($"{str} = {prx}"); var prx2 = IObjectPrx.Parse(prx.ToString() !, communicator); TestHelper.Assert(prx.Equals(prx2)); // round-trip works } foreach (string str in ice2ProxyArray) { var prx = IObjectPrx.Parse(str, communicator); TestHelper.Assert(prx.Protocol == Protocol.Ice2); // output.WriteLine($"{str} = {prx}"); var prx2 = IObjectPrx.Parse(prx.ToString() !, communicator); TestHelper.Assert(prx.Equals(prx2)); // round-trip works } foreach (string str in ice3ProxyArray) { var prx = IObjectPrx.Parse(str, communicator); TestHelper.Assert(prx.Protocol == (Protocol)3); // output.WriteLine($"{str} = {prx}"); var prx2 = IObjectPrx.Parse(prx.ToString() !, communicator); TestHelper.Assert(prx.Equals(prx2)); // round-trip works } string[] badProxyArray = { "ice+tcp://host.zeroc.com:foo", // missing host "ice+tcp:identity?protocol=invalid", // invalid protocol "ice+universal://host.zeroc.com", // missing transport "ice+universal://host.zeroc.com?transport=100&protocol=ice1", // invalid protocol "ice://*****:*****@adapter test", "id -f \"facet x", "id -f \'facet x", "test -f facet@test @test", "test -p 2.0", "test:tcp@adapterId", "test: :tcp", "id:opaque -t 99 -v abcd -x abc", // invalid x option "id:opaque", // missing -t and -v "id:opaque -t 1 -t 1 -v abcd", // repeated -t "id:opaque -t 1 -v abcd -v abcd", "id:opaque -v abcd", "id:opaque -t 1", "id:opaque -t -v abcd", "id:opaque -t 1 -v", "id:opaque -t x -v abcd", "id:opaque -t -1 -v abcd", // -t must be >= 0 "id:opaque -t 99 -v x?c", // invalid char in v "id:opaque -t 99 -v xc", // invalid length for base64 input }; foreach (string str in badProxyArray) { try { _ = IObjectPrx.Parse(str, communicator); TestHelper.Assert(false); } catch (FormatException) { // expected } } string rf = helper.GetTestProxy("test"); var baseProxy = IObjectPrx.Parse(rf, communicator); TestHelper.Assert(baseProxy != null); var b1 = IObjectPrx.Parse("ice:test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("ice:test ", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" ice:test ", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" ice:test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("test ", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test ", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); // The following tests are only relevant to the ice1 format b1 = IObjectPrx.Parse("'test -f facet'", communicator); TestHelper.Assert(b1.Identity.Name == "test -f facet" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("\"test -f facet'", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("\"test -f facet\"", communicator); TestHelper.Assert(b1.Identity.Name == "test -f facet" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test\"", communicator); TestHelper.Assert(b1.Identity.Name == "test -f facet@test" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test @test\"", communicator); TestHelper.Assert(b1.Identity.Name == "test -f facet@test @test" && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("test test", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\040test", communicator); TestHelper.Assert(b1.Identity.Name == "test test" && b1.Identity.Category.Length == 0); try { b1 = IObjectPrx.Parse("test\\777", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\40test", communicator); TestHelper.Assert(b1.Identity.Name == "test test"); // Test some octal and hex corner cases. b1 = IObjectPrx.Parse("test\\4test", communicator); TestHelper.Assert(b1.Identity.Name == "test\u0004test"); b1 = IObjectPrx.Parse("test\\04test", communicator); TestHelper.Assert(b1.Identity.Name == "test\u0004test"); b1 = IObjectPrx.Parse("test\\004test", communicator); TestHelper.Assert(b1.Identity.Name == "test\u0004test"); b1 = IObjectPrx.Parse("test\\1114test", communicator); TestHelper.Assert(b1.Identity.Name == "test\u00494test"); b1 = IObjectPrx.Parse("test\\b\\f\\n\\r\\t\\'\\\"\\\\test", communicator); TestHelper.Assert(b1.Identity.Name == "test\b\f\n\r\t\'\"\\test" && b1.Identity.Category.Length == 0); // End of ice1 format-only tests b1 = IObjectPrx.Parse("ice:category/test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category" && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("ice+tcp://host:10000/test?source-address=::1", communicator); TestHelper.Assert(b1.Equals(IObjectPrx.Parse(b1.ToString() !, communicator))); b1 = IObjectPrx.Parse("ice:adapter//test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("ice:adapter/category/test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category" && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("ice:adapter:tcp/category/test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category" && b1.AdapterId.Equals("adapter:tcp")); // preferred syntax with escape: TestHelper.Assert(b1.Equals(IObjectPrx.Parse("ice:adapter%3Atcp/category/test", communicator))); b1 = IObjectPrx.Parse("category/test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category" && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test:tcp -h host -p 10000 --sourceAddress \"::1\"", communicator); TestHelper.Assert(b1.Equals(IObjectPrx.Parse(b1.ToString() !, communicator))); b1 = IObjectPrx.Parse( "test:udp -h host -p 10000 --sourceAddress \"::1\" --interface \"0:0:0:0:0:0:0:1%lo\"", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test@adapter", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("category/test@adapter", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category" && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("category/test@adapter:tcp", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category" && b1.AdapterId.Equals("adapter:tcp")); // The following tests are only for the ice1 format: b1 = IObjectPrx.Parse("'category 1/test'@adapter", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category 1" && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test 1'@adapter", communicator); TestHelper.Assert(b1.Identity.Name == "test 1" && b1.Identity.Category == "category" && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test'@'adapter 1'", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category" && b1.AdapterId.Equals("adapter 1")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@adapter", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category /test@foo" && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@\"adapter:tcp\"", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category == "category /test@foo" && b1.AdapterId.Equals("adapter:tcp")); // End of ice1 format-only tests. b1 = IObjectPrx.Parse("ice:id#facet", communicator); TestHelper.Assert(b1.Identity.Name == "id" && b1.Identity.Category.Length == 0 && b1.Facet == "facet"); b1 = IObjectPrx.Parse("ice:id#facet%20x", communicator); TestHelper.Assert(b1.Identity.Name == "id" && b1.Identity.Category.Length == 0 && b1.Facet == "facet x"); b1 = IObjectPrx.Parse("id -f facet", communicator); TestHelper.Assert(b1.Identity.Name == "id" && b1.Identity.Category.Length == 0 && b1.Facet == "facet"); b1 = IObjectPrx.Parse("id -f 'facet x'", communicator); TestHelper.Assert(b1.Identity.Name == "id" && b1.Identity.Category.Length == 0 && b1.Facet == "facet x"); // The following tests are only for the ice1 format: b1 = IObjectPrx.Parse("id -f \"facet x\"", communicator); TestHelper.Assert(b1.Identity.Name == "id" && b1.Identity.Category.Length == 0 && b1.Facet == "facet x"); b1 = IObjectPrx.Parse("test -f facet:tcp", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet == "facet" && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f \"facet:tcp\"", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet == "facet:tcp" && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f facet@test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet == "facet" && b1.AdapterId.Equals("test")); b1 = IObjectPrx.Parse("test -f 'facet@test'", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet == "facet@test" && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f 'facet@test'@test", communicator); TestHelper.Assert(b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.Facet == "facet@test" && b1.AdapterId.Equals("test")); // End of ice1 format-only tests. b1 = IObjectPrx.Parse("ice:test", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.Twoway); TestHelper.Assert(!b1.IsOneway); b1 = IObjectPrx.Parse("test", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.Twoway); TestHelper.Assert(!b1.IsOneway); b1 = IObjectPrx.Parse("test -t", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.Twoway); b1 = IObjectPrx.Parse("test -o", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.Oneway); b1 = IObjectPrx.Parse("test -O", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.BatchOneway); b1 = IObjectPrx.Parse("test -d", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.Datagram); b1 = IObjectPrx.Parse("test -D", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.BatchDatagram); b1 = IObjectPrx.Parse("ice:test", communicator); TestHelper.Assert(b1.Protocol == Protocol.Ice2 && b1.Encoding == Encoding.V2_0); b1 = IObjectPrx.Parse("test", communicator); TestHelper.Assert(b1.Protocol == Protocol.Ice1 && b1.Encoding == Encoding.V1_1); b1 = IObjectPrx.Parse("ice:test?encoding=6.5", communicator); TestHelper.Assert(b1.Encoding.Major == 6 && b1.Encoding.Minor == 5); b1 = IObjectPrx.Parse("test -e 6.5", communicator); TestHelper.Assert(b1.Encoding.Major == 6 && b1.Encoding.Minor == 5); b1 = IObjectPrx.Parse("ice:test?encoding=2.1&protocol=6", communicator); TestHelper.Assert(b1.Protocol == (Protocol)6 && b1.Encoding.Major == 2 && b1.Encoding.Minor == 1); // Test invalid endpoint syntax // TODO: why are we testing this here? try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", " : "); TestHelper.Assert(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", "tcp: "); TestHelper.Assert(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", ":tcp"); TestHelper.Assert(false); } catch (FormatException) { } // Test for bug ICE-5543: escaped escapes in Identity.Parse var id = new Identity("test", ",X2QNUAzSBcJ_e$AV;E\\"); var id2 = Identity.Parse(id.ToString(communicator.ToStringMode), uriFormat: false); var id3 = Identity.Parse(id.ToString()); // new URI style TestHelper.Assert(id == id2); TestHelper.Assert(id == id3); id = new Identity("test", ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\"); id2 = Identity.Parse(id.ToString(communicator.ToStringMode), uriFormat: false); id3 = Identity.Parse(id.ToString()); TestHelper.Assert(id == id2); TestHelper.Assert(id == id3); id = new Identity("/test", "cat/"); string idStr = id.ToString(communicator.ToStringMode); TestHelper.Assert(idStr == "cat\\//\\/test"); id2 = Identity.Parse(idStr, uriFormat: false); id3 = Identity.Parse(id.ToString()); TestHelper.Assert(id == id2); TestHelper.Assert(id == id3); // Input string in ice1 format with various pitfalls idStr = "\\342\\x82\\254\\60\\x9\\60\\"; id = Identity.Parse(idStr, uriFormat: false); TestHelper.Assert(id.Name == "€0\t0\\" && id.Category.Length == 0); try { // Illegal character < 32 _ = Identity.Parse("xx\01FooBar", uriFormat: false); TestHelper.Assert(false); } catch (FormatException) { } try { // Illegal surrogate _ = Identity.Parse("xx\\ud911", uriFormat: false); TestHelper.Assert(false); } catch (FormatException) { } // Testing bytes 127(\x7F, \177) and € // € is encoded as 0x20AC (UTF-16) and 0xE2 0x82 0xAC (UTF-8) id = new Identity("test", "\x7f€"); idStr = id.ToString(); TestHelper.Assert(idStr == "%7F%E2%82%AC/test"); id2 = Identity.Parse(idStr); TestHelper.Assert(id == id2); idStr = id.ToString(ToStringMode.Unicode); TestHelper.Assert(idStr == "\\u007f€/test"); id2 = Identity.Parse(idStr, uriFormat: false); TestHelper.Assert(id == id2); idStr = id.ToString(ToStringMode.ASCII); TestHelper.Assert(idStr == "\\u007f\\u20ac/test"); id2 = Identity.Parse(idStr, uriFormat: false); TestHelper.Assert(id == id2); idStr = id.ToString(ToStringMode.Compat); TestHelper.Assert(idStr == "\\177\\342\\202\\254/test"); id2 = Identity.Parse(idStr, uriFormat: false); TestHelper.Assert(id == id2); // More unicode character id = new Identity("banana \x0E-\ud83c\udf4c\u20ac\u00a2\u0024", "greek \ud800\udd6a"); idStr = id.ToString(); TestHelper.Assert(idStr == "greek%20%F0%90%85%AA/banana%20%0E-%F0%9F%8D%8C%E2%82%AC%C2%A2%24"); id2 = Identity.Parse(idStr); TestHelper.Assert(id == id2); idStr = id.ToString(ToStringMode.Unicode); TestHelper.Assert(idStr == "greek \ud800\udd6a/banana \\u000e-\ud83c\udf4c\u20ac\u00a2$"); id2 = Identity.Parse(idStr, uriFormat: false); TestHelper.Assert(id == id2); idStr = id.ToString(ToStringMode.ASCII); TestHelper.Assert(idStr == "greek \\U0001016a/banana \\u000e-\\U0001f34c\\u20ac\\u00a2$"); id2 = Identity.Parse(idStr, uriFormat: false); TestHelper.Assert(id == id2); idStr = id.ToString(ToStringMode.Compat); id2 = Identity.Parse(idStr, uriFormat: false); TestHelper.Assert(idStr == "greek \\360\\220\\205\\252/banana \\016-\\360\\237\\215\\214\\342\\202\\254\\302\\242$"); TestHelper.Assert(id == id2); output.WriteLine("ok"); output.Write("testing proxyToString... "); output.Flush(); b1 = IObjectPrx.Parse(rf, communicator); if (b1.GetConnection() is Connection connection) // not coloc-optimized target { IObjectPrx b2 = connection.CreateProxy(Identity.Parse("fixed"), IObjectPrx.Factory); if (connection.Endpoint.Protocol == Protocol.Ice1) { TestHelper.Assert(b2.ToString() == "fixed -t -e 1.1"); } else { TestHelper.Assert(b2.ToString() == "ice:fixed"); } } output.WriteLine("ok"); output.Write("testing propertyToProxy... "); output.Flush(); string propertyPrefix = "Foo.Proxy"; communicator.SetProperty(propertyPrefix, helper.GetTestProxy("test", 0)); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert( b1.Identity.Name == "test" && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); string property; property = propertyPrefix + ".Locator"; TestHelper.Assert(b1.Locator == null); communicator.SetProperty(property, "ice+tcp://host:10000/locator"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.Locator != null && b1.Locator.Identity.Name == "locator"); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; TestHelper.Assert(b1.LocatorCacheTimeout == Timeout.InfiniteTimeSpan); communicator.SetProperty(property, "1s"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.LocatorCacheTimeout == TimeSpan.FromSeconds(1)); communicator.SetProperty(property, ""); // Now retest with an indirect proxy. communicator.SetProperty(propertyPrefix, "test"); property = propertyPrefix + ".Locator"; communicator.SetProperty(property, "ice+tcp://host:10000/locator"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.Locator != null && b1.Locator.Identity.Name == "locator"); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; TestHelper.Assert(b1.LocatorCacheTimeout == Timeout.InfiniteTimeSpan); communicator.SetProperty(property, "1s"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.LocatorCacheTimeout == TimeSpan.FromSeconds(1)); communicator.SetProperty(property, ""); // This cannot be tested so easily because the property is cached // on communicator initialization. // //communicator.SetProperty("Default.LocatorCacheTimeout", "60"); //b1 = communicator.propertyToProxy(propertyPrefix); //TestHelper.Assert(b1.LocatorCacheTimeout == 60); //communicator.SetProperty("Default.LocatorCacheTimeout", ""); communicator.SetProperty(propertyPrefix, helper.GetTestProxy("test", 0)); property = propertyPrefix + ".Router"; TestHelper.Assert(b1.Router == null); communicator.SetProperty(property, "ice+tcp://host:10000/router"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.Router != null && b1.Router.Identity.Name == "router"); communicator.RemoveProperty(property); property = propertyPrefix + ".PreferNonSecure"; TestHelper.Assert(b1.PreferNonSecure); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(!b1.PreferNonSecure); communicator.RemoveProperty(property); property = propertyPrefix + ".ConnectionCached"; TestHelper.Assert(b1.IsConnectionCached); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(!b1.IsConnectionCached); communicator.RemoveProperty(property); property = propertyPrefix + ".InvocationTimeout"; TestHelper.Assert(b1.InvocationTimeout == -1); communicator.SetProperty(property, "1000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.InvocationTimeout == 1000); communicator.RemoveProperty(property); property = propertyPrefix + ".EndpointSelection"; TestHelper.Assert(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Random"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Ordered"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.EndpointSelection == EndpointSelectionType.Ordered); communicator.RemoveProperty(property); property = propertyPrefix + ".Context.c1"; TestHelper.Assert(!b1.Context.ContainsKey("c1")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.Context["c1"].Equals("TEST")); property = propertyPrefix + ".Context.c2"; TestHelper.Assert(!b1.Context.ContainsKey("c2")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory) !; TestHelper.Assert(b1.Context["c2"].Equals("TEST")); communicator.SetProperty(propertyPrefix + ".Context.c1", ""); communicator.SetProperty(propertyPrefix + ".Context.c2", ""); output.WriteLine("ok"); output.Write("testing IObjectPrx.ToProperty... "); output.Flush(); IRouterPrx router = IRouterPrx.Parse("ice:router?encoding=1.1", communicator).Clone( cacheConnection: true, preferNonSecure: true, endpointSelection: EndpointSelectionType.Random, locatorCacheTimeout: TimeSpan.FromSeconds(200), invocationTimeout: 1500); ILocatorPrx?locator = ILocatorPrx.Parse("ice:locator", communicator).Clone( cacheConnection: false, preferNonSecure: true, endpointSelection: EndpointSelectionType.Random, locatorCacheTimeout: TimeSpan.FromSeconds(300), invocationTimeout: 1500, router: router); b1 = IObjectPrx.Parse("ice:test", communicator).Clone( cacheConnection: true, preferNonSecure: false, endpointSelection: EndpointSelectionType.Ordered, locatorCacheTimeout: TimeSpan.FromSeconds(100), invocationTimeout: 1234, locator: locator); Dictionary <string, string> proxyProps = b1.ToProperty("Test"); TestHelper.Assert(proxyProps.Count == 18); TestHelper.Assert(proxyProps["Test"] == "ice:test"); TestHelper.Assert(proxyProps["Test.ConnectionCached"] == "1"); TestHelper.Assert(proxyProps["Test.PreferNonSecure"] == "0"); TestHelper.Assert(proxyProps["Test.EndpointSelection"] == "Ordered"); TestHelper.Assert(proxyProps["Test.LocatorCacheTimeout"] == "100s"); TestHelper.Assert(proxyProps["Test.InvocationTimeout"] == "1234"); TestHelper.Assert(proxyProps["Test.Locator"] == "ice:locator"); // strange test with an indirect locator! TestHelper.Assert(proxyProps["Test.Locator.ConnectionCached"] == "0"); TestHelper.Assert(proxyProps["Test.Locator.PreferNonSecure"] == "1"); TestHelper.Assert(proxyProps["Test.Locator.EndpointSelection"] == "Random"); TestHelper.Assert(proxyProps["Test.Locator.LocatorCacheTimeout"] == "5m"); TestHelper.Assert(proxyProps["Test.Locator.InvocationTimeout"] == "1500"); TestHelper.Assert(proxyProps["Test.Locator.Router"] == "ice:router?encoding=1.1"); // also very strange TestHelper.Assert(proxyProps["Test.Locator.Router.ConnectionCached"] == "1"); TestHelper.Assert(proxyProps["Test.Locator.Router.PreferNonSecure"] == "1"); TestHelper.Assert(proxyProps["Test.Locator.Router.EndpointSelection"] == "Random"); TestHelper.Assert(proxyProps["Test.Locator.Router.LocatorCacheTimeout"] == "200s"); TestHelper.Assert(proxyProps["Test.Locator.Router.InvocationTimeout"] == "1500"); output.WriteLine("ok"); output.Write("testing IObjectPrx.Communicator... "); output.Flush(); TestHelper.Assert(baseProxy.Communicator == communicator); output.WriteLine("ok"); output.Write("testing proxy Clone... "); TestHelper.Assert(baseProxy.Clone(facet: "facet", IObjectPrx.Factory).Facet == "facet"); TestHelper.Assert(baseProxy.Clone(adapterId: "id").AdapterId.Equals("id")); TestHelper.Assert(!baseProxy.Clone(invocationMode: InvocationMode.Twoway).IsOneway); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Oneway).IsOneway); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Datagram).IsOneway); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.BatchOneway).InvocationMode == InvocationMode.BatchOneway); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Datagram).InvocationMode == InvocationMode.Datagram); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.BatchDatagram).InvocationMode == InvocationMode.BatchDatagram); TestHelper.Assert(baseProxy.Clone(preferNonSecure: true).PreferNonSecure); TestHelper.Assert(!baseProxy.Clone(preferNonSecure: false).PreferNonSecure); try { baseProxy.Clone(invocationTimeout: 0); TestHelper.Assert(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: -1); } catch (ArgumentException) { TestHelper.Assert(false); } try { baseProxy.Clone(invocationTimeout: -2); TestHelper.Assert(false); } catch (ArgumentException) { } try { baseProxy.Clone(locatorCacheTimeout: TimeSpan.Zero); } catch (ArgumentException) { TestHelper.Assert(false); } try { baseProxy.Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan); } catch (ArgumentException) { TestHelper.Assert(false); } try { baseProxy.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(-2)); TestHelper.Assert(false); } catch (ArgumentException) { } output.WriteLine("ok"); output.Write("testing proxy comparison... "); output.Flush(); TestHelper.Assert(IObjectPrx.Parse("ice:foo", communicator).Equals(IObjectPrx.Parse("ice:foo", communicator))); TestHelper.Assert(!IObjectPrx.Parse("ice:foo", communicator).Equals(IObjectPrx.Parse("ice:foo2", communicator))); var compObj = IObjectPrx.Parse("ice:foo", communicator); TestHelper.Assert(compObj.Clone(facet: "facet", IObjectPrx.Factory).Equals( compObj.Clone(facet: "facet", IObjectPrx.Factory))); TestHelper.Assert(!compObj.Clone(facet: "facet", IObjectPrx.Factory).Equals( compObj.Clone(facet: "facet1", IObjectPrx.Factory))); TestHelper.Assert(compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Oneway))); TestHelper.Assert(!compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Twoway))); TestHelper.Assert(compObj.Clone(cacheConnection: true).Equals(compObj.Clone(cacheConnection: true))); TestHelper.Assert(!compObj.Clone(cacheConnection: false).Equals(compObj.Clone(cacheConnection: true))); TestHelper.Assert(compObj.Clone(endpointSelection: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelection: EndpointSelectionType.Random))); TestHelper.Assert(!compObj.Clone(endpointSelection: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelection: EndpointSelectionType.Ordered))); TestHelper.Assert(compObj.Clone(connectionId: "id2").Equals(compObj.Clone(connectionId: "id2"))); TestHelper.Assert(!compObj.Clone(connectionId: "id1").Equals(compObj.Clone(connectionId: "id2"))); TestHelper.Assert(compObj.Clone(connectionId: "id1").ConnectionId.Equals("id1")); TestHelper.Assert(compObj.Clone(connectionId: "id2").ConnectionId.Equals("id2")); var loc1 = ILocatorPrx.Parse("ice+tcp://host:10000/loc1", communicator); var loc2 = ILocatorPrx.Parse("ice+tcp://host:10000/loc2", communicator); TestHelper.Assert(compObj.Clone(clearLocator: true).Equals(compObj.Clone(clearLocator: true))); TestHelper.Assert(compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc1))); TestHelper.Assert(!compObj.Clone(locator: loc1).Equals(compObj.Clone(clearLocator: true))); TestHelper.Assert(!compObj.Clone(clearLocator: true).Equals(compObj.Clone(locator: loc2))); TestHelper.Assert(!compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc2))); var rtr1 = IRouterPrx.Parse("ice+tcp://host:10000/rtr1", communicator); var rtr2 = IRouterPrx.Parse("ice+tcp://host:10000/rtr2", communicator); TestHelper.Assert(compObj.Clone(clearRouter: true).Equals(compObj.Clone(clearRouter: true))); TestHelper.Assert(compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr1))); TestHelper.Assert(!compObj.Clone(router: rtr1).Equals(compObj.Clone(clearRouter: true))); TestHelper.Assert(!compObj.Clone(clearRouter: true).Equals(compObj.Clone(router: rtr2))); TestHelper.Assert(!compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr2))); var ctx1 = new Dictionary <string, string> { ["ctx1"] = "v1" }; var ctx2 = new Dictionary <string, string> { ["ctx2"] = "v2" }; TestHelper.Assert(compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: new Dictionary <string, string>()))); TestHelper.Assert(compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx1))); TestHelper.Assert(!compObj.Clone(context: ctx1).Equals( compObj.Clone(context: new Dictionary <string, string>()))); TestHelper.Assert(!compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: ctx2))); TestHelper.Assert(!compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx2))); TestHelper.Assert(compObj.Clone(preferNonSecure: true).Equals(compObj.Clone(preferNonSecure: true))); TestHelper.Assert(!compObj.Clone(preferNonSecure: true).Equals(compObj.Clone(preferNonSecure: false))); var compObj1 = IObjectPrx.Parse("ice+tcp://127.0.0.1:10000/foo", communicator); var compObj2 = IObjectPrx.Parse("ice+tcp://127.0.0.1:10001/foo", communicator); TestHelper.Assert(!compObj1.Equals(compObj2)); compObj1 = IObjectPrx.Parse("ice:MyAdapter1//foo", communicator); compObj2 = IObjectPrx.Parse("ice:MyAdapter2//foo", communicator); TestHelper.Assert(!compObj1.Equals(compObj2)); TestHelper.Assert(compObj1.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(20)) .Equals(compObj1.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(20)))); TestHelper.Assert(!compObj1.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)) .Equals(compObj1.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(20)))); TestHelper.Assert(compObj1.Clone(invocationTimeout: 20).Equals(compObj1.Clone(invocationTimeout: 20))); TestHelper.Assert(!compObj1.Clone(invocationTimeout: 10).Equals(compObj1.Clone(invocationTimeout: 20))); compObj1 = IObjectPrx.Parse("ice+tcp://127.0.0.1:10000/foo", communicator); compObj2 = IObjectPrx.Parse("ice:MyAdapter1//foo", communicator); TestHelper.Assert(!compObj1.Equals(compObj2)); IReadOnlyList <Endpoint> endpts1 = IObjectPrx.Parse("ice+tcp://127.0.0.1:10000/foo", communicator).Endpoints; IReadOnlyList <Endpoint> endpts2 = IObjectPrx.Parse("ice+tcp://127.0.0.1:10001/foo", communicator).Endpoints; TestHelper.Assert(!endpts1[0].Equals(endpts2[0])); TestHelper.Assert(endpts1[0].Equals( IObjectPrx.Parse("ice+tcp://127.0.0.1:10000/foo", communicator).Endpoints[0])); if (baseProxy.GetConnection() is Connection baseConnection) { Connection baseConnection2 = baseProxy.Clone(connectionId: "base2").GetConnection() !; compObj1 = compObj1.Clone(fixedConnection: baseConnection); compObj2 = compObj2.Clone(fixedConnection: baseConnection2); TestHelper.Assert(!compObj1.Equals(compObj2)); } output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var cl = IMyClassPrx.CheckedCast(baseProxy); TestHelper.Assert(cl != null); var derived = IMyDerivedClassPrx.CheckedCast(cl); TestHelper.Assert(derived != null); TestHelper.Assert(cl.Equals(baseProxy)); TestHelper.Assert(derived.Equals(baseProxy)); TestHelper.Assert(cl.Equals(derived)); try { IMyDerivedClassPrx.CheckedCast(cl.Clone(facet: "facet", IObjectPrx.Factory)); TestHelper.Assert(false); } catch (ObjectNotExistException) { } output.WriteLine("ok"); output.Write("testing checked cast with context... "); output.Flush(); Dictionary <string, string> c = cl.GetContext(); TestHelper.Assert(c == null || c.Count == 0); c = new Dictionary <string, string> { ["one"] = "hello", ["two"] = "world" }; cl = IMyClassPrx.CheckedCast(baseProxy, c); Dictionary <string, string> c2 = cl !.GetContext(); TestHelper.Assert(c.DictionaryEquals(c2)); output.WriteLine("ok"); output.Write("testing ice_fixed... "); output.Flush(); { if (cl.GetConnection() is Connection connection2) { TestHelper.Assert(!cl.IsFixed); IMyClassPrx prx = cl.Clone(fixedConnection: connection2); TestHelper.Assert(prx.IsFixed); prx.IcePing(); TestHelper.Assert(cl.Clone("facet", IObjectPrx.Factory, fixedConnection: connection2).Facet == "facet"); TestHelper.Assert(cl.Clone(invocationMode: InvocationMode.Oneway, fixedConnection: connection2).IsOneway); var ctx = new Dictionary <string, string> { ["one"] = "hello", ["two"] = "world" }; TestHelper.Assert(cl.Clone(fixedConnection: connection2).Context.Count == 0); TestHelper.Assert(cl.Clone(context: ctx, fixedConnection: connection2).Context.Count == 2); TestHelper.Assert(cl.Clone(fixedConnection: connection2).InvocationTimeout == -1); TestHelper.Assert(cl.Clone(invocationTimeout: 10, fixedConnection: connection2).InvocationTimeout == 10); TestHelper.Assert(cl.Clone(fixedConnection: connection2).GetConnection() == connection2); TestHelper.Assert(cl.Clone(fixedConnection: connection2).Clone(fixedConnection: connection2).GetConnection() == connection2); Connection?fixedConnection = cl.Clone(connectionId: "ice_fixed").GetConnection(); TestHelper.Assert(cl.Clone(fixedConnection: connection2).Clone(fixedConnection: fixedConnection).GetConnection() == fixedConnection); try { cl.Clone(invocationMode: InvocationMode.Datagram, fixedConnection: connection2); TestHelper.Assert(false); } catch (ArgumentException) { } } } output.WriteLine("ok"); output.Write("testing encoding versioning... "); string ref13 = helper.GetTestProxy("test", 0); IMyClassPrx cl13 = IMyClassPrx.Parse(ref13, communicator).Clone(encoding: new Encoding(1, 3)); try { cl13.IcePing(); TestHelper.Assert(false); } catch (NotSupportedException) { // expected } output.WriteLine("ok"); if (communicator.DefaultProtocol == Protocol.Ice2) { output.Write("testing protocol versioning... "); output.Flush(); string ref3 = helper.GetTestProxy("test", 0); ref3 += "?protocol=3"; string transport = helper.GetTestTransport(); ref3 = ref3.Replace($"ice+{transport}", "ice+universal"); ref3 += $"&transport={transport}"; var cl3 = IMyClassPrx.Parse(ref3, communicator); try { cl3.IcePing(); TestHelper.Assert(false); } catch (NotSupportedException) { // expected } output.WriteLine("ok"); } output.Write("testing ice2 universal endpoints... "); output.Flush(); var p1 = IObjectPrx.Parse("ice+universal://127.0.0.1:4062/test?transport=tcp", communicator); TestHelper.Assert(p1.ToString() == "ice+tcp://127.0.0.1/test"); // uses default port p1 = IObjectPrx.Parse( "ice+universal://127.0.0.1:4062/test?transport=tcp&alt-endpoint=host2:10000?transport=tcp", communicator); TestHelper.Assert(p1.ToString() == "ice+tcp://127.0.0.1/test?alt-endpoint=host2:10000"); p1 = IObjectPrx.Parse( "ice+universal://127.0.0.1:4062/test?transport=tcp&alt-endpoint=host2:10000?transport=99$option=a", communicator); TestHelper.Assert(p1.ToString() == "ice+tcp://127.0.0.1/test?alt-endpoint=ice+universal://host2:10000?transport=99$option=a"); output.WriteLine("ok"); output.Write("testing ice1 opaque endpoints... "); output.Flush(); // Legal TCP endpoint expressed as opaque endpoint p1 = IObjectPrx.Parse("test:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==", communicator); TestHelper.Assert(p1.ToString() == "test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000"); // Two legal TCP endpoints expressed as opaque endpoints p1 = IObjectPrx.Parse(@"test:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==: opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA==", communicator); TestHelper.Assert(p1.ToString() == "test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000:tcp -h 127.0.0.2 -p 12011 -t 10000"); // Test that an SSL endpoint and an unknown-transport endpoint get written back out as an opaque // endpoint. p1 = IObjectPrx.Parse( "test:opaque -e 1.1 -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -e 1.1 -t 99 -v abch", communicator); TestHelper.Assert(p1.ToString() == "test -t -e 1.1:ssl -h 127.0.0.1 -p 10001 -t -1:opaque -t 99 -e 1.1 -v abch"); output.WriteLine("ok"); output.Write("testing communicator shutdown/destroy... "); output.Flush(); { var com = new Communicator(); com.ShutdownAsync(); com.WaitForShutdownAsync(); com.Dispose(); com.ShutdownAsync(); com.WaitForShutdownAsync(); com.Dispose(); } output.WriteLine("ok"); return(cl); }
internal RouterInfo(IRouterPrx router) => Router = router;
/// <summary>Creates a new object adapter with the specified router proxy. This method generates a UUID for /// the object adapter name and then calls <see cref="CreateObjectAdapterWithRouter(string, IRouterPrx)"/>. /// </summary> /// <param name="router">The proxy to the router.</param> /// <returns>The new object adapter.</returns> public ObjectAdapter CreateObjectAdapterWithRouter(IRouterPrx router) => CreateObjectAdapterWithRouter(Guid.NewGuid().ToString(), router);
public static Test.ITestIntfPrx allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string @ref = "test:" + helper.getTestEndpoint(0); Ice.IObjectPrx @base = IObjectPrx.Parse(@ref, communicator); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.ITestIntfPrx.CheckedCast(@base); test(obj != null); test(obj.Equals(@base)); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); test(false); } catch (ArgumentException) { } adapter.Destroy(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); adapter.Destroy(); output.WriteLine("ok"); } output.Write("creating/activating/deactivating object adapter in one operation... "); output.Flush(); obj.transient(); obj.transientAsync().Wait(); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { var comm = new Communicator(communicator.GetProperties()); IObjectPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator).IcePingAsync(); comm.destroy(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.SetProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000"); var adapter = communicator.createObjectAdapter("PAdapter"); test(adapter.GetPublishedEndpoints().Length == 1); var endpt = adapter.GetPublishedEndpoints()[0]; test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000")); var prx = IObjectPrx.Parse("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000", communicator); adapter.SetPublishedEndpoints(prx.Endpoints); test(adapter.GetPublishedEndpoints().Length == 2); test(Collections.Equals(adapter.CreateProxy(new Identity("dummy", "")).Endpoints, prx.Endpoints)); test(Collections.Equals(adapter.GetPublishedEndpoints(), prx.Endpoints)); adapter.RefreshPublishedEndpoints(); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].Equals(endpt)); communicator.SetProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000"); adapter.RefreshPublishedEndpoints(); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000")); adapter.Destroy(); test(adapter.GetPublishedEndpoints().Length == 0); } output.WriteLine("ok"); if (obj.GetConnection() != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); var adapter = communicator.createObjectAdapter(""); obj.GetConnection().setAdapter(adapter); obj.GetConnection().setAdapter(null); adapter.Deactivate(); try { obj.GetConnection().setAdapter(adapter); test(false); } catch (ObjectAdapterDeactivatedException) { } output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); { var routerId = new Identity(); routerId.name = "router"; var router = IRouterPrx.UncheckedCast(@base.Clone(routerId, connectionId: "rc")); var adapter = communicator.createObjectAdapterWithRouter("", router); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000")); adapter.RefreshPublishedEndpoints(); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000")); try { adapter.SetPublishedEndpoints(router.Endpoints); test(false); } catch (ArgumentException) { // Expected. } adapter.Destroy(); try { routerId.name = "test"; router = IRouterPrx.UncheckedCast(@base.Clone(routerId)); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = IRouterPrx.Parse($"test:{helper.getTestEndpoint(1)}", communicator); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", helper.getTestEndpoint(10)); try { communicator.createObjectAdapterWithEndpoints("Adpt2", helper.getTestEndpoint(10)); test(false); } catch (LocalException) { // Expected can't re-use the same endpoint. } adapter1.Destroy(); } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.Clone(connectionTimeout: 100).IcePing(); // Use timeout to speed up testing on Windows test(false); } catch (LocalException) { output.WriteLine("ok"); } return(obj); }
public override void Run(string[] args) { Dictionary <string, string> properties = CreateTestProperties(ref args); // // We must disable connection warnings, because we attempt to // ping the router before session establishment, as well as // after session destruction. Both will cause a // ConnectionLostException. // properties["Ice.Warn.Connections"] = "0"; properties["Ice.Default.Protocol"] = "ice1"; using (var communicator = Initialize(properties)) { IObjectPrx routerBase; { Console.Out.Write("testing stringToProxy for router... "); Console.Out.Flush(); routerBase = IObjectPrx.Parse($"Glacier2/router -e 1.1:{GetTestEndpoint(50)}", communicator); Console.Out.WriteLine("ok"); } IRouterPrx?router; { Console.Out.Write("testing checked cast for router... "); Console.Out.Flush(); router = IRouterPrx.CheckedCast(routerBase); Assert(router != null); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing router finder... "); Console.Out.Flush(); IRouterFinderPrx finder = IRouterFinderPrx.Parse($"Ice/RouterFinder -e 1.1:{GetTestEndpoint(50)}", communicator); Assert(finder.GetRouter() !.Identity.Equals(router.Identity)); Console.Out.WriteLine("ok"); } { Console.Out.Write("installing router with communicator... "); Console.Out.Flush(); communicator.DefaultRouter = router; Console.Out.WriteLine("ok"); } { Console.Out.Write("getting the session timeout... "); Console.Out.Flush(); long sessionTimeout = router.GetSessionTimeout(); long acmTimeout = router.GetACMTimeout(); Assert(sessionTimeout == 30 && acmTimeout == 30); Console.Out.WriteLine("ok"); } ICallbackPrx twoway; { Console.Out.Write("testing stringToProxy for server object... "); Console.Out.Flush(); twoway = ICallbackPrx.Parse($"c1/callback:{GetTestEndpoint(0)}", communicator); Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to ping server before session creation... "); Console.Out.Flush(); try { twoway.IcePing(); Assert(false); } catch (ConnectionLostException) { Console.Out.WriteLine("ok"); } catch (TransportException) { Assert(false); } } { Console.Out.Write("trying to create session with wrong password... "); Console.Out.Flush(); try { router.CreateSession("userid", "xxx"); Assert(false); } catch (PermissionDeniedException) { Console.Out.WriteLine("ok"); } catch (CannotCreateSessionException) { Assert(false); } } { Console.Out.Write("trying to destroy non-existing session... "); Console.Out.Flush(); try { router.DestroySession(); Assert(false); } catch (SessionNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("creating session with correct password... "); Console.Out.Flush(); try { router.CreateSession("userid", "abc123"); } catch (PermissionDeniedException) { Assert(false); } catch (CannotCreateSessionException) { Assert(false); } Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to create a second session... "); Console.Out.Flush(); try { router.CreateSession("userid", "abc123"); Assert(false); } catch (PermissionDeniedException) { Assert(false); } catch (CannotCreateSessionException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("pinging server after session creation... "); Console.Out.Flush(); twoway.IcePing(); Console.Out.WriteLine("ok"); } { Console.Out.Write("pinging object with client endpoint... "); IObjectPrx baseC = IObjectPrx.Parse($"collocated:{GetTestEndpoint(50)}", communicator); try { baseC.IcePing(); } catch (ObjectNotExistException) { } Console.Out.WriteLine("ok"); } ObjectAdapter adapter; { Console.Out.Write("creating and activating callback receiver adapter... "); Console.Out.Flush(); communicator.SetProperty("Ice.PrintAdapterReady", "0"); adapter = communicator.CreateObjectAdapterWithRouter("CallbackReceiverAdapter", router); adapter.Activate(); Console.Out.WriteLine("ok"); } string category; { Console.Out.Write("getting category from router... "); Console.Out.Flush(); category = router.GetCategoryForClient(); Console.Out.WriteLine("ok"); } CallbackReceiver callbackReceiverImpl; ICallbackReceiver callbackReceiver; ICallbackReceiverPrx twowayR; ICallbackReceiverPrx fakeTwowayR; { Console.Out.Write("creating and adding callback receiver object... "); Console.Out.Flush(); callbackReceiverImpl = new CallbackReceiver(); callbackReceiver = callbackReceiverImpl; Identity callbackReceiverIdent = new Identity("callbackReceiver", category); twowayR = adapter.Add(callbackReceiverIdent, callbackReceiver, ICallbackReceiverPrx.Factory); Identity fakeCallbackReceiverIdent = new Identity("callbackReceiver", "dummy"); fakeTwowayR = adapter.Add(fakeCallbackReceiverIdent, callbackReceiver, ICallbackReceiverPrx.Factory); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing oneway callback... "); Console.Out.Flush(); ICallbackPrx oneway = twoway.Clone(oneway: true); ICallbackReceiverPrx onewayR = twowayR.Clone(oneway: true); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "o"; oneway.initiateCallback(onewayR, context); callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing twoway callback... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; twoway.initiateCallback(twowayR, context); callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("ditto, but with user exception... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; try { twoway.initiateCallbackEx(twowayR, context); Assert(false); } catch (CallbackException ex) { Assert(ex.someValue == 3.14); Assert(ex.someString.Equals("3.14")); } callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("trying twoway callback with fake category... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; try { twoway.initiateCallback(fakeTwowayR, context); Assert(false); } catch (ObjectNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("testing whether other allowed category is accepted... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; ICallbackPrx otherCategoryTwoway = twoway.Clone(Identity.Parse("c2/callback"), ICallbackPrx.Factory); otherCategoryTwoway.initiateCallback(twowayR, context); callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing whether disallowed category gets rejected... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; try { ICallbackPrx otherCategoryTwoway = twoway.Clone(Identity.Parse("c3/callback"), ICallbackPrx.Factory); otherCategoryTwoway.initiateCallback(twowayR, context); Assert(false); } catch (ObjectNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("testing whether user-id as category is accepted... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; ICallbackPrx otherCategoryTwoway = twoway.Clone(Identity.Parse("_userid/callback"), ICallbackPrx.Factory); otherCategoryTwoway.initiateCallback(twowayR, context); callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } if (args.Length >= 1 && args[0].Equals("--shutdown")) { Console.Out.Write("testing server shutdown... "); Console.Out.Flush(); twoway.shutdown(); // No ping, otherwise the router prints a warning message if it's // started with --Ice.Warn.Connections. Console.Out.WriteLine("ok"); /* * try * { * base.IcePing(); * Assert(false); * } * // If we use the glacier router, the exact exception reason gets * // lost. * catch(Ice.UnknownLocalException ex) * { * Console.Out.WriteLine("ok"); * } */ } { Console.Out.Write("destroying session... "); Console.Out.Flush(); try { router.DestroySession(); } catch (System.Exception) { Assert(false); } Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to ping server after session destruction... "); Console.Out.Flush(); try { twoway.IcePing(); Assert(false); } catch (ConnectionLostException) { Console.Out.WriteLine("ok"); } catch (TransportException) { Assert(false); } } if (args.Length >= 1 && args[0].Equals("--shutdown")) { { Console.Out.Write("uninstalling router with communicator... "); Console.Out.Flush(); communicator.DefaultRouter = null; Console.Out.WriteLine("ok"); } IProcessPrx process; { Console.Out.Write("testing stringToProxy for admin object... "); process = IProcessPrx.Parse($"Glacier2/admin -e 1.1 -f Process:{GetTestEndpoint(51)}", communicator); Console.Out.WriteLine("ok"); } /* * { * Console.Out.Write("uninstalling router with process object... "); * processBase.ice_router(null); * Console.Out.WriteLine("ok"); * } */ Console.Out.Write("testing Glacier2 shutdown... "); process.Shutdown(); try { process.IcePing(); Assert(false); } catch (System.Exception) { Console.Out.WriteLine("ok"); } } } }
public static IMyClassPrx allTests(TestHelper helper) { Communicator?communicator = helper.Communicator(); TestHelper.Assert(communicator != null); System.IO.TextWriter output = helper.GetWriter(); output.Write("testing stringToProxy... "); output.Flush(); string rf = "test:" + helper.GetTestEndpoint(0); var baseProxy = IObjectPrx.Parse(rf, communicator); TestHelper.Assert(baseProxy != null); IObjectPrx?b1; b1 = IObjectPrx.Parse("test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("test ", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test ", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("'test -f facet'", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("\"test -f facet'", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("\"test -f facet\"", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test\"", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test -f facet@test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test @test\"", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test -f facet@test @test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("test test", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\040test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test test") && b1.Identity.Category.Length == 0); try { b1 = IObjectPrx.Parse("test\\777", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\40test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test test")); // Test some octal and hex corner cases. b1 = IObjectPrx.Parse("test\\4test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\04test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\004test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\1114test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test\u00494test")); b1 = IObjectPrx.Parse("test\\b\\f\\n\\r\\t\\'\\\"\\\\test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test\b\f\n\r\t\'\"\\test") && b1.Identity.Category.Length == 0); b1 = IObjectPrx.Parse("category/test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test:tcp --sourceAddress \"::1\"", communicator); TestHelper.Assert(b1.Equals(IObjectPrx.Parse(b1.ToString() !, communicator))); b1 = IObjectPrx.Parse("test:udp --sourceAddress \"::1\" --interface \"0:0:0:0:0:0:0:1%lo\"", communicator); TestHelper.Assert(b1.Equals(IObjectPrx.Parse(b1.ToString() !, communicator))); try { b1 = IObjectPrx.Parse("", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("\"\"", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("\"\" test", communicator); // Invalid trailing characters. TestHelper.Assert(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("test:", communicator); // Missing endpoint. TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test@adapter", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Equals("adapter")); try { b1 = IObjectPrx.Parse("id@adapter test", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("category/test@adapter", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("category/test@adapter:tcp", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter:tcp")); b1 = IObjectPrx.Parse("'category 1/test'@adapter", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category 1") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test 1'@adapter", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test 1") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test'@'adapter 1'", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter 1")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@adapter", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@\"adapter:tcp\"", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") && b1.AdapterId.Equals("adapter:tcp")); b1 = IObjectPrx.Parse("id -f facet", communicator); TestHelper.Assert(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet")); b1 = IObjectPrx.Parse("id -f 'facet x'", communicator); TestHelper.Assert(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet x")); b1 = IObjectPrx.Parse("id -f \"facet x\"", communicator); TestHelper.Assert(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet x")); try { b1 = IObjectPrx.Parse("id -f \"facet x", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("id -f \'facet x", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test -f facet:tcp", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f \"facet:tcp\"", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet:tcp") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f facet@test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet") && b1.AdapterId.Equals("test")); b1 = IObjectPrx.Parse("test -f 'facet@test'", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet@test") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f 'facet@test'@test", communicator); TestHelper.Assert(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet@test") && b1.AdapterId.Equals("test")); try { b1 = IObjectPrx.Parse("test -f facet@test @test", communicator); TestHelper.Assert(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test", communicator); TestHelper.Assert(!b1.IsOneway); b1 = IObjectPrx.Parse("test -t", communicator); TestHelper.Assert(!b1.IsOneway); b1 = IObjectPrx.Parse("test -o", communicator); TestHelper.Assert(b1.IsOneway); b1 = IObjectPrx.Parse("test -O", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.BatchOneway); b1 = IObjectPrx.Parse("test -d", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.Datagram); b1 = IObjectPrx.Parse("test -D", communicator); TestHelper.Assert(b1.InvocationMode == InvocationMode.BatchDatagram); b1 = IObjectPrx.Parse("test", communicator); TestHelper.Assert(b1.Encoding.Equals(communicator.DefaultEncoding)); b1 = IObjectPrx.Parse("test -e 1.0", communicator); TestHelper.Assert(b1.Encoding.Major == 1 && b1.Encoding.Minor == 0); b1 = IObjectPrx.Parse("test -e 6.5", communicator); TestHelper.Assert(b1.Encoding.Major == 6 && b1.Encoding.Minor == 5); b1 = IObjectPrx.Parse("test -p ice1 -e 1.0", communicator); TestHelper.Assert(b1.ToString() !.Equals("test -t -p ice1 -e 1.0")); b1 = IObjectPrx.Parse("test -p 1.0 -e 1.0", communicator); TestHelper.Assert(b1.ToString() !.Equals("test -t -p ice1 -e 1.0")); b1 = IObjectPrx.Parse("test -p ice2 -e 1.0", communicator); TestHelper.Assert(b1.ToString() !.Equals("test -t -p ice2 -e 1.0")); b1 = IObjectPrx.Parse("test -p 2.0 -e 1.0", communicator); TestHelper.Assert(b1.ToString() !.Equals("test -t -p ice2 -e 1.0")); b1 = IObjectPrx.Parse("test -p 6 -e 1.0", communicator); TestHelper.Assert(b1.ToString() !.Equals("test -t -p 6 -e 1.0")); b1 = IObjectPrx.Parse("test -p 6.0 -e 1.0", communicator); TestHelper.Assert(b1.ToString() !.Equals("test -t -p 6 -e 1.0")); try { IObjectPrx.Parse("test:tcp@adapterId", communicator); TestHelper.Assert(false); } catch (FormatException) { } // This is an unknown endpoint warning, not a parse exception. // //try //{ // b1 = communicator.stringToProxy("test -f the:facet:tcp"); // TestHelper.Assert(false); //} //catch(EndpointParseException) //{ //} try { IObjectPrx.Parse("test: :tcp", communicator); TestHelper.Assert(false); } catch (FormatException) { } // // Test invalid endpoint syntax // try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", " : "); TestHelper.Assert(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", "tcp: "); TestHelper.Assert(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", ":tcp"); TestHelper.Assert(false); } catch (FormatException) { } // // Test for bug ICE-5543: escaped escapes in stringToIdentity // var id = new Identity("test", ",X2QNUAzSBcJ_e$AV;E\\"); var id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); TestHelper.Assert(id.Equals(id2)); id = new Identity("test", ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\"); id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); TestHelper.Assert(id.Equals(id2)); id = new Identity("/test", "cat/"); string idStr = id.ToString(communicator.ToStringMode); TestHelper.Assert(idStr == "cat\\//\\/test"); id2 = Identity.Parse(idStr); TestHelper.Assert(id.Equals(id2)); // Input string with various pitfalls id = Identity.Parse("\\342\\x82\\254\\60\\x9\\60\\"); TestHelper.Assert(id.Name == "€0\t0\\" && id.Category == ""); try { // Illegal character < 32 id = Identity.Parse("xx\01FooBar"); TestHelper.Assert(false); } catch (FormatException) { } try { // Illegal surrogate id = Identity.Parse("xx\\ud911"); TestHelper.Assert(false); } catch (FormatException) { } // Testing bytes 127(\x7F, \177) and € id = new Identity("test", "\x7f€"); idStr = id.ToString(ToStringMode.Unicode); TestHelper.Assert(idStr == "\\u007f€/test"); id2 = Identity.Parse(idStr); TestHelper.Assert(id.Equals(id2)); TestHelper.Assert(id.ToString() == idStr); idStr = id.ToString(ToStringMode.ASCII); TestHelper.Assert(idStr == "\\u007f\\u20ac/test"); id2 = Identity.Parse(idStr); TestHelper.Assert(id.Equals(id2)); idStr = id.ToString(ToStringMode.Compat); TestHelper.Assert(idStr == "\\177\\342\\202\\254/test"); id2 = Identity.Parse(idStr); TestHelper.Assert(id.Equals(id2)); id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); TestHelper.Assert(id.Equals(id2)); // More unicode character id = new Identity("banana \x0E-\ud83c\udf4c\u20ac\u00a2\u0024", "greek \ud800\udd6a"); idStr = id.ToString(ToStringMode.Unicode); TestHelper.Assert(idStr == "greek \ud800\udd6a/banana \\u000e-\ud83c\udf4c\u20ac\u00a2$"); id2 = Identity.Parse(idStr); TestHelper.Assert(id.Equals(id2)); idStr = id.ToString(ToStringMode.ASCII); TestHelper.Assert(idStr == "greek \\U0001016a/banana \\u000e-\\U0001f34c\\u20ac\\u00a2$"); id2 = Identity.Parse(idStr); TestHelper.Assert(id.Equals(id2)); idStr = id.ToString(ToStringMode.Compat); id2 = Identity.Parse(idStr); TestHelper.Assert(idStr == "greek \\360\\220\\205\\252/banana \\016-\\360\\237\\215\\214\\342\\202\\254\\302\\242$"); TestHelper.Assert(id.Equals(id2)); output.WriteLine("ok"); output.Write("testing proxyToString... "); output.Flush(); b1 = IObjectPrx.Parse(rf, communicator); var b2 = IObjectPrx.Parse(b1.ToString() !, communicator); TestHelper.Assert(b1.Equals(b2)); if (b1.GetConnection() is Connection connection) // not colloc-optimized target { b2 = connection.CreateProxy(Identity.Parse("fixed"), IObjectPrx.Factory); TestHelper.Assert(b2.ToString() == b2.ToString()); } output.WriteLine("ok"); output.Write("testing propertyToProxy... "); output.Flush(); string propertyPrefix = "Foo.Proxy"; communicator.SetProperty(propertyPrefix, "test:" + helper.GetTestEndpoint(0)); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); string property; property = propertyPrefix + ".Locator"; TestHelper.Assert(b1.Locator == null); communicator.SetProperty(property, "locator:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator")); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; TestHelper.Assert(b1.LocatorCacheTimeout == Timeout.InfiniteTimeSpan); communicator.SetProperty(property, "1s"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.LocatorCacheTimeout == TimeSpan.FromSeconds(1)); communicator.SetProperty(property, ""); // Now retest with an indirect proxy. communicator.SetProperty(propertyPrefix, "test"); property = propertyPrefix + ".Locator"; communicator.SetProperty(property, "locator:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator")); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; TestHelper.Assert(b1.LocatorCacheTimeout == Timeout.InfiniteTimeSpan); communicator.SetProperty(property, "1s"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.LocatorCacheTimeout == TimeSpan.FromSeconds(1)); communicator.SetProperty(property, ""); // This cannot be tested so easily because the property is cached // on communicator initialization. // //communicator.SetProperty("Default.LocatorCacheTimeout", "60"); //b1 = communicator.propertyToProxy(propertyPrefix); //TestHelper.Assert(b1.LocatorCacheTimeout == 60); //communicator.SetProperty("Default.LocatorCacheTimeout", ""); communicator.SetProperty(propertyPrefix, "test:" + helper.GetTestEndpoint(0)); property = propertyPrefix + ".Router"; TestHelper.Assert(b1.Router == null); communicator.SetProperty(property, "router:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.Router != null && b1.Router.Identity.Name.Equals("router")); communicator.RemoveProperty(property); property = propertyPrefix + ".PreferNonSecure"; TestHelper.Assert(b1.PreferNonSecure); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && !b1.PreferNonSecure); communicator.RemoveProperty(property); property = propertyPrefix + ".ConnectionCached"; TestHelper.Assert(b1.IsConnectionCached); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && !b1.IsConnectionCached); communicator.RemoveProperty(property); property = propertyPrefix + ".InvocationTimeout"; TestHelper.Assert(b1.InvocationTimeout == -1); communicator.SetProperty(property, "1000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.InvocationTimeout == 1000); communicator.RemoveProperty(property); property = propertyPrefix + ".EndpointSelection"; TestHelper.Assert(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Random"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Ordered"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.EndpointSelection == EndpointSelectionType.Ordered); communicator.RemoveProperty(property); property = propertyPrefix + ".CollocationOptimized"; TestHelper.Assert(b1.IsCollocationOptimized); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && !b1.IsCollocationOptimized); communicator.RemoveProperty(property); property = propertyPrefix + ".Context.c1"; TestHelper.Assert(!b1.Context.ContainsKey("c1")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.Context["c1"].Equals("TEST")); property = propertyPrefix + ".Context.c2"; TestHelper.Assert(!b1.Context.ContainsKey("c2")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); TestHelper.Assert(b1 != null && b1.Context["c2"].Equals("TEST")); communicator.SetProperty(propertyPrefix + ".Context.c1", ""); communicator.SetProperty(propertyPrefix + ".Context.c2", ""); output.WriteLine("ok"); output.Write("testing proxyToProperty... "); output.Flush(); var router = IRouterPrx.Parse("router", communicator).Clone( collocationOptimized: false, cacheConnection: true, preferNonSecure: true, endpointSelection: EndpointSelectionType.Random, locatorCacheTimeout: TimeSpan.FromSeconds(200), invocationTimeout: 1500); var locator = ILocatorPrx.Parse("locator", communicator).Clone( collocationOptimized: true, cacheConnection: false, preferNonSecure: true, endpointSelection: EndpointSelectionType.Random, locatorCacheTimeout: TimeSpan.FromSeconds(300), invocationTimeout: 1500, router: router); b1 = IObjectPrx.Parse("test", communicator).Clone( collocationOptimized: true, cacheConnection: true, preferNonSecure: false, endpointSelection: EndpointSelectionType.Ordered, locatorCacheTimeout: TimeSpan.FromSeconds(100), invocationTimeout: 1234, encoding: Encoding.V2_0, locator: locator); Dictionary <string, string> proxyProps = b1.ToProperty("Test"); TestHelper.Assert(proxyProps.Count == 21); string defaultProtocolName = communicator.DefaultProtocol.GetName(); TestHelper.Assert(proxyProps["Test"] == $"test -t -p {defaultProtocolName} -e 2.0"); TestHelper.Assert(proxyProps["Test.CollocationOptimized"] == "1"); TestHelper.Assert(proxyProps["Test.ConnectionCached"] == "1"); TestHelper.Assert(proxyProps["Test.PreferNonSecure"] == "0"); TestHelper.Assert(proxyProps["Test.EndpointSelection"] == "Ordered"); TestHelper.Assert(proxyProps["Test.LocatorCacheTimeout"] == "100s"); TestHelper.Assert(proxyProps["Test.InvocationTimeout"] == "1234"); TestHelper.Assert(proxyProps["Test.Locator"] == $"locator -t -p {defaultProtocolName} -e {Encoding.V2_0}"); // Locator collocation optimization is always disabled. //TestHelper.Assert(proxyProps["Test.Locator.CollocationOptimized"] == "1"); TestHelper.Assert(proxyProps["Test.Locator.ConnectionCached"] == "0"); TestHelper.Assert(proxyProps["Test.Locator.PreferNonSecure"] == "1"); TestHelper.Assert(proxyProps["Test.Locator.EndpointSelection"] == "Random"); TestHelper.Assert(proxyProps["Test.Locator.LocatorCacheTimeout"] == "5m"); TestHelper.Assert(proxyProps["Test.Locator.InvocationTimeout"] == "1500"); TestHelper.Assert(proxyProps["Test.Locator.Router"] == $"router -t -p {defaultProtocolName} -e {communicator.DefaultEncoding}"); TestHelper.Assert(proxyProps["Test.Locator.Router.CollocationOptimized"] == "0"); TestHelper.Assert(proxyProps["Test.Locator.Router.ConnectionCached"] == "1"); TestHelper.Assert(proxyProps["Test.Locator.Router.PreferNonSecure"] == "1"); TestHelper.Assert(proxyProps["Test.Locator.Router.EndpointSelection"] == "Random"); TestHelper.Assert(proxyProps["Test.Locator.Router.LocatorCacheTimeout"] == "200s"); TestHelper.Assert(proxyProps["Test.Locator.Router.InvocationTimeout"] == "1500"); output.WriteLine("ok"); output.Write("testing ice_getCommunicator... "); output.Flush(); TestHelper.Assert(baseProxy.Communicator == communicator); output.WriteLine("ok"); output.Write("testing proxy methods... "); TestHelper.Assert(baseProxy.Clone(facet: "facet", IObjectPrx.Factory).Facet.Equals("facet")); TestHelper.Assert(baseProxy.Clone(adapterId: "id").AdapterId.Equals("id")); TestHelper.Assert(!baseProxy.Clone(invocationMode: InvocationMode.Twoway).IsOneway); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Oneway).IsOneway); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Datagram).IsOneway); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.BatchOneway).InvocationMode == InvocationMode.BatchOneway); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.Datagram).InvocationMode == InvocationMode.Datagram); TestHelper.Assert(baseProxy.Clone(invocationMode: InvocationMode.BatchDatagram).InvocationMode == InvocationMode.BatchDatagram); TestHelper.Assert(baseProxy.Clone(collocationOptimized: true).IsCollocationOptimized); TestHelper.Assert(!baseProxy.Clone(collocationOptimized: false).IsCollocationOptimized); TestHelper.Assert(baseProxy.Clone(preferNonSecure: true).PreferNonSecure); TestHelper.Assert(!baseProxy.Clone(preferNonSecure: false).PreferNonSecure); try { baseProxy.Clone(connectionTimeout: 0); TestHelper.Assert(false); } catch (ArgumentException) { } try { baseProxy.Clone(connectionTimeout: -1); } catch (ArgumentException) { TestHelper.Assert(false); } try { baseProxy.Clone(connectionTimeout: -2); TestHelper.Assert(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: 0); TestHelper.Assert(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: -1); } catch (ArgumentException) { TestHelper.Assert(false); } try { baseProxy.Clone(invocationTimeout: -2); TestHelper.Assert(false); } catch (ArgumentException) { } try { baseProxy.Clone(locatorCacheTimeout: TimeSpan.Zero); } catch (ArgumentException) { TestHelper.Assert(false); } try { baseProxy.Clone(locatorCacheTimeout: Timeout.InfiniteTimeSpan); } catch (ArgumentException) { TestHelper.Assert(false); } try { baseProxy.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(-2)); TestHelper.Assert(false); } catch (ArgumentException) { } output.WriteLine("ok"); output.Write("testing proxy comparison... "); output.Flush(); TestHelper.Assert(Equals(IObjectPrx.Parse("foo", communicator), IObjectPrx.Parse("foo", communicator))); TestHelper.Assert(!IObjectPrx.Parse("foo", communicator).Equals(IObjectPrx.Parse("foo2", communicator))); var compObj = IObjectPrx.Parse("foo", communicator); TestHelper.Assert(compObj.Clone(facet: "facet", IObjectPrx.Factory).Equals( compObj.Clone(facet: "facet", IObjectPrx.Factory))); TestHelper.Assert(!compObj.Clone(facet: "facet", IObjectPrx.Factory).Equals( compObj.Clone(facet: "facet1", IObjectPrx.Factory))); TestHelper.Assert(compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Oneway))); TestHelper.Assert(!compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Twoway))); TestHelper.Assert(compObj.Clone(collocationOptimized: true).Equals(compObj.Clone(collocationOptimized: true))); TestHelper.Assert(!compObj.Clone(collocationOptimized: false).Equals(compObj.Clone(collocationOptimized: true))); TestHelper.Assert(compObj.Clone(cacheConnection: true).Equals(compObj.Clone(cacheConnection: true))); TestHelper.Assert(!compObj.Clone(cacheConnection: false).Equals(compObj.Clone(cacheConnection: true))); TestHelper.Assert(compObj.Clone(endpointSelection: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelection: EndpointSelectionType.Random))); TestHelper.Assert(!compObj.Clone(endpointSelection: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelection: EndpointSelectionType.Ordered))); TestHelper.Assert(compObj.Clone(connectionId: "id2").Equals(compObj.Clone(connectionId: "id2"))); TestHelper.Assert(!compObj.Clone(connectionId: "id1").Equals(compObj.Clone(connectionId: "id2"))); TestHelper.Assert(compObj.Clone(connectionId: "id1").ConnectionId.Equals("id1")); TestHelper.Assert(compObj.Clone(connectionId: "id2").ConnectionId.Equals("id2")); TestHelper.Assert(compObj.Clone(compress: true).Equals(compObj.Clone(compress: true))); TestHelper.Assert(!compObj.Clone(compress: false).Equals(compObj.Clone(compress: true))); TestHelper.Assert(!compObj.Compress.HasValue); TestHelper.Assert(compObj.Clone(compress: true).Compress !.Value == true); TestHelper.Assert(compObj.Clone(compress: false).Compress !.Value == false); TestHelper.Assert(compObj.Clone(connectionTimeout: 20).Equals(compObj.Clone(connectionTimeout: 20))); TestHelper.Assert(!compObj.Clone(connectionTimeout: 10).Equals(compObj.Clone(connectionTimeout: 20))); TestHelper.Assert(!compObj.ConnectionTimeout.HasValue); TestHelper.Assert(compObj.Clone(connectionTimeout: 10).ConnectionTimeout !.Value == 10); TestHelper.Assert(compObj.Clone(connectionTimeout: 20).ConnectionTimeout !.Value == 20); var loc1 = ILocatorPrx.Parse("loc1:default -p 10000", communicator); var loc2 = ILocatorPrx.Parse("loc2:default -p 10000", communicator); TestHelper.Assert(compObj.Clone(clearLocator: true).Equals(compObj.Clone(clearLocator: true))); TestHelper.Assert(compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc1))); TestHelper.Assert(!compObj.Clone(locator: loc1).Equals(compObj.Clone(clearLocator: true))); TestHelper.Assert(!compObj.Clone(clearLocator: true).Equals(compObj.Clone(locator: loc2))); TestHelper.Assert(!compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc2))); var rtr1 = IRouterPrx.Parse("rtr1:default -p 10000", communicator); var rtr2 = IRouterPrx.Parse("rtr2:default -p 10000", communicator); TestHelper.Assert(compObj.Clone(clearRouter: true).Equals(compObj.Clone(clearRouter: true))); TestHelper.Assert(compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr1))); TestHelper.Assert(!compObj.Clone(router: rtr1).Equals(compObj.Clone(clearRouter: true))); TestHelper.Assert(!compObj.Clone(clearRouter: true).Equals(compObj.Clone(router: rtr2))); TestHelper.Assert(!compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr2))); Dictionary <string, string> ctx1 = new Dictionary <string, string>(); ctx1["ctx1"] = "v1"; Dictionary <string, string> ctx2 = new Dictionary <string, string>(); ctx2["ctx2"] = "v2"; TestHelper.Assert(compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: new Dictionary <string, string>()))); TestHelper.Assert(compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx1))); TestHelper.Assert(!compObj.Clone(context: ctx1).Equals( compObj.Clone(context: new Dictionary <string, string>()))); TestHelper.Assert(!compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: ctx2))); TestHelper.Assert(!compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx2))); TestHelper.Assert(compObj.Clone(preferNonSecure: true).Equals(compObj.Clone(preferNonSecure: true))); TestHelper.Assert(!compObj.Clone(preferNonSecure: true).Equals(compObj.Clone(preferNonSecure: false))); var compObj1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator); var compObj2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator); TestHelper.Assert(!compObj1.Equals(compObj2)); compObj1 = IObjectPrx.Parse("foo@MyAdapter1", communicator); compObj2 = IObjectPrx.Parse("foo@MyAdapter2", communicator); TestHelper.Assert(!compObj1.Equals(compObj2)); TestHelper.Assert(compObj1.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(20)) .Equals(compObj1.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(20)))); TestHelper.Assert(!compObj1.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(10)) .Equals(compObj1.Clone(locatorCacheTimeout: TimeSpan.FromSeconds(20)))); TestHelper.Assert(compObj1.Clone(invocationTimeout: 20).Equals(compObj1.Clone(invocationTimeout: 20))); TestHelper.Assert(!compObj1.Clone(invocationTimeout: 10).Equals(compObj1.Clone(invocationTimeout: 20))); compObj1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 1000", communicator); compObj2 = IObjectPrx.Parse("foo@MyAdapter1", communicator); TestHelper.Assert(!compObj1.Equals(compObj2)); var endpts1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints; var endpts2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator).Endpoints; TestHelper.Assert(!endpts1[0].Equals(endpts2[0])); TestHelper.Assert(endpts1[0].Equals(IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints[0])); if (baseProxy.GetConnection() is Connection baseConnection) { Connection baseConnection2 = baseProxy.Clone(connectionId: "base2").GetConnection() !; compObj1 = compObj1.Clone(fixedConnection: baseConnection); compObj2 = compObj2.Clone(fixedConnection: baseConnection2); TestHelper.Assert(!compObj1.Equals(compObj2)); } output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var cl = IMyClassPrx.CheckedCast(baseProxy); TestHelper.Assert(cl != null); var derived = IMyDerivedClassPrx.CheckedCast(cl); TestHelper.Assert(derived != null); TestHelper.Assert(cl.Equals(baseProxy)); TestHelper.Assert(derived.Equals(baseProxy)); TestHelper.Assert(cl.Equals(derived)); try { IMyDerivedClassPrx.CheckedCast(cl.Clone(facet: "facet", IObjectPrx.Factory)); TestHelper.Assert(false); } catch (ObjectNotExistException) { } output.WriteLine("ok"); output.Write("testing checked cast with context... "); output.Flush(); Dictionary <string, string> c = cl.getContext(); TestHelper.Assert(c == null || c.Count == 0); c = new Dictionary <string, string>(); c["one"] = "hello"; c["two"] = "world"; cl = IMyClassPrx.CheckedCast(baseProxy, c); Dictionary <string, string> c2 = cl !.getContext(); TestHelper.Assert(c.DictionaryEqual(c2)); output.WriteLine("ok"); output.Write("testing ice_fixed... "); output.Flush(); { if (cl.GetConnection() is Connection connection2) { TestHelper.Assert(!cl.IsFixed); IMyClassPrx prx = cl.Clone(fixedConnection: connection2); TestHelper.Assert(prx.IsFixed); prx.IcePing(); TestHelper.Assert(cl.Clone("facet", IObjectPrx.Factory, fixedConnection: connection2).Facet.Equals("facet")); TestHelper.Assert(cl.Clone(invocationMode: InvocationMode.Oneway, fixedConnection: connection2).IsOneway); Dictionary <string, string> ctx = new Dictionary <string, string>(); ctx["one"] = "hello"; ctx["two"] = "world"; TestHelper.Assert(cl.Clone(fixedConnection: connection2).Context.Count == 0); TestHelper.Assert(cl.Clone(context: ctx, fixedConnection: connection2).Context.Count == 2); TestHelper.Assert(cl.Clone(fixedConnection: connection2).InvocationTimeout == -1); TestHelper.Assert(cl.Clone(invocationTimeout: 10, fixedConnection: connection2).InvocationTimeout == 10); TestHelper.Assert(cl.Clone(fixedConnection: connection2).GetConnection() == connection2); TestHelper.Assert(cl.Clone(fixedConnection: connection2).Clone(fixedConnection: connection2).GetConnection() == connection2); TestHelper.Assert(!cl.Clone(fixedConnection: connection2).ConnectionTimeout.HasValue); TestHelper.Assert(cl.Clone(compress: true, fixedConnection: connection2).Compress !.Value); Connection?fixedConnection = cl.Clone(connectionId: "ice_fixed").GetConnection(); TestHelper.Assert(cl.Clone(fixedConnection: connection2).Clone(fixedConnection: fixedConnection).GetConnection() == fixedConnection); try { cl.Clone(invocationMode: InvocationMode.Datagram, fixedConnection: connection2); TestHelper.Assert(false); } catch (ArgumentException) { } } } output.WriteLine("ok"); output.Write("testing encoding versioning... "); string ref13 = "test -e 1.3:" + helper.GetTestEndpoint(0); var cl13 = IMyClassPrx.Parse(ref13, communicator); try { cl13.IcePing(); TestHelper.Assert(false); } catch (NotSupportedException) { // expected } output.WriteLine("ok"); output.Write("testing protocol versioning... "); output.Flush(); string ref3 = "test -p 3:" + helper.GetTestEndpoint(0); var cl3 = IMyClassPrx.Parse(ref3, communicator); try { cl3.IcePing(); TestHelper.Assert(false); } catch (NotSupportedException) { // expected } output.WriteLine("ok"); output.Write("testing opaque endpoints... "); output.Flush(); try { // Invalid -x option IObjectPrx.Parse("id:opaque -t 99 -v abcd -x abc", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Missing -t and -v IObjectPrx.Parse("id:opaque", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Repeated -t IObjectPrx.Parse("id:opaque -t 1 -t 1 -v abcd", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Repeated -v IObjectPrx.Parse("id:opaque -t 1 -v abcd -v abcd", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Missing -t IObjectPrx.Parse("id:opaque -v abcd", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Missing -v IObjectPrx.Parse("id:opaque -t 1", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Missing arg for -t IObjectPrx.Parse("id:opaque -t -v abcd", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Missing arg for -v IObjectPrx.Parse("id:opaque -t 1 -v", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Not a number for -t IObjectPrx.Parse("id:opaque -t x -v abcd", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // < 0 for -t IObjectPrx.Parse("id:opaque -t -1 -v abcd", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Invalid char for -v IObjectPrx.Parse("id:opaque -t 99 -v x?c", communicator); TestHelper.Assert(false); } catch (FormatException) { } try { // Invalid lenght for base64 input IObjectPrx.Parse("id:opaque -t 99 -v xc", communicator); TestHelper.Assert(false); } catch (FormatException) { } // Legal TCP endpoint expressed as opaque endpoint // Opaque endpoint encoded with 1.1 encoding. var p1 = IObjectPrx.Parse("test -e 1.1 -p ice2:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==", communicator); TestHelper.Assert(p1.ToString() !.Equals("test -t -p ice2 -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000")); if (!(communicator.GetPropertyAsBool("Ice.IPv6") ?? false)) { // Two legal TCP endpoints expressed as opaque endpoints p1 = IObjectPrx.Parse("test -e 1.1 -p ice2:" + "" + "opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:" + "opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA==", communicator); TestHelper.Assert(p1.ToString() == "test -t -p ice2 -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000:tcp -h 127.0.0.2 -p 12011 -t 10000"); // Test that an SSL endpoint and a nonsense endpoint get written back out as an opaque endpoint. p1 = IObjectPrx.Parse("test -e 1.1 -p ice2:opaque -e 1.1 -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -e 1.1 -t 99 -v abch", communicator); TestHelper.Assert(p1.ToString() == "test -t -p ice2 -e 1.1:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.1 -v abch"); } output.WriteLine("ok"); output.Write("testing communicator shutdown/destroy... "); output.Flush(); { Communicator com = new Communicator(); com.Shutdown(); TestHelper.Assert(com.IsShutdown()); com.WaitForShutdown(); com.Destroy(); com.Shutdown(); TestHelper.Assert(com.IsShutdown()); com.WaitForShutdown(); com.Destroy(); } output.WriteLine("ok"); return(cl); }
/// <summary>Creates a new object adapter with the specified router proxy. This method generates a UUID for /// the object adapter name and then calls /// <see cref="CreateObjectAdapterWithRouter(string, IRouterPrx, bool, TaskScheduler?, CancellationToken)"/>. /// </summary> /// <param name="router">The proxy to the router.</param> /// <param name="serializeDispatch">Indicates whether or not this object adapter serializes the dispatching of /// of requests received over the same connection.</param> /// <param name="taskScheduler">The optional task scheduler to use for dispatching requests.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The new object adapter.</returns> public ObjectAdapter CreateObjectAdapterWithRouter( IRouterPrx router, bool serializeDispatch = false, TaskScheduler?taskScheduler = null, CancellationToken cancel = default) => CreateObjectAdapterWithRouterAsync(router, serializeDispatch, taskScheduler, cancel).GetResult();