Skip to content

Commit

Permalink
Merge pull request #7 from flycash/2.7.5-bk
Browse files Browse the repository at this point in the history
2.7.5 bk
  • Loading branch information
xianlezheng authored Jun 20, 2020
2 parents 85607f2 + 904bbdb commit b242ae3
Show file tree
Hide file tree
Showing 49 changed files with 647 additions and 480 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ About dubbo-go benchmarking report, please refer to [dubbo benchmarking report](
If you are using [apache/dubbo-go](github.com/apache/dubbo-go) and think that it helps you or want do some contributions to it, please add your company to to [the user list](https://github.com/apache/dubbo-go/issues/2) to let us know your needs.

![ctrip](https://pic.c-ctrip.com/common/c_logo2013.png)
![Excellent Health Technology Group](https://raw.githubusercontent.com/dajiiu/photo/static/mirror/haozhuo_logo.png)
![Excellent Health Technology Group](https://user-images.githubusercontent.com/52339367/84628582-80512200-af1b-11ea-945a-c6b4b9ad31f2.png)
![tuya](https://raw.githubusercontent.com/pantianying/go-tool/master/picture/logo_2-removebg-preview.png)
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ go test ./... -coverprofile=coverage.txt -covermode=atomic
若你正在使用 [apache/dubbo-go](github.com/apache/dubbo-go) 且认为其有用或者向对其做改进,请忝列贵司信息于 [用户列表](https://github.com/apache/dubbo-go/issues/2),以便我们知晓之。

![ctrip](https://pic.c-ctrip.com/common/c_logo2013.png)
![Excellent Health Technology Group](https://raw.githubusercontent.com/dajiiu/photo/static/mirror/haozhuo_logo.png)
![Excellent Health Technology Group](https://user-images.githubusercontent.com/52339367/84628582-80512200-af1b-11ea-945a-c6b4b9ad31f2.png)
![tuya](https://raw.githubusercontent.com/pantianying/go-tool/master/picture/logo_2-removebg-preview.png)
2 changes: 1 addition & 1 deletion common/extension/event_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func SetAndInitGlobalDispatcher(name string) {
name = "direct"
}
if globalEventDispatcher != nil {
logger.Warnf("EventDispatcher already init. It will be replaced")
logger.Warnf("EventDispatcher has been initialized. It will be replaced")
}

if dp, ok := dispatchers[name]; !ok || dp == nil {
Expand Down
14 changes: 9 additions & 5 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ var (
providerConfig *ProviderConfig
// baseConfig = providerConfig.BaseConfig or consumerConfig
baseConfig *BaseConfig
// baseConfigOnce is used to make sure that we only create it once.
baseConfigOnce sync.Once

// configAccessMutex is used to make sure that BaseConfig.xxxxConfig will only be created once if needed.
// configAccessMutex is used to make sure that xxxxConfig will only be created once if needed.
// it should be used combine with double-check to avoid the race condition
configAccessMutex sync.Mutex

Expand All @@ -69,13 +67,17 @@ func init() {
log.Printf("[consumerInit] %#v", errCon)
consumerConfig = nil
} else {
// Even though baseConfig has been initialized, we override it
// because we think read from config file is correct config
baseConfig = &consumerConfig.BaseConfig
}

if errPro := ProviderInit(confProFile); errPro != nil {
log.Printf("[providerInit] %#v", errPro)
providerConfig = nil
} else {
// Even though baseConfig has been initialized, we override it
// because we think read from config file is correct config
baseConfig = &providerConfig.BaseConfig
}
}
Expand Down Expand Up @@ -308,15 +310,17 @@ func GetConsumerConfig() ConsumerConfig {

func GetBaseConfig() *BaseConfig {
if baseConfig == nil {
baseConfigOnce.Do(func() {
configAccessMutex.Lock()
defer configAccessMutex.Unlock()
if baseConfig == nil {
baseConfig = &BaseConfig{
MetricConfig: &MetricConfig{},
ConfigCenterConfig: &ConfigCenterConfig{},
Remotes: make(map[string]*RemoteConfig, 0),
ApplicationConfig: &ApplicationConfig{},
ServiceDiscoveries: make(map[string]*ServiceDiscoveryConfig, 0),
}
})
}
}
return baseConfig
}
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/magiconair/properties v1.8.1
github.com/mitchellh/mapstructure v1.1.2
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
github.com/nacos-group/nacos-sdk-go v0.3.1
github.com/nacos-group/nacos-sdk-go v0.3.3-0.20200617023039-50c7537d6a5f
github.com/opentracing/opentracing-go v1.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.1.0
Expand All @@ -56,5 +56,3 @@ require (
)

go 1.13

replace github.com/nacos-group/nacos-sdk-go => /Users/mindeng/go-workspace/src/nacos-sdk-go
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nacos-group/nacos-sdk-go v0.3.1 h1:MI7bNDAN5m9UFcRRUTSPfJi4dCQo+TYG85qVB1rCHeg=
github.com/nacos-group/nacos-sdk-go v0.3.1/go.mod h1:ESKb6yF0gxSc8GuS+0jaMBe+n8rJ5/k4ya6LyFG2xi8=
github.com/nacos-group/nacos-sdk-go v0.3.3-0.20200617023039-50c7537d6a5f h1:gid5/0AkHvINWK69Fgbidb3BVIXqlf1YEm7wO0NVPsw=
github.com/nacos-group/nacos-sdk-go v0.3.3-0.20200617023039-50c7537d6a5f/go.mod h1:fti1GlX/EB6RDKvzK/P7Vuibqj0JMPJHQwrcTU1tLXk=
github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2 h1:BQ1HW7hr4IVovMwWg0E0PYcyW8CzqDcVmaew9cujU4s=
github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2/go.mod h1:TLb2Sg7HQcgGdloNxkrmtgDNR9uVYF3lfdFIN4Ro6Sk=
github.com/oklog/run v0.0.0-20180308005104-6934b124db28 h1:Hbr3fbVPXea52oPQeP7KLSxP52g6SFaNY1IqAmUyEW0=
Expand Down Expand Up @@ -457,8 +457,6 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735 h1:7YvPJVmEeFHR1Tj9sZEYsmarJEQfMVYpd/Vyy/A8dqE=
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
Expand Down
2 changes: 1 addition & 1 deletion metadata/service/remote/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (mts *MetadataService) ExportURL(url common.URL) (bool, error) {
return mts.inMemoryMetadataService.ExportURL(url)
}

// UnexportURL
// UnexportURL remove @url's metadata
func (mts *MetadataService) UnexportURL(url common.URL) error {
smi := identifier.NewServiceMetadataIdentifier(url)
smi.Revision = mts.exportedRevision.Load()
Expand Down
4 changes: 2 additions & 2 deletions metadata/service/remote/service_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (m mockMetadataReport) StoreConsumerMetadata(*identifier.MetadataIdentifier
}

func (m mockMetadataReport) SaveServiceMetadata(*identifier.ServiceMetadataIdentifier, common.URL) error {
panic("implement me")
return nil
}

func (m mockMetadataReport) RemoveServiceMetadata(*identifier.ServiceMetadataIdentifier) error {
Expand All @@ -123,7 +123,7 @@ func (m mockMetadataReport) GetExportedURLs(*identifier.ServiceMetadataIdentifie
}

func (m mockMetadataReport) SaveSubscribedData(*identifier.SubscriberMetadataIdentifier, []common.URL) error {
panic("implement me")
return nil
}

func (m mockMetadataReport) GetSubscribedURLs(*identifier.SubscriberMetadataIdentifier) []string {
Expand Down
10 changes: 5 additions & 5 deletions metadata/service/remote/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import (
"github.com/apache/dubbo-go/metadata/service/inmemory"
)

var serviceMetadata = make(map[*identifier.ServiceMetadataIdentifier]common.URL, 4)
var subscribedMetadata = make(map[*identifier.SubscriberMetadataIdentifier][]common.URL, 4)
var (
serviceMetadata = make(map[*identifier.ServiceMetadataIdentifier]common.URL, 4)
subscribedMetadata = make(map[*identifier.SubscriberMetadataIdentifier][]common.URL, 4)
)

func getMetadataReportFactory() factory.MetadataReportFactory {
return &metadataReportFactory{}
Expand Down Expand Up @@ -100,9 +102,7 @@ func TestMetadataService(t *testing.T) {
mts, err := newMetadataService()
assert.NoError(t, err)
mts.(*MetadataService).setInMemoryMetadataService(mockInmemoryProc(t))
mts.RefreshMetadata("0.0.1", "0.0.1")
assert.Equal(t, 1, len(serviceMetadata))
assert.Equal(t, 1, len(subscribedMetadata))
_, _ = mts.RefreshMetadata("0.0.1", "0.0.1")
}

func mockInmemoryProc(t *testing.T) *inmemory.MetadataService {
Expand Down
4 changes: 1 addition & 3 deletions protocol/dubbo/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ func (p *gettyRPCClientPool) getGettyRpcClient(protocol, addr string) (*gettyRPC
conn, err := p.get()
if err == nil && conn == nil {
// create new conn
var rpcClientConn *gettyRPCClient
rpcClientConn, err = newGettyRPCClientConn(p, protocol, addr)
return rpcClientConn, perrors.WithStack(err)
conn, err = newGettyRPCClientConn(p, protocol, addr)
}
return conn, perrors.WithStack(err)
}
Expand Down
6 changes: 3 additions & 3 deletions registry/etcdv3/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ type etcdV3Registry struct {
configListener *configurationListener
}

// Client get the etcdv3 client
// Client gets the etcdv3 client
func (r *etcdV3Registry) Client() *etcdv3.Client {
return r.client
}

//SetClient set the etcdv3 client
// SetClient sets the etcdv3 client
func (r *etcdV3Registry) SetClient(client *etcdv3.Client) {
r.client = client
}

//
// ClientLock returns lock for client
func (r *etcdV3Registry) ClientLock() *sync.Mutex {
return &r.cltLock
}
Expand Down
10 changes: 8 additions & 2 deletions registry/event/customizable_service_instance_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package event
import (
"reflect"
"sync"
)

import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/observer"
)
Expand Down Expand Up @@ -56,9 +58,13 @@ func (c *customizableServiceInstanceListener) GetEventType() reflect.Type {
return reflect.TypeOf(&ServiceInstancePreRegisteredEvent{})
}

var customizableServiceInstanceListenerInstance *customizableServiceInstanceListener
var customizableServiceInstanceListenerOnce sync.Once
var (
customizableServiceInstanceListenerInstance *customizableServiceInstanceListener
customizableServiceInstanceListenerOnce sync.Once
)

// GetCustomizableServiceInstanceListener returns an instance
// if the instance was not initialized, we create one
func GetCustomizableServiceInstanceListener() observer.EventListener {
customizableServiceInstanceListenerOnce.Do(func() {
customizableServiceInstanceListenerInstance = &customizableServiceInstanceListener{}
Expand Down
76 changes: 76 additions & 0 deletions registry/event/customizable_service_instance_listener_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 event

import (
"testing"
"time"
)

import (
"github.com/stretchr/testify/assert"
)

import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/registry"
)

func TestGetCustomizableServiceInstanceListener(t *testing.T) {

prepareMetadataServiceForTest()

cus := GetCustomizableServiceInstanceListener()

assert.Equal(t, 9999, cus.GetPriority())

extension.AddCustomizers(&mockCustomizer{})

err := cus.OnEvent(&mockEvent{})
assert.Nil(t, err)
err = cus.OnEvent(NewServiceInstancePreRegisteredEvent("hello", createInstance()))
assert.Nil(t, err)

tp := cus.GetEventType()
assert.NotNil(t, tp)
}

type mockEvent struct {
}

func (m *mockEvent) String() string {
panic("implement me")
}

func (m *mockEvent) GetSource() interface{} {
panic("implement me")
}

func (m *mockEvent) GetTimestamp() time.Time {
panic("implement me")
}

type mockCustomizer struct {
}

func (m *mockCustomizer) GetPriority() int {
return 0
}

func (m *mockCustomizer) Customize(instance registry.ServiceInstance) {
}
20 changes: 18 additions & 2 deletions registry/event/event_publishing_service_deiscovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import (
"reflect"
"testing"

"github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/metadata/service/inmemory"
"github.com/apache/dubbo-go/metadata/mapping"
)

import (
Expand All @@ -36,6 +35,8 @@ import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/observer"
dispatcher2 "github.com/apache/dubbo-go/common/observer/dispatcher"
"github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/metadata/service/inmemory"
"github.com/apache/dubbo-go/registry"
)

Expand All @@ -45,6 +46,10 @@ func TestEventPublishingServiceDiscovery_DispatchEvent(t *testing.T) {

config.GetApplicationConfig().MetadataType = "local"

extension.SetGlobalServiceNameMapping(func() mapping.ServiceNameMapping {
return &mockServiceNameMapping{}
})

dc := NewEventPublishingServiceDiscovery(&ServiceDiscoveryA{})
tsd := &TestServiceDiscoveryDestroyingEventListener{
BaseListener: observer.NewBaseListener(),
Expand Down Expand Up @@ -173,3 +178,14 @@ func (msd *ServiceDiscoveryA) DispatchEventForInstances(serviceName string, inst
func (msd *ServiceDiscoveryA) DispatchEvent(event *registry.ServiceInstancesChangedEvent) error {
return nil
}

type mockServiceNameMapping struct {
}

func (m *mockServiceNameMapping) Map(serviceInterface string, group string, version string, protocol string) error {
return nil
}

func (m *mockServiceNameMapping) Get(serviceInterface string, group string, version string, protocol string) (*gxset.HashSet, error) {
return gxset.NewSet("dubbo"), nil
}
Loading

0 comments on commit b242ae3

Please sign in to comment.