protected virtual TestLabeledConfigurationSource CreateLabeledSource(ConfigurationSourceConfig config) { TestDataCenterSetting Setting = new TestDataCenterSetting("labeled-key-1", "v-0", null, null); TestDataCenterSetting Setting1 = new TestDataCenterSetting("labeled-key-1", "v-1", "sh-1", "app-1"); TestDataCenterSetting Setting2 = new TestDataCenterSetting("labeled-key-1", "v-2", "sh-2", "app-1"); TestDataCenterSetting Setting3 = new TestDataCenterSetting("labeled-key-1", "v-3", "sh-1", "app-2"); return(new TestLabeledConfigurationSource(config, new List <TestDataCenterSetting>() { Setting, Setting1, Setting2, Setting3 })); }
protected override IConfigurationManager CreateManager(Dictionary <int, IConfigurationSource> sources) { Dictionary <int, IConfigurationSource> sourceList = new Dictionary <int, IConfigurationSource>(sources); ConfigurationSourceConfig config = ConfigurationSources.NewConfig("labeled-source"); TestLabeledConfigurationSource source = CreateLabeledSource(config); sourceList[int.MaxValue - 1] = source; config = ConfigurationSources.NewConfig("dynamic-labeled-source"); source = CreateDynamicLabeledSource(config); sourceList[int.MaxValue] = source; return(CreateLabeledManager(sourceList)); }
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); }
protected virtual ILabeledConfigurationManager CreateLabeledManager() { ConfigurationSourceConfig sourceConfig = ConfigurationSources.NewConfig("labeled-source"); Console.WriteLine("source config: " + sourceConfig + "\n"); TestDataCenterSetting Setting1 = new TestDataCenterSetting("exist", "ok", "sh-1", "app-1"); TestDataCenterSetting Setting2 = new TestDataCenterSetting("int-value", "1", "sh-1", "app-1"); TestDataCenterSetting Setting3 = new TestDataCenterSetting("list-value", "s1, s2, s3", "sh-1", "app-1"); TestDataCenterSetting Setting4 = new TestDataCenterSetting("map-value", "k1: v1, k2: v2, k3: v3", "sh-1", "app-1"); TestDataCenterSetting Setting5 = new TestDataCenterSetting("int-list-value", "1, 2, 3", "sh-1", "app-1"); TestDataCenterSetting Setting6 = new TestDataCenterSetting("int-long-map-value", "1: 2, 3: 4, 5: 6", "sh-1", "app-1"); TestLabeledConfigurationSource source = new TestLabeledConfigurationSource(sourceConfig, new List <TestDataCenterSetting>() { Setting1, Setting2, Setting3, Setting4, Setting5, Setting6 }); ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("test") .AddSource(1, source).Build(); Console.WriteLine("manager config: " + managerConfig + "\n"); return(LabeledConfigurationManagers.NewManager(managerConfig)); }
public TestDynamicLabeledConfigurationSource(ConfigurationSourceConfig config, ICollection <TestDataCenterSetting> dataCenterSettings) : base(config, dataCenterSettings) { _concurrentSettings = (ConcurrentDictionary <TestDataCenterSetting, TestDataCenterSetting>)_settings; }
public static MemoryDictionaryConfigurationSource NewMemoryDictionarySource(string name) { ConfigurationSourceConfig config = ConfigurationSources.NewConfig(name); return(new MemoryDictionaryConfigurationSource(config)); }
public static EnvironmentVariableConfigurationSource NewEnvironmentVariableSource(string name) { ConfigurationSourceConfig config = ConfigurationSources.NewConfig(name); return(new EnvironmentVariableConfigurationSource(config)); }
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); }
public DynamicDcConfigurationSource(ConfigurationSourceConfig config) : base(config) { }