Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nacos client #1255

Merged
merged 26 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
518be2b
build(deps): bump actions/cache from v2.1.4 to v2.1.5
dependabot[bot] Apr 19, 2021
3162e41
Merge pull request #1162 from apache/dependabot/github_actions/develo…
AlexStocks Apr 21, 2021
2138190
Merge branch 'develop' of https://github.com/apache/dubbo-go into dev…
AlexStocks Apr 27, 2021
bef8e95
Merge branch '3.0' into develop
AlexStocks Apr 27, 2021
a85b65b
Merge branch '3.0' into develop
AlexStocks May 9, 2021
9e38afe
Merge branch '3.0' into develop
AlexStocks May 10, 2021
f0ad730
Merge branch '3.0' into develop
AlexStocks May 10, 2021
4cb6e44
improve etcd version and change create to put (#1203)
ztelur May 15, 2021
56d9d71
Merge branch '3.0' into develop
AlexStocks May 15, 2021
cc74aa5
Merge branch '3.0' into develop
AlexStocks May 18, 2021
40082d4
Merge branch '3.0' into develop
AlexStocks May 21, 2021
bec69c5
up:remoting nacos
zhaoyunxing92 Jun 4, 2021
daff04e
add:nacos service discovery
zhaoyunxing92 Jun 4, 2021
0bb95d6
up:设置默认值
zhaoyunxing92 Jun 5, 2021
c032f19
up:nacos registroy client
zhaoyunxing92 Jun 5, 2021
e97320e
up:nacon config client
zhaoyunxing92 Jun 5, 2021
3fad0be
up:go fmt
zhaoyunxing92 Jun 5, 2021
441e0b4
up:nacos config client
zhaoyunxing92 Jun 5, 2021
3fa236e
Merge branch 'apache:master' into nacos-client
zhaoyunxing92 Jun 11, 2021
dd4ad37
up:test
zhaoyunxing92 Jun 11, 2021
70e5386
up:修改初æ测试方法
zhaoyunxing92 Jun 11, 2021
d1ed6a1
merge
zhaoyunxing92 Jun 11, 2021
03b0574
up:fmt
zhaoyunxing92 Jun 11, 2021
cad80ab
up:triple version
zhaoyunxing92 Jun 12, 2021
79ff40c
up:修改配置操作
zhaoyunxing92 Jun 12, 2021
654e491
rm:移除nacos客户端,解决冲突
zhaoyunxing92 Jun 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
up:修改配置操作
  • Loading branch information
zhaoyunxing92 committed Jun 12, 2021
commit 79ff40c901c8a60d9d0ce975e2b43f1f0fbbe4bf
10 changes: 5 additions & 5 deletions config_center/nacos/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package nacos

import (
"strings"
"testing"
"time"
)
Expand All @@ -32,9 +31,10 @@ import (
)

func TestNewNacosClient(t *testing.T) {
server := mockCommonNacosServer()
nacosURL := strings.ReplaceAll(server.URL, "http", "registry")

nacosURL := "registry://127.0.0.1:8848"
registryUrl, _ := common.NewURL(nacosURL)

c := &nacosDynamicConfiguration{
url: registryUrl,
done: make(chan struct{}),
Expand All @@ -55,9 +55,9 @@ func TestNewNacosClient(t *testing.T) {
}

func TestSetNacosClient(t *testing.T) {
server := mockCommonNacosServer()
nacosURL := "registry://" + server.Listener.Addr().String()
nacosURL := "registry://127.0.0.1:8848"
registryUrl, _ := common.NewURL(nacosURL)

c := &nacosDynamicConfiguration{
url: registryUrl,
done: make(chan struct{}),
Expand Down
6 changes: 1 addition & 5 deletions config_center/nacos/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,7 @@ func (n *nacosDynamicConfiguration) IsAvailable() bool {
}

func (n *nacosDynamicConfiguration) closeConfigs() {
n.cltLock.Lock()
client := n.client
n.client = nil
n.cltLock.Unlock()
// Close the old configClient first to close the tmp node
client.Close()
n.client.Close()
logger.Infof("begin to close provider n configClient")
}
112 changes: 25 additions & 87 deletions config_center/nacos/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
package nacos

import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"time"
Expand All @@ -37,104 +33,46 @@ import (
"dubbo.apache.org/dubbo-go/v3/config_center/parser"
)

// run mock config server
func runMockConfigServer(configHandler func(http.ResponseWriter, *http.Request),
configListenHandler func(http.ResponseWriter, *http.Request)) *httptest.Server {
uriHandlerMap := make(map[string]func(http.ResponseWriter, *http.Request))

uriHandlerMap["/nacos/v1/cs/configs"] = configHandler
uriHandlerMap["/nacos/v1/cs/configs/listener"] = configListenHandler

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
uri := r.RequestURI
for path, handler := range uriHandlerMap {
if uri == path {
handler(w, r)
break
}
}
}))

return ts
}

func mockCommonNacosServer() *httptest.Server {
return runMockConfigServer(func(writer http.ResponseWriter, _ *http.Request) {
data := "true"
fmt.Fprintf(writer, "%s", data)
}, func(writer http.ResponseWriter, _ *http.Request) {
data := `dubbo.properties%02dubbo%02dubbo.service.com.ikurento.user.UserProvider.cluster=failback`
fmt.Fprintf(writer, "%s", data)
})
func getNacosConfig(t *testing.T) config_center.DynamicConfiguration {
registryUrl, err := common.NewURL("registry://console.nacos.io:80")
assert.Nil(t, err)
nacosConfig, err := newNacosDynamicConfiguration(registryUrl)
assert.Nil(t, err)
return nacosConfig
}

func initNacosData(t *testing.T) (*nacosDynamicConfiguration, error) {
server := mockCommonNacosServer()
nacosURL := strings.ReplaceAll(server.URL, "http", "registry")
regurl, _ := common.NewURL(nacosURL)
factory := &nacosDynamicConfigurationFactory{}
nacosConfiguration, err := factory.GetDynamicConfiguration(regurl)
assert.NoError(t, err)

nacosConfiguration.SetParser(&parser.DefaultConfigurationParser{})

return nacosConfiguration.(*nacosDynamicConfiguration), err
func TestPublishConfig(t *testing.T) {
nacosConfig := getNacosConfig(t)
data := `dubbo.protocol.name=dubbo`
err := nacosConfig.PublishConfig("dubbo.properties", "dubbo-go", data)
assert.Nil(t, err)
}

func TestGetConfig(t *testing.T) {
nacos, err := initNacosData(t)
assert.NoError(t, err)
configs, err := nacos.GetProperties("dubbo.properties", config_center.WithGroup("dubbo"))
assert.Empty(t, configs)
assert.NoError(t, err)
_, err = nacos.Parser().Parse(configs)
assert.NoError(t, err)
}
nacosConfig := getNacosConfig(t)
nacosConfig.SetParser(&parser.DefaultConfigurationParser{})

func TestNacosDynamicConfiguration_GetConfigKeysByGroup(t *testing.T) {
data := `
{
"PageItems": [
{
"dataId": "application"
}
]
}
`
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(data))
assert.Nil(t, err)
}))

nacosURL := strings.ReplaceAll(ts.URL, "http", "registry")
regurl, _ := common.NewURL(nacosURL)
nacosConfiguration, err := newNacosDynamicConfiguration(regurl)
config, err := nacosConfig.GetProperties("dubbo.properties", config_center.WithGroup("dubbo-go"))
assert.NotEmpty(t, config)
assert.NoError(t, err)

nacosConfiguration.SetParser(&parser.DefaultConfigurationParser{})

configs, err := nacosConfiguration.GetConfigKeysByGroup("dubbo")
assert.Nil(t, err)
assert.Equal(t, 1, configs.Size())
assert.True(t, configs.Contains("application"))
parse, err := nacosConfig.Parser().Parse(config)
assert.NoError(t, err)
assert.Equal(t, parse["dubbo.protocol.name"], "dubbo")
}

func TestNacosDynamicConfigurationPublishConfig(t *testing.T) {
nacos, err := initNacosData(t)
assert.Nil(t, err)
key := "myKey"
group := "/custom/a/b"
value := "MyValue"
err = nacos.PublishConfig(key, group, value)
assert.Nil(t, err)
func TestGetConfigKeysByGroup(t *testing.T) {
nacosConfig := getNacosConfig(t)
config, err := nacosConfig.GetConfigKeysByGroup("dubbo-go")
assert.NoError(t, err)
assert.True(t, config.Contains("dubbo.properties"))
}

func TestAddListener(t *testing.T) {
nacos, err := initNacosData(t)
assert.NoError(t, err)
nacosConfig := getNacosConfig(t)
listener := &mockDataListener{}
time.Sleep(time.Second * 2)
nacos.AddListener("dubbo.properties", listener)
nacosConfig.AddListener("dubbo.properties", listener)
}

func TestRemoveListener(_ *testing.T) {
Expand Down