public void TestIncrementalPollingSource() { var config = new ConcurrentDictionaryConfiguration(); DynamicPropertyFactory.InitWithConfigurationSource(config); DynamicStringProperty prop1 = new DynamicStringProperty("prop1", null); DynamicStringProperty prop2 = new DynamicStringProperty("prop2", null); config.AddProperty("prop1", "original"); DummyPollingSource source = new DummyPollingSource(true); FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, true); scheduler.IgnoreDeletesFromSource = false; // ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source,scheduler); scheduler.StartPolling(source, config); Assert.AreEqual("original", config.GetProperty("prop1")); Assert.AreEqual("original", prop1.Value); source.SetAdded("prop2=new"); Thread.Sleep(200); Assert.AreEqual("original", config.GetProperty("prop1")); Assert.AreEqual("new", config.GetProperty("prop2")); Assert.AreEqual("new", prop2.Value); source.SetDeleted("prop1=DoesNotMatter"); source.SetChanged("prop2=changed"); source.SetAdded(""); Thread.Sleep(200); Assert.IsFalse(config.ContainsKey("prop1")); Assert.IsNull(prop1.Value); Assert.AreEqual("changed", config.GetProperty("prop2")); Assert.AreEqual("changed", prop2.Value); }
public void TestFastProperyTimestamp() { m_Config.StopLoading(); DynamicStringProperty prop = new DynamicStringProperty("Archaius.Net.Test.Timestamp", "hello"); DateTime initialTime = prop.ChangedTime; Thread.Sleep(10); Assert.AreEqual(initialTime, prop.ChangedTime); m_Config.SetProperty(prop.Name, "goodbye"); Assert.IsTrue((prop.ChangedTime - initialTime) > TimeSpan.FromMilliseconds(8)); }
public void TestProperties() { ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); DynamicPropertyFactory factory = DynamicPropertyFactory.InitWithConfigurationSource(config); DynamicStringProperty prop1 = factory.GetStringProperty("prop1", null); DynamicStringProperty prop2 = factory.GetStringProperty("prop2", null); DynamicStringProperty prop3 = factory.GetStringProperty("prop3", null); DynamicStringProperty prop4 = factory.GetStringProperty("prop4", null); AbstractConfiguration containerConfig = new ConcurrentDictionaryConfiguration(); containerConfig.AddProperty("prop1", "prop1"); containerConfig.AddProperty("prop2", "prop2"); AbstractConfiguration baseConfig = new ConcurrentDictionaryConfiguration(); baseConfig.AddProperty("prop3", "prop3"); baseConfig.AddProperty("prop1", "prop1FromBase"); // Make container configuration the highest priority config.SetContainerConfiguration(containerConfig, "container configuration", 0); config.AddConfiguration(baseConfig, "base configuration"); Assert.AreEqual("prop1", config.GetProperty("prop1")); Assert.AreEqual("prop1", prop1.Value); Assert.AreEqual("prop2", prop2.Value); Assert.AreEqual("prop3", prop3.Value); containerConfig.SetProperty("prop1", "newvalue"); Assert.AreEqual("newvalue", prop1.Value); Assert.AreEqual("newvalue", config.GetProperty("prop1")); baseConfig.AddProperty("prop4", "prop4"); Assert.AreEqual("prop4", config.GetProperty("prop4")); Assert.AreEqual("prop4", prop4.Value); baseConfig.SetProperty("prop1", "newvaluefrombase"); Assert.AreEqual("newvalue", prop1.Value); containerConfig.ClearProperty("prop1"); Assert.AreEqual("newvaluefrombase", config.GetProperty("prop1")); Assert.AreEqual("newvaluefrombase", prop1.Value); config.SetOverrideProperty("prop2", "overridden"); config.SetProperty("prop2", "fromContainer"); Assert.AreEqual("overridden", config.GetProperty("prop2")); Assert.AreEqual("overridden", prop2.Value); config.clearOverrideProperty("prop2"); Assert.AreEqual("fromContainer", prop2.Value); Assert.AreEqual("fromContainer", config.GetProperty("prop2")); config.SetProperty("prop3", "fromContainer"); Assert.AreEqual("fromContainer", prop3.Value); Assert.AreEqual("fromContainer", config.GetProperty("prop3")); config.ClearProperty("prop3"); Assert.AreEqual("prop3", prop3.Value); Assert.AreEqual("prop3", config.GetProperty("prop3")); }
public void TestCallbacksAddUnsubscribe() { var dp = new DynamicStringProperty("TestProperty", null); dp.PropertyChanged += OnPropertyChanged; // Trigger callback ConfigurationManager.GetConfigInstance().SetProperty("TestProperty", "cde"); Assert.IsTrue(m_CallbackFlag); dp.ClearPropertyChangedHandlers(); // Trigger callback again ConfigurationManager.GetConfigInstance().SetProperty("TestProperty", "def"); Assert.IsTrue(m_CallbackFlag); dp.PropertyChanged += OnPropertyChanged; ConfigurationManager.GetConfigInstance().SetProperty("TestProperty", "efg"); Assert.IsFalse(m_CallbackFlag); }
public void TestAsFileBased() { DynamicStringProperty prop = new DynamicStringProperty("props1", null); DynamicStringProperty prop2 = new DynamicStringProperty("props2", null); DynamicIntProperty prop3 = new DynamicIntProperty("props3", 0); Thread.Sleep(1000); Assert.AreEqual("xyz", prop.Value); Assert.AreEqual("abc", prop2.Value); Assert.AreEqual(0, prop3.Value); ModifyConfigFile(); // Waiting for reload Thread.Sleep(2000); Assert.IsNull(prop.Value); Assert.AreEqual("456", prop2.Value); Assert.AreEqual(123, prop3.Value); m_Config.StopLoading(); Thread.Sleep(2000); m_Config.SetProperty("props2", "000"); Assert.AreEqual("000", prop2.Value); }
public void TestDefaultConfig() { Environment.SetEnvironmentVariable("xyz", "fromSystem"); DynamicStringProperty prop = new DynamicStringProperty("xyz", null); Assert.IsNotNull(DynamicPropertyFactory.BackingConfigurationSource); Assert.AreEqual("fromSystem", prop.Value); object lastModified = null; EventHandler <ConfigurationEventArgs> handler = (sender, args) => { if (!args.BeforeOperation) { lastModified = args.Value; } }; ConfigurationManager.GetConfigInstance().ConfigurationChanged += handler; try { // Because environment variables default to higher priority than application settings, this set will no-op ConfigurationManager.GetConfigInstance().SetProperty("xyz", "override"); Assert.AreEqual("fromSystem", prop.Value); Assert.AreEqual(null, lastModified); var newConfig = new ConcurrentDictionaryConfiguration(); newConfig.SetProperty("xyz", "fromNewConfig"); ConfigurationManager.Install(newConfig); Assert.AreEqual("fromNewConfig", prop.Value); ConfigurationManager.GetConfigInstance().SetProperty("xyz", "new"); Assert.AreEqual("new", lastModified); Assert.AreEqual("new", prop.Value); Assert.AreEqual(3, newConfig.ConfigurationChangedEventHandlers.Length); } catch (Exception ex) { ConfigurationManager.GetConfigInstance().ConfigurationChanged -= handler; } }
public void TestDefaultConfig() { Environment.SetEnvironmentVariable("xyz", "fromSystem"); DynamicStringProperty prop = new DynamicStringProperty("xyz", null); Assert.IsNotNull(DynamicPropertyFactory.BackingConfigurationSource); Assert.AreEqual("fromSystem", prop.Value); object lastModified = null; EventHandler<ConfigurationEventArgs> handler = (sender, args) => { if (!args.BeforeOperation) { lastModified = args.Value; } }; ConfigurationManager.GetConfigInstance().ConfigurationChanged += handler; try { // Because environment variables default to higher priority than application settings, this set will no-op ConfigurationManager.GetConfigInstance().SetProperty("xyz", "override"); Assert.AreEqual("fromSystem", prop.Value); Assert.AreEqual(null, lastModified); var newConfig = new ConcurrentDictionaryConfiguration(); newConfig.SetProperty("xyz", "fromNewConfig"); ConfigurationManager.Install(newConfig); Assert.AreEqual("fromNewConfig", prop.Value); ConfigurationManager.GetConfigInstance().SetProperty("xyz", "new"); Assert.AreEqual("new", lastModified); Assert.AreEqual("new", prop.Value); Assert.AreEqual(3, newConfig.ConfigurationChangedEventHandlers.Length); } catch (Exception ex) { ConfigurationManager.GetConfigInstance().ConfigurationChanged -= handler; } }