Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
3002a665
Commit
3002a665
authored
4 years ago
by
flycash
Browse files
Options
Downloads
Patches
Plain Diff
Test CRUD for instance methods
parent
fa4471a7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
go.mod
+2
-2
2 additions, 2 deletions
go.mod
go.sum
+3
-0
3 additions, 0 deletions
go.sum
registry/nacos/service_discovery.go
+5
-1
5 additions, 1 deletion
registry/nacos/service_discovery.go
registry/nacos/service_discovery_test.go
+82
-9
82 additions, 9 deletions
registry/nacos/service_discovery_test.go
with
92 additions
and
12 deletions
go.mod
+
2
−
2
View file @
3002a665
...
@@ -14,7 +14,7 @@ require (
...
@@ -14,7 +14,7 @@ require (
github.com/creasty/defaults
v1.3.0
github.com/creasty/defaults
v1.3.0
github.com/dubbogo/getty
v1.3.3
github.com/dubbogo/getty
v1.3.3
github.com/dubbogo/go-zookeeper
v1.0.0
github.com/dubbogo/go-zookeeper
v1.0.0
github.com/dubbogo/gost
v1.
7
.0
github.com/dubbogo/gost
v1.
8
.0
github.com/emicklei/go-restful/v3
v3.0.0
github.com/emicklei/go-restful/v3
v3.0.0
github.com/fastly/go-utils
v0.0.0-20180712184237-d95a45783239 // indirect
github.com/fastly/go-utils
v0.0.0-20180712184237-d95a45783239 // indirect
github.com/go-errors/errors
v1.0.1 // indirect
github.com/go-errors/errors
v1.0.1 // indirect
...
@@ -38,7 +38,7 @@ require (
...
@@ -38,7 +38,7 @@ require (
github.com/magiconair/properties
v1.8.1
github.com/magiconair/properties
v1.8.1
github.com/mitchellh/mapstructure
v1.1.2
github.com/mitchellh/mapstructure
v1.1.2
github.com/modern-go/concurrent
v0.0.0-20180306012644-bacd9c7ef1dd
github.com/modern-go/concurrent
v0.0.0-20180306012644-bacd9c7ef1dd
github.com/nacos-group/nacos-sdk-go
v0.0.0-2019
0723125407-0242d42e3dbb
github.com/nacos-group/nacos-sdk-go
v0.0.0-2019
1128082542-fe1b325b125c
github.com/opentracing/opentracing-go
v1.1.0
github.com/opentracing/opentracing-go
v1.1.0
github.com/pkg/errors
v0.8.1
github.com/pkg/errors
v0.8.1
github.com/prometheus/client_golang
v1.1.0
github.com/prometheus/client_golang
v1.1.0
...
...
This diff is collapsed.
Click to expand it.
go.sum
+
3
−
0
View file @
3002a665
...
@@ -115,6 +115,8 @@ github.com/dubbogo/gost v1.5.2 h1:ri/03971hdpnn3QeCU+4UZgnRNGDXLDGDucR/iozZm8=
...
@@ -115,6 +115,8 @@ github.com/dubbogo/gost v1.5.2 h1:ri/03971hdpnn3QeCU+4UZgnRNGDXLDGDucR/iozZm8=
github.com/dubbogo/gost
v1.5.2/go.mod h1:
pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost
v1.5.2/go.mod h1:
pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost
v1.7.0 h1:
lWNBIE2hk1Aj2be2uXkyRTpZG0RQZj0/xbXnkIq6EHE=
github.com/dubbogo/gost
v1.7.0 h1:
lWNBIE2hk1Aj2be2uXkyRTpZG0RQZj0/xbXnkIq6EHE=
github.com/dubbogo/gost
v1.7.0/go.mod h1:
pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost
v1.7.0/go.mod h1:
pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost
v1.8.0 h1:
9ACbQe5OwMjqtinQcNJC5xp16kky27OsfSGw5L9A6vw=
github.com/dubbogo/gost
v1.8.0/go.mod h1:
pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/duosecurity/duo_api_golang
v0.0.0-20190308151101-6c680f768e74 h1:
2MIhn2R6oXQbgW5yHfS+d6YqyMfXiu2L55rFZC4UD/M=
github.com/duosecurity/duo_api_golang
v0.0.0-20190308151101-6c680f768e74 h1:
2MIhn2R6oXQbgW5yHfS+d6YqyMfXiu2L55rFZC4UD/M=
github.com/duosecurity/duo_api_golang
v0.0.0-20190308151101-6c680f768e74/go.mod h1:
UqXY1lYT/ERa4OEAywUqdok1T4RCRdArkhic1Opuavo=
github.com/duosecurity/duo_api_golang
v0.0.0-20190308151101-6c680f768e74/go.mod h1:
UqXY1lYT/ERa4OEAywUqdok1T4RCRdArkhic1Opuavo=
github.com/elazarl/go-bindata-assetfs
v0.0.0-20160803192304-e1a2a7ec64b0 h1:
ZoRgc53qJCfSLimXqJDrmBhnt5GChDsExMCK7t48o0Y=
github.com/elazarl/go-bindata-assetfs
v0.0.0-20160803192304-e1a2a7ec64b0 h1:
ZoRgc53qJCfSLimXqJDrmBhnt5GChDsExMCK7t48o0Y=
...
@@ -385,6 +387,7 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m
...
@@ -385,6 +387,7 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack
v0.0.0-20161129095857-cc309e4a2223/go.mod h1:
qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack
v0.0.0-20161129095857-cc309e4a2223/go.mod h1:
qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nacos-group/nacos-sdk-go
v0.0.0-20190723125407-0242d42e3dbb h1:
lbmvw8r9W55w+aQgWn35W1nuleRIECMoqUrmwAOAvoI=
github.com/nacos-group/nacos-sdk-go
v0.0.0-20190723125407-0242d42e3dbb h1:
lbmvw8r9W55w+aQgWn35W1nuleRIECMoqUrmwAOAvoI=
github.com/nacos-group/nacos-sdk-go
v0.0.0-20190723125407-0242d42e3dbb/go.mod h1:
CEkSvEpoveoYjA81m4HNeYQ0sge0LFGKSEqO3JKHllo=
github.com/nacos-group/nacos-sdk-go
v0.0.0-20190723125407-0242d42e3dbb/go.mod h1:
CEkSvEpoveoYjA81m4HNeYQ0sge0LFGKSEqO3JKHllo=
github.com/nacos-group/nacos-sdk-go
v0.0.0-20191128082542-fe1b325b125c/go.mod h1:
CEkSvEpoveoYjA81m4HNeYQ0sge0LFGKSEqO3JKHllo=
github.com/nicolai86/scaleway-sdk
v1.10.2-0.20180628010248-798f60e20bb2 h1:
BQ1HW7hr4IVovMwWg0E0PYcyW8CzqDcVmaew9cujU4s=
github.com/nicolai86/scaleway-sdk
v1.10.2-0.20180628010248-798f60e20bb2 h1:
BQ1HW7hr4IVovMwWg0E0PYcyW8CzqDcVmaew9cujU4s=
github.com/nicolai86/scaleway-sdk
v1.10.2-0.20180628010248-798f60e20bb2/go.mod h1:
TLb2Sg7HQcgGdloNxkrmtgDNR9uVYF3lfdFIN4Ro6Sk=
github.com/nicolai86/scaleway-sdk
v1.10.2-0.20180628010248-798f60e20bb2/go.mod h1:
TLb2Sg7HQcgGdloNxkrmtgDNR9uVYF3lfdFIN4Ro6Sk=
github.com/oklog/run
v0.0.0-20180308005104-6934b124db28 h1:
Hbr3fbVPXea52oPQeP7KLSxP52g6SFaNY1IqAmUyEW0=
github.com/oklog/run
v0.0.0-20180308005104-6934b124db28 h1:
Hbr3fbVPXea52oPQeP7KLSxP52g6SFaNY1IqAmUyEW0=
...
...
This diff is collapsed.
Click to expand it.
registry/nacos/service_discovery.go
+
5
−
1
View file @
3002a665
...
@@ -70,7 +70,7 @@ func (n *nacosServiceDiscovery) Register(instance registry.ServiceInstance) erro
...
@@ -70,7 +70,7 @@ func (n *nacosServiceDiscovery) Register(instance registry.ServiceInstance) erro
// so we should unregister the instance and then register it again.
// so we should unregister the instance and then register it again.
// the error handling is hard to implement
// the error handling is hard to implement
func
(
n
*
nacosServiceDiscovery
)
Update
(
instance
registry
.
ServiceInstance
)
error
{
func
(
n
*
nacosServiceDiscovery
)
Update
(
instance
registry
.
ServiceInstance
)
error
{
// T
he
// T
ODO(wait for nacos support)
err
:=
n
.
Unregister
(
instance
)
err
:=
n
.
Unregister
(
instance
)
if
err
!=
nil
{
if
err
!=
nil
{
return
perrors
.
WithStack
(
err
)
return
perrors
.
WithStack
(
err
)
...
@@ -237,6 +237,9 @@ func (n *nacosServiceDiscovery) DispatchEvent(event *registry.ServiceInstancesCh
...
@@ -237,6 +237,9 @@ func (n *nacosServiceDiscovery) DispatchEvent(event *registry.ServiceInstancesCh
func
(
n
*
nacosServiceDiscovery
)
toRegisterInstance
(
instance
registry
.
ServiceInstance
)
vo
.
RegisterInstanceParam
{
func
(
n
*
nacosServiceDiscovery
)
toRegisterInstance
(
instance
registry
.
ServiceInstance
)
vo
.
RegisterInstanceParam
{
metadata
:=
instance
.
GetMetadata
()
metadata
:=
instance
.
GetMetadata
()
if
metadata
==
nil
{
metadata
=
make
(
map
[
string
]
string
,
1
)
}
metadata
[
idKey
]
=
instance
.
GetId
()
metadata
[
idKey
]
=
instance
.
GetId
()
return
vo
.
RegisterInstanceParam
{
return
vo
.
RegisterInstanceParam
{
ServiceName
:
instance
.
GetServiceName
(),
ServiceName
:
instance
.
GetServiceName
(),
...
@@ -246,6 +249,7 @@ func (n *nacosServiceDiscovery) toRegisterInstance(instance registry.ServiceInst
...
@@ -246,6 +249,7 @@ func (n *nacosServiceDiscovery) toRegisterInstance(instance registry.ServiceInst
Enable
:
instance
.
IsEnable
(),
Enable
:
instance
.
IsEnable
(),
Healthy
:
instance
.
IsHealthy
(),
Healthy
:
instance
.
IsHealthy
(),
GroupName
:
n
.
group
,
GroupName
:
n
.
group
,
Ephemeral
:
true
,
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
registry/nacos/service_discovery_test.go
+
82
−
9
View file @
3002a665
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
package
nacos
package
nacos
import
(
import
(
"net/url"
"strconv"
"strconv"
"testing"
"testing"
...
@@ -27,21 +26,95 @@ import (
...
@@ -27,21 +26,95 @@ import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/registry"
)
)
func
TestNacosServiceDiscovery_Destroy
(
t
*
testing
.
T
)
{
func
TestNacosServiceDiscovery_Destroy
(
t
*
testing
.
T
)
{
serviceDiscovry
,
err
:=
extension
.
GetServiceDiscovery
(
constant
.
NACOS_KEY
,
mockUrl
())
serviceDiscovry
,
err
:=
extension
.
GetServiceDiscovery
(
constant
.
NACOS_KEY
,
mockUrl
())
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
serviceDiscovry
)
assert
.
NotNil
(
t
,
serviceDiscovry
)
err
=
serviceDiscovry
.
Destroy
()
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
serviceDiscovry
.
(
*
nacosServiceDiscovery
)
.
namingClient
)
}
func
TestNacosServiceDiscovery_CRUD
(
t
*
testing
.
T
)
{
serviceName
:=
"service-name"
id
:=
"id"
host
:=
"host"
port
:=
123
instance
:=
&
registry
.
DefaultServiceInstance
{
Id
:
id
,
ServiceName
:
serviceName
,
Host
:
host
,
Port
:
port
,
Enable
:
true
,
Healthy
:
true
,
Metadata
:
nil
,
}
// clean data
serviceDiscovry
,
_
:=
extension
.
GetServiceDiscovery
(
constant
.
NACOS_KEY
,
mockUrl
())
// clean data for local test
serviceDiscovry
.
Unregister
(
&
registry
.
DefaultServiceInstance
{
Id
:
id
,
ServiceName
:
serviceName
,
Host
:
host
,
Port
:
port
,
})
// serviceDiscovry.Unregister(®istry.DefaultServiceInstance{
// Id: id,
// ServiceName: serviceName,
// Host: host,
// Port: 321,
// })
//
// serviceDiscovry.Unregister(®istry.DefaultServiceInstance{
// Id: id,
// ServiceName: serviceName,
// Host: "my.c",
// Port: 321,
// })
err
:=
serviceDiscovry
.
Register
(
instance
)
assert
.
Nil
(
t
,
err
)
page
:=
serviceDiscovry
.
GetHealthyInstancesByPage
(
serviceName
,
0
,
10
,
true
)
assert
.
NotNil
(
t
,
page
)
assert
.
Equal
(
t
,
0
,
page
.
GetOffset
())
assert
.
Equal
(
t
,
10
,
page
.
GetPageSize
())
assert
.
Equal
(
t
,
1
,
page
.
GetDataSize
())
instance
=
page
.
GetData
()[
0
]
.
(
*
registry
.
DefaultServiceInstance
)
assert
.
NotNil
(
t
,
instance
)
assert
.
Equal
(
t
,
id
,
instance
.
GetId
())
assert
.
Equal
(
t
,
host
,
instance
.
GetHost
())
assert
.
Equal
(
t
,
port
,
instance
.
GetPort
())
assert
.
Equal
(
t
,
serviceName
,
instance
.
GetServiceName
())
assert
.
Equal
(
t
,
0
,
len
(
instance
.
GetMetadata
()))
instance
.
Metadata
[
"a"
]
=
"b"
err
=
serviceDiscovry
.
Update
(
instance
)
assert
.
Nil
(
t
,
err
)
pageMap
:=
serviceDiscovry
.
GetRequestInstances
([]
string
{
serviceName
},
0
,
1
)
assert
.
Equal
(
t
,
1
,
len
(
pageMap
))
page
=
pageMap
[
serviceName
]
assert
.
NotNil
(
t
,
page
)
assert
.
Equal
(
t
,
1
,
len
(
page
.
GetData
()))
instance
=
page
.
GetData
()[
0
]
.
(
*
registry
.
DefaultServiceInstance
)
v
,
_
:=
instance
.
Metadata
[
"a"
]
assert
.
Equal
(
t
,
"b"
,
v
)
}
}
func
mockUrl
()
*
common
.
URL
{
func
mockUrl
()
*
common
.
URL
{
urlMap
:=
url
.
Values
{}
regurl
,
_
:=
common
.
NewURL
(
"registry://console.nacos.io:80"
,
common
.
WithParamsValue
(
constant
.
ROLE_KEY
,
strconv
.
Itoa
(
common
.
PROVIDER
)))
urlMap
.
Set
(
constant
.
GROUP_KEY
,
"guangzhou-idc"
)
return
&
regurl
urlMap
.
Set
(
constant
.
ROLE_KEY
,
strconv
.
Itoa
(
common
.
PROVIDER
))
urlMap
.
Set
(
constant
.
INTERFACE_KEY
,
"com.ikurento.user.UserProvider"
)
urlMap
.
Set
(
constant
.
VERSION_KEY
,
"1.0.0"
)
urlMap
.
Set
(
constant
.
CLUSTER_KEY
,
"mock"
)
url
,
_
:=
common
.
NewURL
(
"dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider"
,
common
.
WithParams
(
urlMap
),
common
.
WithMethods
([]
string
{
"GetUser"
,
"AddUser"
}))
return
&
url
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment