Skip to content
Snippets Groups Projects
Commit 85c89b77 authored by 高辛格's avatar 高辛格
Browse files

revert

parent dd8728e1
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
)
func Test_Register(t *testing.T) {
func TestNacosRegistry_Register(t *testing.T) {
regurl, _ := common.NewURL(context.TODO(), "registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
urlMap := url.Values{}
urlMap.Set(constant.GROUP_KEY, "guangzhou-idc")
......@@ -85,71 +85,71 @@ func TestNacosRegistry_Subscribe(t *testing.T) {
}
//func TestNacosRegistry_Subscribe_del(t *testing.T) {
// regurl, _ := common.NewURL(context.TODO(), "registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
// urlMap := url.Values{}
// urlMap.Set(constant.GROUP_KEY, "guangzhou-idc")
// 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")
// urlMap.Set(constant.NACOS_PATH_KEY, "")
// url1, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
// url2, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.2:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
//
// reg, _ := newNacosRegistry(&regurl)
// err := reg.Register(url1)
// assert.Nil(t, err)
// if err != nil {
// t.Errorf("register1 error:%s \n", err.Error())
// return
// }
// err = reg.Register(url2)
// assert.Nil(t, err)
// if err != nil {
// t.Errorf("register2 error:%s \n", err.Error())
// return
// }
//
// regurl.Params.Set(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
// reg2, _ := newNacosRegistry(&regurl)
// listener, err := reg2.Subscribe(url1)
// assert.Nil(t, err)
// if err != nil {
// t.Errorf("subscribe error:%s \n", err.Error())
// return
// }
//
// serviceEvent1, _ := listener.Next()
// assert.NoError(t, err)
// if err != nil {
// t.Errorf("listener1 error:%s \n", err.Error())
// return
// }
// t.Logf("serviceEvent1:%+v \n", serviceEvent1)
// assert.Regexp(t, ".*ServiceEvent{Action{add}.*", serviceEvent1.String())
//
// serviceEvent2, _ := listener.Next()
// assert.NoError(t, err)
// if err != nil {
// t.Errorf("listener2 error:%s \n", err.Error())
// return
// }
// t.Logf("serviceEvent2:%+v \n", serviceEvent2)
// assert.Regexp(t, ".*ServiceEvent{Action{add}.*", serviceEvent2.String())
//
// nacosReg := reg.(*nacosRegistry)
// //deregister instance to mock instance offline
// nacosReg.namingClient.DeregisterInstance(vo.DeregisterInstanceParam{Ip: "127.0.0.2", Port: 20000, ServiceName: "providers:com.ikurento.user.UserProvider:1.0.0:guangzhou-idc"})
//
// serviceEvent3, _ := listener.Next()
// assert.NoError(t, err)
// if err != nil {
// return
// }
// t.Logf("serviceEvent3:%+v \n", serviceEvent3)
// assert.Regexp(t, ".*ServiceEvent{Action{delete}.*", serviceEvent3.String())
//}
func TestNacosRegistry_Subscribe_del(t *testing.T) {
regurl, _ := common.NewURL(context.TODO(), "registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
urlMap := url.Values{}
urlMap.Set(constant.GROUP_KEY, "guangzhou-idc")
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")
urlMap.Set(constant.NACOS_PATH_KEY, "")
url1, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
url2, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.2:20000/com.ikurento.user.UserProvider", common.WithParams(urlMap), common.WithMethods([]string{"GetUser", "AddUser"}))
reg, _ := newNacosRegistry(&regurl)
err := reg.Register(url1)
assert.Nil(t, err)
if err != nil {
t.Errorf("register1 error:%s \n", err.Error())
return
}
err = reg.Register(url2)
assert.Nil(t, err)
if err != nil {
t.Errorf("register2 error:%s \n", err.Error())
return
}
regurl.Params.Set(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
reg2, _ := newNacosRegistry(&regurl)
listener, err := reg2.Subscribe(url1)
assert.Nil(t, err)
if err != nil {
t.Errorf("subscribe error:%s \n", err.Error())
return
}
serviceEvent1, _ := listener.Next()
assert.NoError(t, err)
if err != nil {
t.Errorf("listener1 error:%s \n", err.Error())
return
}
t.Logf("serviceEvent1:%+v \n", serviceEvent1)
assert.Regexp(t, ".*ServiceEvent{Action{add}.*", serviceEvent1.String())
serviceEvent2, _ := listener.Next()
assert.NoError(t, err)
if err != nil {
t.Errorf("listener2 error:%s \n", err.Error())
return
}
t.Logf("serviceEvent2:%+v \n", serviceEvent2)
assert.Regexp(t, ".*ServiceEvent{Action{add}.*", serviceEvent2.String())
nacosReg := reg.(*nacosRegistry)
//deregister instance to mock instance offline
nacosReg.namingClient.DeregisterInstance(vo.DeregisterInstanceParam{Ip: "127.0.0.2", Port: 20000, ServiceName: "providers:com.ikurento.user.UserProvider:1.0.0:guangzhou-idc"})
serviceEvent3, _ := listener.Next()
assert.NoError(t, err)
if err != nil {
return
}
t.Logf("serviceEvent3:%+v \n", serviceEvent3)
assert.Regexp(t, ".*ServiceEvent{Action{delete}.*", serviceEvent3.String())
}
func TestNacosListener_Close(t *testing.T) {
regurl, _ := common.NewURL(context.TODO(), "registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
......
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