Skip to content
Snippets Groups Projects
Commit eb9c999c authored by amudong's avatar amudong
Browse files

add config_center nacos client_test.go

parent 172a4863
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,8 @@ type NacosClient struct {
Client *config_client.IConfigClient
exit chan struct{}
Timeout time.Duration
once sync.Once
onceClose func()
}
type Option func(*Options)
......@@ -108,11 +110,11 @@ func ValidateNacosClient(container nacosClientFacade, opts ...Option) error {
})
container.NacosClient().Client = &client
if err != nil {
//TODO
logger.Errorf("nacos create config client error:%v", err)
}
}
return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", url.PrimitiveURL)
return perrors.WithMessagef(err, "newNacosClient(address:%+v)", url.PrimitiveURL)
}
func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*NacosClient, error) {
......@@ -126,6 +128,9 @@ func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*N
NacosAddrs: nacosAddrs,
Timeout: timeout,
exit: make(chan struct{}),
onceClose: func() {
close(n.exit)
},
}
svrConfList := []nacosconst.ServerConfig{}
......@@ -167,7 +172,7 @@ func (n *NacosClient) stop() bool {
case <-n.exit:
return true
default:
close(n.exit)
n.once.Do(n.onceClose)
}
return false
......@@ -199,5 +204,5 @@ func (n *NacosClient) Close() {
n.Lock()
n.Client = nil
n.Unlock()
logger.Warnf("nacosClient{name:%s, zk addr:%s} exit now.", n.name, n.NacosAddrs)
logger.Warnf("nacosClient{name:%s, nacos addr:%s} exit now.", n.name, n.NacosAddrs)
}
package nacos
import (
"context"
"fmt"
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
import (
"github.com/apache/dubbo-go/common"
)
func Test_newNacosClient(t *testing.T) {
registryUrl, _ := common.NewURL(context.TODO(), "registry://console.nacos.io:80")
c := &nacosDynamicConfiguration{
url: &registryUrl,
done: make(chan struct{}),
}
err := ValidateNacosClient(c, WithNacosName(NacosClientName))
if err != nil {
fmt.Println("nacos client start error ,error message is", err)
}
assert.NoError(t, err)
c.wg.Add(1)
go HandleClientRestart(c)
c.client.Close()
<-c.client.Done()
fmt.Println("nacos client close done")
c.Destroy()
}
......@@ -49,8 +49,9 @@ type nacosDynamicConfiguration struct {
func newNacosDynamicConfiguration(url *common.URL) (*nacosDynamicConfiguration, error) {
c := &nacosDynamicConfiguration{
rootPath: "/" + url.GetParam(constant.CONFIG_NAMESPACE_KEY, config_center.DEFAULT_GROUP) + "/config",
url: url,
rootPath: "/" + url.GetParam(constant.CONFIG_NAMESPACE_KEY, config_center.DEFAULT_GROUP) + "/config",
url: url,
done: make(chan struct{}),
}
err := ValidateNacosClient(c, WithNacosName(NacosClientName))
if err != nil {
......@@ -148,7 +149,7 @@ func (n *nacosDynamicConfiguration) IsAvailable() bool {
func (r *nacosDynamicConfiguration) closeConfigs() {
r.cltLock.Lock()
defer r.cltLock.Unlock()
logger.Infof("begin to close provider zk client")
logger.Infof("begin to close provider nacos client")
// Close the old client first to close the tmp node
r.client.Close()
r.client = nil
......
......@@ -26,6 +26,7 @@ import (
)
import (
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/remoting"
)
......@@ -49,7 +50,8 @@ func (l *nacosDynamicConfiguration) addListener(key string, listener config_cent
newListener[listener] = cancel
l.keyListeners.Store(key, newListener)
} else {
// TODO check goroutine
// TODO check goroutine alive, but this version of go_nacos_sdk is not support.
logger.Infof("profile:%s. this profile is already listening", key)
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment