diff --git a/registry/nacos/base_registry.go b/registry/nacos/base_registry.go index b6ce09bc715b3b0775820629ff8d07863dbd6675..a92df4cdc20471b8c61e44a13a1ce5670af67607 100644 --- a/registry/nacos/base_registry.go +++ b/registry/nacos/base_registry.go @@ -22,12 +22,16 @@ import ( "strconv" "strings" "time" +) +import ( "github.com/nacos-group/nacos-sdk-go/clients" "github.com/nacos-group/nacos-sdk-go/clients/naming_client" nacosConstant "github.com/nacos-group/nacos-sdk-go/common/constant" perrors "github.com/pkg/errors" +) +import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" ) diff --git a/registry/nacos/service_discovery.go b/registry/nacos/service_discovery.go index 746ab7088bee92151b350f2bb4dfe9b31bcd975c..5a730e935d1fe7ff852cb8af8ab0f0de2345f257 100644 --- a/registry/nacos/service_discovery.go +++ b/registry/nacos/service_discovery.go @@ -23,7 +23,9 @@ import ( "github.com/nacos-group/nacos-sdk-go/model" "github.com/nacos-group/nacos-sdk-go/vo" perrors "github.com/pkg/errors" +) +import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" @@ -105,7 +107,7 @@ func (n *nacosServiceDiscovery) GetServices() *gxset.HashSet { } for _, e := range services { - res.Add(e) + res.Add(e.Name) } return res } @@ -249,7 +251,7 @@ func (n *nacosServiceDiscovery) toRegisterInstance(instance registry.ServiceInst Enable: instance.IsEnable(), Healthy: instance.IsHealthy(), GroupName: n.group, - Ephemeral: true, + Ephemeral: true, } } diff --git a/registry/nacos/service_discovery_test.go b/registry/nacos/service_discovery_test.go index 6d59b4ad89ad765c48a178600e08f913b4b33332..a756e8669301919d406a4bcf0e1c962cf532a5c6 100644 --- a/registry/nacos/service_discovery_test.go +++ b/registry/nacos/service_discovery_test.go @@ -20,9 +20,13 @@ package nacos import ( "strconv" "testing" +) +import ( "github.com/stretchr/testify/assert" +) +import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" @@ -65,20 +69,6 @@ func TestNacosServiceDiscovery_CRUD(t *testing.T) { Port: port, }) - // serviceDiscovry.Unregister(®istry.DefaultServiceInstance{ - // Id: id, - // ServiceName: serviceName, - // Host: host, - // Port: 321, - // }) - // - // serviceDiscovry.Unregister(®istry.DefaultServiceInstance{ - // Id: id, - // ServiceName: serviceName, - // Host: "my.c", - // Port: 321, - // }) - err := serviceDiscovry.Register(instance) assert.Nil(t, err) @@ -97,7 +87,6 @@ func TestNacosServiceDiscovery_CRUD(t *testing.T) { assert.Equal(t, serviceName, instance.GetServiceName()) assert.Equal(t, 0, len(instance.GetMetadata())) - instance.Metadata["a"] = "b" err = serviceDiscovry.Update(instance) @@ -112,6 +101,19 @@ func TestNacosServiceDiscovery_CRUD(t *testing.T) { instance = page.GetData()[0].(*registry.DefaultServiceInstance) v, _ := instance.Metadata["a"] assert.Equal(t, "b", v) + + // test dispatcher event + err = serviceDiscovry.DispatchEventByServiceName(serviceName) + assert.Nil(t, err) + + // test AddListener + err = serviceDiscovry.AddListener(®istry.ServiceInstancesChangedListener{}) + assert.Nil(t, err) +} + +func TestNacosServiceDiscovery_GetDefaultPageSize(t *testing.T) { + serviceDiscovry, _ := extension.GetServiceDiscovery(constant.NACOS_KEY, mockUrl()) + assert.Equal(t, registry.DefaultPageSize, serviceDiscovry.GetDefaultPageSize()) } func mockUrl() *common.URL {