Skip to content

Commit

Permalink
up:代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyunxing92 committed Jun 26, 2021
1 parent 036ce96 commit 68ab7bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
7 changes: 4 additions & 3 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ func (b *configCenter) prepareEnvironment(baseConfig BaseConfig, configCenterUrl
logger.Errorf("Get dynamic configuration error , error message is %v", err)
return perrors.WithStack(err)
}
config.GetEnvInstance().SetDynamicConfiguration(dynamicConfig)
envInstance := config.GetEnvInstance()
envInstance.SetDynamicConfiguration(dynamicConfig)
content, err := dynamicConfig.GetProperties(baseConfig.ConfigCenterConfig.ConfigFile,
config_center.WithGroup(baseConfig.ConfigCenterConfig.Group))
if err != nil {
Expand Down Expand Up @@ -164,15 +165,15 @@ func (b *configCenter) prepareEnvironment(baseConfig BaseConfig, configCenterUrl
if err != nil {
return perrors.WithStack(err)
}
config.GetEnvInstance().UpdateExternalConfigMap(mapContent)
envInstance.UpdateExternalConfigMap(mapContent)

// appGroup config file
if len(appContent) != 0 {
appMapContent, err := dynamicConfig.Parser().Parse(appContent)
if err != nil {
return perrors.WithStack(err)
}
config.GetEnvInstance().UpdateAppExternalConfigMap(appMapContent)
envInstance.UpdateAppExternalConfigMap(appMapContent)
}

return nil
Expand Down
24 changes: 2 additions & 22 deletions config/config_center_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestStartConfigCenterWithRemoteRef(t *testing.T) {
baseConfig := &BaseConfig{
Remotes: m,
ConfigCenterConfig: &ConfigCenterConfig{
Protocol: "mock",
Group: "dubbo",
RemoteRef: "mock",
ConfigFile: "mockDubbo.properties",
Expand All @@ -71,25 +72,4 @@ func TestStartConfigCenterWithRemoteRef(t *testing.T) {
b, v := config.GetEnvInstance().Configuration().Back().Value.(*config.InmemoryConfiguration).GetProperty("dubbo.application.organization")
assert.True(t, b)
assert.Equal(t, "ikurento.com", v)
}

func TestStartConfigCenterWithRemoteRefError(t *testing.T) {
extension.SetConfigCenterFactory("mock", func() config_center.DynamicConfigurationFactory {
return &config_center.MockDynamicConfigurationFactory{}
})
m := make(map[string]*RemoteConfig)
m["mock"] = &RemoteConfig{Address: "172.0.0.1"}
baseConfig := &BaseConfig{
Remotes: m,
ConfigCenterConfig: &ConfigCenterConfig{
Protocol: "mock",
Group: "dubbo",
RemoteRef: "mock",
ConfigFile: "mockDubbo.properties",
},
}

c := &configCenter{}
err := c.startConfigCenter(*baseConfig)
assert.Error(t, err)
}
}

0 comments on commit 68ab7bf

Please sign in to comment.