Compare commits
3 Commits
4c1e1621f1
...
fbb487cb1b
Author | SHA1 | Date |
---|---|---|
|
fbb487cb1b | |
|
683dce244d | |
|
0cd7a26811 |
|
@ -56,6 +56,8 @@ func (ed *SubscribeCallback) AddCallbackFunc(serviceName string, clusters string
|
||||||
func (ed *SubscribeCallback) RemoveCallbackFunc(serviceName string, clusters string, callbackFunc *func(services []model.Instance, err error)) {
|
func (ed *SubscribeCallback) RemoveCallbackFunc(serviceName string, clusters string, callbackFunc *func(services []model.Instance, err error)) {
|
||||||
logger.Info("removing " + serviceName + " with " + clusters + " to listener map")
|
logger.Info("removing " + serviceName + " with " + clusters + " to listener map")
|
||||||
key := util.GetServiceCacheKey(serviceName, clusters)
|
key := util.GetServiceCacheKey(serviceName, clusters)
|
||||||
|
defer ed.mux.Unlock()
|
||||||
|
ed.mux.Lock()
|
||||||
funcs, ok := ed.callbackFuncMap.Get(key)
|
funcs, ok := ed.callbackFuncMap.Get(key)
|
||||||
if ok && funcs != nil {
|
if ok && funcs != nil {
|
||||||
var newFuncs []*func(services []model.Instance, err error)
|
var newFuncs []*func(services []model.Instance, err error)
|
||||||
|
|
|
@ -30,25 +30,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEventDispatcher_AddCallbackFuncs(t *testing.T) {
|
func TestEventDispatcher_AddCallbackFuncs(t *testing.T) {
|
||||||
service := model.Service{
|
|
||||||
Clusters: strings.Join([]string{"default"}, ","),
|
|
||||||
CacheMillis: 10000,
|
|
||||||
Checksum: "abcd",
|
|
||||||
LastRefTime: uint64(time.Now().Unix()),
|
|
||||||
}
|
|
||||||
var hosts []model.Instance
|
|
||||||
host := model.Instance{
|
|
||||||
Enable: true,
|
|
||||||
InstanceId: "123",
|
|
||||||
Port: 8080,
|
|
||||||
Ip: "127.0.0.1",
|
|
||||||
Weight: 10,
|
|
||||||
ServiceName: "public@@Test",
|
|
||||||
ClusterName: strings.Join([]string{"default"}, ","),
|
|
||||||
}
|
|
||||||
hosts = append(hosts, host)
|
|
||||||
service.Hosts = hosts
|
|
||||||
|
|
||||||
ed := NewSubscribeCallback()
|
ed := NewSubscribeCallback()
|
||||||
param := vo.SubscribeParam{
|
param := vo.SubscribeParam{
|
||||||
ServiceName: "Test",
|
ServiceName: "Test",
|
||||||
|
@ -70,25 +51,6 @@ func TestEventDispatcher_AddCallbackFuncs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEventDispatcher_RemoveCallbackFuncs(t *testing.T) {
|
func TestEventDispatcher_RemoveCallbackFuncs(t *testing.T) {
|
||||||
service := model.Service{
|
|
||||||
Clusters: strings.Join([]string{"default"}, ","),
|
|
||||||
CacheMillis: 10000,
|
|
||||||
Checksum: "abcd",
|
|
||||||
LastRefTime: uint64(time.Now().Unix()),
|
|
||||||
}
|
|
||||||
var hosts []model.Instance
|
|
||||||
host := model.Instance{
|
|
||||||
Enable: true,
|
|
||||||
InstanceId: "123",
|
|
||||||
Port: 8080,
|
|
||||||
Ip: "127.0.0.1",
|
|
||||||
Weight: 10,
|
|
||||||
ServiceName: "public@@Test",
|
|
||||||
ClusterName: strings.Join([]string{"default"}, ","),
|
|
||||||
}
|
|
||||||
hosts = append(hosts, host)
|
|
||||||
service.Hosts = hosts
|
|
||||||
|
|
||||||
ed := NewSubscribeCallback()
|
ed := NewSubscribeCallback()
|
||||||
param := vo.SubscribeParam{
|
param := vo.SubscribeParam{
|
||||||
ServiceName: "Test",
|
ServiceName: "Test",
|
||||||
|
@ -170,6 +132,6 @@ func TestSubscribeCallback_ServiceChanged(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ed.AddCallbackFunc(util.GetGroupName(param2.ServiceName, param2.GroupName), strings.Join(param2.Clusters, ","), ¶m2.SubscribeCallback)
|
ed.AddCallbackFunc(util.GetGroupName(param2.ServiceName, param2.GroupName), strings.Join(param2.Clusters, ","), ¶m2.SubscribeCallback)
|
||||||
cacheKey := util.GetServiceCacheKey(util.GetGroupName(service.Name, service.GroupName), service.Clusters)
|
cacheKey := util.GetServiceCacheKey(service.Name, service.Clusters)
|
||||||
ed.ServiceChanged(cacheKey, &service)
|
ed.ServiceChanged(cacheKey, &service)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue