Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
c2f29590
Commit
c2f29590
authored
Jun 3, 2020
by
Patrick Jiang(白泽)
Committed by
GitHub
Jun 3, 2020
Browse files
Options
Downloads
Plain Diff
Merge pull request #549 from Patrick0308/config-center-zk-test-cover
Improve code coverage of zookeeper config center
parents
4eedccd5
51ca7ce1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
config_center/zookeeper/impl.go
+0
-28
0 additions, 28 deletions
config_center/zookeeper/impl.go
config_center/zookeeper/impl_test.go
+28
-9
28 additions, 9 deletions
config_center/zookeeper/impl_test.go
with
28 additions
and
37 deletions
config_center/zookeeper/impl.go
+
0
−
28
View file @
c2f29590
...
...
@@ -20,11 +20,9 @@ package zookeeper
import
(
"strings"
"sync"
"time"
)
import
(
"github.com/dubbogo/go-zookeeper/zk"
gxset
"github.com/dubbogo/gost/container/set"
perrors
"github.com/pkg/errors"
)
...
...
@@ -81,32 +79,6 @@ func newZookeeperDynamicConfiguration(url *common.URL) (*zookeeperDynamicConfigu
}
func
newMockZookeeperDynamicConfiguration
(
url
*
common
.
URL
,
opts
...
zookeeper
.
Option
)
(
*
zk
.
TestCluster
,
*
zookeeperDynamicConfiguration
,
error
)
{
c
:=
&
zookeeperDynamicConfiguration
{
url
:
url
,
rootPath
:
"/"
+
url
.
GetParam
(
constant
.
CONFIG_NAMESPACE_KEY
,
config_center
.
DEFAULT_GROUP
)
+
"/config"
,
}
var
(
tc
*
zk
.
TestCluster
err
error
)
tc
,
c
.
client
,
_
,
err
=
zookeeper
.
NewMockZookeeperClient
(
"test"
,
15
*
time
.
Second
,
opts
...
)
if
err
!=
nil
{
logger
.
Errorf
(
"mock zookeeper client start error ,error message is %v"
,
err
)
return
tc
,
c
,
err
}
c
.
wg
.
Add
(
1
)
go
zookeeper
.
HandleClientRestart
(
c
)
c
.
listener
=
zookeeper
.
NewZkEventListener
(
c
.
client
)
c
.
cacheListener
=
NewCacheListener
(
c
.
rootPath
)
err
=
c
.
client
.
Create
(
c
.
rootPath
)
go
c
.
listener
.
ListenServiceEvent
(
url
,
c
.
rootPath
,
c
.
cacheListener
)
return
tc
,
c
,
err
}
func
(
c
*
zookeeperDynamicConfiguration
)
AddListener
(
key
string
,
listener
config_center
.
ConfigurationListener
,
opions
...
config_center
.
Option
)
{
c
.
cacheListener
.
AddListener
(
key
,
listener
)
}
...
...
This diff is collapsed.
Click to expand it.
config_center/zookeeper/impl_test.go
+
28
−
9
View file @
c2f29590
...
...
@@ -18,6 +18,7 @@ package zookeeper
import
(
"fmt"
"strconv"
"sync"
"testing"
)
...
...
@@ -30,16 +31,28 @@ import (
import
(
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/config_center/parser"
)
func
initZkData
(
group
string
,
t
*
testing
.
T
)
(
*
zk
.
TestCluster
,
*
zookeeperDynamicConfiguration
)
{
regurl
,
_
:=
common
.
NewURL
(
"registry://127.0.0.1:1111"
)
ts
,
reg
,
err
:=
newMockZookeeperDynamicConfiguration
(
&
regurl
)
reg
.
SetParser
(
&
parser
.
DefaultConfigurationParser
{})
ts
,
err
:=
zk
.
StartTestCluster
(
1
,
nil
,
nil
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
ts
.
Servers
[
0
])
urlString
:=
"registry://127.0.0.1:"
+
strconv
.
Itoa
(
ts
.
Servers
[
0
]
.
Port
)
regurl
,
err
:=
common
.
NewURL
(
urlString
)
assert
.
NoError
(
t
,
err
)
regurl
.
AddParam
(
constant
.
REGISTRY_TIMEOUT_KEY
,
"15s"
)
zkFactory
:=
&
zookeeperDynamicConfigurationFactory
{}
reg
,
err
:=
zkFactory
.
GetDynamicConfiguration
(
&
regurl
)
zreg
,
ok
:=
reg
.
(
*
zookeeperDynamicConfiguration
)
assert
.
True
(
t
,
ok
)
assert
.
NoError
(
t
,
err
)
assert
.
True
(
t
,
zreg
.
IsAvailable
())
assert
.
Equal
(
t
,
zreg
.
GetUrl
(),
regurl
)
assert
.
True
(
t
,
zreg
.
RestartCallBack
())
zreg
.
SetParser
(
&
parser
.
DefaultConfigurationParser
{})
data
:=
`
dubbo.consumer.request_timeout=5s
...
...
@@ -63,20 +76,20 @@ func initZkData(group string, t *testing.T) (*zk.TestCluster, *zookeeperDynamicC
dubbo.service.com.ikurento.user.UserProvider.cluster=failover
`
if
group
!=
""
{
err
=
reg
.
client
.
Create
(
reg
.
rootPath
+
"/dubbo/dubbo.properties"
)
err
=
z
reg
.
client
.
Create
(
z
reg
.
rootPath
+
"/dubbo/dubbo.properties"
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
reg
.
client
.
Conn
.
Set
(
reg
.
rootPath
+
"/dubbo/dubbo.properties"
,
[]
byte
(
data
),
0
)
_
,
err
=
z
reg
.
client
.
Conn
.
Set
(
z
reg
.
rootPath
+
"/dubbo/dubbo.properties"
,
[]
byte
(
data
),
0
)
assert
.
NoError
(
t
,
err
)
}
else
{
err
=
reg
.
client
.
Create
(
reg
.
rootPath
+
"/dubbo.properties"
)
err
=
z
reg
.
client
.
Create
(
z
reg
.
rootPath
+
"/dubbo.properties"
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
reg
.
client
.
Conn
.
Set
(
reg
.
rootPath
+
"/dubbo.properties"
,
[]
byte
(
data
),
0
)
_
,
err
=
z
reg
.
client
.
Conn
.
Set
(
z
reg
.
rootPath
+
"/dubbo.properties"
,
[]
byte
(
data
),
0
)
assert
.
NoError
(
t
,
err
)
}
return
ts
,
reg
return
ts
,
z
reg
}
func
Test_GetConfig
(
t
*
testing
.
T
)
{
...
...
@@ -87,6 +100,12 @@ func Test_GetConfig(t *testing.T) {
m
,
err
:=
reg
.
Parser
()
.
Parse
(
configs
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"5s"
,
m
[
"dubbo.consumer.request_timeout"
])
configs
,
err
=
reg
.
GetProperties
(
"dubbo.properties"
)
assert
.
Error
(
t
,
err
)
configs
,
err
=
reg
.
GetInternalProperty
(
"dubbo.properties"
)
assert
.
Error
(
t
,
err
)
configs
,
err
=
reg
.
GetRule
(
"dubbo.properties"
)
assert
.
Error
(
t
,
err
)
}
func
Test_AddListener
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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