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)); }
protected virtual TestDynamicConfigurationSource CreateDynamicSource() { ConfigurationSourceConfig sourceConfig = ConfigurationSources.NewConfig("test-source"); Dictionary <string, string> properties = new Dictionary <string, string>(); properties["exist"] = "ok.2"; properties["exist2"] = "ok2.2"; properties["exist3"] = "ok3.2"; properties["exist4"] = "ok4.2"; TestDynamicConfigurationSource source = new TestDynamicConfigurationSource(sourceConfig, properties); Console.WriteLine("source config: " + sourceConfig + "\n"); return(source); }
public LargeApp() { // OwnManagerComponent both users config and defines how to config properties itself _ownManagerComponent = new OwnManagerComponent(); // OuterManagerComponent only uses config, let the component's user to define how to config // each user can define different config way PropertiesFileConfigurationSourceConfig sourceConfig = StringPropertySources .NewPropertiesFileSourceConfigBuilder().SetName("properties-file") .SetFileName("outer-component.properties").Build(); IConfigurationSource source = StringPropertySources.NewPropertiesFileSource(sourceConfig); ConfigurationManagerConfig managerConfig = ConfigurationManagers.NewConfigBuilder().SetName("outer-component") .AddSource(1, source).Build(); IConfigurationManager manager = ConfigurationManagers.NewManager(managerConfig); _outerManagerComponent = new OuterManagerComponent(manager); // LabeledPropertyComponent only uses config, let the component's user to define how to config // each user can define different config way YamlFileConfigurationSourceConfig labeledSourceConfig = new YamlFileConfigurationSourceConfig.Builder() .SetName("yaml-file").SetFileName("labeled-property-component.yaml").Build(); IConfigurationSource labeledSource = new YamlDcConfigurationSource(labeledSourceConfig); DynamicDcConfigurationSource dynamicLabeledSource = new DynamicDcConfigurationSource( ConfigurationSources.NewConfig("dynamic-labeled-source")); ConfigurationManagerConfig managerConfig2 = ConfigurationManagers.NewConfigBuilder() .SetName("labeled-property-component").AddSource(1, labeledSource).AddSource(2, dynamicLabeledSource) .Build(); ILabeledConfigurationManager manager2 = LabeledConfigurationManagers.NewManager(managerConfig2); _labeledPropertyComponent = new LabeledPropertyComponent(manager2); // large app's config PropertiesFileConfigurationSourceConfig sourceConfig2 = StringPropertySources .NewPropertiesFileSourceConfigBuilder().SetName("properties-file").SetFileName("app.properties") .Build(); IConfigurationSource source2 = StringPropertySources.NewPropertiesFileSource(sourceConfig2); ConfigurationManagerConfig managerConfig3 = ConfigurationManagers.NewConfigBuilder().SetName("outer-component") .AddSource(1, source2).Build(); IConfigurationManager manager3 = ConfigurationManagers.NewManager(managerConfig3); _appProperties = new StringProperties(manager3); }
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); }
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); }