From 3d0b1c91ab1699a0cfa8f498de90cdc1e2d74b5f Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Fri, 26 Jun 2020 13:22:34 +0800 Subject: [PATCH 01/19] modify metareport interface --- metadata/report/delegate/delegate_report.go | 14 ++++++++++++-- metadata/report/nacos/report.go | 20 ++------------------ metadata/report/nacos/report_test.go | 7 ++++--- metadata/report/report.go | 2 +- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/metadata/report/delegate/delegate_report.go b/metadata/report/delegate/delegate_report.go index cb7e42030b..282e751443 100644 --- a/metadata/report/delegate/delegate_report.go +++ b/metadata/report/delegate/delegate_report.go @@ -19,6 +19,7 @@ package delegate import ( "encoding/json" + perrors "github.com/pkg/errors" "runtime/debug" "sync" "time" @@ -241,11 +242,20 @@ func (mr *MetadataReport) GetExportedURLs(identifier *identifier.ServiceMetadata // SaveSubscribedData will delegate to call remote metadata's sdk to save subscribed data func (mr *MetadataReport) SaveSubscribedData(identifier *identifier.SubscriberMetadataIdentifier, urls []common.URL) error { + urlStrList := make([]string, 0, len(urls)) + for _, url := range urls { + urlStrList = append(urlStrList, url.String()) + } + bytes, err := json.Marshal(urlStrList) + if err != nil { + return perrors.WithMessage(err, "Could not convert the array to json") + } + report := instance.GetMetadataReportInstance() if mr.syncReport { - return report.SaveSubscribedData(identifier, urls) + return report.SaveSubscribedData(identifier, string(bytes)) } - go report.SaveSubscribedData(identifier, urls) + go report.SaveSubscribedData(identifier, string(bytes)) return nil } diff --git a/metadata/report/nacos/report.go b/metadata/report/nacos/report.go index 8f29c7de0f..312fd27c84 100644 --- a/metadata/report/nacos/report.go +++ b/metadata/report/nacos/report.go @@ -18,7 +18,6 @@ package nacos import ( - "encoding/json" "net/url" ) @@ -98,26 +97,11 @@ func (n *nacosMetadataReport) GetExportedURLs(metadataIdentifier *identifier.Ser } // SaveSubscribedData will convert the urlList to json array and then store it -func (n *nacosMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urlList []common.URL) error { - if len(urlList) == 0 { - logger.Warnf("The url list is empty") - return nil - } - urlStrList := make([]string, 0, len(urlList)) - - for _, e := range urlList { - urlStrList = append(urlStrList, e.String()) - } - - bytes, err := json.Marshal(urlStrList) - - if err != nil { - return perrors.WithMessage(err, "Could not convert the array to json") - } +func (n *nacosMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urlListStr string) error { return n.storeMetadata(vo.ConfigParam{ DataId: subscriberMetadataIdentifier.GetIdentifierKey(), Group: subscriberMetadataIdentifier.Group, - Content: string(bytes), + Content: urlListStr, }) } diff --git a/metadata/report/nacos/report_test.go b/metadata/report/nacos/report_test.go index 19ca2e5a48..254b92363b 100644 --- a/metadata/report/nacos/report_test.go +++ b/metadata/report/nacos/report_test.go @@ -18,6 +18,7 @@ package nacos import ( + "encoding/json" "strconv" "testing" ) @@ -57,9 +58,9 @@ func TestNacosMetadataReport_CRUD(t *testing.T) { assert.Equal(t, 1, len(exportedUrls)) subMi := newSubscribeMetadataIdentifier() - urlList := make([]common.URL, 0, 1) - urlList = append(urlList, serviceUrl) - err = rpt.SaveSubscribedData(subMi, urlList) + urlList := []string{serviceUrl.String()} + bytes, _ := json.Marshal(urlList) + err = rpt.SaveSubscribedData(subMi, string(bytes)) assert.Nil(t, err) subscribeUrl := rpt.GetSubscribedURLs(subMi) diff --git a/metadata/report/report.go b/metadata/report/report.go index 61cdda1f96..d5930dc1fd 100644 --- a/metadata/report/report.go +++ b/metadata/report/report.go @@ -29,7 +29,7 @@ type MetadataReport interface { SaveServiceMetadata(*identifier.ServiceMetadataIdentifier, common.URL) error RemoveServiceMetadata(*identifier.ServiceMetadataIdentifier) error GetExportedURLs(*identifier.ServiceMetadataIdentifier) []string - SaveSubscribedData(*identifier.SubscriberMetadataIdentifier, []common.URL) error + SaveSubscribedData(*identifier.SubscriberMetadataIdentifier, string) error GetSubscribedURLs(*identifier.SubscriberMetadataIdentifier) []string GetServiceDefinition(*identifier.MetadataIdentifier) string } From b8f53463a8714c35539d3bc717e0d7864c1a42c8 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Fri, 26 Jun 2020 16:16:53 +0800 Subject: [PATCH 02/19] fix bug --- metadata/service/remote/service_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/metadata/service/remote/service_test.go b/metadata/service/remote/service_test.go index 308c631e41..0c1de355c1 100644 --- a/metadata/service/remote/service_test.go +++ b/metadata/service/remote/service_test.go @@ -39,7 +39,7 @@ import ( ) var serviceMetadata = make(map[*identifier.ServiceMetadataIdentifier]common.URL, 4) -var subscribedMetadata = make(map[*identifier.SubscriberMetadataIdentifier][]common.URL, 4) +var subscribedMetadata = make(map[*identifier.SubscriberMetadataIdentifier]string, 4) func getMetadataReportFactory() factory.MetadataReportFactory { return &metadataReportFactory{} @@ -77,9 +77,9 @@ func (metadataReport) GetExportedURLs(*identifier.ServiceMetadataIdentifier) []s return nil } -func (mr *metadataReport) SaveSubscribedData(id *identifier.SubscriberMetadataIdentifier, urls []common.URL) error { - logger.Infof("SaveSubscribedData, , url is %v", urls) - subscribedMetadata[id] = urls +func (mr *metadataReport) SaveSubscribedData(id *identifier.SubscriberMetadataIdentifier, urlListStr string) error { + logger.Infof("SaveSubscribedData, , url is %v", urlListStr) + subscribedMetadata[id] = urlListStr return nil } @@ -93,8 +93,7 @@ func (metadataReport) GetServiceDefinition(*identifier.MetadataIdentifier) strin func TestMetadataService(t *testing.T) { extension.SetMetadataReportFactory("mock", getMetadataReportFactory) - u, err := common.NewURL(fmt.Sprintf( - "mock://127.0.0.1:20000/?sync.report=true")) + u, err := common.NewURL(fmt.Sprintf("mock://127.0.0.1:20000/?sync.report=true")) assert.NoError(t, err) instance.GetMetadataReportInstance(&u) mts, err := NewMetadataService() From b2a04fd033a1b223253648a51bf15dc80fa44445 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Fri, 26 Jun 2020 17:40:30 +0800 Subject: [PATCH 03/19] consul metadata report --- metadata/report/consul/report.go | 132 ++++++++++++++++++++++++++ metadata/report/consul/report_test.go | 18 ++++ metadata/report/nacos/report.go | 28 +++--- 3 files changed, 162 insertions(+), 16 deletions(-) create mode 100644 metadata/report/consul/report.go create mode 100644 metadata/report/consul/report_test.go diff --git a/metadata/report/consul/report.go b/metadata/report/consul/report.go new file mode 100644 index 0000000000..8225b22a07 --- /dev/null +++ b/metadata/report/consul/report.go @@ -0,0 +1,132 @@ +/* + * 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 consul + +import ( + consul "github.com/hashicorp/consul/api" +) + +import ( + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/extension" + "github.com/apache/dubbo-go/metadata/identifier" + "github.com/apache/dubbo-go/metadata/report" + "github.com/apache/dubbo-go/metadata/report/factory" +) + +func init() { + mf := &consulMetadataReportFactory{} + extension.SetMetadataReportFactory("consul", func() factory.MetadataReportFactory { + return mf + }) +} + +// consulMetadataReport is the implementation of +// MetadataReport based on Consul. +type consulMetadataReport struct { + client *consul.Client +} + +// StoreProviderMetadata stores the metadata. +func (m *consulMetadataReport) StoreProviderMetadata(providerIdentifier *identifier.MetadataIdentifier, serviceDefinitions string) error { + kv := &consul.KVPair{Key: providerIdentifier.GetIdentifierKey(), Value: []byte(serviceDefinitions)} + _, err := m.client.KV().Put(kv, nil) + return err +} + +// StoreConsumerMetadata stores the metadata. +func (m *consulMetadataReport) StoreConsumerMetadata(consumerMetadataIdentifier *identifier.MetadataIdentifier, serviceParameterString string) error { + kv := &consul.KVPair{Key: consumerMetadataIdentifier.GetIdentifierKey(), Value: []byte(serviceParameterString)} + _, err := m.client.KV().Put(kv, nil) + return err +} + +// SaveServiceMetadata saves the metadata. +func (m *consulMetadataReport) SaveServiceMetadata(metadataIdentifier *identifier.ServiceMetadataIdentifier, url common.URL) error { + kv := &consul.KVPair{Key: metadataIdentifier.GetIdentifierKey(), Value: []byte(url.String())} + _, err := m.client.KV().Put(kv, nil) + return err +} + +// RemoveServiceMetadata removes the metadata. +func (m *consulMetadataReport) RemoveServiceMetadata(metadataIdentifier *identifier.ServiceMetadataIdentifier) error { + k := metadataIdentifier.GetIdentifierKey() + _, err := m.client.KV().Delete(k, nil) + return err +} + +// GetExportedURLs gets the urls. +func (m *consulMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) []string { + k := metadataIdentifier.GetIdentifierKey() + kv, _, err := m.client.KV().Get(k, nil) + if err != nil { + panic(err) + } + + if kv == nil { + return []string{} + } + return []string{string(kv.Value)} +} + +// SaveSubscribedData saves the urls. +func (m *consulMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urlListStr string) error { + kv := &consul.KVPair{Key: subscriberMetadataIdentifier.GetIdentifierKey(), Value: []byte(urlListStr)} + _, err := m.client.KV().Put(kv, nil) + return err +} + +// GetSubscribedURLs gets the urls. +func (m *consulMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) []string { + k := subscriberMetadataIdentifier.GetIdentifierKey() + kv, _, err := m.client.KV().Get(k, nil) + if err != nil { + panic(err) + } + + if kv == nil { + return []string{} + } + return []string{string(kv.Value)} +} + +// GetServiceDefinition gets the service definition. +func (m *consulMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) string { + k := metadataIdentifier.GetIdentifierKey() + kv, _, err := m.client.KV().Get(k, nil) + if err != nil { + panic(err) + } + + if kv == nil { + return "" + } + return string(kv.Value) +} + +type consulMetadataReportFactory struct { +} + +func (m *consulMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport { + config := &consul.Config{Address: url.Location} + client, err := consul.NewClient(config) + if err != nil { + panic(err) + } + return &consulMetadataReport{client: client} +} \ No newline at end of file diff --git a/metadata/report/consul/report_test.go b/metadata/report/consul/report_test.go new file mode 100644 index 0000000000..d51c32c4f1 --- /dev/null +++ b/metadata/report/consul/report_test.go @@ -0,0 +1,18 @@ +/* + * 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 consul diff --git a/metadata/report/nacos/report.go b/metadata/report/nacos/report.go index 312fd27c84..f5a065b273 100644 --- a/metadata/report/nacos/report.go +++ b/metadata/report/nacos/report.go @@ -38,19 +38,19 @@ import ( ) func init() { - ftry := &nacosMetadataReportFactory{} + mf := &nacosMetadataReportFactory{} extension.SetMetadataReportFactory("nacos", func() factory.MetadataReportFactory { - return ftry + return mf }) } -// nacosMetadataReport is the implementation of MetadataReport based Nacos +// nacosMetadataReport is the implementation +// of MetadataReport based on Nacos. type nacosMetadataReport struct { client config_client.IConfigClient } -// StoreProviderMetadata will store the metadata -// metadata including the basic info of the server, provider info, and other user custom info +// StoreProviderMetadata stores the metadata. func (n *nacosMetadataReport) StoreProviderMetadata(providerIdentifier *identifier.MetadataIdentifier, serviceDefinitions string) error { return n.storeMetadata(vo.ConfigParam{ DataId: providerIdentifier.GetIdentifierKey(), @@ -59,8 +59,7 @@ func (n *nacosMetadataReport) StoreProviderMetadata(providerIdentifier *identifi }) } -// StoreConsumerMetadata will store the metadata -// metadata including the basic info of the server, consumer info, and other user custom info +// StoreConsumerMetadata stores the metadata. func (n *nacosMetadataReport) StoreConsumerMetadata(consumerMetadataIdentifier *identifier.MetadataIdentifier, serviceParameterString string) error { return n.storeMetadata(vo.ConfigParam{ DataId: consumerMetadataIdentifier.GetIdentifierKey(), @@ -69,8 +68,7 @@ func (n *nacosMetadataReport) StoreConsumerMetadata(consumerMetadataIdentifier * }) } -// SaveServiceMetadata will store the metadata -// metadata including the basic info of the server, service info, and other user custom info +// SaveServiceMetadata saves the metadata. func (n *nacosMetadataReport) SaveServiceMetadata(metadataIdentifier *identifier.ServiceMetadataIdentifier, url common.URL) error { return n.storeMetadata(vo.ConfigParam{ DataId: metadataIdentifier.GetIdentifierKey(), @@ -79,7 +77,7 @@ func (n *nacosMetadataReport) SaveServiceMetadata(metadataIdentifier *identifier }) } -// RemoveServiceMetadata will remove the service metadata +// RemoveServiceMetadata removes the metadata. func (n *nacosMetadataReport) RemoveServiceMetadata(metadataIdentifier *identifier.ServiceMetadataIdentifier) error { return n.deleteMetadata(vo.ConfigParam{ DataId: metadataIdentifier.GetIdentifierKey(), @@ -87,8 +85,7 @@ func (n *nacosMetadataReport) RemoveServiceMetadata(metadataIdentifier *identifi }) } -// GetExportedURLs will look up the exported urls. -// if not found, an empty list will be returned. +// GetExportedURLs gets the urls. func (n *nacosMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) []string { return n.getConfigAsArray(vo.ConfigParam{ DataId: metadataIdentifier.GetIdentifierKey(), @@ -96,7 +93,7 @@ func (n *nacosMetadataReport) GetExportedURLs(metadataIdentifier *identifier.Ser }) } -// SaveSubscribedData will convert the urlList to json array and then store it +// SaveSubscribedData saves the urls. func (n *nacosMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urlListStr string) error { return n.storeMetadata(vo.ConfigParam{ DataId: subscriberMetadataIdentifier.GetIdentifierKey(), @@ -105,8 +102,7 @@ func (n *nacosMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *i }) } -// GetSubscribedURLs will lookup the url -// if not found, an empty list will be returned +// GetSubscribedURLs gets the urls. func (n *nacosMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) []string { return n.getConfigAsArray(vo.ConfigParam{ DataId: subscriberMetadataIdentifier.GetIdentifierKey(), @@ -114,7 +110,7 @@ func (n *nacosMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *id }) } -// GetServiceDefinition will lookup the service definition +// GetServiceDefinition gets the service definition. func (n *nacosMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) string { return n.getConfig(vo.ConfigParam{ DataId: metadataIdentifier.GetIdentifierKey(), From 117f85f2cbfa3f7ba59d496e614d34a40c7926ee Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Fri, 26 Jun 2020 18:36:13 +0800 Subject: [PATCH 04/19] zookeeper metadata report --- metadata/report/consul/report.go | 10 +- metadata/report/nacos/report.go | 6 +- metadata/report/zookeeper/report.go | 126 +++++++++++++++++++++++ metadata/report/zookeeper/report_test.go | 18 ++++ remoting/zookeeper/client.go | 6 +- 5 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 metadata/report/zookeeper/report.go create mode 100644 metadata/report/zookeeper/report_test.go diff --git a/metadata/report/consul/report.go b/metadata/report/consul/report.go index 8225b22a07..ca57f40363 100644 --- a/metadata/report/consul/report.go +++ b/metadata/report/consul/report.go @@ -37,7 +37,7 @@ func init() { } // consulMetadataReport is the implementation of -// MetadataReport based on Consul. +// MetadataReport based on consul. type consulMetadataReport struct { client *consul.Client } @@ -85,8 +85,8 @@ func (m *consulMetadataReport) GetExportedURLs(metadataIdentifier *identifier.Se } // SaveSubscribedData saves the urls. -func (m *consulMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urlListStr string) error { - kv := &consul.KVPair{Key: subscriberMetadataIdentifier.GetIdentifierKey(), Value: []byte(urlListStr)} +func (m *consulMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urls string) error { + kv := &consul.KVPair{Key: subscriberMetadataIdentifier.GetIdentifierKey(), Value: []byte(urls)} _, err := m.client.KV().Put(kv, nil) return err } @@ -122,11 +122,11 @@ func (m *consulMetadataReport) GetServiceDefinition(metadataIdentifier *identifi type consulMetadataReportFactory struct { } -func (m *consulMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport { +func (mf *consulMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport { config := &consul.Config{Address: url.Location} client, err := consul.NewClient(config) if err != nil { panic(err) } return &consulMetadataReport{client: client} -} \ No newline at end of file +} diff --git a/metadata/report/nacos/report.go b/metadata/report/nacos/report.go index f5a065b273..7db4c85d9a 100644 --- a/metadata/report/nacos/report.go +++ b/metadata/report/nacos/report.go @@ -45,7 +45,7 @@ func init() { } // nacosMetadataReport is the implementation -// of MetadataReport based on Nacos. +// of MetadataReport based on nacos. type nacosMetadataReport struct { client config_client.IConfigClient } @@ -94,11 +94,11 @@ func (n *nacosMetadataReport) GetExportedURLs(metadataIdentifier *identifier.Ser } // SaveSubscribedData saves the urls. -func (n *nacosMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urlListStr string) error { +func (n *nacosMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urls string) error { return n.storeMetadata(vo.ConfigParam{ DataId: subscriberMetadataIdentifier.GetIdentifierKey(), Group: subscriberMetadataIdentifier.Group, - Content: urlListStr, + Content: urls, }) } diff --git a/metadata/report/zookeeper/report.go b/metadata/report/zookeeper/report.go new file mode 100644 index 0000000000..76948379ed --- /dev/null +++ b/metadata/report/zookeeper/report.go @@ -0,0 +1,126 @@ +/* + * 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 ( + "strings" +) + +import ( + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/common/extension" + "github.com/apache/dubbo-go/metadata/identifier" + "github.com/apache/dubbo-go/metadata/report" + "github.com/apache/dubbo-go/metadata/report/factory" + "github.com/apache/dubbo-go/remoting/zookeeper" +) + +func init() { + mf := &zookeeperMetadataReportFactory{} + extension.SetMetadataReportFactory("consul", func() factory.MetadataReportFactory { + return mf + }) +} + +// zookeeperMetadataReport is the implementation of +// MetadataReport based on zookeeper. +type zookeeperMetadataReport struct { + client *zookeeper.ZookeeperClient + rootDir string +} + +// StoreProviderMetadata stores the metadata. +func (m *zookeeperMetadataReport) StoreProviderMetadata(providerIdentifier *identifier.MetadataIdentifier, serviceDefinitions string) error { + k := m.rootDir + providerIdentifier.GetFilePathKey() + return m.client.CreateWithValue(k, []byte(serviceDefinitions)) +} + +// StoreConsumerMetadata stores the metadata. +func (m *zookeeperMetadataReport) StoreConsumerMetadata(consumerMetadataIdentifier *identifier.MetadataIdentifier, serviceParameterString string) error { + k := m.rootDir + consumerMetadataIdentifier.GetFilePathKey() + return m.client.CreateWithValue(k, []byte(serviceParameterString)) +} + +// SaveServiceMetadata saves the metadata. +func (m *zookeeperMetadataReport) SaveServiceMetadata(metadataIdentifier *identifier.ServiceMetadataIdentifier, url common.URL) error { + k := m.rootDir + metadataIdentifier.GetFilePathKey() + return m.client.CreateWithValue(k, []byte(url.String())) +} + +// RemoveServiceMetadata removes the metadata. +func (m *zookeeperMetadataReport) RemoveServiceMetadata(metadataIdentifier *identifier.ServiceMetadataIdentifier) error { + k := m.rootDir + metadataIdentifier.GetFilePathKey() + return m.client.Delete(k) +} + +// GetExportedURLs gets the urls. +func (m *zookeeperMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) []string { + k := m.rootDir + metadataIdentifier.GetFilePathKey() + v, _, err := m.client.GetContent(k) + if err != nil { + panic(err) + } + return []string{string(v)} +} + +// SaveSubscribedData saves the urls. +func (m *zookeeperMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier, urls string) error { + k := m.rootDir + subscriberMetadataIdentifier.GetFilePathKey() + return m.client.CreateWithValue(k, []byte(urls)) +} + +// GetSubscribedURLs gets the urls. +func (m *zookeeperMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) []string { + k := m.rootDir + subscriberMetadataIdentifier.GetFilePathKey() + v, _, err := m.client.GetContent(k) + if err != nil { + panic(err) + } + return []string{string(v)} +} + +// GetServiceDefinition gets the service definition. +func (m *zookeeperMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) string { + k := m.rootDir + metadataIdentifier.GetFilePathKey() + v, _, err := m.client.GetContent(k) + if err != nil { + panic(err) + } + return string(v) +} + +type zookeeperMetadataReportFactory struct { +} + +func (mf *zookeeperMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport { + client, err := zookeeper.NewZookeeperClient("zookeeperMetadataReport", strings.Split(url.Location, ","), 15) + if err != nil { + panic(err) + } + + rootDir := url.GetParam(constant.GROUP_KEY, "dubbo") + if !strings.HasPrefix(rootDir, constant.PATH_SEPARATOR) { + rootDir = constant.PATH_SEPARATOR + rootDir + } + if rootDir != constant.PATH_SEPARATOR { + rootDir = rootDir + constant.PATH_SEPARATOR + } + + return &zookeeperMetadataReport{client: client, rootDir: rootDir} +} diff --git a/metadata/report/zookeeper/report_test.go b/metadata/report/zookeeper/report_test.go new file mode 100644 index 0000000000..e386d95ef8 --- /dev/null +++ b/metadata/report/zookeeper/report_test.go @@ -0,0 +1,18 @@ +/* + * 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 diff --git a/remoting/zookeeper/client.go b/remoting/zookeeper/client.go index 7904dc74e8..b6c49e7056 100644 --- a/remoting/zookeeper/client.go +++ b/remoting/zookeeper/client.go @@ -89,8 +89,6 @@ func StateToString(state zk.State) string { default: return state.String() } - - return "zookeeper unknown state" } // Options ... @@ -137,7 +135,7 @@ func ValidateZookeeperClient(container zkClientFacade, opts ...Option) error { return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", url.Location) } zkAddresses := strings.Split(url.Location, ",") - newClient, err := newZookeeperClient(options.zkName, zkAddresses, timeout) + newClient, err := NewZookeeperClient(options.zkName, zkAddresses, timeout) if err != nil { logger.Warnf("newZookeeperClient(name{%s}, zk address{%v}, timeout{%d}) = error{%v}", options.zkName, url.Location, timeout.String(), err) @@ -165,7 +163,7 @@ func ValidateZookeeperClient(container zkClientFacade, opts ...Option) error { return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", url.PrimitiveURL) } -func newZookeeperClient(name string, zkAddrs []string, timeout time.Duration) (*ZookeeperClient, error) { +func NewZookeeperClient(name string, zkAddrs []string, timeout time.Duration) (*ZookeeperClient, error) { var ( err error event <-chan zk.Event From f1576d1b63612de8770f402ac915c3f76b4b2025 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Fri, 26 Jun 2020 19:03:05 +0800 Subject: [PATCH 05/19] fix --- metadata/service/remote/service_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/metadata/service/remote/service_test.go b/metadata/service/remote/service_test.go index 0c1de355c1..12ef472ecb 100644 --- a/metadata/service/remote/service_test.go +++ b/metadata/service/remote/service_test.go @@ -77,9 +77,9 @@ func (metadataReport) GetExportedURLs(*identifier.ServiceMetadataIdentifier) []s return nil } -func (mr *metadataReport) SaveSubscribedData(id *identifier.SubscriberMetadataIdentifier, urlListStr string) error { - logger.Infof("SaveSubscribedData, , url is %v", urlListStr) - subscribedMetadata[id] = urlListStr +func (mr *metadataReport) SaveSubscribedData(id *identifier.SubscriberMetadataIdentifier, urls string) error { + logger.Infof("SaveSubscribedData, , url is %v", urls) + subscribedMetadata[id] = urls return nil } From 242e9f27d26684a40ab8c5813c73f51bc855c18d Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Fri, 26 Jun 2020 22:54:47 +0800 Subject: [PATCH 06/19] fix --- metadata/report/nacos/report_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/metadata/report/nacos/report_test.go b/metadata/report/nacos/report_test.go index 254b92363b..5a646c9a38 100644 --- a/metadata/report/nacos/report_test.go +++ b/metadata/report/nacos/report_test.go @@ -42,6 +42,7 @@ func TestNacosMetadataReport_CRUD(t *testing.T) { providerMi := newMetadataIdentifier("server") providerMeta := "provider" err := rpt.StoreProviderMetadata(providerMi, providerMeta) + assert.Nil(t, err) consumerMi := newMetadataIdentifier("client") consumerMeta := "consumer" @@ -50,7 +51,6 @@ func TestNacosMetadataReport_CRUD(t *testing.T) { serviceMi := newServiceMetadataIdentifier() serviceUrl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) - err = rpt.SaveServiceMetadata(serviceMi, serviceUrl) assert.Nil(t, err) @@ -68,7 +68,6 @@ func TestNacosMetadataReport_CRUD(t *testing.T) { err = rpt.RemoveServiceMetadata(serviceMi) assert.Nil(t, err) - } func newSubscribeMetadataIdentifier() *identifier.SubscriberMetadataIdentifier { @@ -76,7 +75,6 @@ func newSubscribeMetadataIdentifier() *identifier.SubscriberMetadataIdentifier { Revision: "subscribe", MetadataIdentifier: *newMetadataIdentifier("provider"), } - } func newServiceMetadataIdentifier() *identifier.ServiceMetadataIdentifier { From 81a458c43b0dd2ccdc28ba784cfbbc690595899f Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Fri, 26 Jun 2020 23:25:48 +0800 Subject: [PATCH 07/19] import sort --- metadata/report/delegate/delegate_report.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/report/delegate/delegate_report.go b/metadata/report/delegate/delegate_report.go index 282e751443..08092a7ddc 100644 --- a/metadata/report/delegate/delegate_report.go +++ b/metadata/report/delegate/delegate_report.go @@ -19,7 +19,6 @@ package delegate import ( "encoding/json" - perrors "github.com/pkg/errors" "runtime/debug" "sync" "time" @@ -27,6 +26,7 @@ import ( import ( "github.com/go-co-op/gocron" + perrors "github.com/pkg/errors" "go.uber.org/atomic" ) From 404cd00af894e42933f292e9cb1053f6fae78698 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Sat, 27 Jun 2020 21:59:54 +0800 Subject: [PATCH 08/19] consul metadata report unit test --- metadata/report/consul/report_test.go | 144 ++++++++++++++++++++++++++ metadata/report/nacos/report_test.go | 4 +- registry/consul/utils_test.go | 43 +------- remoting/consul/agent.go | 70 +++++++++++++ remoting/consul/agent_test.go | 32 ++++++ 5 files changed, 253 insertions(+), 40 deletions(-) create mode 100644 remoting/consul/agent.go create mode 100644 remoting/consul/agent_test.go diff --git a/metadata/report/consul/report_test.go b/metadata/report/consul/report_test.go index d51c32c4f1..5d7a9a3517 100644 --- a/metadata/report/consul/report_test.go +++ b/metadata/report/consul/report_test.go @@ -16,3 +16,147 @@ */ package consul + +import ( + "encoding/json" + "net/url" + "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" + "github.com/apache/dubbo-go/metadata/identifier" + "github.com/apache/dubbo-go/metadata/report" + "github.com/apache/dubbo-go/remoting/consul" +) + +func newProviderRegistryUrl(host string, port int) *common.URL { + url1 := common.NewURLWithOptions( + common.WithIp(host), + common.WithPort(strconv.Itoa(port)), + common.WithParams(url.Values{}), + common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)), + ) + return url1 +} + +func newBaseMetadataIdentifier(side string) *identifier.BaseMetadataIdentifier { + return &identifier.BaseMetadataIdentifier{ + ServiceInterface: "org.apache.HelloWorld", + Version: "1.0.0", + Group: "group", + Side: side, + } +} + +func newMetadataIdentifier(side string) *identifier.MetadataIdentifier { + return &identifier.MetadataIdentifier{ + Application: "application", + BaseMetadataIdentifier: *newBaseMetadataIdentifier(side), + } +} + +func newServiceMetadataIdentifier(side string) *identifier.ServiceMetadataIdentifier { + return &identifier.ServiceMetadataIdentifier{ + Revision: "1.0", + Protocol: "dubbo", + BaseMetadataIdentifier: *newBaseMetadataIdentifier(side), + } +} + +func newSubscribeMetadataIdentifier(side string) *identifier.SubscriberMetadataIdentifier { + return &identifier.SubscriberMetadataIdentifier{ + Revision: "1.0", + MetadataIdentifier: *newMetadataIdentifier(side), + } +} + +type consulMetadataReportTestSuite struct { + t *testing.T + m report.MetadataReport +} + +func newConsulMetadataReportTestSuite(t *testing.T, m report.MetadataReport) *consulMetadataReportTestSuite { + return &consulMetadataReportTestSuite{t: t, m: m} +} + +func (suite *consulMetadataReportTestSuite) testStoreProviderMetadata() { + providerMi := newMetadataIdentifier("provider") + providerMeta := "provider" + err := suite.m.StoreProviderMetadata(providerMi, providerMeta) + assert.NoError(suite.t, err) +} + +func (suite *consulMetadataReportTestSuite) testStoreConsumerMetadata() { + consumerMi := newMetadataIdentifier("consumer") + consumerMeta := "consumer" + err := suite.m.StoreProviderMetadata(consumerMi, consumerMeta) + assert.NoError(suite.t, err) +} + +func (suite *consulMetadataReportTestSuite) testSaveServiceMetadata(url common.URL) { + serviceMi := newServiceMetadataIdentifier("provider") + err := suite.m.SaveServiceMetadata(serviceMi, url) + assert.NoError(suite.t, err) +} + +func (suite *consulMetadataReportTestSuite) testRemoveServiceMetadata() { + serviceMi := newServiceMetadataIdentifier("provider") + err := suite.m.RemoveServiceMetadata(serviceMi) + assert.NoError(suite.t, err) +} + +func (suite *consulMetadataReportTestSuite) testGetExportedURLs() { + serviceMi := newServiceMetadataIdentifier("provider") + urls := suite.m.GetExportedURLs(serviceMi) + assert.Equal(suite.t, 1, len(urls)) +} + +func (suite *consulMetadataReportTestSuite) testSaveSubscribedData(url common.URL) { + subscribeMi := newSubscribeMetadataIdentifier("provider") + urls := []string{url.String()} + bytes, _ := json.Marshal(urls) + err := suite.m.SaveSubscribedData(subscribeMi, string(bytes)) + assert.Nil(suite.t, err) +} + +func (suite *consulMetadataReportTestSuite) testGetSubscribedURLs() { + subscribeMi := newSubscribeMetadataIdentifier("provider") + urls := suite.m.GetSubscribedURLs(subscribeMi) + assert.Equal(suite.t, 1, len(urls)) +} + +func (suite *consulMetadataReportTestSuite) testGetServiceDefinition() { + providerMi := newMetadataIdentifier("provider") + providerMeta := suite.m.GetServiceDefinition(providerMi) + assert.Equal(suite.t, "provider", providerMeta) +} + +func test1(t *testing.T) { + consulAgent := consul.NewConsulAgent(t, 8500) + defer consulAgent.Close() + + url := newProviderRegistryUrl("localhost", 8500) + mf := extension.GetMetadataReportFactory("consul") + m := mf.CreateMetadataReport(url) + + suite := newConsulMetadataReportTestSuite(t, m) + suite.testStoreProviderMetadata() + suite.testStoreConsumerMetadata() + suite.testSaveServiceMetadata(*url) + suite.testGetExportedURLs() + suite.testRemoveServiceMetadata() + suite.testSaveSubscribedData(*url) + suite.testGetServiceDefinition() +} + +func TestConsulMetadataReport(t *testing.T) { + t.Run("test1", test1) +} diff --git a/metadata/report/nacos/report_test.go b/metadata/report/nacos/report_test.go index 5a646c9a38..971c7bfe8f 100644 --- a/metadata/report/nacos/report_test.go +++ b/metadata/report/nacos/report_test.go @@ -58,8 +58,8 @@ func TestNacosMetadataReport_CRUD(t *testing.T) { assert.Equal(t, 1, len(exportedUrls)) subMi := newSubscribeMetadataIdentifier() - urlList := []string{serviceUrl.String()} - bytes, _ := json.Marshal(urlList) + urls := []string{serviceUrl.String()} + bytes, _ := json.Marshal(urls) err = rpt.SaveSubscribedData(subMi, string(bytes)) assert.Nil(t, err) diff --git a/registry/consul/utils_test.go b/registry/consul/utils_test.go index d66600b773..1ef2004139 100644 --- a/registry/consul/utils_test.go +++ b/registry/consul/utils_test.go @@ -19,24 +19,19 @@ package consul import ( "fmt" - "io/ioutil" "net" "net/url" - "os" "strconv" "sync" "testing" ) -import ( - "github.com/hashicorp/consul/agent" -) - import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/registry" "github.com/apache/dubbo-go/remoting" + "github.com/apache/dubbo-go/remoting/consul" ) var ( @@ -90,34 +85,6 @@ func newConsumerUrl(host string, port int, service string, protocol string) comm return *url1 } -type testConsulAgent struct { - dataDir string - testAgent *agent.TestAgent -} - -func newConsulAgent(t *testing.T, port int) *testConsulAgent { - dataDir, _ := ioutil.TempDir("./", "agent") - hcl := ` - ports { - http = ` + strconv.Itoa(port) + ` - } - data_dir = "` + dataDir + `" - ` - testAgent := &agent.TestAgent{Name: t.Name(), DataDir: dataDir, HCL: hcl} - testAgent.Start(t) - - consulAgent := &testConsulAgent{ - dataDir: dataDir, - testAgent: testAgent, - } - return consulAgent -} - -func (consulAgent *testConsulAgent) close() { - consulAgent.testAgent.Shutdown() - os.RemoveAll(consulAgent.dataDir) -} - type testServer struct { listener net.Listener wg sync.WaitGroup @@ -184,8 +151,8 @@ func (suite *consulRegistryTestSuite) close() { // register -> subscribe -> unregister func test1(t *testing.T) { - consulAgent := newConsulAgent(t, registryPort) - defer consulAgent.close() + consulAgent := consul.NewConsulAgent(t, registryPort) + defer consulAgent.Close() server := newServer(providerHost, providerPort) defer server.close() @@ -204,8 +171,8 @@ func test1(t *testing.T) { // subscribe -> register func test2(t *testing.T) { - consulAgent := newConsulAgent(t, registryPort) - defer consulAgent.close() + consulAgent := consul.NewConsulAgent(t, registryPort) + defer consulAgent.Close() server := newServer(providerHost, providerPort) defer server.close() diff --git a/remoting/consul/agent.go b/remoting/consul/agent.go new file mode 100644 index 0000000000..fd0694bde3 --- /dev/null +++ b/remoting/consul/agent.go @@ -0,0 +1,70 @@ +/* + * 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 consul + +import ( + "io/ioutil" + "os" + "strconv" + "testing" +) + +import ( + "github.com/hashicorp/consul/agent" +) + +// Consul agent, used for test, simulates +// an embedded consul server. +type ConsulAgent struct { + dataDir string + testAgent *agent.TestAgent +} + +func NewConsulAgent(t *testing.T, port int) *ConsulAgent { + dataDir, _ := ioutil.TempDir("./", "agent") + hcl := ` + ports { + http = ` + strconv.Itoa(port) + ` + } + data_dir = "` + dataDir + `" + ` + testAgent := &agent.TestAgent{Name: t.Name(), DataDir: dataDir, HCL: hcl} + testAgent.Start(t) + + consulAgent := &ConsulAgent{ + dataDir: dataDir, + testAgent: testAgent, + } + return consulAgent +} + +func (consulAgent *ConsulAgent) Close() error { + var err error + + err = consulAgent.testAgent.Shutdown() + if err != nil { + return err + } + + err = os.RemoveAll(consulAgent.dataDir) + if err != nil { + return err + } + + return nil +} diff --git a/remoting/consul/agent_test.go b/remoting/consul/agent_test.go new file mode 100644 index 0000000000..8cf0ac6cd8 --- /dev/null +++ b/remoting/consul/agent_test.go @@ -0,0 +1,32 @@ +/* + * 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 consul + +import ( + "testing" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestNewConsulAgent(t *testing.T) { + consulAgent := NewConsulAgent(t, 8500) + err := consulAgent.Close() + assert.NoError(t, err) +} From f004237e5bca0ba0fa22c8addf83ab09f07de774 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Sun, 28 Jun 2020 15:31:41 +0800 Subject: [PATCH 09/19] zookeeper metadata report unit test --- .gitignore | 4 +- before_ut.bat | 5 +- before_ut.sh | 9 +- metadata/report/zookeeper/report.go | 9 +- metadata/report/zookeeper/report_test.go | 145 +++++++++++++++++++++++ remoting/zookeeper/client.go | 2 +- 6 files changed, 164 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 568e9f2454..f7622f8ac9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,15 +20,13 @@ classes # go mod, go test vendor/ -coverage.txt - logs/ .vscode/ -coverage.txt # unit test remoting/zookeeper/zookeeper-4unittest/ config_center/zookeeper/zookeeper-4unittest/ registry/zookeeper/zookeeper-4unittest/ +metadata/report/zookeeper/zookeeper-4unittest/ registry/consul/agent* config_center/apollo/mockDubbog.properties.json diff --git a/before_ut.bat b/before_ut.bat index 5e1c877af2..b7c70e8d13 100644 --- a/before_ut.bat +++ b/before_ut.bat @@ -34,4 +34,7 @@ md cluster\router\chain\zookeeper-4unittest\contrib\fatjar xcopy /f "%zkJar%" "cluster/router/chain/zookeeper-4unittest/contrib/fatjar/" md cluster\router\condition\zookeeper-4unittest\contrib\fatjar -xcopy /f "%zkJar%" "cluster/router/condition/zookeeper-4unittest/contrib/fatjar/" \ No newline at end of file +xcopy /f "%zkJar%" "cluster/router/condition/zookeeper-4unittest/contrib/fatjar/" + +md metadata\report\zookeeper\zookeeper-4unittest\contrib\fatjar +xcopy /f "%zkJar%" "metadata/report/zookeeper/zookeeper-4unittest/contrib/fatjar/" \ No newline at end of file diff --git a/before_ut.sh b/before_ut.sh index 7ee92e57a2..210e9e723b 100755 --- a/before_ut.sh +++ b/before_ut.sh @@ -25,13 +25,16 @@ if [ ! -f "${zkJar}" ]; then fi mkdir -p config_center/zookeeper/zookeeper-4unittest/contrib/fatjar -cp ${zkJar} config_center/zookeeper/zookeeper-4unittest/contrib/fatjar/ +cp ${zkJar} config_center/zookeeper/zookeeper-4unittest/contrib/fatjar mkdir -p registry/zookeeper/zookeeper-4unittest/contrib/fatjar -cp ${zkJar} registry/zookeeper/zookeeper-4unittest/contrib/fatjar/ +cp ${zkJar} registry/zookeeper/zookeeper-4unittest/contrib/fatjar mkdir -p cluster/router/chain/zookeeper-4unittest/contrib/fatjar cp ${zkJar} cluster/router/chain/zookeeper-4unittest/contrib/fatjar mkdir -p cluster/router/condition/zookeeper-4unittest/contrib/fatjar -cp ${zkJar} cluster/router/condition/zookeeper-4unittest/contrib/fatjar \ No newline at end of file +cp ${zkJar} cluster/router/condition/zookeeper-4unittest/contrib/fatjar + +mkdir -p metadata/report/zookeeper/zookeeper-4unittest/contrib/fatjar +cp ${zkJar} metadata/report/zookeeper/zookeeper-4unittest/contrib/fatjar \ No newline at end of file diff --git a/metadata/report/zookeeper/report.go b/metadata/report/zookeeper/report.go index 76948379ed..911a8d83ca 100644 --- a/metadata/report/zookeeper/report.go +++ b/metadata/report/zookeeper/report.go @@ -19,6 +19,7 @@ package zookeeper import ( "strings" + "time" ) import ( @@ -33,7 +34,7 @@ import ( func init() { mf := &zookeeperMetadataReportFactory{} - extension.SetMetadataReportFactory("consul", func() factory.MetadataReportFactory { + extension.SetMetadataReportFactory("zookeeper", func() factory.MetadataReportFactory { return mf }) } @@ -109,7 +110,11 @@ type zookeeperMetadataReportFactory struct { } func (mf *zookeeperMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport { - client, err := zookeeper.NewZookeeperClient("zookeeperMetadataReport", strings.Split(url.Location, ","), 15) + client, err := zookeeper.NewZookeeperClient( + "zookeeperMetadataReport", + strings.Split(url.Location, ","), + 15 * time.Second, + ) if err != nil { panic(err) } diff --git a/metadata/report/zookeeper/report_test.go b/metadata/report/zookeeper/report_test.go index e386d95ef8..2de70451e0 100644 --- a/metadata/report/zookeeper/report_test.go +++ b/metadata/report/zookeeper/report_test.go @@ -16,3 +16,148 @@ */ package zookeeper + +import ( + "encoding/json" + "net/url" + "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/common/extension" + "github.com/apache/dubbo-go/metadata/identifier" + "github.com/apache/dubbo-go/metadata/report" +) + +func newProviderRegistryUrl(host string, port int) *common.URL { + url1 := common.NewURLWithOptions( + common.WithIp(host), + common.WithPort(strconv.Itoa(port)), + common.WithParams(url.Values{}), + common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)), + ) + return url1 +} + +func newBaseMetadataIdentifier(side string) *identifier.BaseMetadataIdentifier { + return &identifier.BaseMetadataIdentifier{ + ServiceInterface: "org.apache.HelloWorld", + Version: "1.0.0", + Group: "group", + Side: side, + } +} + +func newMetadataIdentifier(side string) *identifier.MetadataIdentifier { + return &identifier.MetadataIdentifier{ + Application: "application", + BaseMetadataIdentifier: *newBaseMetadataIdentifier(side), + } +} + +func newServiceMetadataIdentifier(side string) *identifier.ServiceMetadataIdentifier { + return &identifier.ServiceMetadataIdentifier{ + Revision: "1.0", + Protocol: "dubbo", + BaseMetadataIdentifier: *newBaseMetadataIdentifier(side), + } +} + +func newSubscribeMetadataIdentifier(side string) *identifier.SubscriberMetadataIdentifier { + return &identifier.SubscriberMetadataIdentifier{ + Revision: "1.0", + MetadataIdentifier: *newMetadataIdentifier(side), + } +} + +type zookeeperMetadataReportTestSuite struct { + t *testing.T + m report.MetadataReport +} + +func newZookeeperMetadataReportTestSuite(t *testing.T, m report.MetadataReport) *zookeeperMetadataReportTestSuite { + return &zookeeperMetadataReportTestSuite{t: t, m: m} +} + +func (suite *zookeeperMetadataReportTestSuite) testStoreProviderMetadata() { + providerMi := newMetadataIdentifier("provider") + providerMeta := "provider" + err := suite.m.StoreProviderMetadata(providerMi, providerMeta) + assert.NoError(suite.t, err) +} + +func (suite *zookeeperMetadataReportTestSuite) testStoreConsumerMetadata() { + consumerMi := newMetadataIdentifier("consumer") + consumerMeta := "consumer" + err := suite.m.StoreProviderMetadata(consumerMi, consumerMeta) + assert.NoError(suite.t, err) +} + +func (suite *zookeeperMetadataReportTestSuite) testSaveServiceMetadata(url common.URL) { + serviceMi := newServiceMetadataIdentifier("provider") + err := suite.m.SaveServiceMetadata(serviceMi, url) + assert.NoError(suite.t, err) +} + +func (suite *zookeeperMetadataReportTestSuite) testRemoveServiceMetadata() { + serviceMi := newServiceMetadataIdentifier("provider") + err := suite.m.RemoveServiceMetadata(serviceMi) + assert.NoError(suite.t, err) +} + +func (suite *zookeeperMetadataReportTestSuite) testGetExportedURLs() { + serviceMi := newServiceMetadataIdentifier("provider") + urls := suite.m.GetExportedURLs(serviceMi) + assert.Equal(suite.t, 1, len(urls)) +} + +func (suite *zookeeperMetadataReportTestSuite) testSaveSubscribedData(url common.URL) { + subscribeMi := newSubscribeMetadataIdentifier("provider") + urls := []string{url.String()} + bytes, _ := json.Marshal(urls) + err := suite.m.SaveSubscribedData(subscribeMi, string(bytes)) + assert.Nil(suite.t, err) +} + +func (suite *zookeeperMetadataReportTestSuite) testGetSubscribedURLs() { + subscribeMi := newSubscribeMetadataIdentifier("provider") + urls := suite.m.GetSubscribedURLs(subscribeMi) + assert.Equal(suite.t, 1, len(urls)) +} + +func (suite *zookeeperMetadataReportTestSuite) testGetServiceDefinition() { + providerMi := newMetadataIdentifier("provider") + providerMeta := suite.m.GetServiceDefinition(providerMi) + assert.Equal(suite.t, "provider", providerMeta) +} + +func test1(t *testing.T) { + testCluster, err := zk.StartTestCluster(1, nil, nil) + assert.NoError(t, err) + defer testCluster.Stop() + + url := newProviderRegistryUrl("127.0.0.1", testCluster.Servers[0].Port) + mf := extension.GetMetadataReportFactory("zookeeper") + m := mf.CreateMetadataReport(url) + + suite := newZookeeperMetadataReportTestSuite(t, m) + suite.testStoreProviderMetadata() + suite.testStoreConsumerMetadata() + suite.testSaveServiceMetadata(*url) + suite.testGetExportedURLs() + suite.testRemoveServiceMetadata() + suite.testSaveSubscribedData(*url) + suite.testGetServiceDefinition() +} + +func TestZookeeperMetadataReport(t *testing.T) { + t.Run("test1", test1) +} diff --git a/remoting/zookeeper/client.go b/remoting/zookeeper/client.go index b6c49e7056..feceeb1197 100644 --- a/remoting/zookeeper/client.go +++ b/remoting/zookeeper/client.go @@ -253,7 +253,7 @@ func (z *ZookeeperClient) HandleZkEvent(session <-chan zk.Event) { case <-z.exit: return case event = <-session: - logger.Warnf("client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}", + logger.Infof("client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}", z.name, event.Type, event.Server, event.Path, event.State, StateToString(event.State), event.Err) switch (int)(event.State) { case (int)(zk.StateDisconnected): From ecf7fa15689c0969384602a2506dc17fc87d4fe1 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Sun, 28 Jun 2020 15:45:40 +0800 Subject: [PATCH 10/19] go fmt --- metadata/report/zookeeper/report.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/report/zookeeper/report.go b/metadata/report/zookeeper/report.go index 911a8d83ca..7873dd7899 100644 --- a/metadata/report/zookeeper/report.go +++ b/metadata/report/zookeeper/report.go @@ -113,7 +113,7 @@ func (mf *zookeeperMetadataReportFactory) CreateMetadataReport(url *common.URL) client, err := zookeeper.NewZookeeperClient( "zookeeperMetadataReport", strings.Split(url.Location, ","), - 15 * time.Second, + 15*time.Second, ) if err != nil { panic(err) From 44dbdfe1aebb46efa995990e397db33396147fda Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Sun, 28 Jun 2020 19:28:15 +0800 Subject: [PATCH 11/19] global var for empty slice --- metadata/report/consul/report.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/metadata/report/consul/report.go b/metadata/report/consul/report.go index ca57f40363..690534220b 100644 --- a/metadata/report/consul/report.go +++ b/metadata/report/consul/report.go @@ -29,6 +29,10 @@ import ( "github.com/apache/dubbo-go/metadata/report/factory" ) +var ( + emptyStrSlice = make([]string, 0) +) + func init() { mf := &consulMetadataReportFactory{} extension.SetMetadataReportFactory("consul", func() factory.MetadataReportFactory { @@ -79,7 +83,7 @@ func (m *consulMetadataReport) GetExportedURLs(metadataIdentifier *identifier.Se } if kv == nil { - return []string{} + return emptyStrSlice } return []string{string(kv.Value)} } @@ -100,7 +104,7 @@ func (m *consulMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *i } if kv == nil { - return []string{} + return emptyStrSlice } return []string{string(kv.Value)} } From f440a3141f0472e47f3abb84c88ed6c12b9b9910 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Sun, 28 Jun 2020 20:10:40 +0800 Subject: [PATCH 12/19] fix --- metadata/report/consul/report_test.go | 1 + metadata/report/zookeeper/report.go | 12 ++++++++++++ metadata/report/zookeeper/report_test.go | 1 + 3 files changed, 14 insertions(+) diff --git a/metadata/report/consul/report_test.go b/metadata/report/consul/report_test.go index 5d7a9a3517..7996421f72 100644 --- a/metadata/report/consul/report_test.go +++ b/metadata/report/consul/report_test.go @@ -154,6 +154,7 @@ func test1(t *testing.T) { suite.testGetExportedURLs() suite.testRemoveServiceMetadata() suite.testSaveSubscribedData(*url) + suite.testGetSubscribedURLs() suite.testGetServiceDefinition() } diff --git a/metadata/report/zookeeper/report.go b/metadata/report/zookeeper/report.go index 7873dd7899..955393f79c 100644 --- a/metadata/report/zookeeper/report.go +++ b/metadata/report/zookeeper/report.go @@ -32,6 +32,10 @@ import ( "github.com/apache/dubbo-go/remoting/zookeeper" ) +var ( + emptyStrSlice = make([]string, 0) +) + func init() { mf := &zookeeperMetadataReportFactory{} extension.SetMetadataReportFactory("zookeeper", func() factory.MetadataReportFactory { @@ -77,6 +81,10 @@ func (m *zookeeperMetadataReport) GetExportedURLs(metadataIdentifier *identifier if err != nil { panic(err) } + + if len(v) == 0 { + return emptyStrSlice + } return []string{string(v)} } @@ -93,6 +101,10 @@ func (m *zookeeperMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier if err != nil { panic(err) } + + if len(v) == 0 { + return emptyStrSlice + } return []string{string(v)} } diff --git a/metadata/report/zookeeper/report_test.go b/metadata/report/zookeeper/report_test.go index 2de70451e0..c83022bd34 100644 --- a/metadata/report/zookeeper/report_test.go +++ b/metadata/report/zookeeper/report_test.go @@ -155,6 +155,7 @@ func test1(t *testing.T) { suite.testGetExportedURLs() suite.testRemoveServiceMetadata() suite.testSaveSubscribedData(*url) + suite.testGetSubscribedURLs() suite.testGetServiceDefinition() } From e030e25c50a0a64a9770d86a50a176fb08402e53 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Mon, 29 Jun 2020 12:30:23 +0800 Subject: [PATCH 13/19] remove panic --- metadata/report/consul/report.go | 27 +++++++++---------- metadata/report/consul/report_test.go | 9 ++++--- metadata/report/delegate/delegate_report.go | 6 ++--- metadata/report/nacos/report.go | 29 ++++++++++++--------- metadata/report/nacos/report_test.go | 6 +++-- metadata/report/report.go | 6 ++--- metadata/report/zookeeper/report.go | 25 +++++++++--------- metadata/report/zookeeper/report_test.go | 9 ++++--- 8 files changed, 64 insertions(+), 53 deletions(-) diff --git a/metadata/report/consul/report.go b/metadata/report/consul/report.go index 690534220b..2d3d00d608 100644 --- a/metadata/report/consul/report.go +++ b/metadata/report/consul/report.go @@ -34,9 +34,8 @@ var ( ) func init() { - mf := &consulMetadataReportFactory{} extension.SetMetadataReportFactory("consul", func() factory.MetadataReportFactory { - return mf + return &consulMetadataReportFactory{} }) } @@ -75,17 +74,17 @@ func (m *consulMetadataReport) RemoveServiceMetadata(metadataIdentifier *identif } // GetExportedURLs gets the urls. -func (m *consulMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) []string { +func (m *consulMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) ([]string, error) { k := metadataIdentifier.GetIdentifierKey() kv, _, err := m.client.KV().Get(k, nil) if err != nil { - panic(err) + return emptyStrSlice, err } if kv == nil { - return emptyStrSlice + return emptyStrSlice, nil } - return []string{string(kv.Value)} + return []string{string(kv.Value)}, nil } // SaveSubscribedData saves the urls. @@ -96,31 +95,31 @@ func (m *consulMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier * } // GetSubscribedURLs gets the urls. -func (m *consulMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) []string { +func (m *consulMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) ([]string, error) { k := subscriberMetadataIdentifier.GetIdentifierKey() kv, _, err := m.client.KV().Get(k, nil) if err != nil { - panic(err) + return emptyStrSlice, err } if kv == nil { - return emptyStrSlice + return emptyStrSlice, nil } - return []string{string(kv.Value)} + return []string{string(kv.Value)}, nil } // GetServiceDefinition gets the service definition. -func (m *consulMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) string { +func (m *consulMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) (string, error) { k := metadataIdentifier.GetIdentifierKey() kv, _, err := m.client.KV().Get(k, nil) if err != nil { - panic(err) + return "", err } if kv == nil { - return "" + return "", nil } - return string(kv.Value) + return string(kv.Value), nil } type consulMetadataReportFactory struct { diff --git a/metadata/report/consul/report_test.go b/metadata/report/consul/report_test.go index 7996421f72..b982d71765 100644 --- a/metadata/report/consul/report_test.go +++ b/metadata/report/consul/report_test.go @@ -115,8 +115,9 @@ func (suite *consulMetadataReportTestSuite) testRemoveServiceMetadata() { func (suite *consulMetadataReportTestSuite) testGetExportedURLs() { serviceMi := newServiceMetadataIdentifier("provider") - urls := suite.m.GetExportedURLs(serviceMi) + urls, err := suite.m.GetExportedURLs(serviceMi) assert.Equal(suite.t, 1, len(urls)) + assert.NoError(suite.t, err) } func (suite *consulMetadataReportTestSuite) testSaveSubscribedData(url common.URL) { @@ -129,14 +130,16 @@ func (suite *consulMetadataReportTestSuite) testSaveSubscribedData(url common.UR func (suite *consulMetadataReportTestSuite) testGetSubscribedURLs() { subscribeMi := newSubscribeMetadataIdentifier("provider") - urls := suite.m.GetSubscribedURLs(subscribeMi) + urls, err := suite.m.GetSubscribedURLs(subscribeMi) assert.Equal(suite.t, 1, len(urls)) + assert.NoError(suite.t, err) } func (suite *consulMetadataReportTestSuite) testGetServiceDefinition() { providerMi := newMetadataIdentifier("provider") - providerMeta := suite.m.GetServiceDefinition(providerMi) + providerMeta, err := suite.m.GetServiceDefinition(providerMi) assert.Equal(suite.t, "provider", providerMeta) + assert.NoError(suite.t, err) } func test1(t *testing.T) { diff --git a/metadata/report/delegate/delegate_report.go b/metadata/report/delegate/delegate_report.go index 08092a7ddc..64103b259a 100644 --- a/metadata/report/delegate/delegate_report.go +++ b/metadata/report/delegate/delegate_report.go @@ -235,7 +235,7 @@ func (mr *MetadataReport) RemoveServiceMetadata(identifier *identifier.ServiceMe } // GetExportedURLs will delegate to call remote metadata's sdk to get exported urls -func (mr *MetadataReport) GetExportedURLs(identifier *identifier.ServiceMetadataIdentifier) []string { +func (mr *MetadataReport) GetExportedURLs(identifier *identifier.ServiceMetadataIdentifier) ([]string, error) { report := instance.GetMetadataReportInstance() return report.GetExportedURLs(identifier) } @@ -260,13 +260,13 @@ func (mr *MetadataReport) SaveSubscribedData(identifier *identifier.SubscriberMe } // GetSubscribedURLs will delegate to call remote metadata's sdk to get subscribed urls -func (MetadataReport) GetSubscribedURLs(identifier *identifier.SubscriberMetadataIdentifier) []string { +func (MetadataReport) GetSubscribedURLs(identifier *identifier.SubscriberMetadataIdentifier) ([]string, error) { report := instance.GetMetadataReportInstance() return report.GetSubscribedURLs(identifier) } // GetServiceDefinition will delegate to call remote metadata's sdk to get service definitions -func (MetadataReport) GetServiceDefinition(identifier *identifier.MetadataIdentifier) string { +func (MetadataReport) GetServiceDefinition(identifier *identifier.MetadataIdentifier) (string, error) { report := instance.GetMetadataReportInstance() return report.GetServiceDefinition(identifier) } diff --git a/metadata/report/nacos/report.go b/metadata/report/nacos/report.go index 7db4c85d9a..988ea12838 100644 --- a/metadata/report/nacos/report.go +++ b/metadata/report/nacos/report.go @@ -38,9 +38,8 @@ import ( ) func init() { - mf := &nacosMetadataReportFactory{} extension.SetMetadataReportFactory("nacos", func() factory.MetadataReportFactory { - return mf + return &nacosMetadataReportFactory{} }) } @@ -86,7 +85,7 @@ func (n *nacosMetadataReport) RemoveServiceMetadata(metadataIdentifier *identifi } // GetExportedURLs gets the urls. -func (n *nacosMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) []string { +func (n *nacosMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) ([]string, error) { return n.getConfigAsArray(vo.ConfigParam{ DataId: metadataIdentifier.GetIdentifierKey(), Group: metadataIdentifier.Group, @@ -103,7 +102,7 @@ func (n *nacosMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *i } // GetSubscribedURLs gets the urls. -func (n *nacosMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) []string { +func (n *nacosMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) ([]string, error) { return n.getConfigAsArray(vo.ConfigParam{ DataId: subscriberMetadataIdentifier.GetIdentifierKey(), Group: subscriberMetadataIdentifier.Group, @@ -111,7 +110,7 @@ func (n *nacosMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *id } // GetServiceDefinition gets the service definition. -func (n *nacosMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) string { +func (n *nacosMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) (string, error) { return n.getConfig(vo.ConfigParam{ DataId: metadataIdentifier.GetIdentifierKey(), Group: metadataIdentifier.Group, @@ -145,28 +144,34 @@ func (n *nacosMetadataReport) deleteMetadata(param vo.ConfigParam) error { // getConfigAsArray will read the config and then convert it as an one-element array // error or config not found, an empty list will be returned. -func (n *nacosMetadataReport) getConfigAsArray(param vo.ConfigParam) []string { - cfg := n.getConfig(param) +func (n *nacosMetadataReport) getConfigAsArray(param vo.ConfigParam) ([]string, error) { res := make([]string, 0, 1) + + cfg, err := n.getConfig(param) + if err != nil { + return res, err + } if len(cfg) == 0 { - return res + return res, nil } + decodeCfg, err := url.QueryUnescape(cfg) if err != nil { logger.Errorf("The config is invalid: %s", cfg) - return res + return res, err } res = append(res, decodeCfg) - return res + return res, nil } // getConfig will read the config -func (n *nacosMetadataReport) getConfig(param vo.ConfigParam) string { +func (n *nacosMetadataReport) getConfig(param vo.ConfigParam) (string, error) { cfg, err := n.client.GetConfig(param) if err != nil { logger.Errorf("Finding the configuration failed: %v", param) + return "", err } - return cfg + return cfg, nil } type nacosMetadataReportFactory struct { diff --git a/metadata/report/nacos/report_test.go b/metadata/report/nacos/report_test.go index 971c7bfe8f..be01eb22f7 100644 --- a/metadata/report/nacos/report_test.go +++ b/metadata/report/nacos/report_test.go @@ -54,8 +54,9 @@ func TestNacosMetadataReport_CRUD(t *testing.T) { err = rpt.SaveServiceMetadata(serviceMi, serviceUrl) assert.Nil(t, err) - exportedUrls := rpt.GetExportedURLs(serviceMi) + exportedUrls, err := rpt.GetExportedURLs(serviceMi) assert.Equal(t, 1, len(exportedUrls)) + assert.Nil(t, err) subMi := newSubscribeMetadataIdentifier() urls := []string{serviceUrl.String()} @@ -63,8 +64,9 @@ func TestNacosMetadataReport_CRUD(t *testing.T) { err = rpt.SaveSubscribedData(subMi, string(bytes)) assert.Nil(t, err) - subscribeUrl := rpt.GetSubscribedURLs(subMi) + subscribeUrl, err := rpt.GetSubscribedURLs(subMi) assert.Equal(t, 1, len(subscribeUrl)) + assert.Nil(t, err) err = rpt.RemoveServiceMetadata(serviceMi) assert.Nil(t, err) diff --git a/metadata/report/report.go b/metadata/report/report.go index d5930dc1fd..3ef8f5925e 100644 --- a/metadata/report/report.go +++ b/metadata/report/report.go @@ -28,8 +28,8 @@ type MetadataReport interface { StoreConsumerMetadata(*identifier.MetadataIdentifier, string) error SaveServiceMetadata(*identifier.ServiceMetadataIdentifier, common.URL) error RemoveServiceMetadata(*identifier.ServiceMetadataIdentifier) error - GetExportedURLs(*identifier.ServiceMetadataIdentifier) []string + GetExportedURLs(*identifier.ServiceMetadataIdentifier) ([]string, error) SaveSubscribedData(*identifier.SubscriberMetadataIdentifier, string) error - GetSubscribedURLs(*identifier.SubscriberMetadataIdentifier) []string - GetServiceDefinition(*identifier.MetadataIdentifier) string + GetSubscribedURLs(*identifier.SubscriberMetadataIdentifier) ([]string, error) + GetServiceDefinition(*identifier.MetadataIdentifier) (string, error) } diff --git a/metadata/report/zookeeper/report.go b/metadata/report/zookeeper/report.go index 955393f79c..58c4791c2b 100644 --- a/metadata/report/zookeeper/report.go +++ b/metadata/report/zookeeper/report.go @@ -37,9 +37,8 @@ var ( ) func init() { - mf := &zookeeperMetadataReportFactory{} extension.SetMetadataReportFactory("zookeeper", func() factory.MetadataReportFactory { - return mf + return &zookeeperMetadataReportFactory{} }) } @@ -75,17 +74,17 @@ func (m *zookeeperMetadataReport) RemoveServiceMetadata(metadataIdentifier *iden } // GetExportedURLs gets the urls. -func (m *zookeeperMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) []string { +func (m *zookeeperMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) ([]string, error) { k := m.rootDir + metadataIdentifier.GetFilePathKey() v, _, err := m.client.GetContent(k) if err != nil { - panic(err) + return emptyStrSlice, err } if len(v) == 0 { - return emptyStrSlice + return emptyStrSlice, nil } - return []string{string(v)} + return []string{string(v)}, nil } // SaveSubscribedData saves the urls. @@ -95,27 +94,27 @@ func (m *zookeeperMetadataReport) SaveSubscribedData(subscriberMetadataIdentifie } // GetSubscribedURLs gets the urls. -func (m *zookeeperMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) []string { +func (m *zookeeperMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) ([]string, error) { k := m.rootDir + subscriberMetadataIdentifier.GetFilePathKey() v, _, err := m.client.GetContent(k) if err != nil { - panic(err) + return emptyStrSlice, err } if len(v) == 0 { - return emptyStrSlice + return emptyStrSlice, nil } - return []string{string(v)} + return []string{string(v)}, nil } // GetServiceDefinition gets the service definition. -func (m *zookeeperMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) string { +func (m *zookeeperMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) (string, error) { k := m.rootDir + metadataIdentifier.GetFilePathKey() v, _, err := m.client.GetContent(k) if err != nil { - panic(err) + return "", err } - return string(v) + return string(v), nil } type zookeeperMetadataReportFactory struct { diff --git a/metadata/report/zookeeper/report_test.go b/metadata/report/zookeeper/report_test.go index c83022bd34..5d25e3c496 100644 --- a/metadata/report/zookeeper/report_test.go +++ b/metadata/report/zookeeper/report_test.go @@ -115,8 +115,9 @@ func (suite *zookeeperMetadataReportTestSuite) testRemoveServiceMetadata() { func (suite *zookeeperMetadataReportTestSuite) testGetExportedURLs() { serviceMi := newServiceMetadataIdentifier("provider") - urls := suite.m.GetExportedURLs(serviceMi) + urls, err := suite.m.GetExportedURLs(serviceMi) assert.Equal(suite.t, 1, len(urls)) + assert.NoError(suite.t, err) } func (suite *zookeeperMetadataReportTestSuite) testSaveSubscribedData(url common.URL) { @@ -129,14 +130,16 @@ func (suite *zookeeperMetadataReportTestSuite) testSaveSubscribedData(url common func (suite *zookeeperMetadataReportTestSuite) testGetSubscribedURLs() { subscribeMi := newSubscribeMetadataIdentifier("provider") - urls := suite.m.GetSubscribedURLs(subscribeMi) + urls, err := suite.m.GetSubscribedURLs(subscribeMi) assert.Equal(suite.t, 1, len(urls)) + assert.NoError(suite.t, err) } func (suite *zookeeperMetadataReportTestSuite) testGetServiceDefinition() { providerMi := newMetadataIdentifier("provider") - providerMeta := suite.m.GetServiceDefinition(providerMi) + providerMeta, err := suite.m.GetServiceDefinition(providerMi) assert.Equal(suite.t, "provider", providerMeta) + assert.NoError(suite.t, err) } func test1(t *testing.T) { From a601a33732672421c8b5e652063f3682221fd35e Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Mon, 29 Jun 2020 13:19:29 +0800 Subject: [PATCH 14/19] fix bug --- metadata/service/remote/service_test.go | 27 +++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/metadata/service/remote/service_test.go b/metadata/service/remote/service_test.go index 12ef472ecb..3b4a12045c 100644 --- a/metadata/service/remote/service_test.go +++ b/metadata/service/remote/service_test.go @@ -73,8 +73,8 @@ func (metadataReport) RemoveServiceMetadata(*identifier.ServiceMetadataIdentifie return nil } -func (metadataReport) GetExportedURLs(*identifier.ServiceMetadataIdentifier) []string { - return nil +func (metadataReport) GetExportedURLs(*identifier.ServiceMetadataIdentifier) ([]string, error) { + return nil, nil } func (mr *metadataReport) SaveSubscribedData(id *identifier.SubscriberMetadataIdentifier, urls string) error { @@ -83,12 +83,12 @@ func (mr *metadataReport) SaveSubscribedData(id *identifier.SubscriberMetadataId return nil } -func (metadataReport) GetSubscribedURLs(*identifier.SubscriberMetadataIdentifier) []string { - return nil +func (metadataReport) GetSubscribedURLs(*identifier.SubscriberMetadataIdentifier) ([]string, error) { + return nil, nil } -func (metadataReport) GetServiceDefinition(*identifier.MetadataIdentifier) string { - return "" +func (metadataReport) GetServiceDefinition(*identifier.MetadataIdentifier) (string, error) { + return "", nil } func TestMetadataService(t *testing.T) { @@ -111,6 +111,7 @@ func mockInmemoryProc(t *testing.T) *inmemory.MetadataService { version := "0.0.1" protocol := "dubbo" beanName := "UserProvider" + userProvider := &definition.UserProvider{} u, err := common.NewURL(fmt.Sprintf( "%v://127.0.0.1:20000/com.ikurento.user.UserProvider1?anyhost=true&"+ @@ -119,13 +120,17 @@ func mockInmemoryProc(t *testing.T) *inmemory.MetadataService { "owner=ZX&pid=1447&revision=0.0.1&side=provider&timeout=3000×tamp=1556509797245&group=%v&version=%v&bean.name=%v", protocol, serviceName, group, version, beanName)) assert.NoError(t, err) - mts.ExportURL(u) - mts.SubscribeURL(u) + _, err = mts.ExportURL(u) + assert.NoError(t, err) + _, err = mts.SubscribeURL(u) + assert.NoError(t, err) + + _, err = common.ServiceMap.Register(serviceName, protocol, userProvider) + assert.NoError(t, err) + err = mts.PublishServiceDefinition(u) + assert.NoError(t, err) - userProvider := &definition.UserProvider{} - common.ServiceMap.Register(serviceName, protocol, userProvider) - mts.PublishServiceDefinition(u) expected := "{\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," + "\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," + "\"Parameters\":null}],\"Types\":null}" From f00d104bfb91ffda9245ac7697cd793f6508d087 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Mon, 29 Jun 2020 13:32:16 +0800 Subject: [PATCH 15/19] rename consul agent for test --- metadata/report/factory/report_factory.go | 4 ---- remoting/consul/{agent.go => test_agent.go} | 0 remoting/consul/{agent_test.go => test_agent_test.go} | 0 3 files changed, 4 deletions(-) rename remoting/consul/{agent.go => test_agent.go} (100%) rename remoting/consul/{agent_test.go => test_agent_test.go} (100%) diff --git a/metadata/report/factory/report_factory.go b/metadata/report/factory/report_factory.go index 8769ebdd2f..9f00007cef 100644 --- a/metadata/report/factory/report_factory.go +++ b/metadata/report/factory/report_factory.go @@ -22,10 +22,6 @@ import ( "github.com/apache/dubbo-go/metadata/report" ) -var ( - MetadataReportInstance report.MetadataReport -) - // MetadataReportFactory interface will create metadata report type MetadataReportFactory interface { CreateMetadataReport(*common.URL) report.MetadataReport diff --git a/remoting/consul/agent.go b/remoting/consul/test_agent.go similarity index 100% rename from remoting/consul/agent.go rename to remoting/consul/test_agent.go diff --git a/remoting/consul/agent_test.go b/remoting/consul/test_agent_test.go similarity index 100% rename from remoting/consul/agent_test.go rename to remoting/consul/test_agent_test.go From a23c6d23bcd1520712d71209117054ad20b7a0dc Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Wed, 1 Jul 2020 21:02:39 +0800 Subject: [PATCH 16/19] fix --- metadata/report/consul/report.go | 22 ++++++---------------- metadata/report/nacos/report.go | 10 +++++----- metadata/report/zookeeper/report.go | 21 ++++++--------------- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/metadata/report/consul/report.go b/metadata/report/consul/report.go index 2d3d00d608..eb2bdc25ec 100644 --- a/metadata/report/consul/report.go +++ b/metadata/report/consul/report.go @@ -34,8 +34,9 @@ var ( ) func init() { + mf := &consulMetadataReportFactory{} extension.SetMetadataReportFactory("consul", func() factory.MetadataReportFactory { - return &consulMetadataReportFactory{} + return mf }) } @@ -77,13 +78,9 @@ func (m *consulMetadataReport) RemoveServiceMetadata(metadataIdentifier *identif func (m *consulMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) ([]string, error) { k := metadataIdentifier.GetIdentifierKey() kv, _, err := m.client.KV().Get(k, nil) - if err != nil { + if err != nil || kv == nil { return emptyStrSlice, err } - - if kv == nil { - return emptyStrSlice, nil - } return []string{string(kv.Value)}, nil } @@ -98,13 +95,9 @@ func (m *consulMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier * func (m *consulMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) ([]string, error) { k := subscriberMetadataIdentifier.GetIdentifierKey() kv, _, err := m.client.KV().Get(k, nil) - if err != nil { + if err != nil || kv == nil { return emptyStrSlice, err } - - if kv == nil { - return emptyStrSlice, nil - } return []string{string(kv.Value)}, nil } @@ -112,19 +105,16 @@ func (m *consulMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *i func (m *consulMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) (string, error) { k := metadataIdentifier.GetIdentifierKey() kv, _, err := m.client.KV().Get(k, nil) - if err != nil { + if err != nil || kv == nil { return "", err } - - if kv == nil { - return "", nil - } return string(kv.Value), nil } type consulMetadataReportFactory struct { } +// nolint func (mf *consulMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport { config := &consul.Config{Address: url.Location} client, err := consul.NewClient(config) diff --git a/metadata/report/nacos/report.go b/metadata/report/nacos/report.go index 988ea12838..d69913bd8f 100644 --- a/metadata/report/nacos/report.go +++ b/metadata/report/nacos/report.go @@ -38,8 +38,9 @@ import ( ) func init() { + mf := &nacosMetadataReportFactory{} extension.SetMetadataReportFactory("nacos", func() factory.MetadataReportFactory { - return &nacosMetadataReportFactory{} + return mf }) } @@ -148,18 +149,16 @@ func (n *nacosMetadataReport) getConfigAsArray(param vo.ConfigParam) ([]string, res := make([]string, 0, 1) cfg, err := n.getConfig(param) - if err != nil { + if err != nil || len(cfg) == 0 { return res, err } - if len(cfg) == 0 { - return res, nil - } decodeCfg, err := url.QueryUnescape(cfg) if err != nil { logger.Errorf("The config is invalid: %s", cfg) return res, err } + res = append(res, decodeCfg) return res, nil } @@ -177,6 +176,7 @@ func (n *nacosMetadataReport) getConfig(param vo.ConfigParam) (string, error) { type nacosMetadataReportFactory struct { } +// nolint func (n *nacosMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport { client, err := nacos.NewNacosConfigClient(url) if err != nil { diff --git a/metadata/report/zookeeper/report.go b/metadata/report/zookeeper/report.go index 58c4791c2b..8f46bb0230 100644 --- a/metadata/report/zookeeper/report.go +++ b/metadata/report/zookeeper/report.go @@ -37,8 +37,9 @@ var ( ) func init() { + mf := &zookeeperMetadataReportFactory{} extension.SetMetadataReportFactory("zookeeper", func() factory.MetadataReportFactory { - return &zookeeperMetadataReportFactory{} + return mf }) } @@ -77,13 +78,9 @@ func (m *zookeeperMetadataReport) RemoveServiceMetadata(metadataIdentifier *iden func (m *zookeeperMetadataReport) GetExportedURLs(metadataIdentifier *identifier.ServiceMetadataIdentifier) ([]string, error) { k := m.rootDir + metadataIdentifier.GetFilePathKey() v, _, err := m.client.GetContent(k) - if err != nil { + if err != nil || len(v) == 0 { return emptyStrSlice, err } - - if len(v) == 0 { - return emptyStrSlice, nil - } return []string{string(v)}, nil } @@ -97,13 +94,9 @@ func (m *zookeeperMetadataReport) SaveSubscribedData(subscriberMetadataIdentifie func (m *zookeeperMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) ([]string, error) { k := m.rootDir + subscriberMetadataIdentifier.GetFilePathKey() v, _, err := m.client.GetContent(k) - if err != nil { + if err != nil || len(v) == 0 { return emptyStrSlice, err } - - if len(v) == 0 { - return emptyStrSlice, nil - } return []string{string(v)}, nil } @@ -111,15 +104,13 @@ func (m *zookeeperMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier func (m *zookeeperMetadataReport) GetServiceDefinition(metadataIdentifier *identifier.MetadataIdentifier) (string, error) { k := m.rootDir + metadataIdentifier.GetFilePathKey() v, _, err := m.client.GetContent(k) - if err != nil { - return "", err - } - return string(v), nil + return string(v), err } type zookeeperMetadataReportFactory struct { } +// nolint func (mf *zookeeperMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport { client, err := zookeeper.NewZookeeperClient( "zookeeperMetadataReport", From 724854429c4c471c481e8d40385ecbe2acd6e701 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Wed, 1 Jul 2020 21:04:37 +0800 Subject: [PATCH 17/19] fix typo --- metadata/report/delegate/delegate_report_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metadata/report/delegate/delegate_report_test.go b/metadata/report/delegate/delegate_report_test.go index 04c9e64839..3dfca577ba 100644 --- a/metadata/report/delegate/delegate_report_test.go +++ b/metadata/report/delegate/delegate_report_test.go @@ -75,14 +75,14 @@ func TestMetadataReport_MetadataReportRetryWithLimit(t *testing.T) { func mockNewMetadataReport(t *testing.T) *MetadataReport { syncReportKey := "false" - retryPeroidKey := "3" + retryPeriodKey := "3" retryTimesKey := "100" cycleReportKey := "true" url, err := common.NewURL(fmt.Sprintf( "test://127.0.0.1:20000/?"+constant.SYNC_REPORT_KEY+"=%v&"+constant.RETRY_PERIOD_KEY+"=%v&"+ constant.RETRY_TIMES_KEY+"=%v&"+constant.CYCLE_REPORT_KEY+"=%v", - syncReportKey, retryPeroidKey, retryTimesKey, cycleReportKey)) + syncReportKey, retryPeriodKey, retryTimesKey, cycleReportKey)) assert.NoError(t, err) instance.SetMetadataReportUrl(url) mtr, err := NewMetadataReport() From f66dda85423af05e7776b11508eedc25553b3716 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Wed, 1 Jul 2020 21:18:02 +0800 Subject: [PATCH 18/19] update zk library version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ba3cf3e219..85efde193c 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/creasty/defaults v1.3.0 github.com/dubbogo/getty v1.3.5 - github.com/dubbogo/go-zookeeper v1.0.0 + github.com/dubbogo/go-zookeeper v1.0.1 github.com/dubbogo/gost v1.9.0 github.com/emicklei/go-restful/v3 v3.0.0 github.com/go-co-op/gocron v0.1.1 diff --git a/go.sum b/go.sum index eb84bde1fb..00b1eb02ee 100644 --- a/go.sum +++ b/go.sum @@ -106,8 +106,8 @@ github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dubbogo/getty v1.3.5 h1:xJxdDj9jm7wlrRSsVZSk2TDNxJbbac5GpxV0QpjO+Tw= github.com/dubbogo/getty v1.3.5/go.mod h1:T55vN8Q6tZjf2AQZiGmkujneD3LfqYbv2b3QjacwYOY= -github.com/dubbogo/go-zookeeper v1.0.0 h1:RsYdlGwhDW+iKXM3eIIcvt34P2swLdmQfuIJxsHlGoM= -github.com/dubbogo/go-zookeeper v1.0.0/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= +github.com/dubbogo/go-zookeeper v1.0.1 h1:irLzvOsDOTNsN8Sv9tvYYxVu6DCQfLtziZQtUHmZgz8= +github.com/dubbogo/go-zookeeper v1.0.1/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= github.com/dubbogo/gost v1.5.1/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= github.com/dubbogo/gost v1.9.0 h1:UT+dWwvLyJiDotxJERO75jB3Yxgsdy10KztR5ycxRAk= github.com/dubbogo/gost v1.9.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= From 302dbc220e46e022c8cbb86a430b1aa0e39733c2 Mon Sep 17 00:00:00 2001 From: "xg.gao" Date: Wed, 1 Jul 2020 23:38:42 +0800 Subject: [PATCH 19/19] simplify and comment --- metadata/report/consul/report_test.go | 3 +-- metadata/report/report.go | 27 +++++++++++++++++++++++- metadata/report/zookeeper/report_test.go | 3 +-- registry/consul/utils_test.go | 12 ++++------- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/metadata/report/consul/report_test.go b/metadata/report/consul/report_test.go index b982d71765..34ee29de94 100644 --- a/metadata/report/consul/report_test.go +++ b/metadata/report/consul/report_test.go @@ -38,13 +38,12 @@ import ( ) func newProviderRegistryUrl(host string, port int) *common.URL { - url1 := common.NewURLWithOptions( + return common.NewURLWithOptions( common.WithIp(host), common.WithPort(strconv.Itoa(port)), common.WithParams(url.Values{}), common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)), ) - return url1 } func newBaseMetadataIdentifier(side string) *identifier.BaseMetadataIdentifier { diff --git a/metadata/report/report.go b/metadata/report/report.go index 3ef8f5925e..62a9055e84 100644 --- a/metadata/report/report.go +++ b/metadata/report/report.go @@ -22,14 +22,39 @@ import ( "github.com/apache/dubbo-go/metadata/identifier" ) -// MetadataReport is an interface of remote metadata report +// MetadataReport is an interface of +// remote metadata report. type MetadataReport interface { + // StoreProviderMetadata stores the metadata. + // Metadata includes the basic info of the server, + // provider info, and other user custom info. StoreProviderMetadata(*identifier.MetadataIdentifier, string) error + + // StoreConsumerMetadata stores the metadata. + // Metadata includes the basic info of the server, + // consumer info, and other user custom info. StoreConsumerMetadata(*identifier.MetadataIdentifier, string) error + + // SaveServiceMetadata saves the metadata. + // Metadata includes the basic info of the server, + // service info, and other user custom info. SaveServiceMetadata(*identifier.ServiceMetadataIdentifier, common.URL) error + + // RemoveServiceMetadata removes the metadata. RemoveServiceMetadata(*identifier.ServiceMetadataIdentifier) error + + // GetExportedURLs gets the urls. + // If not found, an empty list will be returned. GetExportedURLs(*identifier.ServiceMetadataIdentifier) ([]string, error) + + // SaveSubscribedData saves the urls. + // If not found, an empty str will be returned. SaveSubscribedData(*identifier.SubscriberMetadataIdentifier, string) error + + // GetSubscribedURLs gets the urls. + // If not found, an empty list will be returned. GetSubscribedURLs(*identifier.SubscriberMetadataIdentifier) ([]string, error) + + // GetServiceDefinition gets the service definition. GetServiceDefinition(*identifier.MetadataIdentifier) (string, error) } diff --git a/metadata/report/zookeeper/report_test.go b/metadata/report/zookeeper/report_test.go index 5d25e3c496..a1e46e2e8d 100644 --- a/metadata/report/zookeeper/report_test.go +++ b/metadata/report/zookeeper/report_test.go @@ -38,13 +38,12 @@ import ( ) func newProviderRegistryUrl(host string, port int) *common.URL { - url1 := common.NewURLWithOptions( + return common.NewURLWithOptions( common.WithIp(host), common.WithPort(strconv.Itoa(port)), common.WithParams(url.Values{}), common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)), ) - return url1 } func newBaseMetadataIdentifier(side string) *identifier.BaseMetadataIdentifier { diff --git a/registry/consul/utils_test.go b/registry/consul/utils_test.go index 1ef2004139..327dd95f71 100644 --- a/registry/consul/utils_test.go +++ b/registry/consul/utils_test.go @@ -46,43 +46,39 @@ var ( ) func newProviderRegistryUrl(host string, port int) *common.URL { - url1 := common.NewURLWithOptions( + return common.NewURLWithOptions( common.WithIp(host), common.WithPort(strconv.Itoa(port)), common.WithParams(url.Values{}), common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)), ) - return url1 } func newConsumerRegistryUrl(host string, port int) *common.URL { - url1 := common.NewURLWithOptions( + return common.NewURLWithOptions( common.WithIp(host), common.WithPort(strconv.Itoa(port)), common.WithParams(url.Values{}), common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER)), ) - return url1 } func newProviderUrl(host string, port int, service string, protocol string) common.URL { - url1 := common.NewURLWithOptions( + return *common.NewURLWithOptions( common.WithIp(host), common.WithPort(strconv.Itoa(port)), common.WithPath(service), common.WithProtocol(protocol), ) - return *url1 } func newConsumerUrl(host string, port int, service string, protocol string) common.URL { - url1 := common.NewURLWithOptions( + return *common.NewURLWithOptions( common.WithIp(host), common.WithPort(strconv.Itoa(port)), common.WithPath(service), common.WithProtocol(protocol), ) - return *url1 } type testServer struct {