public void Disconnect() { if (null != communicator) { communicator.destroy(); } }
private void destroyServiceCommunicator(string service, Ice.Communicator communicator) { if (communicator != null) { try { communicator.shutdown(); communicator.waitForShutdown(); } catch (Ice.CommunicatorDestroyedException) { // // Ignore, the service might have already destroyed // the communicator for its own reasons. // } catch (System.Exception e) { _logger.warning("ServiceManager: exception while shutting down communicator for service " + service + "\n" + e.ToString()); } removeAdminFacets("IceBox.Service." + service + "."); try { communicator.destroy(); } catch (System.Exception e) { _logger.warning("ServiceManager: exception while destroying communicator for service " + service + "\n" + e.ToString()); } } }
/// <summary> /// Represents a connection to R2D2. On construction, this object creates a two-way /// connection with the bot. To properly shutdown the connection, make sure that /// the Dispose method is called; this is especially important if you wish to create a /// new BotConnection later. /// </summary> /// <param name="botToBase">Object implementing functions that receive from the bot</param> /// <param name="hostname">Hostname of the bo.</param> public BotConnection(BotToBaseDisp_ botToBase, string hostname = "R2D2") { try { Console.WriteLine("Starting server"); communicator = Ice.Util.initialize(); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints( "BotToBaseAdapter", "tcp -p " + BOT_TO_BASE_PORT); adapter.add(botToBase, communicator.stringToIdentity("BotToBaseImpl")); adapter.activate(); Console.WriteLine("Connecting to R2D2"); Ice.ObjectPrx prx = communicator.stringToProxy( string.Format("BaseToBotImpl:tcp -h {0} -p {1}", hostname, BASE_TO_BOT_PORT)); BotProxy = BaseToBotPrxHelper.checkedCast(prx); if (BotProxy == null) throw new ApplicationException("Invalid proxy"); // Pings are necessary to ensure that the connection is live. // We want R2D2 to stop immediately if the connection goes dead. new Thread(pinger).Start(); } catch { if (communicator != null) { communicator.destroy(); } throw; } }
static void Main(string[] args) { int status = 0; Ice.Communicator ic = null; ic = Ice.Util.initialize(ref args); Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000"); Ice.Object obj = new PrinterI(); adapter.add(obj, ic.stringToIdentity("SimplePrinter")); adapter.activate(); Console.WriteLine("started"); ic.waitForShutdown(); if (ic != null) { ic.destroy(); status = 1; } Environment.Exit(status); }
/// <summary> /// Disconnect from Qwerk device. /// </summary> /// public void Disconnect( ) { hostAddress = null; if (video != null) { video.SignalToStop( ); // wait for aroung 250 ms for (int i = 0; (i < 5) && (video.IsRunning); i++) { System.Threading.Thread.Sleep(50); } // abort camera if it can not be stopped if (video.IsRunning) { video.Stop( ); } } leds = null; digitalOuts = null; digitalIns = null; analogIns = null; video = null; motors = null; servos = null; // destroy ICE communicator if (iceCommunicator != null) { iceCommunicator.destroy( ); iceCommunicator = null; } }
public static bool stream() { Ice.Communicator communicator = Ice.Util.initialize(); Ice.OutputStream output = Ice.Util.createOutputStream(communicator); PersonPrx person = PersonPrxHelper.uncheckedCast(communicator.stringToProxy("person:default")); PersonPrxHelper.write(output, person); communicator.destroy(); return(true); }
private void Window_Closed(object sender, EventArgs e) { if (communicator_ == null) { return; } communicator_.destroy(); communicator_ = null; }
public void main() { int args = Application.Current.Host.Source.OriginalString.IndexOf("?"); Dictionary <string, string> properties = new Dictionary <string, string>(); if (args > 0 && args + 1 < Application.Current.Host.Source.OriginalString.Length) { string[] props = Application.Current.Host.Source.OriginalString.Substring(args + 1).Split(';'); foreach (string prop in props) { int pos = prop.IndexOf('='); if (pos > 0) { properties[prop.Substring(0, pos)] = prop.Substring(pos + 1); } } } System.Threading.Thread t = new System.Threading.Thread(() => { Ice.Communicator communicator = null; try { Ice.InitializationData initializationData = initData(); if (initializationData.properties == null) { initializationData.properties = Ice.Util.createProperties(); } foreach (KeyValuePair <String, String> entry in properties) { if (initializationData.properties.getProperty(entry.Key).Equals("")) { initializationData.properties.setProperty(entry.Key, entry.Value); } } communicator = Ice.Util.initialize(initializationData); run(communicator); completed(); } catch (System.Exception ex) { failed(ex); } finally { if (communicator != null) { communicator.destroy(); } } }); t.Start(); }
public void shutdown() { //alway call this, Ice needs to be closed cleanly logger.Info("IceApp " + Name + " shutdown"); foreach (Ice.Identity iceid in _ServantIds) // that least should be empty, but deregister them avoid corrupting db { //logger.Info("deregistering: " + iceid); _deregister(iceid); } if (Communicator != null) { Communicator.destroy(); } }
static void Main(string[] args) { try { Ice.Communicator communicator = Ice.Util.initialize(); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints( "converter", "tcp -p 10000"); adapter.add(new ConverterI(), communicator.stringToIdentity("converter")); adapter.activate(); communicator.waitForShutdown(); communicator.destroy(); } catch (System.Exception ex) { System.Console.Error.WriteLine(ex); System.Environment.Exit(1); } }
public static int Main(string[] args) { try { Ice.Communicator communicator = Ice.Util.initialize(ref args); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "tcp -p 10000"); adapter.add(new HelloI(), communicator.stringToIdentity("hello")); adapter.activate(); communicator.waitForShutdown(); communicator.destroy(); return(0); } catch (System.Exception ex) { System.Console.Error.WriteLine(ex); return(1); } }
public static void createServer(String proxyName) { try { Ice.Communicator communicator = Ice.Util.initialize(); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints( "proxyName", "tcp -p 10003"); adapter.add(new RemoteLogI(), communicator.stringToIdentity(proxyName)); adapter.activate(); communicator.waitForShutdown(); communicator.destroy(); } catch (System.Exception ex) { System.Console.Error.WriteLine(ex); System.Environment.Exit(1); } }
static void Main(string[] args) { try { Ice.Communicator communicator = Ice.Util.initialize(); ConverterPrx cvt = ConverterPrxHelper.checkedCast(communicator.stringToProxy("converter:tcp -p 10000 -h localhost")); string upper = cvt.toUpper("hello world"); System.Console.WriteLine("Server returned: " + upper); while (true) { ; //holds the window to show the console output } communicator.destroy(); } catch (System.Exception ex) { System.Console.Error.WriteLine(ex); System.Environment.Exit(1); } }
public static void createClient(string ip, string port, string proxyname, string name, string time, string msg) { try { Ice.Communicator communicator = Ice.Util.initialize(); logStation = RemoteLogPrxHelper.checkedCast( communicator.stringToProxy(String.Format("{0}:tcp -h {1} -p {2}", proxyname, ip, port))); System.Console.WriteLine("Connection Successful"); Client.logStation.log(name, time, msg); while (true) { } ; communicator.destroy(); } catch (System.Exception ex) { System.Console.Error.WriteLine(ex); System.Environment.Exit(1); } }
internal void destroy() { Ice.Communicator sendLogCommunicator = null; lock (this) { if (!_destroyed) { _destroyed = true; sendLogCommunicator = _sendLogCommunicator; _sendLogCommunicator = null; } } // // Destroy outside lock to avoid deadlock when there are outstanding two-way log calls sent to // remote logggers // if (sendLogCommunicator != null) { sendLogCommunicator.destroy(); } }
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); logger.attachRemoteLogger(myProxy, null, null, -1); remoteLogger.wait(1); foreach (var m in logMessages) { remoteLogger.checkNextInit(prefix, m.type, m.message, m.traceCategory); } com.trace("testCat", "rtrace"); com.warning("rwarning"); com.error("rerror"); com.print("rprint"); remoteLogger.wait(4); 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", ""); 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); logger.attachRemoteLogger(myProxy, messageTypes, categories, 4); remoteLogger.wait(1); foreach (var m in logMessages) { remoteLogger.checkNextInit(prefix, m.type, m.message, m.traceCategory); } com.warning("rwarning2"); com.trace("testCat", "rtrace2"); com.warning("rwarning3"); com.error("rerror2"); com.print("rprint2"); remoteLogger.wait(2); remoteLogger.checkNextLog(Ice.LogMessageType.TraceMessage, "rtrace2", "testCat"); remoteLogger.checkNextLog(Ice.LogMessageType.ErrorMessage, "rerror2", ""); // // 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(); }
public static void Main(string[] args) { int status = 0; try { ic = Ice.Util.initialize(ref args); String line = null; do { Console.WriteLine("8==>"); line = Console.ReadLine(); if (line == null) break; Console.WriteLine("8==> == " + line); if (line.Equals("c")) createAccount(); else if (line.Equals("t")) transfer(); else if (line.Equals("d")) delete(); else if (line.Equals("l")) loan(); else if (line.Equals("b")) getBalance(); } while (!line.Equals("x")); Console.ReadKey(); } catch (Exception e) { Console.ReadKey(); Console.Error.WriteLine(e); status = 1; } if (ic != null) { try { ic.destroy(); } catch (Exception e) { Console.Error.WriteLine(e); status = 1; } } Console.ReadKey(); Environment.Exit(status); }
public static void allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var manager = Test.ServerManagerPrxHelper.checkedCast( communicator.stringToProxy("ServerManager :" + helper.getTestEndpoint(0))); test(manager != null); var locator = Test.TestLocatorPrxHelper.uncheckedCast(communicator.getDefaultLocator()); test(locator != null); var registry = Test.TestLocatorRegistryPrxHelper.checkedCast(locator.getRegistry()); test(registry != null); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); Ice.ObjectPrx @base = communicator.stringToProxy("test @ TestAdapter"); Ice.ObjectPrx base2 = communicator.stringToProxy("test @ TestAdapter"); Ice.ObjectPrx base3 = communicator.stringToProxy("test"); Ice.ObjectPrx base4 = communicator.stringToProxy("ServerManager"); Ice.ObjectPrx base5 = communicator.stringToProxy("test2"); Ice.ObjectPrx base6 = communicator.stringToProxy("test @ ReplicatedAdapter"); output.WriteLine("ok"); output.Write("testing ice_locator and ice_getLocator... "); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); Ice.LocatorPrx anotherLocator = Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("anotherLocator")); @base = @base.ice_locator(anotherLocator); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0); communicator.setDefaultLocator(null); @base = communicator.stringToProxy("test @ TestAdapter"); test(@base.ice_getLocator() == null); @base = @base.ice_locator(anotherLocator); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0); communicator.setDefaultLocator(locator); @base = communicator.stringToProxy("test @ TestAdapter"); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); // // We also test ice_router/ice_getRouter(perhaps we should add a // test/Ice/router test?) // test(@base.ice_getRouter() == null); Ice.RouterPrx anotherRouter = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("anotherRouter")); @base = @base.ice_router(anotherRouter); test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), anotherRouter) == 0); Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("dummyrouter")); communicator.setDefaultRouter(router); @base = communicator.stringToProxy("test @ TestAdapter"); test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), communicator.getDefaultRouter()) == 0); communicator.setDefaultRouter(null); @base = communicator.stringToProxy("test @ TestAdapter"); test(@base.ice_getRouter() == null); output.WriteLine("ok"); output.Write("starting server... "); output.Flush(); manager.startServer(); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrxHelper.checkedCast(@base); test(obj != null); var obj2 = Test.TestIntfPrxHelper.checkedCast(base2); test(obj2 != null); var obj3 = Test.TestIntfPrxHelper.checkedCast(base3); test(obj3 != null); var obj4 = Test.ServerManagerPrxHelper.checkedCast(base4); test(obj4 != null); var obj5 = Test.TestIntfPrxHelper.checkedCast(base5); test(obj5 != null); var obj6 = Test.TestIntfPrxHelper.checkedCast(base6); test(obj6 != null); output.WriteLine("ok"); output.Write("testing id@AdapterId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing id@ReplicaGroupId indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj6.ice_ping(); } catch (Ice.LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing identity indirect proxy... "); output.Flush(); obj.shutdown(); manager.startServer(); try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = Test.TestIntfPrxHelper.checkedCast(base5); obj5.ice_ping(); } catch (Ice.LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing proxy with unknown identity... "); output.Flush(); try { @base = communicator.stringToProxy("unknown/unknown"); @base.ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject.Equals("object")); test(ex.id.Equals("unknown/unknown")); } output.WriteLine("ok"); output.Write("testing proxy with unknown adapter... "); output.Flush(); try { @base = communicator.stringToProxy("test @ TestAdapterUnknown"); @base.ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject.Equals("object adapter")); test(ex.id.Equals("TestAdapterUnknown")); } output.WriteLine("ok"); output.Write("testing locator cache timeout... "); output.Flush(); Ice.ObjectPrx basencc = communicator.stringToProxy("test@TestAdapter").ice_connectionCached(false); int count = locator.getRequestCount(); basencc.ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. test(++count == locator.getRequestCount()); basencc.ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. test(++count == locator.getRequestCount()); basencc.ice_locatorCacheTimeout(2).ice_ping(); // 2s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms basencc.ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. test(++count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. count += 2; test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(2).ice_ping(); // 2s timeout test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1300); // 1300ms communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout count += 2; test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(-1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_locatorCacheTimeout(-1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter").ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test").ice_ping(); test(count == locator.getRequestCount()); test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() == 99); output.WriteLine("ok"); output.Write("testing proxy from server... "); output.Flush(); obj = Test.TestIntfPrxHelper.checkedCast(communicator.stringToProxy("test@TestAdapter")); var hello = obj.getHello(); test(hello.ice_getAdapterId().Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.ice_getAdapterId().Equals("ReplicatedAdapter")); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator request queuing... "); output.Flush(); hello = (Test.HelloPrx)obj.getReplicatedHello().ice_locatorCacheTimeout(0).ice_connectionCached(false); count = locator.getRequestCount(); hello.ice_ping(); test(++count == locator.getRequestCount()); List <Ice.AsyncResult <Test.Callback_Hello_sayHello> > results = new List <Ice.AsyncResult <Test.Callback_Hello_sayHello> >(); for (int i = 0; i < 1000; i++) { Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello(). whenCompleted( () => { }, (Ice.Exception ex) => { test(false); }); results.Add(result); } foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results) { result.waitForCompleted(); } results.Clear(); test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } count = locator.getRequestCount(); hello = (Test.HelloPrx)hello.ice_adapterId("unknown"); for (int i = 0; i < 1000; i++) { Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello(). whenCompleted( () => { test(false); }, (Ice.Exception ex) => { test(ex is Ice.NotRegisteredException); }); results.Add(result); } foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results) { result.waitForCompleted(); } results.Clear(); // XXX: // Take into account the retries. test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); if (locator.getRequestCount() > count + 800) { output.Write("queuing = " + (locator.getRequestCount() - count)); } output.WriteLine("ok"); output.Write("testing adapter locator cache... "); output.Flush(); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestAdapter3")); } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); registry.setAdapterDirectProxy("TestAdapter3", communicator.stringToProxy("dummy:tcp")); communicator.stringToProxy("test@TestAdapter3").ice_ping(); } catch (Ice.LocalException) { test(false); } try { communicator.stringToProxy("test@TestAdapter3").ice_locatorCacheTimeout(0).ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); } catch (Ice.LocalException) { test(false); } output.WriteLine("ok"); output.Write("testing well-known object locator cache... "); output.Flush(); registry.addObject(communicator.stringToProxy("test3@TestUnknown")); try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestUnknown")); } registry.addObject(communicator.stringToProxy("test3@TestAdapter4")); // Update registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp")); try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } try { communicator.stringToProxy("test@TestAdapter4").ice_locatorCacheTimeout(0).ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test@TestAdapter4").ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.addObject(communicator.stringToProxy("test3@TestAdapter")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } registry.addObject(communicator.stringToProxy("test4")); try { communicator.stringToProxy("test4").ice_ping(); test(false); } catch (Ice.NoEndpointException) { } output.WriteLine("ok"); output.Write("testing locator cache background updates... "); output.Flush(); { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.BackgroundLocatorCacheUpdates", "1"); Ice.Communicator ic = helper.initialize(initData); registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter")); registry.addObject(communicator.stringToProxy("test3@TestAdapter")); count = locator.getRequestCount(); ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. ic.stringToProxy("test3").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.setAdapterDirectProxy("TestAdapter5", null); registry.addObject(communicator.stringToProxy("test3:tcp")); ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. try { while (true) { ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (Ice.LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (Ice.LocalException) { // Expected to fail once they endpoints have been updated in the background. } ic.destroy(); } output.WriteLine("ok"); output.Write("testing proxy from server after shutdown... "); output.Flush(); hello = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing object migration... "); output.Flush(); hello = Test.HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); obj.migrateHello(); hello.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.migrateHello(); hello.sayHello(); output.WriteLine("ok"); output.Write("testing locator encoding resolution... "); output.Flush(); hello = Test.HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); count = locator.getRequestCount(); communicator.stringToProxy("test@TestAdapter").ice_encodingVersion(Ice.Util.Encoding_1_1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter10").ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping(); test(++count == locator.getRequestCount()); communicator.stringToProxy("test -e 1.0@TestAdapter10-2").ice_ping(); test(++count == locator.getRequestCount()); output.WriteLine("ok"); output.Write("shutdown server... "); output.Flush(); obj.shutdown(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj2.ice_ping(); test(false); } catch (Ice.LocalException) { } try { obj3.ice_ping(); test(false); } catch (Ice.LocalException) { } try { obj5.ice_ping(); test(false); } catch (Ice.LocalException) { } output.WriteLine("ok"); output.Write("testing indirect proxies to collocated objects... "); output.Flush(); // // Set up test for calling a collocated object through an // indirect, adapterless reference. // Ice.Properties properties = communicator.getProperties(); properties.setProperty("Ice.PrintAdapterReady", "0"); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "tcp -h *"); adapter.setLocator(locator); Ice.Identity id = new Ice.Identity(); id.name = Guid.NewGuid().ToString(); registry.addObject(adapter.add(new HelloI(), id)); adapter.activate(); var helloPrx = Test.HelloPrxHelper.checkedCast( communicator.stringToProxy("\"" + communicator.identityToString(id) + "\"")); test(helloPrx.ice_getConnection() == null); adapter.deactivate(); output.WriteLine("ok"); output.Write("shutdown server manager... "); output.Flush(); manager.shutdown(); output.WriteLine("ok"); }
/// <summary> /// Cleanup resources associated with the connection. /// </summary> public void Dispose() { communicator.destroy(); }
public static void allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); string @ref = "communicator:" + helper.getTestEndpoint(0); Test.RemoteCommunicatorPrx com = Test.RemoteCommunicatorPrxHelper.uncheckedCast(communicator.stringToProxy(@ref)); var rand = new Random(unchecked ((int)DateTime.Now.Ticks)); var output = helper.getWriter(); output.Write("testing binding with single endpoint... "); output.Flush(); { Test.RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter", "default"); var test1 = adapter.getTestIntf(); var test2 = adapter.getTestIntf(); test(test1.ice_getConnection() == test2.ice_getConnection()); test1.ice_ping(); test2.ice_ping(); com.deactivateObjectAdapter(adapter); var test3 = Test.TestIntfPrxHelper.uncheckedCast(test1); test(test3.ice_getConnection() == test1.ice_getConnection()); test(test3.ice_getConnection() == test2.ice_getConnection()); try { test3.ice_ping(); test(false); } catch (Ice.ConnectFailedException) { } catch (Ice.ConnectTimeoutException) { } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter11", "default")); adapters.Add(com.createObjectAdapter("Adapter12", "default")); adapters.Add(com.createObjectAdapter("Adapter13", "default")); // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // List <string> names = new List <string>(); names.Add("Adapter11"); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test1.ice_ping(); test(test1.ice_getConnection() == test2.ice_getConnection()); test(test2.ice_getConnection() == test3.ice_getConnection()); names.Remove(test1.getAdapterName()); test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } // // Ensure that the proxy correctly caches the connection(we // always send the request over the same connection.) // { foreach (var adpt in adapters) { adpt.getTestIntf().ice_ping(); } var t = createTestIntfPrx(adapters); string name = t.getAdapterName(); int nRetry = 10; int i; for (i = 0; i < nRetry && t.getAdapterName().Equals(name); i++) { ; } test(i == nRetry); foreach (var adpt in adapters) { adpt.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com.deactivateObjectAdapter((Test.RemoteObjectAdapterPrx)adapters[0]); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test(test1.ice_getConnection() == test2.ice_getConnection()); test(test2.ice_getConnection() == test3.ice_getConnection()); names.Remove(test1.getAdapterName()); test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapter. // com.deactivateObjectAdapter((Test.RemoteObjectAdapterPrx)adapters[2]); var obj = createTestIntfPrx(adapters); test(obj.getAdapterName().Equals("Adapter12")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing binding with multiple random endpoints... "); output.Flush(); { var adapters = new Test.RemoteObjectAdapterPrx[5]; adapters[0] = com.createObjectAdapter("AdapterRandom11", "default"); adapters[1] = com.createObjectAdapter("AdapterRandom12", "default"); adapters[2] = com.createObjectAdapter("AdapterRandom13", "default"); adapters[3] = com.createObjectAdapter("AdapterRandom14", "default"); adapters[4] = com.createObjectAdapter("AdapterRandom15", "default"); int count = 20; int adapterCount = adapters.Length; while (--count > 0) { Test.TestIntfPrx[] proxies; if (count == 1) { com.deactivateObjectAdapter(adapters[4]); --adapterCount; } proxies = new Test.TestIntfPrx[10]; int i; for (i = 0; i < proxies.Length; ++i) { var adpts = new Test.RemoteObjectAdapterPrx[rand.Next(adapters.Length)]; if (adpts.Length == 0) { adpts = new Test.RemoteObjectAdapterPrx[1]; } for (int j = 0; j < adpts.Length; ++j) { adpts[j] = adapters[rand.Next(adapters.Length)]; } proxies[i] = createTestIntfPrx(new List <Test.RemoteObjectAdapterPrx>(adpts)); } for (i = 0; i < proxies.Length; i++) { proxies[i].begin_getAdapterName(); } for (i = 0; i < proxies.Length; i++) { try { proxies[i].ice_ping(); } catch (Ice.LocalException) { } } List <Ice.Connection> connections = new List <Ice.Connection>(); for (i = 0; i < proxies.Length; i++) { if (proxies[i].ice_getCachedConnection() != null) { if (!connections.Contains(proxies[i].ice_getCachedConnection())) { connections.Add(proxies[i].ice_getCachedConnection()); } } } test(connections.Count <= adapterCount); foreach (var a in adapters) { try { a.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } catch (Ice.LocalException) { // Expected if adapter is down. } } } } output.WriteLine("ok"); output.Write("testing binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI11", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI12", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI13", "default")); // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // List <string> names = new List <string>(); names.Add("AdapterAMI11"); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test1.ice_ping(); test(test1.ice_getConnection() == test2.ice_getConnection()); test(test2.ice_getConnection() == test3.ice_getConnection()); names.Remove(getAdapterNameWithAMI(test1)); test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } // // Ensure that the proxy correctly caches the connection(we // always send the request over the same connection.) // { foreach (var adpt in adapters) { adpt.getTestIntf().ice_ping(); } var t = createTestIntfPrx(adapters); string name = getAdapterNameWithAMI(t); int nRetry = 10; int i; for (i = 0; i < nRetry && getAdapterNameWithAMI(t).Equals(name); i++) { ; } test(i == nRetry); foreach (var adpt in adapters) { adpt.getTestIntf().ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com.deactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { var adpts = new List <Test.RemoteObjectAdapterPrx>(adapters); var test1 = createTestIntfPrx(adpts); shuffle(ref adpts); var test2 = createTestIntfPrx(adpts); shuffle(ref adpts); var test3 = createTestIntfPrx(adpts); test(test1.ice_getConnection() == test2.ice_getConnection()); test(test2.ice_getConnection() == test3.ice_getConnection()); names.Remove(getAdapterNameWithAMI(test1)); test1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapter. // com.deactivateObjectAdapter(adapters[2]); var obj = createTestIntfPrx(adapters); test(getAdapterNameWithAMI(obj).Equals("AdapterAMI12")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing random endpoint selection... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter21", "default")); adapters.Add(com.createObjectAdapter("Adapter22", "default")); adapters.Add(com.createObjectAdapter("Adapter23", "default")); var obj = createTestIntfPrx(adapters); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); var names = new List <string>(); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Random)); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing ordered endpoint selection... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter31", "default")); adapters.Add(com.createObjectAdapter("Adapter32", "default")); adapters.Add(com.createObjectAdapter("Adapter33", "default")); var obj = createTestIntfPrx(adapters); obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter31"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter32"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter33"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (Ice.ConnectFailedException) { } catch (Ice.ConnectTimeoutException) { } Ice.Endpoint[] endpoints = obj.ice_getEndpoints(); adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("Adapter36", endpoints[2].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter36"); i++) { ; } test(i == nRetry); obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); adapters.Add(com.createObjectAdapter("Adapter35", endpoints[1].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter35"); i++) { ; } test(i == nRetry); obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); adapters.Add(com.createObjectAdapter("Adapter34", endpoints[0].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter34"); i++) { ; } test(i == nRetry); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding with single endpoint... "); output.Flush(); { var adapter = com.createObjectAdapter("Adapter41", "default"); var test1 = Test.TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false)); var test2 = Test.TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false)); test(!test1.ice_isConnectionCached()); test(!test2.ice_isConnectionCached()); test(test1.ice_getConnection() != null && test2.ice_getConnection() != null); test(test1.ice_getConnection() == test2.ice_getConnection()); test1.ice_ping(); com.deactivateObjectAdapter(adapter); var test3 = Test.TestIntfPrxHelper.uncheckedCast(test1); try { test(test3.ice_getConnection() == test1.ice_getConnection()); test(false); } catch (Ice.ConnectFailedException) { } catch (Ice.ConnectTimeoutException) { } } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter51", "default")); adapters.Add(com.createObjectAdapter("Adapter52", "default")); adapters.Add(com.createObjectAdapter("Adapter53", "default")); var obj = Test.TestIntfPrxHelper.uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false)); test(!obj.ice_isConnectionCached()); List <string> names = new List <string>(); names.Add("Adapter51"); names.Add("Adapter52"); names.Add("Adapter53"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); } com.deactivateObjectAdapter(adapters[0]); names.Add("Adapter52"); names.Add("Adapter53"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); } com.deactivateObjectAdapter(adapters[2]); test(obj.getAdapterName().Equals("Adapter52")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding with multiple endpoints and AMI... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI51", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI52", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI53", "default")); var obj = Test.TestIntfPrxHelper.uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false)); test(!obj.ice_isConnectionCached()); var names = new List <string>(); names.Add("AdapterAMI51"); names.Add("AdapterAMI52"); names.Add("AdapterAMI53"); while (names.Count > 0) { names.Remove(getAdapterNameWithAMI(obj)); } com.deactivateObjectAdapter(adapters[0]); names.Add("AdapterAMI52"); names.Add("AdapterAMI53"); while (names.Count > 0) { names.Remove(getAdapterNameWithAMI(obj)); } com.deactivateObjectAdapter(adapters[2]); test(getAdapterNameWithAMI(obj).Equals("AdapterAMI52")); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter61", "default")); adapters.Add(com.createObjectAdapter("Adapter62", "default")); adapters.Add(com.createObjectAdapter("Adapter63", "default")); var obj = createTestIntfPrx(adapters); obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_connectionCached(false)); test(!obj.ice_isConnectionCached()); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter61"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter62"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter63"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (Ice.ConnectFailedException) { } catch (Ice.ConnectTimeoutException) { } Ice.Endpoint[] endpoints = obj.ice_getEndpoints(); adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("Adapter66", endpoints[2].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter66"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("Adapter65", endpoints[1].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter65"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("Adapter64", endpoints[0].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter64"); i++) { ; } test(i == nRetry); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing per request binding and ordered endpoint selection and AMI... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI61", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI62", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI63", "default")); var obj = createTestIntfPrx(adapters); obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); obj = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_connectionCached(false)); test(!obj.ice_isConnectionCached()); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI61"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[0]); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter(adapters[2]); try { obj.getAdapterName(); } catch (Ice.ConnectFailedException) { } catch (Ice.ConnectTimeoutException) { } Ice.Endpoint[] endpoints = obj.ice_getEndpoints(); adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("AdapterAMI66", endpoints[2].ToString())); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI66"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("AdapterAMI65", endpoints[1].ToString())); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI65"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("AdapterAMI64", endpoints[0].ToString())); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI64"); i++) { ; } test(i == nRetry); deactivate(com, adapters); } output.WriteLine("ok"); output.Write("testing endpoint mode filtering... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter71", "default")); adapters.Add(com.createObjectAdapter("Adapter72", "udp")); var obj = createTestIntfPrx(adapters); test(obj.getAdapterName().Equals("Adapter71")); var testUDP = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_datagram()); test(obj.ice_getConnection() != testUDP.ice_getConnection()); try { testUDP.getAdapterName(); } catch (Ice.TwowayOnlyException) { } } output.WriteLine("ok"); if (communicator.getProperties().getProperty("Ice.Plugin.IceSSL").Length > 0) { output.Write("testing unsecure vs. secure endpoints... "); output.Flush(); { var adapters = new List <Test.RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter81", "ssl")); adapters.Add(com.createObjectAdapter("Adapter82", "tcp")); var obj = createTestIntfPrx(adapters); int i; for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter82")); obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } var testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(true)); test(testSecure.ice_isSecure()); testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(false)); test(!testSecure.ice_isSecure()); testSecure = Test.TestIntfPrxHelper.uncheckedCast(obj.ice_secure(true)); test(testSecure.ice_isSecure()); test(obj.ice_getConnection() != testSecure.ice_getConnection()); com.deactivateObjectAdapter(adapters[1]); for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter81")); obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } com.createObjectAdapter("Adapter83", (obj.ice_getEndpoints()[1]).ToString()); // Reactive tcp OA. for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter83")); obj.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); } com.deactivateObjectAdapter(adapters[0]); try { testSecure.ice_ping(); test(false); } catch (Ice.ConnectFailedException) { } catch (Ice.ConnectTimeoutException) { } deactivate(com, adapters); } output.WriteLine("ok"); } { output.Write("testing ipv4 & ipv6 connections... "); output.Flush(); Ice.Properties ipv4 = Ice.Util.createProperties(); ipv4.setProperty("Ice.IPv4", "1"); ipv4.setProperty("Ice.IPv6", "0"); ipv4.setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice.Properties ipv6 = Ice.Util.createProperties(); ipv6.setProperty("Ice.IPv4", "0"); ipv6.setProperty("Ice.IPv6", "1"); ipv6.setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice.Properties bothPreferIPv4 = Ice.Util.createProperties(); bothPreferIPv4.setProperty("Ice.IPv4", "1"); bothPreferIPv4.setProperty("Ice.IPv6", "1"); bothPreferIPv4.setProperty("Ice.PreferIPv6Address", "0"); bothPreferIPv4.setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice.Properties bothPreferIPv6 = Ice.Util.createProperties(); bothPreferIPv6.setProperty("Ice.IPv4", "1"); bothPreferIPv6.setProperty("Ice.IPv6", "1"); bothPreferIPv6.setProperty("Ice.PreferIPv6Address", "1"); bothPreferIPv6.setProperty("Adapter.Endpoints", "tcp -h localhost"); List <Ice.Properties> clientProps = new List <Ice.Properties>(); clientProps.Add(ipv4); clientProps.Add(ipv6); clientProps.Add(bothPreferIPv4); clientProps.Add(bothPreferIPv6); string endpoint = "tcp -p " + helper.getTestPort(2).ToString(); Ice.Properties anyipv4 = ipv4.ice_clone_(); anyipv4.setProperty("Adapter.Endpoints", endpoint); anyipv4.setProperty("Adapter.PublishedEndpoints", endpoint + " -h 127.0.0.1"); Ice.Properties anyipv6 = ipv6.ice_clone_(); anyipv6.setProperty("Adapter.Endpoints", endpoint); anyipv6.setProperty("Adapter.PublishedEndpoints", endpoint + " -h \".1\""); Ice.Properties anyboth = Ice.Util.createProperties(); anyboth.setProperty("Ice.IPv4", "1"); anyboth.setProperty("Ice.IPv6", "1"); anyboth.setProperty("Adapter.Endpoints", endpoint); anyboth.setProperty("Adapter.PublishedEndpoints", endpoint + " -h \"::1\":" + endpoint + " -h 127.0.0.1"); Ice.Properties localipv4 = ipv4.ice_clone_(); localipv4.setProperty("Adapter.Endpoints", "tcp -h 127.0.0.1"); Ice.Properties localipv6 = ipv6.ice_clone_(); localipv6.setProperty("Adapter.Endpoints", "tcp -h \"::1\""); List <Ice.Properties> serverProps = new List <Ice.Properties>(clientProps); serverProps.Add(anyipv4); serverProps.Add(anyipv6); serverProps.Add(anyboth); serverProps.Add(localipv4); serverProps.Add(localipv6); bool ipv6NotSupported = false; foreach (Ice.Properties p in serverProps) { Ice.InitializationData serverInitData = new Ice.InitializationData(); serverInitData.properties = p; Ice.Communicator serverCommunicator = Ice.Util.initialize(serverInitData); Ice.ObjectAdapter oa; try { oa = serverCommunicator.createObjectAdapter("Adapter"); oa.activate(); } catch (Ice.DNSException) { serverCommunicator.destroy(); continue; // IP version not supported. } catch (Ice.SocketException) { if (p == ipv6) { ipv6NotSupported = true; } serverCommunicator.destroy(); continue; // IP version not supported. } Ice.ObjectPrx prx = oa.createProxy(Ice.Util.stringToIdentity("dummy")); try { prx.ice_collocationOptimized(false).ice_ping(); } catch (Ice.LocalException) { serverCommunicator.destroy(); continue; // IP version not supported. } string strPrx = prx.ToString(); foreach (Ice.Properties q in clientProps) { Ice.InitializationData clientInitData = new Ice.InitializationData(); clientInitData.properties = q; Ice.Communicator clientCommunicator = Ice.Util.initialize(clientInitData); prx = clientCommunicator.stringToProxy(strPrx); try { prx.ice_ping(); test(false); } catch (Ice.ObjectNotExistException) { // Expected, no object registered. } catch (Ice.DNSException) { // Expected if no IPv4 or IPv6 address is // associated to localhost or if trying to connect // to an any endpoint with the wrong IP version, // e.g.: resolving an IPv4 address when only IPv6 // is enabled fails with a DNS exception. } catch (Ice.SocketException) { test((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) || (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) || (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) || (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) || (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) || (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) || (p == bothPreferIPv6 && q == ipv6)); } clientCommunicator.destroy(); } serverCommunicator.destroy(); } output.WriteLine("ok"); } com.shutdown(); }
internal static void batchOneways(global::Test.TestHelper helper, Test.MyClassPrx p) { byte[] bs1 = new byte[10 * 1024]; Test.MyClassPrx batch = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway()); batch.ice_flushBatchRequests(); // Empty flush p.opByteSOnewayCallCount(); // Reset the call count for (int i = 0; i < 30; ++i) { try { batch.opByteSOneway(bs1); test(true); } catch (Ice.MemoryLimitException) { test(false); } } int count = 0; while (count < 27) // 3 * 9 requests auto-flushed. { count += p.opByteSOnewayCallCount(); System.Threading.Thread.Sleep(10); } if (batch.ice_getConnection() != null) { Test.MyClassPrx batch1 = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway()); Test.MyClassPrx batch2 = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway()); batch1.ice_ping(); batch2.ice_ping(); batch1.ice_flushBatchRequests(); batch1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); batch1.ice_ping(); batch2.ice_ping(); batch1.ice_getConnection(); batch2.ice_getConnection(); batch1.ice_ping(); batch1.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait); batch1.ice_ping(); batch2.ice_ping(); } Ice.Identity identity = new Ice.Identity(); identity.name = "invalid"; Ice.ObjectPrx batch3 = batch.ice_identity(identity); batch3.ice_ping(); batch3.ice_flushBatchRequests(); // Make sure that a bogus batch request doesn't cause troubles to other ones. batch3.ice_ping(); batch.ice_ping(); batch.ice_flushBatchRequests(); batch.ice_ping(); if (batch.ice_getConnection() != null) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = p.ice_getCommunicator().getProperties().ice_clone_(); BatchRequestInterceptorI interceptor = new BatchRequestInterceptorI(); initData.batchRequestInterceptor = interceptor.enqueue; Ice.Communicator ic = helper.initialize(initData); batch = Test.MyClassPrxHelper.uncheckedCast(ic.stringToProxy(p.ToString()).ice_batchOneway()); test(interceptor.count() == 0); batch.ice_ping(); batch.ice_ping(); batch.ice_ping(); test(interceptor.count() == 0); interceptor.setEnqueue(true); batch.ice_ping(); batch.ice_ping(); batch.ice_ping(); test(interceptor.count() == 3); batch.ice_flushBatchRequests(); batch.ice_ping(); test(interceptor.count() == 1); batch.opByteSOneway(bs1); test(interceptor.count() == 2); batch.opByteSOneway(bs1); test(interceptor.count() == 3); batch.opByteSOneway(bs1); // This should trigger the flush batch.ice_ping(); test(interceptor.count() == 2); ic.destroy(); } p.ice_ping(); bool supportsCompress = true; try { supportsCompress = p.supportsCompress(); } catch (Ice.OperationNotExistException) { } if (supportsCompress && p.ice_getConnection() != null && p.ice_getCommunicator().getProperties().getProperty("Ice.Override.Compress").Equals("")) { Ice.ObjectPrx prx = p.ice_getConnection().createProxy(p.ice_getIdentity()).ice_batchOneway(); Test.MyClassPrx batchC1 = Test.MyClassPrxHelper.uncheckedCast(prx.ice_compress(false)); Test.MyClassPrx batchC2 = Test.MyClassPrxHelper.uncheckedCast(prx.ice_compress(true)); Test.MyClassPrx batchC3 = Test.MyClassPrxHelper.uncheckedCast(prx.ice_identity(identity)); batchC1.opByteSOneway(bs1); batchC1.opByteSOneway(bs1); batchC1.opByteSOneway(bs1); batchC1.ice_getConnection().flushBatchRequests(Ice.CompressBatch.Yes); batchC2.opByteSOneway(bs1); batchC2.opByteSOneway(bs1); batchC2.opByteSOneway(bs1); batchC1.ice_getConnection().flushBatchRequests(Ice.CompressBatch.No); batchC1.opByteSOneway(bs1); batchC1.opByteSOneway(bs1); batchC1.opByteSOneway(bs1); batchC1.ice_getConnection().flushBatchRequests(Ice.CompressBatch.BasedOnProxy); batchC1.opByteSOneway(bs1); batchC2.opByteSOneway(bs1); batchC1.opByteSOneway(bs1); batchC1.ice_getConnection().flushBatchRequests(Ice.CompressBatch.BasedOnProxy); batchC1.opByteSOneway(bs1); batchC3.opByteSOneway(bs1); batchC1.opByteSOneway(bs1); batchC1.ice_getConnection().flushBatchRequests(Ice.CompressBatch.BasedOnProxy); } }
public static Test.TestIntfPrx 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.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); test(false); } catch (Ice.AlreadyRegisteredException) { } 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.end_transient(obj.begin_transient()); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); Ice.Communicator comm = Ice.Util.initialize(initData); comm.stringToProxy("test:" + helper.getTestEndpoint(0)).begin_ice_ping(); comm.destroy(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("PAdapter"); test(adapter.getPublishedEndpoints().Length == 1); Ice.Endpoint endpt = adapter.getPublishedEndpoints()[0]; test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000")); Ice.ObjectPrx prx = communicator.stringToProxy("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000"); adapter.setPublishedEndpoints(prx.ice_getEndpoints()); test(adapter.getPublishedEndpoints().Length == 2); Ice.Identity id = new Ice.Identity(); id.name = "dummy"; test(IceUtilInternal.Arrays.Equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints())); test(IceUtilInternal.Arrays.Equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints())); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].Equals(endpt)); communicator.getProperties().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.ice_getConnection() != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); Ice.ObjectAdapter adapter = communicator.createObjectAdapter(""); obj.ice_getConnection().setAdapter(adapter); obj.ice_getConnection().setAdapter(null); adapter.deactivate(); try { obj.ice_getConnection().setAdapter(adapter); test(false); } catch (Ice.ObjectAdapterDeactivatedException) { } output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); { Ice.Identity routerId = new Ice.Identity(); routerId.name = "router"; Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId).ice_connectionId("rc")); Ice.ObjectAdapter 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.ice_getEndpoints()); test(false); } catch (ArgumentException) { // Expected. } adapter.destroy(); try { routerId.name = "test"; router = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId)); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (Ice.OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + helper.getTestEndpoint(1))); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (Ice.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 (Ice.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.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows test(false); } catch (Ice.LocalException) { output.WriteLine("ok"); } return(obj); }