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

Fix:nacos client reuse #1633

Merged
merged 16 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
修复测试用例
  • Loading branch information
zhaoyunxing92 committed Dec 30, 2021
commit 8c2a9e388cd5d8d55c43200c7eaedd5fc0827e7a
18 changes: 16 additions & 2 deletions metadata/report/nacos/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nacos

import (
"net/http"
"net/url"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -54,7 +55,11 @@ func TestNacosMetadataReport_CRUD(t *testing.T) {
assert.Nil(t, err)

serviceMi := newServiceMetadataIdentifier()
serviceUrl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER)))

serviceUrl, _ := common.NewURL("registry://console.nacos.io:80",
common.WithParamsValue(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER)),
common.WithParamsValue(constant.ClientNameKey, "nacos-client"))

err = rpt.SaveServiceMetadata(serviceMi, serviceUrl)
assert.Nil(t, err)

Expand Down Expand Up @@ -97,7 +102,16 @@ func TestNacosMetadataReportFactory_CreateMetadataReport(t *testing.T) {
}

func newTestReport() report.MetadataReport {
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER)))
params := url.Values{}
params.Set(constant.NacosNotLoadLocalCache, "true")

params.Set(constant.NacosNamespaceID, "nacos")
params.Set(constant.TimeoutKey, "5s")
params.Set(constant.ClientNameKey, "nacos-client")
params.Set(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER))

regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(params))

res := extension.GetMetadataReportFactory("nacos").CreateMetadataReport(regurl)
return res
}
Expand Down
17 changes: 13 additions & 4 deletions registry/nacos/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ func TestNacosRegistry_Register(t *testing.T) {
if !checkNacosServerAlive() {
return
}
regurlMap := url.Values{}
regurlMap.Set(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER))
regurlMap.Set(constant.NacosNotLoadLocalCache, "true")
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap))
params := url.Values{}
params.Set(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER))
params.Set(constant.NacosNotLoadLocalCache, "true")
params.Set(constant.ClientNameKey, "nacos-client")

regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(params))

urlMap := url.Values{}
urlMap.Set(constant.GroupKey, "guangzhou-idc")
urlMap.Set(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER))
urlMap.Set(constant.InterfaceKey, "com.ikurento.user.UserProvider")
urlMap.Set(constant.VersionKey, "1.0.0")
urlMap.Set(constant.ClusterKey, "mock")
urlMap.Set(constant.ClientNameKey, "nacos-client")
testUrl, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))

reg, err := newNacosRegistry(regurl)
Expand Down Expand Up @@ -82,6 +85,7 @@ func TestNacosRegistry_Subscribe(t *testing.T) {
regurlMap := url.Values{}
regurlMap.Set(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER))
regurlMap.Set(constant.NacosNotLoadLocalCache, "true")
regurlMap.Set(constant.ClientNameKey, "nacos-client")
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap))

urlMap := url.Values{}
Expand All @@ -91,6 +95,7 @@ func TestNacosRegistry_Subscribe(t *testing.T) {
urlMap.Set(constant.VersionKey, "1.0.0")
urlMap.Set(constant.ClusterKey, "mock")
urlMap.Set(constant.NacosPathKey, "")
urlMap.Set(constant.ClientNameKey, "nacos-client")
testUrl, _ := common.NewURL("dubbo://127.0.0.1:20000/com.dubbo.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))

reg, _ := newNacosRegistry(regurl)
Expand Down Expand Up @@ -126,6 +131,7 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) {
regurlMap := url.Values{}
regurlMap.Set(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER))
regurlMap.Set(constant.NacosNotLoadLocalCache, "true")
regurlMap.Set(constant.ClientNameKey, "nacos-client")
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap))

urlMap := url.Values{}
Expand All @@ -135,6 +141,7 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) {
urlMap.Set(constant.VersionKey, "2.0.0")
urlMap.Set(constant.ClusterKey, "mock")
urlMap.Set(constant.NacosPathKey, "")
urlMap.Set(constant.ClientNameKey, "nacos-client")
url1, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
url2, _ := common.NewURL("dubbo://127.0.0.2:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))

Expand Down Expand Up @@ -200,6 +207,7 @@ func TestNacosListener_Close(t *testing.T) {
regurlMap := url.Values{}
regurlMap.Set(constant.RegistryRoleKey, strconv.Itoa(common.PROVIDER))
regurlMap.Set(constant.NacosNotLoadLocalCache, "true")
regurlMap.Set(constant.ClientNameKey, "nacos-client")
regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap))

urlMap := url.Values{}
Expand All @@ -209,6 +217,7 @@ func TestNacosListener_Close(t *testing.T) {
urlMap.Set(constant.VersionKey, "1.0.0")
urlMap.Set(constant.ClusterKey, "mock")
urlMap.Set(constant.NacosPathKey, "")
urlMap.Set(constant.ClientNameKey, "nacos-client")
url1, _ := common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider2", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
reg, _ := newNacosRegistry(regurl)
listener, err := reg.(*nacosRegistry).subscribe(url1)
Expand Down