/// <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; } }
public void Initialize(Scene scene) { try { if (!m_enabled) { return; } if (!m_started) { m_started = true; scene.AddCommand(this, "mumble report", "mumble report", "Returns mumble report", MumbleReport); scene.AddCommand(this, "mumble unregister", "mumble unregister <userid>", "Unregister User by userid", UnregisterUser); scene.AddCommand(this, "mumble remove", "mumble remove <UUID>", "Remove Agent by UUID", RemoveAgent); Ice.Communicator comm = Ice.Util.initialize(); if (m_glacier_enabled) { m_router = RouterPrxHelper.uncheckedCast(comm.stringToProxy(m_glacier_ice)); comm.setDefaultRouter(m_router); m_router.createSession(m_glacier_user, m_glacier_pass); } MetaPrx meta = MetaPrxHelper.checkedCast(comm.stringToProxy(m_murmurd_ice)); // Create the adapter comm.getProperties().setProperty("Ice.PrintAdapterReady", "0"); if (m_glacier_enabled) { m_adapter = comm.createObjectAdapterWithRouter("Callback.Client", comm.getDefaultRouter()); } else { m_adapter = comm.createObjectAdapterWithEndpoints("Callback.Client", m_murmur_ice_cb); } m_adapter.activate(); // Create identity and callback for Metaserver Ice.Identity metaCallbackIdent = new Ice.Identity(); metaCallbackIdent.name = "metaCallback"; if (m_router != null) { metaCallbackIdent.category = m_router.getCategoryForClient(); } MetaCallbackPrx meta_callback = MetaCallbackPrxHelper.checkedCast(m_adapter.add(new MetaCallbackImpl(), metaCallbackIdent)); meta.addCallback(meta_callback); m_log.InfoFormat("[MurmurVoice] using murmur server ice '{0}'", m_murmurd_ice); // create a server and figure out the port name Dictionary <string, string> defaults = meta.getDefaultConf(); m_server = ServerPrxHelper.checkedCast(meta.getServer(m_server_id)); // start thread to ping glacier2 router and/or determine if con$ m_keepalive = new KeepAlive(m_server); ThreadStart ka_d = new ThreadStart(m_keepalive.StartPinging); m_keepalive_t = new Thread(ka_d); m_keepalive_t.Start(); // first check the conf for a port, if not then use server id and default port to find the right one. string conf_port = m_server.getConf("port"); if (!String.IsNullOrEmpty(conf_port)) { m_murmurd_port = Convert.ToInt32(conf_port); } else { m_murmurd_port = Convert.ToInt32(defaults["port"]) + m_server_id - 1; } try { m_server.start(); } catch { } m_log.Info("[MurmurVoice] started"); } // starts the server and gets a callback ServerManager manager = new ServerManager(m_server, m_channel_name); // Create identity and callback for this current server AddServerCallback(scene, new ServerCallbackImpl(manager)); AddServerManager(scene, manager); Ice.Identity serverCallbackIdent = new Ice.Identity(); serverCallbackIdent.name = "serverCallback_" + scene.RegionInfo.RegionName.Replace(" ", "_"); if (m_router != null) { serverCallbackIdent.category = m_router.getCategoryForClient(); } m_server.addCallback(ServerCallbackPrxHelper.checkedCast(m_adapter.add(GetServerCallback(scene), serverCallbackIdent))); // Show information on console for debugging purposes m_log.InfoFormat("[MurmurVoice] using murmur server '{0}:{1}', sid '{2}'", m_murmurd_host, m_murmurd_port, m_server_id); m_log.Info("[MurmurVoice] plugin enabled"); m_enabled = true; } catch (Exception e) { m_log.ErrorFormat("[MurmurVoice] plugin initialization failed: {0}", e.ToString()); return; } }
allTests(global::Test.TestHelper helper) { var output = helper.getWriter(); Ice.Communicator communicator = helper.communicator(); Ice.ObjectAdapter oa = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); oa.activate(); Ice.Object servant = new MyObjectI(); // // Register default servant with category "foo" // oa.addDefaultServant(servant, "foo"); // // Start test // output.Write("testing single category... "); output.Flush(); Ice.Object r = oa.findDefaultServant("foo"); test(r == servant); r = oa.findDefaultServant("bar"); test(r == null); Ice.Identity identity = new Ice.Identity(); identity.category = "foo"; string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" }; Test.MyObjectPrx prx = null; for (int idx = 0; idx < 5; ++idx) { identity.name = names[idx]; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); prx.ice_ping(); test(prx.getName() == names[idx]); } identity.name = "ObjectNotExist"; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); try { prx.ice_ping(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } identity.name = "FacetNotExist"; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); try { prx.ice_ping(); test(false); } catch (Ice.FacetNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.FacetNotExistException) { // Expected } identity.category = "bar"; for (int idx = 0; idx < 5; idx++) { identity.name = names[idx]; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); try { prx.ice_ping(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } try { prx.getName(); test(false); } catch (Ice.ObjectNotExistException) { // Expected } } oa.removeDefaultServant("foo"); identity.category = "foo"; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); try { prx.ice_ping(); } catch (Ice.ObjectNotExistException) { // Expected } output.WriteLine("ok"); output.Write("testing default category... "); output.Flush(); oa.addDefaultServant(servant, ""); r = oa.findDefaultServant("bar"); test(r == null); r = oa.findDefaultServant(""); test(r == servant); for (int idx = 0; idx < 5; ++idx) { identity.name = names[idx]; prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity)); prx.ice_ping(); test(prx.getName() == names[idx]); } output.WriteLine("ok"); }
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(); }
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:" + helper.getTestEndpoint(99))); 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:" + helper.getTestEndpoint(99))); 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:" + helper.getTestEndpoint(99))); 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:" + helper.getTestEndpoint(99))); 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"); }
public static Test.ThrowerPrx allTests(global::Test.TestHelper helper) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); { output.Write("testing object adapter registration exceptions... "); Ice.ObjectAdapter first; try { first = communicator.createObjectAdapter("TestAdapter0"); } catch (Ice.InitializationException) { // Expected } communicator.getProperties().setProperty("TestAdapter0.Endpoints", "tcp -h *"); first = communicator.createObjectAdapter("TestAdapter0"); try { communicator.createObjectAdapter("TestAdapter0"); test(false); } catch (Ice.AlreadyRegisteredException) { // Expected. } try { Ice.ObjectAdapter second = communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011"); test(false); // // Quell mono error that variable second isn't used. // second.deactivate(); } catch (Ice.AlreadyRegisteredException) { // Expected } first.deactivate(); output.WriteLine("ok"); } { output.Write("testing servant registration exceptions... "); communicator.getProperties().setProperty("TestAdapter1.Endpoints", "tcp -h *"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1"); Ice.Object obj = new EmptyI(); adapter.add(obj, Ice.Util.stringToIdentity("x")); try { adapter.add(obj, Ice.Util.stringToIdentity("x")); test(false); } catch (Ice.AlreadyRegisteredException) { } try { adapter.add(obj, Ice.Util.stringToIdentity("")); test(false); } catch (Ice.IllegalIdentityException e) { test(e.id.name.Equals("")); } try { adapter.add(null, Ice.Util.stringToIdentity("x")); test(false); } catch (Ice.IllegalServantException) { } adapter.remove(Ice.Util.stringToIdentity("x")); try { adapter.remove(Ice.Util.stringToIdentity("x")); test(false); } catch (Ice.NotRegisteredException) { } adapter.deactivate(); output.WriteLine("ok"); } { output.Write("testing servant locator registration exceptions... "); communicator.getProperties().setProperty("TestAdapter2.Endpoints", "tcp -h *"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter2"); Ice.ServantLocator loc = new ServantLocatorI(); adapter.addServantLocator(loc, "x"); try { adapter.addServantLocator(loc, "x"); test(false); } catch (Ice.AlreadyRegisteredException) { } adapter.deactivate(); output.WriteLine("ok"); } { output.Write("testing object factory registration exception... "); communicator.getValueFactoryManager().add(_ => { return(null); }, "::x"); try { communicator.getValueFactoryManager().add(_ => { return(null); }, "::x"); test(false); } catch (Ice.AlreadyRegisteredException) { } output.WriteLine("ok"); } output.Write("testing stringToProxy... "); output.Flush(); String @ref = "thrower:" + helper.getTestEndpoint(0); Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var thrower = Test.ThrowerPrxHelper.checkedCast(@base); test(thrower != null); test(thrower.Equals(@base)); output.WriteLine("ok"); output.Write("catching exact types... "); output.Flush(); try { thrower.throwAasA(1); test(false); } catch (Test.A ex) { test(ex.aMem == 1); } catch (Exception ex) { Console.WriteLine(ex); test(false); } try { thrower.throwAorDasAorD(1); test(false); } catch (Test.A ex) { test(ex.aMem == 1); } catch (Exception) { test(false); } try { thrower.throwAorDasAorD(-1); test(false); } catch (Test.D ex) { test(ex.dMem == -1); } catch (Exception) { test(false); } try { thrower.throwBasB(1, 2); test(false); } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } try { thrower.throwCasC(1, 2, 3); test(false); } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching base types... "); output.Flush(); try { thrower.throwBasB(1, 2); test(false); } catch (Test.A ex) { test(ex.aMem == 1); } catch (Exception) { test(false); } try { thrower.throwCasC(1, 2, 3); test(false); } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching derived types... "); output.Flush(); try { thrower.throwBasA(1, 2); test(false); } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } try { thrower.throwCasA(1, 2, 3); test(false); } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } try { thrower.throwCasB(1, 2, 3); test(false); } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } output.WriteLine("ok"); if (thrower.supportsUndeclaredExceptions()) { output.Write("catching unknown user exception... "); output.Flush(); try { thrower.throwUndeclaredA(1); test(false); } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } try { thrower.throwUndeclaredB(1, 2); test(false); } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } try { thrower.throwUndeclaredC(1, 2, 3); test(false); } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } output.WriteLine("ok"); } if (thrower.ice_getConnection() != null) { output.Write("testing memory limit marshal exception..."); output.Flush(); try { thrower.throwMemoryLimitException(null); test(false); } catch (Ice.MemoryLimitException) { } catch (Exception) { test(false); } try { thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB test(false); } catch (Ice.ConnectionLostException) { } catch (Ice.UnknownLocalException) { // Expected with JS bidir server } catch (Exception) { test(false); } try { var thrower2 = Test.ThrowerPrxHelper.uncheckedCast( communicator.stringToProxy("thrower:" + helper.getTestEndpoint(1))); try { thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits) } catch (Ice.MemoryLimitException) { } var thrower3 = Test.ThrowerPrxHelper.uncheckedCast( communicator.stringToProxy("thrower:" + helper.getTestEndpoint(2))); try { thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit test(false); } catch (Ice.ConnectionLostException) { } } catch (Ice.ConnectionRefusedException) { // Expected with JS bidir server } output.WriteLine("ok"); } output.Write("catching object not exist exception... "); output.Flush(); { Ice.Identity id = Ice.Util.stringToIdentity("does not exist"); try { var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id)); thrower2.ice_ping(); test(false); } catch (Ice.ObjectNotExistException ex) { test(ex.id.Equals(id)); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("catching facet not exist exception... "); output.Flush(); try { var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet"); try { thrower2.ice_ping(); test(false); } catch (Ice.FacetNotExistException ex) { test(ex.facet.Equals("no such facet")); } } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching operation not exist exception... "); output.Flush(); try { var thrower2 = Test.WrongOperationPrxHelper.uncheckedCast(thrower); thrower2.noSuchOperation(); test(false); } catch (Ice.OperationNotExistException ex) { test(ex.operation.Equals("noSuchOperation")); } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching unknown local exception... "); output.Flush(); try { thrower.throwLocalException(); test(false); } catch (Ice.UnknownLocalException) { } catch (Exception) { test(false); } try { thrower.throwLocalExceptionIdempotent(); test(false); } catch (Ice.UnknownLocalException) { } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching unknown non-Ice exception... "); output.Flush(); try { thrower.throwNonIceException(); test(false); } catch (Ice.UnknownException) { } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("testing asynchronous exceptions... "); output.Flush(); try { thrower.throwAfterResponse(); } catch (Exception) { test(false); } try { thrower.throwAfterException(); test(false); } catch (Test.A) { } catch (Exception) { test(false); } output.WriteLine("ok"); output.Write("catching exact types with AMI mapping... "); output.Flush(); { Callback cb = new Callback(); thrower.begin_throwAasA(1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { test(exc is Test.A); var ex = exc as Test.A; test(ex.aMem == 1); cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwAorDasAorD(1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Test.A ex) { test(ex.aMem == 1); } catch (Test.D ex) { test(ex.dMem == -1); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwAorDasAorD(-1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Test.A ex) { test(ex.aMem == 1); } catch (Test.D ex) { test(ex.dMem == -1); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwBasB(1, 2).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwCasC(1, 2, 3).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching derived types with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); thrower.begin_throwBasA(1, 2).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Test.B ex) { test(ex.aMem == 1); test(ex.bMem == 2); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwCasA(1, 2, 3).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwCasB(1, 2, 3).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Test.C ex) { test(ex.aMem == 1); test(ex.bMem == 2); test(ex.cMem == 3); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); if (thrower.supportsUndeclaredExceptions()) { output.Write("catching unknown user exception with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); thrower.begin_throwUndeclaredA(1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwUndeclaredB(1, 2).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); } output.Write("catching object not exist exception with new AMI mapping... "); output.Flush(); { Ice.Identity id = Ice.Util.stringToIdentity("does not exist"); var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id)); Callback cb = new Callback(); thrower2.begin_throwAasA(1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.ObjectNotExistException ex) { test(ex.id.Equals(id)); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching facet not exist exception with new AMI mapping... "); output.Flush(); { var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet"); Callback cb = new Callback(); thrower2.begin_throwAasA(1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.FacetNotExistException ex) { test(ex.facet.Equals("no such facet")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching operation not exist exception with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); var thrower4 = Test.WrongOperationPrxHelper.uncheckedCast(thrower); thrower4.begin_noSuchOperation().whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.OperationNotExistException ex) { test(ex.operation.Equals("noSuchOperation")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching unknown local exception with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); thrower.begin_throwLocalException().whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownLocalException) { } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwLocalExceptionIdempotent().whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownLocalException) { } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching unknown non-Ice exception with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); thrower.begin_throwNonIceException().whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); if (thrower.supportsUndeclaredExceptions()) { output.Write("catching unknown user exception with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); thrower.begin_throwUndeclaredA(1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwUndeclaredB(1, 2).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownUserException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); } output.Write("catching object not exist exception with new AMI mapping... "); output.Flush(); { Ice.Identity id = Ice.Util.stringToIdentity("does not exist"); var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id)); Callback cb = new Callback(); thrower2.begin_throwAasA(1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.ObjectNotExistException ex) { test(ex.id.Equals(id)); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching facet not exist exception with new AMI mapping... "); output.Flush(); { var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet"); Callback cb = new Callback(); thrower2.begin_throwAasA(1).whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.FacetNotExistException ex) { test(ex.facet.Equals("no such facet")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching operation not exist exception with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); var thrower4 = Test.WrongOperationPrxHelper.uncheckedCast(thrower); thrower4.begin_noSuchOperation().whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.OperationNotExistException ex) { test(ex.operation.Equals("noSuchOperation")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching unknown local exception with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); thrower.begin_throwLocalException().whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownLocalException) { } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } { Callback cb = new Callback(); thrower.begin_throwLocalExceptionIdempotent().whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownLocalException) { } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); output.Write("catching unknown non-Ice exception with new AMI mapping... "); output.Flush(); { Callback cb = new Callback(); thrower.begin_throwNonIceException().whenCompleted( () => { test(false); }, (Ice.Exception exc) => { try { throw exc; } catch (Ice.UnknownException) { } catch (Exception) { test(false); } cb.called(); }); cb.check(); } output.WriteLine("ok"); return(thrower); }
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); }
/// <summary> /// 初始化连接 /// </summary> /// <returns></returns> public bool Init() { try { lock (lockData) { Ice.InitializationData intiData = new Ice.InitializationData(); Ice.Properties properties = Ice.Util.createProperties(); properties.setProperty("Ice.MessageSizeMax", "104857600"); intiData.properties = properties; ic = Ice.Util.initialize(intiData); // 连接 Ice.ObjectPrx objectPrx = ic.stringToProxy(string.Format("{0}:tcp -h {1} -p {2} -t 5000", NMCommunicationRPCId.value, EEMSConfigHelper.GetValueByCommomConfig("config/CommonConfig/netagent_ip", "127.0.0.1"), EEMSConfigHelper.GetValueByCommomConfig("config/CommonConfig/netagent_port", "40050"))); client = NMServerPrxHelper.checkedCast(objectPrx); // 代理 Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints(NMCommunicationRPCId.value, string.Format("tcp -h {0} -p {1} -t 5000", EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/WarnInfoLocalIp", "127.0.0.1"), EEMSConfigHelper.GetValueByCommomConfig("config/CollectClient/WarnInfoClentPort", "42050"))); NMClientI clientI = new NMClientI(); clientI.ReceiveDataHandler += clientI_ReceiveDataHandler; Ice.Object obj = clientI; adapter.add(obj, ic.stringToIdentity(NMCommunicationRPCId.value)); adapter.activate(); NMClientPrx call = NMClientPrxHelper.uncheckedCast(adapter.createProxy(ic.stringToIdentity(NMCommunicationRPCId.value))); client.NMRegistClient(clientID, call); IsConnect = true; } return(true); } catch (Exception e) { // 初始化失败 client = null; LogHelper.Instance.WirteErrorMsg(e.Message); return(false); } finally { if (!isThreadStart) { isThreadStart = true; CheckConnectThread(); } } }
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.IObjectPrx @base = IObjectPrx.Parse(@ref, communicator); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); var obj = Test.TestIntfPrx.CheckedCast(@base); test(obj != null); test(obj.Equals(@base)); output.WriteLine("ok"); { output.Write("creating/destroying/recreating object adapter... "); output.Flush(); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); test(false); } catch (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.transientAsync().Wait(); output.WriteLine("ok"); { output.Write("testing connection closure... "); output.Flush(); for (int i = 0; i < 10; ++i) { var initData = new InitializationData(); initData.properties = communicator.Properties.Clone(); var comm = Util.initialize(initData); IObjectPrx.Parse($"test:{helper.getTestEndpoint(0)}", communicator).IcePingAsync(); comm.destroy(); } output.WriteLine("ok"); } output.Write("testing object adapter published endpoints... "); output.Flush(); { communicator.Properties.setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000"); var adapter = communicator.createObjectAdapter("PAdapter"); test(adapter.GetPublishedEndpoints().Length == 1); var endpt = adapter.GetPublishedEndpoints()[0]; test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000")); var prx = IObjectPrx.Parse("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000", communicator); adapter.SetPublishedEndpoints(prx.Endpoints); test(adapter.GetPublishedEndpoints().Length == 2); test(Collections.Equals(adapter.CreateProxy(new Identity("dummy", "")).Endpoints, prx.Endpoints)); test(Collections.Equals(adapter.GetPublishedEndpoints(), prx.Endpoints)); adapter.RefreshPublishedEndpoints(); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].Equals(endpt)); communicator.Properties.setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000"); adapter.RefreshPublishedEndpoints(); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000")); adapter.Destroy(); test(adapter.GetPublishedEndpoints().Length == 0); } output.WriteLine("ok"); if (obj.GetConnection() != null) { output.Write("testing object adapter with bi-dir connection... "); output.Flush(); var adapter = communicator.createObjectAdapter(""); obj.GetConnection().setAdapter(adapter); obj.GetConnection().setAdapter(null); adapter.Deactivate(); try { obj.GetConnection().setAdapter(adapter); test(false); } catch (ObjectAdapterDeactivatedException) { } output.WriteLine("ok"); } output.Write("testing object adapter with router... "); output.Flush(); { var routerId = new Identity(); routerId.name = "router"; var router = RouterPrx.UncheckedCast(@base.Clone(routerId, connectionId: "rc")); var adapter = communicator.createObjectAdapterWithRouter("", router); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000")); adapter.RefreshPublishedEndpoints(); test(adapter.GetPublishedEndpoints().Length == 1); test(adapter.GetPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000")); try { adapter.SetPublishedEndpoints(router.Endpoints); test(false); } catch (ArgumentException) { // Expected. } adapter.Destroy(); try { routerId.name = "test"; router = RouterPrx.UncheckedCast(@base.Clone(routerId)); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = RouterPrx.Parse($"test:{helper.getTestEndpoint(1)}", communicator); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (ConnectFailedException) { } } output.WriteLine("ok"); output.Write("testing object adapter creation with port in use... "); output.Flush(); { var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", helper.getTestEndpoint(10)); try { communicator.createObjectAdapterWithEndpoints("Adpt2", helper.getTestEndpoint(10)); test(false); } catch (LocalException) { // Expected can't re-use the same endpoint. } adapter1.Destroy(); } output.WriteLine("ok"); output.Write("deactivating object adapter in the server... "); output.Flush(); obj.deactivate(); output.WriteLine("ok"); output.Write("testing whether server is gone... "); output.Flush(); try { obj.Clone(connectionTimeout: 100).IcePing(); // Use timeout to speed up testing on Windows test(false); } catch (LocalException) { output.WriteLine("ok"); } return(obj); }