@@ -18,6 +18,7 @@ package zookeeper
18
18
19
19
import (
20
20
"fmt"
21
+ "strconv"
21
22
"sync"
22
23
"testing"
23
24
)
@@ -30,16 +31,28 @@ import (
30
31
31
32
import (
32
33
"github.com/apache/dubbo-go/common"
34
+ "github.com/apache/dubbo-go/common/constant"
33
35
"github.com/apache/dubbo-go/config_center"
34
36
"github.com/apache/dubbo-go/config_center/parser"
35
37
)
36
38
37
39
func initZkData (group string , t * testing.T ) (* zk.TestCluster , * zookeeperDynamicConfiguration ) {
38
- regurl , _ := common .NewURL ("registry://127.0.0.1:1111" )
39
- ts , reg , err := newMockZookeeperDynamicConfiguration (& regurl )
40
- reg .SetParser (& parser.DefaultConfigurationParser {})
41
-
40
+ ts , err := zk .StartTestCluster (1 , nil , nil )
41
+ assert .NoError (t , err )
42
+ assert .NotNil (t , ts .Servers [0 ])
43
+ urlString := "registry://127.0.0.1:" + strconv .Itoa (ts .Servers [0 ].Port )
44
+ regurl , err := common .NewURL (urlString )
45
+ assert .NoError (t , err )
46
+ regurl .AddParam (constant .REGISTRY_TIMEOUT_KEY , "15s" )
47
+ zkFactory := & zookeeperDynamicConfigurationFactory {}
48
+ reg , err := zkFactory .GetDynamicConfiguration (& regurl )
49
+ zreg , ok := reg .(* zookeeperDynamicConfiguration )
50
+ assert .True (t , ok )
42
51
assert .NoError (t , err )
52
+ assert .True (t , zreg .IsAvailable ())
53
+ assert .Equal (t , zreg .GetUrl (), regurl )
54
+ assert .True (t , zreg .RestartCallBack ())
55
+ zreg .SetParser (& parser.DefaultConfigurationParser {})
43
56
44
57
data := `
45
58
dubbo.consumer.request_timeout=5s
@@ -63,20 +76,20 @@ func initZkData(group string, t *testing.T) (*zk.TestCluster, *zookeeperDynamicC
63
76
dubbo.service.com.ikurento.user.UserProvider.cluster=failover
64
77
`
65
78
if group != "" {
66
- err = reg .client .Create (reg .rootPath + "/dubbo/dubbo.properties" )
79
+ err = zreg .client .Create (zreg .rootPath + "/dubbo/dubbo.properties" )
67
80
assert .NoError (t , err )
68
81
69
- _ , err = reg .client .Conn .Set (reg .rootPath + "/dubbo/dubbo.properties" , []byte (data ), 0 )
82
+ _ , err = zreg .client .Conn .Set (zreg .rootPath + "/dubbo/dubbo.properties" , []byte (data ), 0 )
70
83
assert .NoError (t , err )
71
84
} else {
72
- err = reg .client .Create (reg .rootPath + "/dubbo.properties" )
85
+ err = zreg .client .Create (zreg .rootPath + "/dubbo.properties" )
73
86
assert .NoError (t , err )
74
87
75
- _ , err = reg .client .Conn .Set (reg .rootPath + "/dubbo.properties" , []byte (data ), 0 )
88
+ _ , err = zreg .client .Conn .Set (zreg .rootPath + "/dubbo.properties" , []byte (data ), 0 )
76
89
assert .NoError (t , err )
77
90
}
78
91
79
- return ts , reg
92
+ return ts , zreg
80
93
}
81
94
82
95
func Test_GetConfig (t * testing.T ) {
@@ -87,6 +100,12 @@ func Test_GetConfig(t *testing.T) {
87
100
m , err := reg .Parser ().Parse (configs )
88
101
assert .NoError (t , err )
89
102
assert .Equal (t , "5s" , m ["dubbo.consumer.request_timeout" ])
103
+ configs , err = reg .GetProperties ("dubbo.properties" )
104
+ assert .Error (t , err )
105
+ configs , err = reg .GetInternalProperty ("dubbo.properties" )
106
+ assert .Error (t , err )
107
+ configs , err = reg .GetRule ("dubbo.properties" )
108
+ assert .Error (t , err )
90
109
}
91
110
92
111
func Test_AddListener (t * testing.T ) {
0 commit comments