public void TestConcurrency()
 {
     ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();
     conf.DelimiterParsingDisabled = false;
     var threadCount = 20;
     var operationPerThread = 50;
     var expectedValueCount = threadCount * operationPerThread * 2;
     CountdownEvent doneEvent = new CountdownEvent(20);
     for (int i = 0; i < doneEvent.InitialCount; i++)
     {
         int index = i;
         new Thread(() =>
                    {
                        for (var j = 0; j < operationPerThread; ++j)
                        {
                            conf.AddProperty("key", index);
                            conf.AddProperty("key", "stringValue");
                        }
                        doneEvent.Signal();
                        Thread.Sleep(50);
                    }).Start();
     }
     doneEvent.Wait();
     IList prop = (IList)conf.GetProperty("key");
     Assert.AreEqual(expectedValueCount, prop.Count);
 }
 public void TestSetGet()
 {
     ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();
     conf.DelimiterParsingDisabled = false;
     conf.AddProperty("key1", "xyz");
     Assert.AreEqual("xyz", conf.GetProperty("key1"));
     conf.SetProperty("key1", "newProp");
     Assert.AreEqual("newProp", conf.GetProperty("key1"));
     conf.SetProperty("listProperty", "0,1,2,3");
     Assert.IsTrue(conf.GetProperty("listProperty") is IList);
     IList props = (IList)conf.GetProperty("listProperty");
     for (int i = 0; i < 4; i++)
     {
         Assert.AreEqual(i, int.Parse((string)props[i]));
     }
     conf.AddProperty("listProperty", "4");
     conf.AddProperty("listProperty", new List<string> {"5", "6"});
     props = (IList)conf.GetProperty("listProperty");
     for (int i = 0; i < 7; i++)
     {
         Assert.AreEqual(i, int.Parse((string)props[i]));
     }
     DateTime date = DateTime.Now;
     conf.SetProperty("listProperty", date);
     Assert.AreEqual(date, conf.GetProperty("listProperty"));
 }
Exemplo n.º 3
0
        public void TestConcurrency()
        {
            ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();

            conf.DelimiterParsingDisabled = false;
            var            threadCount        = 20;
            var            operationPerThread = 50;
            var            expectedValueCount = threadCount * operationPerThread * 2;
            CountdownEvent doneEvent          = new CountdownEvent(20);

            for (int i = 0; i < doneEvent.InitialCount; i++)
            {
                int index = i;
                new Thread(() =>
                {
                    for (var j = 0; j < operationPerThread; ++j)
                    {
                        conf.AddProperty("key", index);
                        conf.AddProperty("key", "stringValue");
                    }
                    doneEvent.Signal();
                    Thread.Sleep(50);
                }).Start();
            }
            doneEvent.Wait();
            IList prop = (IList)conf.GetProperty("key");

            Assert.AreEqual(expectedValueCount, prop.Count);
        }
Exemplo n.º 4
0
        public void TestSetGet()
        {
            ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();

            conf.DelimiterParsingDisabled = false;
            conf.AddProperty("key1", "xyz");
            Assert.AreEqual("xyz", conf.GetProperty("key1"));
            conf.SetProperty("key1", "newProp");
            Assert.AreEqual("newProp", conf.GetProperty("key1"));
            conf.SetProperty("listProperty", "0,1,2,3");
            Assert.IsTrue(conf.GetProperty("listProperty") is IList);
            IList props = (IList)conf.GetProperty("listProperty");

            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual(i, int.Parse((string)props[i]));
            }
            conf.AddProperty("listProperty", "4");
            conf.AddProperty("listProperty", new List <string> {
                "5", "6"
            });
            props = (IList)conf.GetProperty("listProperty");
            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual(i, int.Parse((string)props[i]));
            }
            DateTime date = DateTime.Now;

            conf.SetProperty("listProperty", date);
            Assert.AreEqual(date, conf.GetProperty("listProperty"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void TestNoneDeletingPollingSource()
        {
            var config = new ConcurrentDictionaryConfiguration();

            config.AddProperty("prop1", "original");
            DummyPollingSource source = new DummyPollingSource(false);

            source.SetFull("");
            FixedDelayPollingScheduler     scheduler     = new FixedDelayPollingScheduler(0, 10, true);
            ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source, scheduler);

            Thread.Sleep(200);
            Assert.AreEqual("original", pollingConfig.GetProperty("prop1"));
            source.SetFull("prop1=changed");
            Thread.Sleep(200);
            Assert.AreEqual("changed", pollingConfig.GetProperty("prop1"));
            source.SetFull("prop1=changedagain,prop2=new");
            Thread.Sleep(200);
            Assert.AreEqual("changedagain", pollingConfig.GetProperty("prop1"));
            Assert.AreEqual("new", pollingConfig.GetProperty("prop2"));
            source.SetFull("prop3=new");
            Thread.Sleep(200);
            Assert.AreEqual("changedagain", pollingConfig.GetProperty("prop1"));
            Assert.AreEqual("new", pollingConfig.GetProperty("prop2"));
            Assert.AreEqual("new", pollingConfig.GetProperty("prop3"));
        }
Exemplo n.º 8
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);
 }
 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 TestDelimiterParsingDisabled()
 {
     ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();
     conf.DelimiterParsingDisabled = true;
     conf.SetProperty("listProperty", "0,1,2,3");
     Assert.AreEqual("0,1,2,3", conf.GetProperty("listProperty"));
     conf.AddProperty("listProperty2", "0,1,2,3");
     Assert.AreEqual("0,1,2,3", conf.GetProperty("listProperty2"));
     conf.DelimiterParsingDisabled = false;
     Assert.AreEqual("0,1,2,3", conf.GetProperty("listProperty"));
     conf.SetProperty("anotherList", "0,1,2,3");
     var props = (IList)conf.GetProperty("anotherList");
     for (int i = 0; i < 4; i++)
     {
         Assert.AreEqual(i, int.Parse((string)props[i]));
     }
 }
Exemplo n.º 11
0
        public void TestDelimiterParsingDisabled()
        {
            ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();

            conf.DelimiterParsingDisabled = true;
            conf.SetProperty("listProperty", "0,1,2,3");
            Assert.AreEqual("0,1,2,3", conf.GetProperty("listProperty"));
            conf.AddProperty("listProperty2", "0,1,2,3");
            Assert.AreEqual("0,1,2,3", conf.GetProperty("listProperty2"));
            conf.DelimiterParsingDisabled = false;
            Assert.AreEqual("0,1,2,3", conf.GetProperty("listProperty"));
            conf.SetProperty("anotherList", "0,1,2,3");
            var props = (IList)conf.GetProperty("anotherList");

            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual(i, int.Parse((string)props[i]));
            }
        }
Exemplo n.º 12
0
        public void TestNullValue()
        {
            ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();

            try
            {
                conf.SetProperty("xyz", null);
                Assert.Fail("ArgumentNullException is expected.");
            }
            catch (ArgumentNullException e)
            {
            }
            try
            {
                conf.AddProperty("xyz", null);
                Assert.Fail("ArgumentNullException is expected.");
            }
            catch (ArgumentNullException e)
            {
            }
        }
Exemplo n.º 13
0
 public void TestNoneDeletingPollingSource()
 {
     var config = new ConcurrentDictionaryConfiguration();
     config.AddProperty("prop1", "original");
     DummyPollingSource source = new DummyPollingSource(false);
     source.SetFull("");
     FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, true);
     ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source, scheduler);
     Thread.Sleep(200);
     Assert.AreEqual("original", pollingConfig.GetProperty("prop1"));
     source.SetFull("prop1=changed");
     Thread.Sleep(200);
     Assert.AreEqual("changed", pollingConfig.GetProperty("prop1"));
     source.SetFull("prop1=changedagain,prop2=new");
     Thread.Sleep(200);
     Assert.AreEqual("changedagain", pollingConfig.GetProperty("prop1"));
     Assert.AreEqual("new", pollingConfig.GetProperty("prop2"));
     source.SetFull("prop3=new");
     Thread.Sleep(200);
     Assert.AreEqual("changedagain", pollingConfig.GetProperty("prop1"));
     Assert.AreEqual("new", pollingConfig.GetProperty("prop2"));
     Assert.AreEqual("new", pollingConfig.GetProperty("prop3"));
 }
