public void initialize() { Ice.Properties properties = _communicator.getProperties(); bool ipv4 = properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; bool preferIPv6 = properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0; string address; if(ipv4 && !preferIPv6) { address = properties.getPropertyWithDefault("IceDiscovery.Address", "239.255.0.1"); } else { address = properties.getPropertyWithDefault("IceDiscovery.Address", "ff15::1"); } int port = properties.getPropertyAsIntWithDefault("IceDiscovery.Port", 4061); string intf = properties.getProperty("IceDiscovery.Interface"); if(properties.getProperty("IceDiscovery.Multicast.Endpoints").Length == 0) { StringBuilder s = new StringBuilder(); s.Append("udp -h \"").Append(address).Append("\" -p ").Append(port); if(intf.Length != 0) { s.Append(" --interface \"").Append(intf).Append("\""); } properties.setProperty("IceDiscovery.Multicast.Endpoints", s.ToString()); } if(properties.getProperty("IceDiscovery.Reply.Endpoints").Length == 0) { StringBuilder s = new StringBuilder(); s.Append("udp"); if(intf.Length != 0) { s.Append(" -h \"").Append(intf).Append("\""); } properties.setProperty("IceDiscovery.Reply.Endpoints", s.ToString()); } if(properties.getProperty("IceDiscovery.Locator.Endpoints").Length == 0) { properties.setProperty("IceDiscovery.Locator.AdapterId", Guid.NewGuid().ToString()); } _multicastAdapter = _communicator.createObjectAdapter("IceDiscovery.Multicast"); _replyAdapter = _communicator.createObjectAdapter("IceDiscovery.Reply"); _locatorAdapter = _communicator.createObjectAdapter("IceDiscovery.Locator"); // // Setup locatory registry. // LocatorRegistryI locatorRegistry = new LocatorRegistryI(_communicator); Ice.LocatorRegistryPrx locatorRegistryPrx = Ice.LocatorRegistryPrxHelper.uncheckedCast( _locatorAdapter.addWithUUID(locatorRegistry)); string lookupEndpoints = properties.getProperty("IceDiscovery.Lookup"); if(lookupEndpoints.Length == 0) { lookupEndpoints = "udp -h \"" + address + "\" -p " + port; if(intf.Length > 0) { lookupEndpoints += " --interface \"" + intf + "\""; } } Ice.ObjectPrx lookupPrx = _communicator.stringToProxy("IceDiscovery/Lookup -d:" + lookupEndpoints); lookupPrx = lookupPrx.ice_collocationOptimized(false); try { lookupPrx.ice_getConnection(); } catch(Ice.LocalException ex) { StringBuilder b = new StringBuilder(); b.Append("IceDiscovery is unable to establish a multicast connection:\n"); b.Append("proxy = "); b.Append(lookupPrx.ToString()); b.Append('\n'); b.Append(ex.ToString()); throw new Ice.PluginInitializationException(b.ToString()); } // // Add lookup and lookup reply Ice objects // LookupI lookup = new LookupI(locatorRegistry, LookupPrxHelper.uncheckedCast(lookupPrx), properties); _multicastAdapter.add(lookup, Ice.Util.stringToIdentity("IceDiscovery/Lookup")); Ice.ObjectPrx lookupReply = _replyAdapter.addWithUUID(new LookupReplyI(lookup)).ice_datagram(); lookup.setLookupReply(LookupReplyPrxHelper.uncheckedCast(lookupReply)); // // Setup locator on the communicator. // Ice.ObjectPrx loc; loc = _locatorAdapter.addWithUUID( new LocatorI(lookup, Ice.LocatorRegistryPrxHelper.uncheckedCast(locatorRegistryPrx))); _communicator.setDefaultLocator(Ice.LocatorPrxHelper.uncheckedCast(loc)); _multicastAdapter.activate(); _replyAdapter.activate(); _locatorAdapter.activate(); }
public void initialize() { Ice.Properties properties = _communicator.getProperties(); bool ipv4 = properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; bool preferIPv6 = properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0; string address; if(ipv4 && !preferIPv6) { address = properties.getPropertyWithDefault("IceLocatorDiscovery.Address", "239.255.0.1"); } else { address = properties.getPropertyWithDefault("IceLocatorDiscovery.Address", "ff15::1"); } int port = properties.getPropertyAsIntWithDefault("IceLocatorDiscovery.Port", 4061); string intf = properties.getProperty("IceLocatorDiscovery.Interface"); if(properties.getProperty("IceLocatorDiscovery.Reply.Endpoints").Length == 0) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("udp"); if(intf.Length > 0) { s.Append(" -h \""); s.Append(intf); s.Append("\""); } properties.setProperty("IceLocatorDiscovery.Reply.Endpoints", s.ToString()); } if(properties.getProperty("IceLocatorDiscovery.Locator.Endpoints").Length == 0) { properties.setProperty("IceLocatorDiscovery.Locator.AdapterId", Guid.NewGuid().ToString()); } _replyAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Reply"); _locatorAdapter = _communicator.createObjectAdapter("IceLocatorDiscovery.Locator"); // We don't want those adapters to be registered with the locator so clear their locator. _replyAdapter.setLocator(null); _locatorAdapter.setLocator(null); string lookupEndpoints = properties.getProperty("IceLocatorDiscovery.Lookup"); if(lookupEndpoints.Length == 0) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("udp -h \""); s.Append(address); s.Append("\" -p "); s.Append(port); if(intf.Length > 0) { s.Append(" --interface \""); s.Append(intf); s.Append("\""); } lookupEndpoints = s.ToString(); } Ice.ObjectPrx lookupPrx = _communicator.stringToProxy("IceLocatorDiscovery/Lookup -d:" + lookupEndpoints); lookupPrx = lookupPrx.ice_collocationOptimized(false); // No colloc optimization for the multicast proxy! try { lookupPrx.ice_getConnection(); // Ensure we can establish a connection to the multicast proxy } catch (Ice.LocalException ex) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("IceLocatorDiscovery is unable to establish a multicast connection:\n"); s.Append("proxy = "); s.Append(lookupPrx.ToString()); s.Append("\n"); s.Append(ex); throw new Ice.PluginInitializationException(s.ToString()); } Ice.LocatorPrx voidLo = Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(new VoidLocatorI())); string instanceName = properties.getProperty("IceLocatorDiscovery.InstanceName"); Ice.Identity id = new Ice.Identity(); id.name = "Locator"; id.category = instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString(); LocatorI locator = new LocatorI(LookupPrxHelper.uncheckedCast(lookupPrx), properties, instanceName, voidLo); _communicator.setDefaultLocator(Ice.LocatorPrxHelper.uncheckedCast(_locatorAdapter.addWithUUID(locator))); Ice.ObjectPrx lookupReply = _replyAdapter.addWithUUID(new LookupReplyI(locator)).ice_datagram(); locator.setLookupReply(LookupReplyPrxHelper.uncheckedCast(lookupReply)); _replyAdapter.activate(); _locatorAdapter.activate(); }
public static void allTests(Ice.Communicator communicator) { communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp -p 12030"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter"); PingReplyI replyI = new PingReplyI(); Test.PingReplyPrx reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); adapter.activate(); Console.Out.Write("testing udp... "); Console.Out.Flush(); Ice.ObjectPrx @base = communicator.stringToProxy("test:udp -p 12010").ice_datagram(); Test.TestIntfPrx obj = Test.TestIntfPrxHelper.uncheckedCast(@base); int nRetry = 5; bool ret = false; while (nRetry-- > 0) { replyI.reset(); obj.ping(reply); obj.ping(reply); obj.ping(reply); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } // If the 3 datagrams were not received within the 2 seconds, we try again to // receive 3 new datagrams using a new object. We give up after 5 retries. replyI = new PingReplyI(); reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } test(ret == true); if (communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0) { // // Only run this test if compression is disabled, the test expect fixed message size // to be sent over the wire. // byte[] seq = null; try { seq = new byte[1024]; while (true) { seq = new byte[seq.Length * 2 + 10]; replyI.reset(); obj.sendByteSeq(seq, reply); replyI.waitReply(1, 10000); } } catch (Ice.DatagramLimitException) { // // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException // will be throw when try to send a packet bigger than that. However, Mono 2.10 bug in setting Socket // options could cause the RcvSize/SndSize to contain an arbitrary value so the test might fail // with smaller message sizes. // test(seq.Length > 16384 || IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono); } obj.ice_getConnection().close(false); communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000"); seq = new byte[50000]; try { replyI.reset(); obj.sendByteSeq(seq, reply); bool b = replyI.waitReply(1, 500); // // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet // should not be delivered. However, Mono 2.10 bug in setting Socket options could // cause the RcvSize/SndSize to contain an arbitrary value so the packet might // be delivered successfully. // test(!b || IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono); } catch (Ice.DatagramLimitException) { // // Mono 2.10 bug in setting Socket options could cause the RcvSize/SndSize to contain // an arbitrary value so the message send might fail if the effetive SndSize is minor // than expected. // test(IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono); } catch (Ice.LocalException ex) { Console.Out.WriteLine(ex); test(false); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing udp multicast... "); Console.Out.Flush(); string endpoint; if (communicator.getProperties().getProperty("Ice.IPv6").Equals("1")) { if (IceInternal.AssemblyUtil.osx_) { endpoint = "udp -h \"ff15::1:1\" -p 12020 --interface \"::1\""; } else { endpoint = "udp -h \"ff15::1:1\" -p 12020"; } } else { endpoint = "udp -h 239.255.1.1 -p 12020"; } @base = communicator.stringToProxy("test -d:" + endpoint); TestIntfPrx objMcast = Test.TestIntfPrxHelper.uncheckedCast(@base); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); objMcast.ping(reply); ret = replyI.waitReply(5, 5000); if (ret) { break; } replyI = new PingReplyI(); reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } if (!ret) { Console.Out.WriteLine("failed (is a firewall enabled?)"); } else { Console.Out.WriteLine("ok"); } Console.Out.Write("testing udp bi-dir connection... "); Console.Out.Flush(); obj.ice_getConnection().setAdapter(adapter); objMcast.ice_getConnection().setAdapter(adapter); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); obj.pingBiDir(reply.ice_getIdentity()); obj.pingBiDir(reply.ice_getIdentity()); obj.pingBiDir(reply.ice_getIdentity()); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } replyI = new PingReplyI(); reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } test(ret); Console.Out.WriteLine("ok"); // // Sending the replies back on the multicast UDP connection doesn't work for most // platform (it works for OS X Leopard but not Snow Leopard, doesn't work on SLES, // Windows...). For Windows, see UdpTransceiver constructor for the details. So // we don't run this test. // // Console.Out.Write("testing udp bi-dir connection... "); // nRetry = 5; // while(nRetry-- > 0) // { // replyI.reset(); // objMcast.pingBiDir(reply.ice_getIdentity()); // ret = replyI.waitReply(5, 2000); // if(ret) // { // break; // Success // } // replyI = new PingReplyI(); // reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); // } // if(!ret) // { // Console.Out.WriteLine("failed (is a firewall enabled?)"); // } // else // { // Console.Out.WriteLine("ok"); // } }
public static TestIntfPrx allTests(TestCommon.Application app, bool collocated) { Ice.Communicator communicator = app.communicator(); Write("testing stringToProxy... "); Flush(); String @ref = "Test:" + app.getTestEndpoint(0) + " -t 2000"; Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx testPrx = TestIntfPrxHelper.checkedCast(@base); test(testPrx != null); test(testPrx.Equals(@base)); WriteLine("ok"); Write("base... "); Flush(); { try { testPrx.baseAsBase(); test(false); } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_baseAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.baseAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown derived... "); Flush(); { try { testPrx.unknownDerivedAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known derived as base... "); Flush(); { try { testPrx.knownDerivedAsBase(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known derived as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known derived as derived... "); Flush(); { try { testPrx.knownDerivedAsKnownDerived(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known derived as derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownDerivedAsKnownDerived().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownDerivedAsKnownDerivedAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown intermediate as base... "); Flush(); { try { testPrx.unknownIntermediateAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownIntermediateAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownIntermediateAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of known intermediate as base... "); Flush(); { try { testPrx.knownIntermediateAsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of known intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownIntermediateAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownIntermediateAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of known most derived as base... "); Flush(); { try { testPrx.knownMostDerivedAsBase(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of known most derived as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownMostDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known intermediate as intermediate... "); Flush(); { try { testPrx.knownIntermediateAsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known intermediate as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownIntermediateAsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownIntermediateAsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known most derived as intermediate... "); Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediate(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known most derived as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownMostDerivedAsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known most derived as most derived... "); Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerived(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known most derived as most derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsKnownMostDerived().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownMostDerivedAsKnownMostDerivedAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as base... "); Flush(); { try { testPrx.unknownMostDerived1AsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived1AsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownMostDerived1AsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as intermediate... "); Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived1AsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownMostDerived1AsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown most derived, unknown intermediate thrown as base... "); Flush(); { try { testPrx.unknownMostDerived2AsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived2AsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownMostDerived2AsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("unknown most derived in compact format... "); Flush(); { try { testPrx.unknownMostDerived2AsBaseCompact(); test(false); } catch (Base) { // // For the 1.0 encoding, the unknown exception is sliced to Base. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.UnknownUserException) { // // A MarshalException is raised for the compact format because the // most-derived type is unknown and the exception cannot be sliced. // test(!testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } } WriteLine("ok"); Write("preserved exceptions... "); Flush(); { try { testPrx.unknownPreservedAsBase(); test(false); } catch (Base ex) { if (testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)) { test(ex.ice_getSlicedData() == null); } else { Ice.SlicedData slicedData = ex.ice_getSlicedData(); test(slicedData != null); test(slicedData.slices.Length == 2); test(slicedData.slices[1].typeId.Equals("::Test::SPreserved1")); test(slicedData.slices[0].typeId.Equals("::Test::SPreserved2")); } } try { testPrx.unknownPreservedAsKnownPreserved(); test(false); } catch (KnownPreserved ex) { test(ex.kp.Equals("preserved")); if (testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)) { test(ex.ice_getSlicedData() == null); } else { Ice.SlicedData slicedData = ex.ice_getSlicedData(); test(slicedData != null); test(slicedData.slices.Length == 2); test(slicedData.slices[1].typeId.Equals("::Test::SPreserved1")); test(slicedData.slices[0].typeId.Equals("::Test::SPreserved2")); } } Ice.ObjectAdapter adapter = communicator.createObjectAdapter(""); RelayPrx relay = RelayPrxHelper.uncheckedCast(adapter.addWithUUID(new RelayI())); adapter.activate(); testPrx.ice_getConnection().setAdapter(adapter); try { testPrx.relayKnownPreservedAsBase(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayKnownPreservedAsKnownPreserved(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsBase(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsKnownPreserved(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } adapter.destroy(); } WriteLine("ok"); return(testPrx); }
public static Test.TimeoutPrx allTests(Ice.Communicator communicator) #endif { string sref = "timeout:default -p 12010"; Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); Test.TimeoutPrx timeout = Test.TimeoutPrxHelper.checkedCast(obj); test(timeout != null); Write("testing connect timeout... "); Flush(); { // // Expect ConnectTimeoutException. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(100)); timeout.holdAdapter(500); try { to.op(); test(false); } catch (Ice.ConnectTimeoutException) { // Expected. } } { // // Expect success. // timeout.op(); // Ensure adapter is active. Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); timeout.holdAdapter(500); try { to.op(); } catch (Ice.ConnectTimeoutException) { test(false); } } WriteLine("ok"); // The sequence needs to be large enough to fill the write/recv buffers byte[] seq = new byte[2000000]; Write("testing connection timeout... "); Flush(); { // // Expect TimeoutException. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(100)); timeout.holdAdapter(500); try { to.sendData(seq); test(false); } catch (Ice.TimeoutException) { // Expected. } } { // // Expect success. // timeout.op(); // Ensure adapter is active. Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_timeout(1000)); timeout.holdAdapter(500); try { to.sendData(new byte[1000000]); } catch (Ice.TimeoutException) { test(false); } } WriteLine("ok"); Write("testing invocation timeout... "); Flush(); { Ice.Connection connection = obj.ice_getConnection(); Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(100)); test(connection == to.ice_getConnection()); try { to.sleep(750); test(false); } catch (Ice.InvocationTimeoutException) { } obj.ice_ping(); to = Test.TimeoutPrxHelper.checkedCast(obj.ice_invocationTimeout(500)); test(connection == to.ice_getConnection()); try { to.sleep(250); } catch (Ice.InvocationTimeoutException) { test(false); } test(connection == to.ice_getConnection()); } { // // Expect InvocationTimeoutException. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(100)); Callback cb = new Callback(); to.begin_sleep(750).whenCompleted( () => { test(false); }, (Ice.Exception ex) => { test(ex is Ice.InvocationTimeoutException); cb.called(); }); cb.check(); obj.ice_ping(); } { // // Expect success. // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(500)); Callback cb = new Callback(); to.begin_sleep(250).whenCompleted( () => { cb.called(); }, (Ice.Exception ex) => { test(false); }); cb.check(); } { // // Backward compatible connection timeouts // Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(obj.ice_invocationTimeout(-2).ice_timeout(100)); Ice.Connection con = null; try { con = to.ice_getConnection(); to.sleep(750); test(false); } catch (Ice.TimeoutException) { try { con.getInfo(); test(false); } catch (Ice.TimeoutException) { // Connection got closed as well. } } obj.ice_ping(); try { con = to.ice_getConnection(); to.end_sleep(to.begin_sleep(750)); test(false); } catch (Ice.TimeoutException) { try { con.getInfo(); test(false); } catch (Ice.TimeoutException) { // Connection got closed as well. } } obj.ice_ping(); } WriteLine("ok"); Write("testing close timeout... "); Flush(); { Test.TimeoutPrx to = Test.TimeoutPrxHelper.checkedCast(obj.ice_timeout(100)); Ice.Connection connection = to.ice_getConnection(); timeout.holdAdapter(500); connection.close(false); try { connection.getInfo(); // getInfo() doesn't throw in the closing state. } catch (Ice.LocalException) { test(false); } Thread.Sleep(500); try { connection.getInfo(); test(false); } catch (Ice.CloseConnectionException) { // Expected. } timeout.op(); // Ensure adapter is active. } WriteLine("ok"); Write("testing timeout overrides... "); Flush(); { // // Test Ice.Override.Timeout. This property overrides all // endpoint timeouts. // string[] args = new string[0]; Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Override.Timeout", "100"); Ice.Communicator comm = Ice.Util.initialize(ref args, initData); Test.TimeoutPrx to = Test.TimeoutPrxHelper.checkedCast(comm.stringToProxy(sref)); timeout.holdAdapter(500); try { to.sendData(seq); test(false); } catch (Ice.TimeoutException) { // Expected. } // // Calling ice_timeout() should have no effect. // timeout.op(); // Ensure adapter is active. to = Test.TimeoutPrxHelper.checkedCast(to.ice_timeout(1000)); timeout.holdAdapter(500); try { to.sendData(seq); test(false); } catch (Ice.TimeoutException) { // Expected. } comm.destroy(); } { // // Test Ice.Override.ConnectTimeout. // string[] args = new string[0]; Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Override.ConnectTimeout", "250"); Ice.Communicator comm = Ice.Util.initialize(ref args, initData); timeout.holdAdapter(750); Test.TimeoutPrx to = Test.TimeoutPrxHelper.uncheckedCast(comm.stringToProxy(sref)); try { to.op(); test(false); } catch (Ice.ConnectTimeoutException) { // Expected. } // // Calling ice_timeout() should have no effect on the connect timeout. // timeout.op(); // Ensure adapter is active. timeout.holdAdapter(750); to = Test.TimeoutPrxHelper.uncheckedCast(to.ice_timeout(1000)); try { to.op(); test(false); } catch (Ice.ConnectTimeoutException) { // Expected. } // // Verify that timeout set via ice_timeout() is still used for requests. // timeout.op(); // Ensure adapter is active. to = Test.TimeoutPrxHelper.uncheckedCast(to.ice_timeout(250)); to.ice_getConnection(); // Establish connection. timeout.holdAdapter(750); try { to.sendData(seq); test(false); } catch (Ice.TimeoutException) { // Expected. } comm.destroy(); } { // // Test Ice.Override.CloseTimeout. // Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Override.CloseTimeout", "100"); Ice.Communicator comm = Ice.Util.initialize(initData); comm.stringToProxy(sref).ice_getConnection(); timeout.holdAdapter(500); long begin = System.DateTime.Now.Ticks; comm.destroy(); test(((long)new System.TimeSpan(System.DateTime.Now.Ticks - begin).TotalMilliseconds - begin) < 400); } WriteLine("ok"); Write("testing invocation timeouts with collocated calls... "); Flush(); { communicator.getProperties().setProperty("TimeoutCollocated.AdapterId", "timeoutAdapter"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TimeoutCollocated"); adapter.activate(); Test.TimeoutPrx proxy = Test.TimeoutPrxHelper.uncheckedCast(adapter.addWithUUID(new TimeoutI())); proxy = (Test.TimeoutPrx)proxy.ice_invocationTimeout(100); try { proxy.sleep(300); test(false); } catch (Ice.InvocationTimeoutException) { } try { proxy.end_sleep(proxy.begin_sleep(300)); test(false); } catch (Ice.InvocationTimeoutException) { } Test.TimeoutPrx batchTimeout = (Test.TimeoutPrx)proxy.ice_batchOneway(); batchTimeout.ice_ping(); batchTimeout.ice_ping(); batchTimeout.ice_ping(); ((Test.TimeoutPrx)proxy.ice_invocationTimeout(-1)).begin_sleep(300); // Keep the server thread pool busy. try { batchTimeout.ice_flushBatchRequests(); test(false); } catch (Ice.InvocationTimeoutException) { } batchTimeout.ice_ping(); batchTimeout.ice_ping(); batchTimeout.ice_ping(); ((Test.TimeoutPrx)proxy.ice_invocationTimeout(-1)).begin_sleep(300); // Keep the server thread pool busy. try { batchTimeout.end_ice_flushBatchRequests(batchTimeout.begin_ice_flushBatchRequests()); test(false); } catch (Ice.InvocationTimeoutException) { } adapter.destroy(); } WriteLine("ok"); #if SILVERLIGHT timeout.shutdown(); #else return(timeout); #endif }
public static void allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing communicator operations... "); output.Flush(); { // // Test: Exercise addAdminFacet, findAdminFacet, removeAdminFacet with a typical configuration. // Ice.InitializationData init = new Ice.InitializationData(); init.properties = Ice.Util.createProperties(); init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); init.properties.setProperty("Ice.Admin.InstanceName", "Test"); Ice.Communicator com = Ice.Util.initialize(init); testFacets(com, true); com.destroy(); } { // // Test: Verify that the operations work correctly in the presence of facet filters. // Ice.InitializationData init = new Ice.InitializationData(); init.properties = Ice.Util.createProperties(); init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); init.properties.setProperty("Ice.Admin.InstanceName", "Test"); init.properties.setProperty("Ice.Admin.Facets", "Properties"); Ice.Communicator com = Ice.Util.initialize(init); testFacets(com, false); com.destroy(); } { // // Test: Verify that the operations work correctly with the Admin object disabled. // Ice.Communicator com = Ice.Util.initialize(); testFacets(com, false); com.destroy(); } { // // Test: Verify that the operations work correctly with Ice.Admin.Enabled=1 // Ice.InitializationData init = new Ice.InitializationData(); init.properties = Ice.Util.createProperties(); init.properties.setProperty("Ice.Admin.Enabled", "1"); Ice.Communicator com = Ice.Util.initialize(init); test(com.getAdmin() == null); Ice.Identity id = Ice.Util.stringToIdentity("test-admin"); try { com.createAdmin(null, id); test(false); } catch (Ice.InitializationException) { } Ice.ObjectAdapter adapter = com.createObjectAdapter(""); test(com.createAdmin(adapter, id) != null); test(com.getAdmin() != null); testFacets(com, true); com.destroy(); } { // // Test: Verify that the operations work correctly when creation of the Admin object is delayed. // Ice.InitializationData init = new Ice.InitializationData(); init.properties = Ice.Util.createProperties(); init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); init.properties.setProperty("Ice.Admin.InstanceName", "Test"); init.properties.setProperty("Ice.Admin.DelayCreation", "1"); Ice.Communicator com = Ice.Util.initialize(init); testFacets(com, true); com.getAdmin(); testFacets(com, true); com.destroy(); } output.WriteLine("ok"); string @ref = "factory:" + helper.getTestEndpoint(0) + " -t 10000"; Test.RemoteCommunicatorFactoryPrx factory = Test.RemoteCommunicatorFactoryPrxHelper.uncheckedCast(communicator.stringToProxy(@ref)); output.Write("testing process facet... "); output.Flush(); { // // Test: Verify that Process::shutdown() operation shuts down the communicator. // Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); var com = factory.createCommunicator(props); Ice.ObjectPrx obj = com.getAdmin(); Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process"); proc.shutdown(); com.waitForShutdown(); com.destroy(); } output.WriteLine("ok"); output.Write("testing properties facet... "); output.Flush(); { Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); props.Add("Prop1", "1"); props.Add("Prop2", "2"); props.Add("Prop3", "3"); var com = factory.createCommunicator(props); Ice.ObjectPrx obj = com.getAdmin(); Ice.PropertiesAdminPrx pa = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties"); // // Test: PropertiesAdmin::getProperty() // test(pa.getProperty("Prop2").Equals("2")); test(pa.getProperty("Bogus").Equals("")); // // Test: PropertiesAdmin::getProperties() // Dictionary <string, string> pd = pa.getPropertiesForPrefix(""); test(pd.Count == 5); test(pd["Ice.Admin.Endpoints"].Equals("tcp -h 127.0.0.1")); test(pd["Ice.Admin.InstanceName"].Equals("Test")); test(pd["Prop1"].Equals("1")); test(pd["Prop2"].Equals("2")); test(pd["Prop3"].Equals("3")); Dictionary <string, string> changes; // // Test: PropertiesAdmin::setProperties() // Dictionary <string, string> setProps = new Dictionary <string, string>(); setProps.Add("Prop1", "10"); // Changed setProps.Add("Prop2", "20"); // Changed setProps.Add("Prop3", ""); // Removed setProps.Add("Prop4", "4"); // Added setProps.Add("Prop5", "5"); // Added pa.setProperties(setProps); test(pa.getProperty("Prop1").Equals("10")); test(pa.getProperty("Prop2").Equals("20")); test(pa.getProperty("Prop3").Equals("")); test(pa.getProperty("Prop4").Equals("4")); test(pa.getProperty("Prop5").Equals("5")); changes = com.getChanges(); test(changes.Count == 5); test(changes["Prop1"].Equals("10")); test(changes["Prop2"].Equals("20")); test(changes["Prop3"].Equals("")); test(changes["Prop4"].Equals("4")); test(changes["Prop5"].Equals("5")); pa.setProperties(setProps); changes = com.getChanges(); test(changes.Count == 0); com.destroy(); } output.WriteLine("ok"); output.Write("testing logger facet... "); output.Flush(); { Dictionary <String, String> props = new Dictionary <String, String>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); props.Add("NullLogger", "1"); var com = factory.createCommunicator(props); com.trace("testCat", "trace"); com.warning("warning"); com.error("error"); com.print("print"); Ice.ObjectPrx obj = com.getAdmin(); Ice.LoggerAdminPrx logger = Ice.LoggerAdminPrxHelper.checkedCast(obj, "Logger"); test(logger != null); string prefix = null; // // Get all // Ice.LogMessage[] logMessages = logger.getLog(null, null, -1, out prefix); test(logMessages.Length == 4); test(prefix.Equals("NullLogger")); test(logMessages[0].traceCategory.Equals("testCat") && logMessages[0].message.Equals("trace")); test(logMessages[1].message.Equals("warning")); test(logMessages[2].message.Equals("error")); test(logMessages[3].message.Equals("print")); // // Get only errors and warnings // com.error("error2"); com.print("print2"); com.trace("testCat", "trace2"); com.warning("warning2"); Ice.LogMessageType[] messageTypes = { Ice.LogMessageType.ErrorMessage, Ice.LogMessageType.WarningMessage }; logMessages = logger.getLog(messageTypes, null, -1, out prefix); test(logMessages.Length == 4); test(prefix.Equals("NullLogger")); foreach (var msg in logMessages) { test(msg.type == Ice.LogMessageType.ErrorMessage || msg.type == Ice.LogMessageType.WarningMessage); } // // Get only errors and traces with Cat = "testCat" // com.trace("testCat2", "A"); com.trace("testCat", "trace3"); com.trace("testCat2", "B"); messageTypes = new Ice.LogMessageType[] { Ice.LogMessageType.ErrorMessage, Ice.LogMessageType.TraceMessage }; string[] categories = { "testCat" }; logMessages = logger.getLog(messageTypes, categories, -1, out prefix); test(logMessages.Length == 5); test(prefix.Equals("NullLogger")); foreach (var msg in logMessages) { test(msg.type == Ice.LogMessageType.ErrorMessage || (msg.type == Ice.LogMessageType.TraceMessage && msg.traceCategory.Equals("testCat"))); } // // Same, but limited to last 2 messages(trace3 + error3) // com.error("error3"); logMessages = logger.getLog(messageTypes, categories, 2, out prefix); test(logMessages.Length == 2); test(prefix.Equals("NullLogger")); test(logMessages[0].message.Equals("trace3")); test(logMessages[1].message.Equals("error3")); // // Now, test RemoteLogger // Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("RemoteLoggerAdapter", "tcp -h localhost"); RemoteLoggerI remoteLogger = new RemoteLoggerI(); Ice.RemoteLoggerPrx myProxy = Ice.RemoteLoggerPrxHelper.uncheckedCast(adapter.addWithUUID(remoteLogger)); adapter.activate(); // // No filtering // logMessages = logger.getLog(null, null, -1, out prefix); remoteLogger.checkNextInit(prefix, logMessages); logger.attachRemoteLogger(myProxy, null, null, -1); remoteLogger.wait(1); remoteLogger.checkNextLog(Ice.LogMessageType.TraceMessage, "rtrace", "testCat"); remoteLogger.checkNextLog(Ice.LogMessageType.WarningMessage, "rwarning", ""); remoteLogger.checkNextLog(Ice.LogMessageType.ErrorMessage, "rerror", ""); remoteLogger.checkNextLog(Ice.LogMessageType.PrintMessage, "rprint", ""); com.trace("testCat", "rtrace"); com.warning("rwarning"); com.error("rerror"); com.print("rprint"); remoteLogger.wait(4); test(logger.detachRemoteLogger(myProxy)); test(!logger.detachRemoteLogger(myProxy)); // // Use Error + Trace with "traceCat" filter with 4 limit // logMessages = logger.getLog(messageTypes, categories, 4, out prefix); test(logMessages.Length == 4); remoteLogger.checkNextInit(prefix, logMessages); logger.attachRemoteLogger(myProxy, messageTypes, categories, 4); remoteLogger.wait(1); remoteLogger.checkNextLog(Ice.LogMessageType.TraceMessage, "rtrace2", "testCat"); remoteLogger.checkNextLog(Ice.LogMessageType.ErrorMessage, "rerror2", ""); com.warning("rwarning2"); com.trace("testCat", "rtrace2"); com.warning("rwarning3"); com.error("rerror2"); com.print("rprint2"); remoteLogger.wait(2); // // Attempt reconnection with slightly different proxy // try { logger.attachRemoteLogger(Ice.RemoteLoggerPrxHelper.uncheckedCast(myProxy.ice_oneway()), messageTypes, categories, 4); test(false); } catch (Ice.RemoteLoggerAlreadyAttachedException) { // expected } com.destroy(); } output.WriteLine("ok"); output.Write("testing custom facet... "); output.Flush(); { // // Test: Verify that the custom facet is present. // Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); var com = factory.createCommunicator(props); Ice.ObjectPrx obj = com.getAdmin(); var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet"); tf.op(); com.destroy(); } output.WriteLine("ok"); output.Write("testing facet filtering... "); output.Flush(); { // // Test: Set Ice.Admin.Facets to expose only the Properties facet, // meaning no other facet is available. // Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); props.Add("Ice.Admin.Facets", "Properties"); var com = factory.createCommunicator(props); Ice.ObjectPrx obj = com.getAdmin(); Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process"); test(proc == null); var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet"); test(tf == null); com.destroy(); } { // // Test: Set Ice.Admin.Facets to expose only the Process facet, // meaning no other facet is available. // Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); props.Add("Ice.Admin.Facets", "Process"); var com = factory.createCommunicator(props); Ice.ObjectPrx obj = com.getAdmin(); Ice.PropertiesAdminPrx pa = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties"); test(pa == null); var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet"); test(tf == null); com.destroy(); } { // // Test: Set Ice.Admin.Facets to expose only the TestFacet facet, // meaning no other facet is available. // Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); props.Add("Ice.Admin.Facets", "TestFacet"); var com = factory.createCommunicator(props); Ice.ObjectPrx obj = com.getAdmin(); Ice.PropertiesAdminPrx pa = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties"); test(pa == null); Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process"); test(proc == null); com.destroy(); } { // // Test: Set Ice.Admin.Facets to expose two facets. Use whitespace to separate the // facet names. // Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); props.Add("Ice.Admin.Facets", "Properties TestFacet"); var com = factory.createCommunicator(props); Ice.ObjectPrx obj = com.getAdmin(); Ice.PropertiesAdminPrx pa = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties"); test(pa.getProperty("Ice.Admin.InstanceName").Equals("Test")); var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet"); tf.op(); Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process"); test(proc == null); com.destroy(); } { // // Test: Set Ice.Admin.Facets to expose two facets. Use a comma to separate the // facet names. // Dictionary <string, string> props = new Dictionary <string, string>(); props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); props.Add("Ice.Admin.InstanceName", "Test"); props.Add("Ice.Admin.Facets", "TestFacet, Process"); var com = factory.createCommunicator(props); Ice.ObjectPrx obj = com.getAdmin(); Ice.PropertiesAdminPrx pa = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties"); test(pa == null); var tf = Test.TestFacetPrxHelper.checkedCast(obj, "TestFacet"); tf.op(); Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process"); proc.shutdown(); com.waitForShutdown(); com.destroy(); } output.WriteLine("ok"); factory.shutdown(); }
/// <summary> /// Initializes a new instance of the /// <see cref="T:Ferda.Modules.BoxModuleI"/> class. /// </summary> /// <param name="boxInfo">The box info.</param> /// <param name="myIdentity">My identity.</param> /// <param name="myFactoryProxy">My factory proxy.</param> /// <param name="manager">The manager.</param> /// <param name="adapter">The adapter.</param> /// <param name="localePrefs">The localization preferences.</param> public BoxModuleI(IBoxInfo boxInfo, Ice.Identity myIdentity, BoxModuleFactoryPrx myFactoryProxy, Ferda.ModulesManager.ManagersEnginePrx manager, Ice.ObjectAdapter adapter, string[] localePrefs) { System.Diagnostics.Debug.WriteLine("BoxModuleI Constructor (entering): " + boxInfo.Identifier); // initializes inner fields by specified parameters this.boxInfo = boxInfo; this.iceIdentity = myIdentity; this.stringIceIdentity = Ice.Util.identityToString(IceIdentity); this.myFactoryProxy = myFactoryProxy; this.manager = manager; this.adapter = adapter; this.localePrefs = localePrefs; // add the new box module to the specified adapter adapter.add(this, this.iceIdentity); // get my proxy this.myProxy = BoxModulePrxHelper.uncheckedCast(adapter.createProxy(myIdentity)); // initializes box module`s functions object this.boxInfo.CreateFunctions(this, out this.functionsIceObj, out this.functionsIObj); this.functionsIObj.setBoxModuleInfo(this, this.boxInfo); this.functionsObjPrx = Ice.ObjectPrxHelper.uncheckedCast(adapter.addWithUUID(this.functionsIceObj)); // initializes properties this.properties = new Dictionary<string, PropertyValue>(); foreach (string propertyName in boxInfo.GetPropertiesNames()) { if (!boxInfo.IsPropertyReadOnly(propertyName)) { this.setProperty(propertyName, boxInfo.GetPropertyDefaultValue(propertyName)); } } // initializes sockets (connections and functions) this.connections = new Dictionary<string, Dictionary<string, BoxModulePrx>>(); foreach (string socketName in boxInfo.GetSocketNames()) { connections[socketName] = new Dictionary<string, BoxModulePrx>(); } System.Diagnostics.Debug.WriteLine("BoxModuleI Constructor (leaving): " + this.boxInfo.Identifier); }
public static void allTests(TestCommon.Application app) { Ice.Communicator communicator = app.communicator(); communicator.getProperties().setProperty("ReplyAdapter.Endpoints", "udp"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("ReplyAdapter"); PingReplyI replyI = new PingReplyI(); Test.PingReplyPrx reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); adapter.activate(); Console.Out.Write("testing udp... "); Console.Out.Flush(); Ice.ObjectPrx @base = communicator.stringToProxy("test:" + app.getTestEndpoint(0, "udp")).ice_datagram(); Test.TestIntfPrx obj = Test.TestIntfPrxHelper.uncheckedCast(@base); int nRetry = 5; bool ret = false; while (nRetry-- > 0) { replyI.reset(); obj.ping(reply); obj.ping(reply); obj.ping(reply); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } // If the 3 datagrams were not received within the 2 seconds, we try again to // receive 3 new datagrams using a new object. We give up after 5 retries. replyI = new PingReplyI(); reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } test(ret == true); if (communicator.getProperties().getPropertyAsInt("Ice.Override.Compress") == 0) { // // Only run this test if compression is disabled, the test expect fixed message size // to be sent over the wire. // byte[] seq = null; try { seq = new byte[1024]; while (true) { seq = new byte[seq.Length * 2 + 10]; replyI.reset(); obj.sendByteSeq(seq, reply); replyI.waitReply(1, 10000); } } catch (Ice.DatagramLimitException) { // // The server's Ice.UDP.RcvSize property is set to 16384, which means that DatagramLimitException // will be throw when try to send a packet bigger than that. // test(seq.Length > 16384); } obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); communicator.getProperties().setProperty("Ice.UDP.SndSize", "64000"); seq = new byte[50000]; try { replyI.reset(); obj.sendByteSeq(seq, reply); bool b = replyI.waitReply(1, 500); // // The server's Ice.UDP.RcvSize property is set to 16384, which means this packet // should not be delivered. // test(!b); } catch (Ice.DatagramLimitException) { } catch (Ice.LocalException ex) { Console.Out.WriteLine(ex); test(false); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing udp multicast... "); Console.Out.Flush(); StringBuilder endpoint = new StringBuilder(); if (communicator.getProperties().getProperty("Ice.IPv6").Equals("1")) { endpoint.Append("udp -h \"ff15::1:1\" --interface \"::1\" -p "); // Use loopback to prevent other machines to answer. } else { endpoint.Append("udp -h 239.255.1.1 --interface 127.0.0.1 -p "); // Use loopback to prevent other machines to answer. } endpoint.Append(app.getTestPort(10)); @base = communicator.stringToProxy("test -d:" + endpoint.ToString()); TestIntfPrx objMcast = Test.TestIntfPrxHelper.uncheckedCast(@base); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); objMcast.ping(reply); ret = replyI.waitReply(5, 5000); if (ret) { break; } replyI = new PingReplyI(); reply = (Test.PingReplyPrx)Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } if (!ret) { Console.Out.WriteLine("failed (is a firewall enabled?)"); } else { Console.Out.WriteLine("ok"); } Console.Out.Write("testing udp bi-dir connection... "); Console.Out.Flush(); obj.ice_getConnection().setAdapter(adapter); objMcast.ice_getConnection().setAdapter(adapter); nRetry = 5; while (nRetry-- > 0) { replyI.reset(); obj.pingBiDir(reply.ice_getIdentity()); obj.pingBiDir(reply.ice_getIdentity()); obj.pingBiDir(reply.ice_getIdentity()); ret = replyI.waitReply(3, 2000); if (ret) { break; // Success } replyI = new PingReplyI(); reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); } test(ret); Console.Out.WriteLine("ok"); // // Sending the replies back on the multicast UDP connection doesn't work for most // platform (it works for macOS Leopard but not Snow Leopard, doesn't work on SLES, // Windows...). For Windows, see UdpTransceiver constructor for the details. So // we don't run this test. // // Console.Out.Write("testing udp bi-dir connection... "); // nRetry = 5; // while(nRetry-- > 0) // { // replyI.reset(); // objMcast.pingBiDir(reply.ice_getIdentity()); // ret = replyI.waitReply(5, 2000); // if(ret) // { // break; // Success // } // replyI = new PingReplyI(); // reply = (PingReplyPrx)PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI)).ice_datagram(); // } // if(!ret) // { // Console.Out.WriteLine("failed (is a firewall enabled?)"); // } // else // { // Console.Out.WriteLine("ok"); // } }
public static TestIntfPrx allTests(Ice.Communicator communicator, bool collocated) #endif { Write("testing stringToProxy... "); Flush(); String @ref = "Test:default -p 12010 -t 2000"; Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx testPrx = TestIntfPrxHelper.checkedCast(@base); test(testPrx != null); test(testPrx.Equals(@base)); WriteLine("ok"); Write("base... "); Flush(); { try { testPrx.baseAsBase(); test(false); } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_baseAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown derived... "); Flush(); { try { testPrx.unknownDerivedAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known derived as base... "); Flush(); { try { testPrx.knownDerivedAsBase(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known derived as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known derived as derived... "); Flush(); { try { testPrx.knownDerivedAsKnownDerived(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known derived as derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownDerivedAsKnownDerived().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown intermediate as base... "); Flush(); { try { testPrx.unknownIntermediateAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownIntermediateAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of known intermediate as base... "); Flush(); { try { testPrx.knownIntermediateAsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of known intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownIntermediateAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of known most derived as base... "); Flush(); { try { testPrx.knownMostDerivedAsBase(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of known most derived as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known intermediate as intermediate... "); Flush(); { try { testPrx.knownIntermediateAsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known intermediate as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownIntermediateAsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known most derived as intermediate... "); Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediate(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known most derived as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known most derived as most derived... "); Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerived(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known most derived as most derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsKnownMostDerived().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as base... "); Flush(); { try { testPrx.unknownMostDerived1AsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived1AsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as intermediate... "); Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived1AsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown most derived, unknown intermediate thrown as base... "); Flush(); { try { testPrx.unknownMostDerived2AsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived2AsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("unknown most derived in compact format... "); Flush(); { try { testPrx.unknownMostDerived2AsBaseCompact(); test(false); } catch (Base) { // // For the 1.0 encoding, the unknown exception is sliced to Base. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.UnknownUserException) { // // A MarshalException is raised for the compact format because the // most-derived type is unknown and the exception cannot be sliced. // test(!testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } } WriteLine("ok"); // // No server side in Silverlight // #if !SILVERLIGHT Write("preserved exceptions... "); Flush(); { Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Relay", "default"); RelayPrx relay = RelayPrxHelper.uncheckedCast(adapter.addWithUUID(new RelayI())); adapter.activate(); try { testPrx.relayKnownPreservedAsBase(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayKnownPreservedAsKnownPreserved(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } /* * catch(Exception) * { * test(false); * } */ catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsBase(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsKnownPreserved(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } adapter.destroy(); } WriteLine("ok"); #endif #if SILVERLIGHT testPrx.shutdown(); #else return(testPrx); #endif }