This is an automated email from the ASF dual-hosted git repository. laurence pushed a commit to branch config-api in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
commit f2948997d328028480dbb9fbfc4420fa8fed59a4 Author: LaurenceLiZhixin <[email protected]> AuthorDate: Sat Oct 2 15:55:40 2021 +0800 fix: pass ut --- config/dubbo_bootstrap.go | 117 --------------------- config/logger_config.go | 9 -- config/root_config.go | 92 ++++++++++++++++ config/testdata/application.yaml | 4 +- config/testdata/config/app/application.yaml | 2 +- config/testdata/config/provider/application.yaml | 4 +- .../config/provider/registry_application.yaml | 4 +- config/testdata/consumer_config.yml | 2 +- .../testdata/consumer_config_with_configcenter.yml | 2 +- .../testdata/consumer_config_withoutProtocol.yml | 2 +- config/testdata/provider_config.yml | 2 +- .../testdata/provider_config_withoutProtocol.yml | 2 +- .../service/exporter/configurable/exporter_test.go | 2 +- 13 files changed, 105 insertions(+), 139 deletions(-) diff --git a/config/dubbo_bootstrap.go b/config/dubbo_bootstrap.go deleted file mode 100644 index 1513d79..0000000 --- a/config/dubbo_bootstrap.go +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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 config - -import ( - "sync" -) - -import ( - hessian "github.com/apache/dubbo-go-hessian2" -) - -import ( - "dubbo.apache.org/dubbo-go/v3/common" - "dubbo.apache.org/dubbo-go/v3/common/constant" - "dubbo.apache.org/dubbo-go/v3/common/logger" -) - -var ( - startOnce sync.Once -) - -func registerPOJO() { - hessian.RegisterPOJO(&common.MetadataInfo{}) - hessian.RegisterPOJO(&common.ServiceInfo{}) - hessian.RegisterPOJO(&common.URL{}) -} - -func (rc *RootConfig) Init() error { - registerPOJO() - if err := rc.Logger.Init(); err != nil { - return err - } - if err := rc.ConfigCenter.Init(rc); err != nil { - logger.Warnf("config center doesn't start. error is %s", err) - } - if err := rc.Application.Init(); err != nil { - return err - } - - // init protocol - protocols := rc.Protocols - if len(protocols) <= 0 { - protocol := &ProtocolConfig{} - protocols = make(map[string]*ProtocolConfig, 1) - protocols[constant.DUBBO] = protocol - rc.Protocols = protocols - } - for _, protocol := range protocols { - if err := protocol.Init(); err != nil { - return err - } - } - - // init registry - registries := rc.Registries - if registries != nil { - for _, reg := range registries { - if err := reg.Init(); err != nil { - return err - } - } - } - - // init serviceDiscoveries - serviceDiscoveries := rc.ServiceDiscoveries - if serviceDiscoveries != nil { - for _, sd := range serviceDiscoveries { - if err := sd.Init(); err != nil { - return err - } - } - } - - if err := rc.MetadataReport.Init(rc); err != nil { - return err - } - if err := rc.Metric.Init(); err != nil { - return err - } - if err := initRouterConfig(rc); err != nil { - return err - } - // provider、consumer must last init - if err := rc.Provider.Init(rc); err != nil { - return err - } - if err := rc.Consumer.Init(rc); err != nil { - return err - } - - rc.Start() - return nil -} - -func (rc *RootConfig) Start() { - startOnce.Do(func() { - rc.Provider.Load() - rc.Consumer.Load() - registerServiceInstance() - }) -} diff --git a/config/logger_config.go b/config/logger_config.go index 0e7ec43..444bc38 100644 --- a/config/logger_config.go +++ b/config/logger_config.go @@ -72,16 +72,7 @@ func (LoggerConfig) Prefix() string { return constant.LoggerConfigPrefix } -func GetLoggerConfigInstance() *LoggerConfig { - lc := &LoggerConfig{} - return lc -} - func (lc *LoggerConfig) Init() error { - - if lc == nil { - lc = GetLoggerConfigInstance() - } err := lc.check() if err != nil { return err diff --git a/config/root_config.go b/config/root_config.go index 86e5ed0..c7f8205 100644 --- a/config/root_config.go +++ b/config/root_config.go @@ -19,10 +19,21 @@ package config import ( _ "net/http/pprof" + "sync" ) import ( + hessian "github.com/apache/dubbo-go-hessian2" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/common" "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/common/logger" +) + +var ( + startOnce sync.Once ) // RootConfig is the root config @@ -113,6 +124,86 @@ func (rc *RootConfig) getRegistryIds() []string { } return removeDuplicateElement(ids) } +func registerPOJO() { + hessian.RegisterPOJO(&common.MetadataInfo{}) + hessian.RegisterPOJO(&common.ServiceInfo{}) + hessian.RegisterPOJO(&common.URL{}) +} + +func (rc *RootConfig) Init() error { + registerPOJO() + if err := rc.Logger.Init(); err != nil { + return err + } + if err := rc.ConfigCenter.Init(rc); err != nil { + logger.Warnf("config center doesn't start. error is %s", err) + } + if err := rc.Application.Init(); err != nil { + return err + } + + // init protocol + protocols := rc.Protocols + if len(protocols) <= 0 { + protocol := &ProtocolConfig{} + protocols = make(map[string]*ProtocolConfig, 1) + protocols[constant.DUBBO] = protocol + rc.Protocols = protocols + } + for _, protocol := range protocols { + if err := protocol.Init(); err != nil { + return err + } + } + + // init registry + registries := rc.Registries + if registries != nil { + for _, reg := range registries { + if err := reg.Init(); err != nil { + return err + } + } + } + + // init serviceDiscoveries + serviceDiscoveries := rc.ServiceDiscoveries + if serviceDiscoveries != nil { + for _, sd := range serviceDiscoveries { + if err := sd.Init(); err != nil { + return err + } + } + } + + if err := rc.MetadataReport.Init(rc); err != nil { + return err + } + if err := rc.Metric.Init(); err != nil { + return err + } + if err := initRouterConfig(rc); err != nil { + return err + } + // provider、consumer must last init + if err := rc.Provider.Init(rc); err != nil { + return err + } + if err := rc.Consumer.Init(rc); err != nil { + return err + } + + rc.Start() + return nil +} + +func (rc *RootConfig) Start() { + startOnce.Do(func() { + rc.Provider.Load() + rc.Consumer.Load() + registerServiceInstance() + }) +} // newEmptyRootConfig get empty root config func newEmptyRootConfig() *RootConfig { @@ -126,6 +217,7 @@ func newEmptyRootConfig() *RootConfig { Provider: NewProviderConfigBuilder().Build(), Consumer: NewConsumerConfigBuilder().Build(), Metric: NewMetricConfigBuilder().Build(), + Logger: NewLoggerConfigBuilder().Build(), } return newRootConfig } diff --git a/config/testdata/application.yaml b/config/testdata/application.yaml index f0876a1..2325e87 100644 --- a/config/testdata/application.yaml +++ b/config/testdata/application.yaml @@ -26,10 +26,10 @@ dubbo: services: helloService: interface: org.dubbo.service.HelloService - registry: nacos,zk + registries: nacos,zk orderService: interface: org.dubbo.service.OrderService - registry: nacos + registries: nacos provider: register: true services: \ No newline at end of file diff --git a/config/testdata/config/app/application.yaml b/config/testdata/config/app/application.yaml index 4cd30cc..418201f 100644 --- a/config/testdata/config/app/application.yaml +++ b/config/testdata/config/app/application.yaml @@ -14,7 +14,7 @@ dubbo: interface: org.github.dubbo.HelloService # must be compatible with grpc or dubbo-java provider: register: true - registry: nacos + registries: nacos services: helloService: protocol: dubbo diff --git a/config/testdata/config/provider/application.yaml b/config/testdata/config/provider/application.yaml index 8816257..92f1de7 100644 --- a/config/testdata/config/provider/application.yaml +++ b/config/testdata/config/provider/application.yaml @@ -6,12 +6,12 @@ dubbo: address: nacos://127.0.0.1:8848 provider: register: true - registry: + registries: - nacos - zk services: helloService: interface: org.dubbo.service.HelloService - registry: nacos,zk + registries: nacos,zk orderService: interface: org.dubbo.service.OrderService \ No newline at end of file diff --git a/config/testdata/config/provider/registry_application.yaml b/config/testdata/config/provider/registry_application.yaml index dd08a0d..b00b854 100644 --- a/config/testdata/config/provider/registry_application.yaml +++ b/config/testdata/config/provider/registry_application.yaml @@ -4,10 +4,10 @@ dubbo: timeout: 3s address: naocs://127.0.0.1:8848 provider: - registry: nacos + registries: nacos services: HelloService: interface: org.dubbo.service.HelloService - registry: nacos,zk + registries: nacos,zk OrderService: interface: org.dubbo.service.OrderService \ No newline at end of file diff --git a/config/testdata/consumer_config.yml b/config/testdata/consumer_config.yml index c011c9e..118460b 100644 --- a/config/testdata/consumer_config.yml +++ b/config/testdata/consumer_config.yml @@ -33,7 +33,7 @@ registries : references: "UserProvider": - registry: "hangzhouzk,shanghaizk" + registries: "hangzhouzk,shanghaizk" filter: "" protocol : "dubbo" version: "1.0" diff --git a/config/testdata/consumer_config_with_configcenter.yml b/config/testdata/consumer_config_with_configcenter.yml index fe979da..f6352da 100644 --- a/config/testdata/consumer_config_with_configcenter.yml +++ b/config/testdata/consumer_config_with_configcenter.yml @@ -7,7 +7,7 @@ config_center: address: "127.0.0.1" references: "UserProvider": - registry: "hangzhouzk,shanghaizk" + registries: "hangzhouzk,shanghaizk" filter: "" protocol : "dubbo" interface : "com.ikurento.user.UserProvider" diff --git a/config/testdata/consumer_config_withoutProtocol.yml b/config/testdata/consumer_config_withoutProtocol.yml index 6028a48..4efd21c 100644 --- a/config/testdata/consumer_config_withoutProtocol.yml +++ b/config/testdata/consumer_config_withoutProtocol.yml @@ -33,7 +33,7 @@ registries : references: "UserProvider": - registry: "hangzhouzk,shanghaizk" + registries: "hangzhouzk,shanghaizk" filter: "" version: "1.0" group: "as" diff --git a/config/testdata/provider_config.yml b/config/testdata/provider_config.yml index 3c081c0..10282db 100644 --- a/config/testdata/provider_config.yml +++ b/config/testdata/provider_config.yml @@ -27,7 +27,7 @@ registries : services: "UserProvider": - registry: "hangzhouzk,shanghaizk" + registries: "hangzhouzk,shanghaizk" filter: "" # the name of limiter tps.limiter: "default" diff --git a/config/testdata/provider_config_withoutProtocol.yml b/config/testdata/provider_config_withoutProtocol.yml index 651c2f4..1636b0c 100644 --- a/config/testdata/provider_config_withoutProtocol.yml +++ b/config/testdata/provider_config_withoutProtocol.yml @@ -27,7 +27,7 @@ registries : services: "UserProvider": - registry: "hangzhouzk,shanghaizk" + registries: "hangzhouzk,shanghaizk" filter: "" # equivalent to interface of dubbo.xml interface : "com.ikurento.user.UserProvider" diff --git a/metadata/service/exporter/configurable/exporter_test.go b/metadata/service/exporter/configurable/exporter_test.go index 7afaef6..3ec072c 100644 --- a/metadata/service/exporter/configurable/exporter_test.go +++ b/metadata/service/exporter/configurable/exporter_test.go @@ -70,7 +70,7 @@ func TestConfigurableExporter(t *testing.T) { assert.Equal(t, false, exported.IsExported()) assert.NoError(t, exported.Export(registryURL)) assert.Equal(t, true, exported.IsExported()) - assert.Regexp(t, "dubbo://127.0.0.1:20005/org.apache.dubbo.metadata.MetadataService*", exported.GetExportedURLs()[0].String()) + assert.Regexp(t, "dubbo://:20005/org.apache.dubbo.metadata.MetadataService*", exported.GetExportedURLs()[0].String()) exported.Unexport() assert.Equal(t, false, exported.IsExported()) })