Exemplo n.º 14
0
        public void TestListeners()
        {
            ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();

            object eventSender = null;
            ConfigurationEventArgs eventArgs = null;

            conf.ConfigurationChanged += (sender, args) =>
            {
                eventSender = sender;
                eventArgs   = args;
            };

            conf.AddProperty("key", "1");
            Assert.AreEqual(1, conf.GetInt("key"));
            Assert.AreEqual("key", eventArgs.Name);
            Assert.AreEqual("1", eventArgs.Value);
            Assert.AreSame(conf, eventSender);
            Assert.AreEqual(ConfigurationEventType.AddProperty, eventArgs.Type);
            conf.SetProperty("key", "2");

            Assert.AreEqual("key", eventArgs.Name);
            Assert.AreEqual("2", eventArgs.Value);
            Assert.AreSame(conf, eventSender);
            Assert.AreEqual(ConfigurationEventType.SetProperty, eventArgs.Type);

            conf.ClearProperty("key");
            Assert.AreEqual("key", eventArgs.Name);
            Assert.IsNull(eventArgs.Value);
            Assert.AreSame(conf, eventSender);
            Assert.AreEqual(ConfigurationEventType.ClearProperty, eventArgs.Type);

            conf.Clear();
            Assert.IsEmpty(conf.Keys);
            Assert.AreSame(conf, eventSender);
            Assert.AreEqual(ConfigurationEventType.Clear, eventArgs.Type);
        }
        public void TestListeners()
        {
            ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();

            object eventSender = null;
            ConfigurationEventArgs eventArgs = null;
            conf.ConfigurationChanged += (sender, args) =>
                                       {
                                           eventSender = sender;
                                           eventArgs = args;
                                       };

            conf.AddProperty("key", "1");
            Assert.AreEqual(1, conf.GetInt("key"));
            Assert.AreEqual("key", eventArgs.Name);
            Assert.AreEqual("1", eventArgs.Value);
            Assert.AreSame(conf, eventSender);
            Assert.AreEqual(ConfigurationEventType.AddProperty, eventArgs.Type);
            conf.SetProperty("key", "2");

            Assert.AreEqual("key", eventArgs.Name);
            Assert.AreEqual("2", eventArgs.Value);
            Assert.AreSame(conf, eventSender);
            Assert.AreEqual(ConfigurationEventType.SetProperty, eventArgs.Type);

            conf.ClearProperty("key");
            Assert.AreEqual("key", eventArgs.Name);
            Assert.IsNull(eventArgs.Value);
            Assert.AreSame(conf, eventSender);
            Assert.AreEqual(ConfigurationEventType.ClearProperty, eventArgs.Type);

            conf.Clear();
            Assert.IsEmpty(conf.Keys);
            Assert.AreSame(conf, eventSender);
            Assert.AreEqual(ConfigurationEventType.Clear, eventArgs.Type);
        }
 public void TestNullValue()
 {
     ConcurrentDictionaryConfiguration conf = new ConcurrentDictionaryConfiguration();
     try
     {
         conf.SetProperty("xyz", null);
         Assert.Fail("ArgumentNullException is expected.");
     }
     catch (ArgumentNullException e)
     {
     }
     try
     {
         conf.AddProperty("xyz", null);
         Assert.Fail("ArgumentNullException is expected.");
     }
     catch (ArgumentNullException e)
     {
     }
 }