Exemple #1
0
        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);
        }
Exemple #2
0
        public void TestInstall()
        {
            ConfigurationManager.GetConfigInstance().SetProperty("prop1", "abc");
            Assert.AreEqual("abc", ConfigurationManager.GetConfigInstance().GetProperty("prop1"));
            Assert.AreEqual("abc", m_Prop1.Value);
            ConcurrentDictionaryConfiguration newConfig = new ConcurrentDictionaryConfiguration();

            newConfig.SetProperty("prop1", "fromNewConfig");
            ConfigurationManager.Install(newConfig);
            Assert.AreEqual("fromNewConfig", ConfigurationManager.GetConfigInstance().GetProperty("prop1"));
            Assert.AreEqual("fromNewConfig", m_Prop1.Value);
            newConfig.SetProperty("prop1", "changed");
            Assert.AreEqual("changed", ConfigurationManager.GetConfigInstance().GetProperty("prop1"));
            Assert.AreEqual("changed", m_Prop1.Value);
            try
            {
                ConfigurationManager.Install(new ConcurrentDictionaryConfiguration());
                Assert.Fail("InvalidOperationException expected");
            }
            catch (InvalidOperationException e)
            {
            }
            try
            {
                DynamicPropertyFactory.InitWithConfigurationSource(new ConcurrentDictionaryConfiguration());
                Assert.Fail("InvalidOperationException expected");
            }
            catch (InvalidOperationException e)
            {
            }
        }
Exemple #3
0
        public static void FixtureSetUp()
        {
            CreateConfigFile();

            m_Config = new DynamicUrlConfiguration(100, 500, false, m_ConfigFile);
            Console.WriteLine("Initializing with sources: " + m_Config.Source);
            DynamicPropertyFactory.InitWithConfigurationSource(m_Config);
        }
Exemple #4
0
 /// <summary>
 /// Install the system wide configuration with the ConfigurationManager. This will also install
 /// the configuration with the <see cref="DynamicPropertyFactory"/> by calling <see cref="DynamicPropertyFactory.InitWithConfigurationSource"/>.
 /// This call can be made only once, otherwise IllegalStateException will be thrown.
 /// </summary>
 /// <param name="config"></param>
 public static void Install(AbstractConfiguration config)
 {
     lock (m_ClassLock)
     {
         if (m_CustomConfigurationInstalled)
         {
             throw new InvalidOperationException("A non-default configuration is already installed");
         }
         SetDirect(config);
         if (DynamicPropertyFactory.BackingConfigurationSource != config)
         {
             DynamicPropertyFactory.InitWithConfigurationSource(config);
         }
     }
 }
Exemple #5
0
        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"));
        }