示例#1
0
        public virtual void TestGetLabeledPropertyValuePerf()
        {
            ConfigurationSourceConfig      config        = ConfigurationSources.NewConfig("labeled-source");
            TestLabeledConfigurationSource labeledSource = CreateLabeledSource(config);

            config = ConfigurationSources.NewConfig("dynamic-labeled-source");
            TestDynamicLabeledConfigurationSource dynamicLabeledSource = CreateDynamicLabeledSource(config);
            ILabeledConfigurationManager          manager = CreateLabeledManager(
                new Dictionary <int, IConfigurationSource>()
            {
                { 1, labeledSource }, { 2, dynamicLabeledSource }
            });

            List <IPropertyLabel> labels = new List <IPropertyLabel>();

            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.DC_KEY, "sh-1"));
            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.APP_KEY, "app-1"));
            PropertyLabels      propertyLabels = LabeledConfigurationProperties.NewLabels(labels);
            LabeledKey <string> key            = LabeledConfigurationProperties.NewKeyBuilder <string>().SetKey("labeled-key-1")
                                                 .SetPropertyLabels(propertyLabels).Build();
            PropertyConfig <LabeledKey <string>, string> propertyConfig = ConfigurationProperties
                                                                          .NewConfigBuilder <LabeledKey <string>, string>().SetKey(key).SetDefaultValue("default-value-1").Build();
            String propertyValue = manager.GetPropertyValue(propertyConfig);

            Assert.Equal("v-1-2", propertyValue);

            int      times = 100 * 1000;
            DateTime start = DateTime.Now;

            for (int i = 0; i < times; i++)
            {
                propertyValue = manager.GetPropertyValue(propertyConfig);
            }
            DateTime end     = DateTime.Now;
            TimeSpan elipsed = end - start;

            Console.WriteLine("{0} times GetPropertyValue, total time: {1}, avg time: {2}",
                              times, elipsed.TotalMilliseconds, (double)elipsed.TotalMilliseconds / times);
        }
示例#2
0
        public virtual void TestGetLabeledProperty()
        {
            ConfigurationSourceConfig      config        = ConfigurationSources.NewConfig("labeled-source");
            TestLabeledConfigurationSource labeledSource = CreateLabeledSource(config);

            config = ConfigurationSources.NewConfig("dynamic-labeled-source");
            TestDynamicLabeledConfigurationSource dynamicLabeledSource = CreateDynamicLabeledSource(config);
            ILabeledConfigurationManager          manager = CreateLabeledManager(
                new Dictionary <int, IConfigurationSource>()
            {
                { 1, labeledSource }, { 2, dynamicLabeledSource }
            });

            List <IPropertyLabel> labels = new List <IPropertyLabel>();

            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.DC_KEY, "sh-1"));
            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.APP_KEY, "app-1"));
            PropertyLabels      propertyLabels = LabeledConfigurationProperties.NewLabels(labels);
            LabeledKey <string> key            = LabeledConfigurationProperties.NewKeyBuilder <string>().SetKey("labeled-key-1")
                                                 .SetPropertyLabels(propertyLabels).Build();
            PropertyConfig <LabeledKey <string>, string> propertyConfig = ConfigurationProperties
                                                                          .NewConfigBuilder <LabeledKey <string>, string>().SetKey(key).SetDefaultValue("default-value-1").Build();
            IProperty <LabeledKey <string>, string> property = manager.GetProperty(propertyConfig);

            Console.WriteLine(property);
            Assert.Equal("v-1-2", property.Value);

            labels = new List <IPropertyLabel>();
            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.DC_KEY, "sh-1-not-exist"));
            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.APP_KEY, "app-1"));
            propertyLabels = LabeledConfigurationProperties.NewLabels(labels);
            key            = LabeledConfigurationProperties.NewKeyBuilder <String>().SetKey("labeled-key-1")
                             .SetPropertyLabels(propertyLabels).Build();
            propertyConfig = ConfigurationProperties.NewConfigBuilder <LabeledKey <string>, String>().SetKey(key)
                             .SetDefaultValue("default-value-1").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine(property);
            Assert.Equal("default-value-1", property.Value);

            propertyLabels = LabeledConfigurationProperties.NewLabels(
                LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.DC_KEY, "sh-1"),
                LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.APP_KEY, "app-1"));
            labels = new List <IPropertyLabel>();
            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.DC_KEY, "sh-1-not-exist"));
            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.APP_KEY, "app-1"));
            propertyLabels = LabeledConfigurationProperties.NewLabels(labels, propertyLabels);
            key            = LabeledConfigurationProperties.NewKeyBuilder <string>().SetKey("labeled-key-1")
                             .SetPropertyLabels(propertyLabels).Build();
            propertyConfig = ConfigurationProperties.NewConfigBuilder <LabeledKey <string>, string>().SetKey(key)
                             .SetDefaultValue("default-value-1").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine(property);
            Assert.Equal("v-1-2", property.Value);

            TestDataCenterSetting Setting = new TestDataCenterSetting("labeled-key-1", "v-4-2", "sh-1-not-exist", "app-1");

            dynamicLabeledSource.updateSetting(Setting);
            Thread.Sleep(10);
            Console.WriteLine(property);
            Assert.Equal("v-4-2", property.Value);

            dynamicLabeledSource.removeSetting(Setting);
            Thread.Sleep(10);
            Console.WriteLine(property);
            Assert.Equal("v-1-2", property.Value);

            labels = new List <IPropertyLabel>();
            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.DC_KEY, "sh-1-not-exist"));
            labels.Add(LabeledConfigurationProperties.NewLabel(TestDataCenterSetting.APP_KEY, "app-1"));
            propertyLabels = LabeledConfigurationProperties.NewLabels(labels, PropertyLabels.Empty);
            key            = LabeledConfigurationProperties.NewKeyBuilder <string>().SetKey("labeled-key-1")
                             .SetPropertyLabels(propertyLabels).Build();
            propertyConfig = ConfigurationProperties.NewConfigBuilder <LabeledKey <string>, string>().SetKey(key)
                             .SetDefaultValue("default-value-1").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine(property);
            Assert.Equal("v-0-2", property.Value);
        }