Skip to content

Commit

Permalink
Finish v4.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyixian committed Sep 29, 2022
2 parents 559999e + 800122c commit c9dde04
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 52 deletions.
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -54,8 +54,6 @@ func main() {
Secret: "6ce3ff7e96a24335a9634fe9abca6d51",
}
agollo.SetLogger(&DefaultLogger{})
client, _ := agollo.StartWithConfig(func() (*config.AppConfig, error) {
return c, nil
})
Expand Down
2 changes: 1 addition & 1 deletion component/common_test.go
Expand Up @@ -146,7 +146,7 @@ func SyncServerIPListSuccessCallBack(responseBody []byte, callback http.CallBack
err = json2.Unmarshal(responseBody, &tmpServerInfo)

if err != nil {
log.Error("Unmarshal json Fail,Error:", err)
log.Errorf("Unmarshal json Fail,Error: %s", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion component/remote/abs.go
Expand Up @@ -62,7 +62,7 @@ func (a *AbsApolloConfig) SyncWithNamespace(namespace string, appConfigFunc func
}

if apolloConfig == nil {
log.Warn("apolloConfig is nil")
log.Debug("apolloConfig is nil")
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions component/remote/async.go
Expand Up @@ -138,7 +138,7 @@ func toApolloConfig(resBody []byte) ([]*config.Notification, error) {
err := json.Unmarshal(resBody, &remoteConfig)

if err != nil {
log.Error("Unmarshal Msg Fail,Error:", err)
log.Errorf("Unmarshal Msg Fail,Error: %v", err)
return nil, err
}
return remoteConfig, nil
Expand All @@ -149,7 +149,7 @@ func loadBackupConfig(namespace string, appConfig config.AppConfig) []*config.Ap
config.SplitNamespaces(namespace, func(namespace string) {
c, err := extension.GetFileHandler().LoadConfigFile(appConfig.BackupConfigPath, appConfig.AppID, namespace)
if err != nil {
log.Error("LoadConfigFile error, error", err)
log.Errorf("LoadConfigFile error, error: %v", err)
return
}
if c == nil {
Expand Down Expand Up @@ -177,7 +177,7 @@ func createApolloConfigWithJSON(b []byte, callback http.CallBack) (o interface{}
}
m, err := parser.Parse(apolloConfig.Configurations[defaultContentKey])
if err != nil {
log.Debug("GetContent fail ! error:", err)
log.Debugf("GetContent fail ! error: %v", err)
}

if len(m) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion component/remote/sync.go
Expand Up @@ -85,7 +85,7 @@ func processJSONFiles(b []byte, callback http.CallBack) (o interface{}, err erro
}
m, err := parser.Parse(configurations[defaultContentKey])
if err != nil {
log.Debug("GetContent fail ! error:", err)
log.Debugf("GetContent fail ! error: %v", err)
}

if len(m) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion component/serverlist/sync.go
Expand Up @@ -109,7 +109,7 @@ func SyncServerIPListSuccessCallBack(responseBody []byte, callback http.CallBack
err = json.Unmarshal(responseBody, &tmpServerInfo)

if err != nil {
log.Error("Unmarshal json Fail,Error:", err)
log.Error("Unmarshal json Fail,Error: %v", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion env/config/json/json_config.go
Expand Up @@ -55,7 +55,7 @@ func (t *ConfigFile) Write(content interface{}, configPath string) error {
}
file, e := os.Create(configPath)
if e != nil {
log.Errorf("writeConfigFile fail,error:", e)
log.Errorf("writeConfigFile fail,error: %v", e)
return e
}
defer file.Close()
Expand Down
4 changes: 2 additions & 2 deletions env/file/json/json.go
Expand Up @@ -59,7 +59,7 @@ func (fileHandler *FileHandler) createDir(configPath string) error {
configFileDirMapLock.Lock()
defer configFileDirMapLock.Unlock()
if !configFileDirMap[configPath] {
err := os.Mkdir(configPath, os.ModePerm)
err := os.MkdirAll(configPath, os.ModePerm)
if err != nil && !os.IsExist(err) {
log.Errorf("Create backup dir:%s fail,error:&s", configPath, err)
return err
Expand Down Expand Up @@ -98,7 +98,7 @@ func (fileHandler *FileHandler) GetConfigFile(configDir string, appID string, na
//LoadConfigFile load config from file
func (fileHandler *FileHandler) LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error) {
configFilePath := fileHandler.GetConfigFile(configDir, appID, namespace)
log.Info("load config file from :", configFilePath)
log.Infof("load config file from: %s", configFilePath)
c, e := jsonFileConfig.Load(configFilePath, func(b []byte) (interface{}, error) {
config := &config.ApolloConfig{}
e := json.NewDecoder(bytes.NewBuffer(b)).Decode(config)
Expand Down
6 changes: 3 additions & 3 deletions protocol/http/request.go
Expand Up @@ -99,7 +99,7 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
var err error
url, err := url2.Parse(requestURL)
if err != nil {
log.Error("request Apollo Server url:%s, is invalid %s", requestURL, err)
log.Errorf("request Apollo Server url: %s, is invalid: %v", requestURL, err)
return nil, err
}
var insecureSkipVerify bool
Expand Down Expand Up @@ -167,7 +167,7 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
}
return nil, nil
case http.StatusNotModified:
log.Debug("Config Not Modified:", err)
log.Debugf("Config Not Modified: %v", err)
if callBack != nil && callBack.NotModifyCallBack != nil {
return nil, callBack.NotModifyCallBack()
}
Expand All @@ -180,7 +180,7 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
}
}

log.Error("Over Max Retry Still Error,Error:", err)
log.Errorf("Over Max Retry Still Error,Error: %v", err)
if retry > retries {
err = errors.New("over Max Retry Still Error")
}
Expand Down
4 changes: 2 additions & 2 deletions protocol/http/request_test.go
Expand Up @@ -161,14 +161,14 @@ func getConfigURLSuffix(config *config.AppConfig, namespaceName string) string {

//SyncServerIPListSuccessCallBack 同步服务器列表成功后的回调
func SyncServerIPListSuccessCallBack(responseBody []byte, callback CallBack) (o interface{}, err error) {
log.Debug("get all server info:", string(responseBody))
log.Debugf("get all server info: %s", string(responseBody))

tmpServerInfo := make([]*config.ServerInfo, 0)

err = json2.Unmarshal(responseBody, &tmpServerInfo)

if err != nil {
log.Error("Unmarshal json Fail,Error:", err)
log.Errorf("Unmarshal json Fail,Error: %v", err)
return
}

Expand Down
21 changes: 9 additions & 12 deletions start_test.go
Expand Up @@ -121,7 +121,6 @@ func TestErrorStart(t *testing.T) {

value2 := client.GetValue("key2")
Assert(t, "value2", Equal(value2))

}

func getTestAppConfig() *config.AppConfig {
Expand Down Expand Up @@ -166,14 +165,15 @@ func TestStructInit(t *testing.T) {
Assert(t, "dev1", Equal(apolloConfig.Cluster))
Assert(t, "application1", Equal(apolloConfig.NamespaceName))

//revert file config
// revert file config
env.InitFileConfig()
}

func TestSetLogger(t *testing.T) {
logger := &log.DefaultLogger{}
SetLogger(logger)
Assert(t, log.Logger, Equal(logger))
// TODO log.Logger data race
// logger := &log.DefaultLogger{}
// SetLogger(logger)
// Assert(t, log.Logger, Equal(logger))
}

func TestSetCache(t *testing.T) {
Expand All @@ -182,10 +182,9 @@ func TestSetCache(t *testing.T) {
Assert(t, extension.GetCacheFactory(), Equal(defaultCacheFactory))
}

type TestLoadBalance struct {
}
type TestLoadBalance struct{}

//Load 负载均衡
// Load 负载均衡
func (r *TestLoadBalance) Load(servers map[string]*config.ServerInfo) *config.ServerInfo {
return nil
}
Expand All @@ -199,9 +198,8 @@ func TestSetLoadBalance(t *testing.T) {
Assert(t, t2, Equal(extension.GetLoadBalance()))
}

//testFileHandler 默认备份文件读写
type testFileHandler struct {
}
// testFileHandler 默认备份文件读写
type testFileHandler struct{}

// WriteConfigFile write config to file
func (fileHandler *testFileHandler) WriteConfigFile(config *config.ApolloConfig, configPath string) error {
Expand Down Expand Up @@ -273,5 +271,4 @@ func TestStartWithConfigMustReadFromRemote(t *testing.T) {
Assert(t, "value1", Equal(value))
handler := extension.GetFileHandler()
Assert(t, handler, NotNilVal())

}
14 changes: 13 additions & 1 deletion storage/event_dispatch_test.go
Expand Up @@ -35,6 +35,19 @@ func (t *CustomListener) Event(event *Event) {
t.Keys[event.Key] = event.Value
}

func (t *CustomListener) Value(key string) (interface{}, bool) {
t.l.Lock()
defer t.l.Unlock()
v, ok := t.Keys[key]
return v, ok
}

func (t *CustomListener) Len() int {
t.l.Lock()
defer t.l.Unlock()
return len(t.Keys)
}

func TestDispatch(t *testing.T) {
dispatch := UseEventDispatch()
l := &CustomListener{
Expand Down Expand Up @@ -89,5 +102,4 @@ func TestUnRegisterListener(t *testing.T) {
Assert(t, err, NilVal())
Assert(t, len(dispatch.listeners), Equal(1))
Assert(t, len(dispatch.listeners["ad.*"]), Equal(0))

}

0 comments on commit c9dde04

Please sign in to comment.