attachRemoteLogger(RemoteLoggerPrx prx, LogMessageType[] messageTypes, string[] categories, int messageMax, Current current) { if (prx == null) { return; // can't send this null RemoteLogger anything! } var remoteLogger = prx.Clone(oneway: false); Filters filters = new Filters(messageTypes, categories); LinkedList <LogMessage> initLogMessages = null; lock (this) { if (_sendLogCommunicator == null) { if (_destroyed) { throw new ObjectNotExistException(); } _sendLogCommunicator = createSendLogCommunicator(current.Adapter.Communicator, _logger.getLocalLogger()); } Ice.Identity remoteLoggerId = remoteLogger.Identity; if (_remoteLoggerMap.ContainsKey(remoteLoggerId)) { if (_traceLevel > 0) { _logger.trace(_traceCategory, "rejecting `" + remoteLogger.ToString() + "' with RemoteLoggerAlreadyAttachedException"); } throw new Ice.RemoteLoggerAlreadyAttachedException(); } _remoteLoggerMap.Add(remoteLoggerId, new RemoteLoggerData(changeCommunicator(remoteLogger, _sendLogCommunicator), filters)); if (messageMax != 0) { initLogMessages = new LinkedList <Ice.LogMessage>(_queue); // copy } else { initLogMessages = new LinkedList <Ice.LogMessage>(); } } if (_traceLevel > 0) { _logger.trace(_traceCategory, "attached `" + remoteLogger.ToString() + "'"); } if (initLogMessages.Count > 0) { filterLogMessages(initLogMessages, filters.messageTypes, filters.traceCategories, messageMax); } try { remoteLogger.initAsync(_logger.getPrefix(), initLogMessages.ToArray()).ContinueWith( (t) => { try { t.Wait(); if (_traceLevel > 1) { _logger.trace(_traceCategory, "init on `" + remoteLogger.ToString() + "' completed successfully"); } } catch (System.AggregateException ae) { Debug.Assert(ae.InnerException is Ice.LocalException); deadRemoteLogger(remoteLogger, _logger, (Ice.LocalException)ae.InnerException, "init"); } }, System.Threading.Tasks.TaskScheduler.Current); } catch (Ice.LocalException ex) { deadRemoteLogger(remoteLogger, _logger, ex, "init"); throw; } }
public static void allTests(global::Test.TestHelper helper) { Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing communicator operations... "); output.Flush(); { // // Test: Exercise AddAdminFacet, FindAdminFacet, RemoveAdminFacet with a typical configuration. // InitializationData init = new InitializationData(); init.properties = Util.createProperties(); init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1"); init.properties.setProperty("Ice.Admin.InstanceName", "Test"); Communicator com = Util.initialize(init); testFacets(com, true, false); 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, true); com.destroy(); } { // // Test: Verify that the operations work correctly with the Admin object disabled. // Ice.Communicator com = Ice.Util.initialize(); testFacets(com, false, 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 = Identity.Parse("test-admin"); try { com.CreateAdmin(null, id); test(false); } catch (Ice.InitializationException) { } ObjectAdapter adapter = com.createObjectAdapter(""); test(com.CreateAdmin(adapter, id) != null); test(com.getAdmin() != null); testFacets(com, true, false); 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, false); com.getAdmin(); testFacets(com, true, false); com.destroy(); } output.WriteLine("ok"); var factory = RemoteCommunicatorFactoryPrx.Parse($"factory:{helper.getTestEndpoint(0)} -t 10000", communicator); 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); IObjectPrx obj = com.getAdmin(); ProcessPrx proc = ProcessPrx.UncheckedCast(obj.Clone(facet: "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); IObjectPrx obj = com.getAdmin(); PropertiesAdminPrx pa = PropertiesAdminPrx.UncheckedCast(obj.Clone(facet: "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"); IObjectPrx obj = com.getAdmin(); LoggerAdminPrx logger = LoggerAdminPrx.UncheckedCast(obj.Clone(facet: "Logger")); test(logger != null); string prefix = null; // // Get all // 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"); LogMessageType[] messageTypes = { LogMessageType.ErrorMessage, 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 == LogMessageType.ErrorMessage || msg.type == LogMessageType.WarningMessage); } // // Get only errors and traces with Cat = "testCat" // com.trace("testCat2", "A"); com.trace("testCat", "trace3"); com.trace("testCat2", "B"); messageTypes = new LogMessageType[] { LogMessageType.ErrorMessage, 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 == LogMessageType.ErrorMessage || (msg.type == 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 // ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("RemoteLoggerAdapter", "tcp -h localhost"); RemoteLoggerI remoteLogger = new RemoteLoggerI(); RemoteLoggerPrx myProxy = adapter.Add(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(myProxy.Clone(oneway: true), 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); IObjectPrx obj = com.getAdmin(); var tf = TestFacetPrx.UncheckedCast(obj.Clone(facet: "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); IObjectPrx obj = com.getAdmin(); try { ProcessPrx.CheckedCast(obj.Clone(facet: "Process")); test(false); } catch (FacetNotExistException) { } try { TestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet")); test(false); } catch (FacetNotExistException) { } 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); IObjectPrx obj = com.getAdmin(); try { PropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties")); test(false); } catch (FacetNotExistException) { } try { TestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet")); test(false); } catch (FacetNotExistException) { } 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); IObjectPrx obj = com.getAdmin(); try { PropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties")); test(false); } catch (FacetNotExistException) { } try { ProcessPrx.CheckedCast(obj.Clone(facet: "Process")); test(false); } catch (FacetNotExistException) { } 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); IObjectPrx obj = com.getAdmin(); PropertiesAdminPrx pa = PropertiesAdminPrx.UncheckedCast(obj.Clone(facet: "Properties")); test(pa.getProperty("Ice.Admin.InstanceName").Equals("Test")); var tf = TestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet")); tf !.op(); try { ProcessPrx.CheckedCast(obj.Clone(facet: "Process")); test(false); } catch (FacetNotExistException) { } 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); IObjectPrx obj = com.getAdmin(); try { PropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties")); test(false); } catch (FacetNotExistException) { } var tf = Test.TestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet")); tf.op(); ProcessPrx proc = Ice.ProcessPrx.CheckedCast(obj.Clone(facet: "Process")); proc.shutdown(); com.waitForShutdown(); com.destroy(); } output.WriteLine("ok"); factory.shutdown(); }