Skip to content
Snippets Groups Projects
Commit 274718b6 authored by Xin.Zh's avatar Xin.Zh Committed by AlexStocks
Browse files

Merge pull request #1066 from yakecanlee/feature/fix-zk-configurators

Fix: fix zk listener func pathToKey
parents 7cdd4c4b 8b171be5
No related branches found
No related tags found
No related merge requests found
...@@ -194,7 +194,22 @@ make test ...@@ -194,7 +194,22 @@ make test
</table> </table>
</div> </div>
如果想加入到社区微信群,可以先添加社区负责人 于雨 的微信 AlexanderStocks 。添加微信之前,请先给 dubbo-go 点 star 作为对项目的支持,添加好友时请报上 github ID 以进行验证。 dubbogo 社区已经开通微信公众号 "dubbogo大区",可在微信搜索 "dubbogo大区" 或者扫描如下二维码关注,可通过公众号私信留言加入 dubbogo 微信社区。
<div>
<table>
<tbody>
<tr></tr>
<tr>
<td align="center" valign="middle">
<img width="80px" height="115px" src="./doc/pic/misc/dubbogo-wechat.png">
</a>
</td>
</tr>
<tr></tr>
</tbody>
</table>
</div>
作为一个维护已经帮助构建了经受多家大型微服务系统的社区,我们足以为现有的成绩感到自豪。社区欢迎能提出建设性意见者,只知索取者和喷子请绕行。 作为一个维护已经帮助构建了经受多家大型微服务系统的社区,我们足以为现有的成绩感到自豪。社区欢迎能提出建设性意见者,只知索取者和喷子请绕行。
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
) )
import ( import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/config_center" "github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/remoting" "github.com/apache/dubbo-go/remoting"
) )
...@@ -77,5 +78,12 @@ func (l *CacheListener) DataChange(event remoting.Event) bool { ...@@ -77,5 +78,12 @@ func (l *CacheListener) DataChange(event remoting.Event) bool {
} }
func (l *CacheListener) pathToKey(path string) string { func (l *CacheListener) pathToKey(path string) string {
return strings.Replace(strings.Replace(path, l.rootPath+"/", "", -1), "/", ".", -1) key := strings.Replace(strings.Replace(path, l.rootPath+"/", "", -1), "/", ".", -1)
if strings.HasSuffix(key, constant.CONFIGURATORS_SUFFIX) ||
strings.HasSuffix(key, constant.TagRouterRuleSuffix) ||
strings.HasSuffix(key, constant.ConditionRouterRuleSuffix) {
//governance config, so we remove the "dubbo." prefix
return key[strings.Index(key, ".")+1:]
}
return key
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package zookeeper
import (
"path"
"strconv"
"testing"
)
import (
"github.com/dubbogo/go-zookeeper/zk"
"github.com/stretchr/testify/assert"
)
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/config_center/parser"
)
func initZkDynamicConfiguration(t *testing.T) (*zk.TestCluster, *zookeeperDynamicConfiguration) {
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.application.name=dubbogo
`
err = zreg.client.Create(path.Join(zreg.rootPath, dubboPropertyFileName))
assert.NoError(t, err)
_, err = zreg.client.Conn.Set(path.Join(zreg.rootPath, dubboPropertyFileName), []byte(data), 0)
assert.NoError(t, err)
return ts, zreg
}
func TestZookeeperDynamicConfigurationPathToKey(t *testing.T) {
ts, reg := initZkDynamicConfiguration(t)
defer func() {
err := ts.Stop()
assert.NoError(t, err)
}()
listener := &mockDataListener{}
key := path.Join("dubbogoDemo" + constant.CONFIGURATORS_SUFFIX)
reg.AddListener(key, listener)
listener.wg.Add(1)
data := `
scope: application
key: dubbogoDemo
enabled: true
configs:
- addresses: [0.0.0.0:20880]
side: provider
parameters:
weight: 60
- addresses: [0.0.0.0:20881]
side: provider
parameters:
weight: 40
`
zkPath := path.Join(reg.rootPath, "dubbo", key)
exists, _, err := reg.client.Conn.Exists(zkPath)
assert.NoError(t, err)
if !exists {
err = reg.client.Create(zkPath)
assert.NoError(t, err)
}
_, err = reg.client.SetContent(zkPath, []byte(data), 0)
assert.NoError(t, err)
listener.wg.Wait()
assert.Equal(t, key, listener.event)
}
doc/pic/misc/dubbogo-wechat.png

26.6 KiB

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment