Пример #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);
        }
Пример #2
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 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);
 }
Пример #4
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);
        }
 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]));
     }
 }
Пример #6
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]));
            }
        }
 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"));
 }
Пример #8
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"));
        }