diff --git a/cluster/router/condition_router.go b/cluster/router/condition_router.go index 45959a60f8004349aa0dd699aa261d6be0afca31..b9632e29119691009bf59fb7cc5af24ea33dd120 100644 --- a/cluster/router/condition_router.go +++ b/cluster/router/condition_router.go @@ -23,19 +23,19 @@ import ( "strings" ) +import ( + "github.com/dubbogo/gost/container" + perrors "github.com/pkg/errors" +) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/logger" "github.com/apache/dubbo-go/common/utils" - "github.com/apache/dubbo-go/gostd/container" "github.com/apache/dubbo-go/protocol" ) -import ( - perrors "github.com/pkg/errors" -) - const ( ROUTE_PATTERN = `([&!=,]*)\\s*([^&!=,\\s]+)` FORCE = "force" diff --git a/cluster/router/condition_router_test.go b/cluster/router/condition_router_test.go index b4c6a829d667765c903faf61bfbd68c290b5a6ad..577c5c416f87b8d56e88a540d43bf092784b0756 100644 --- a/cluster/router/condition_router_test.go +++ b/cluster/router/condition_router_test.go @@ -25,6 +25,11 @@ import ( "testing" ) +import ( + perrors "github.com/pkg/errors" + "github.com/stretchr/testify/assert" +) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/logger" @@ -33,11 +38,6 @@ import ( "github.com/apache/dubbo-go/protocol/invocation" ) -import ( - perrors "github.com/pkg/errors" - "github.com/stretchr/testify/assert" -) - type MockInvoker struct { url common.URL available bool diff --git a/common/config/environment.go b/common/config/environment.go index 998f0beefdb7c898c1a15fde4804a53a5ff133fa..8709d69a78263ab99501c4f6db78e78c47d2955b 100644 --- a/common/config/environment.go +++ b/common/config/environment.go @@ -63,32 +63,40 @@ func (env *Environment) UpdateExternalConfigMap(externalMap map[string]string) { func (env *Environment) Configuration() *list.List { list := list.New() memConf := newInmemoryConfiguration() - memConf.setProperties(env.externalConfigMap) + memConf.setProperties(&(env.externalConfigMap)) list.PushBack(memConf) return list } type InmemoryConfiguration struct { - store sync.Map + store *sync.Map } func newInmemoryConfiguration() *InmemoryConfiguration { return &InmemoryConfiguration{} } -func (conf *InmemoryConfiguration) setProperties(p sync.Map) { +func (conf *InmemoryConfiguration) setProperties(p *sync.Map) { conf.store = p } func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) { + if conf.store == nil { + return false, "" + } + v, ok := conf.store.Load(key) if ok { return true, v.(string) } - return false, "" + return false, "" } func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]struct{} { + if conf.store == nil { + return nil + } + properties := make(map[string]struct{}) conf.store.Range(func(key, value interface{}) bool { if idx := strings.Index(key.(string), subKey); idx >= 0 { @@ -100,5 +108,6 @@ func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]stru } return true }) + return properties } diff --git a/config/base_config.go b/config/base_config.go index 19acea2fd6c738734734467daed7fb838bccdffd..54ad8aba368c7d9477faad6fbd97c5dccd32dca1 100644 --- a/config/base_config.go +++ b/config/base_config.go @@ -107,7 +107,8 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC setBaseValue := func(f reflect.Value) { ok, value := config.GetProperty(getKeyPrefix(val, id) + key) if ok { - if f.Kind() == reflect.Int64 { + switch f.Kind() { + case reflect.Int64: x, err := strconv.Atoi(value) if err != nil { logger.Errorf("Dynamic change the configuration in struct {%v} field {%v} error ,error message is {%v}", @@ -120,21 +121,16 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC val.Type().Name(), val.Type().Field(i).Name, perrors.Errorf("the int64 value {%v} from config center is overflow", int64(x))) } } - - } - - if f.Kind() == reflect.String { + case reflect.String: f.SetString(value) - } - if f.Kind() == reflect.Bool { + case reflect.Bool: x, err := strconv.ParseBool(value) if err != nil { logger.Errorf("Dynamic change the configuration in struct {%v} field {%v} error ,error message is {%v}", val.Type().Name(), val.Type().Field(i).Name, err) } f.SetBool(x) - } - if f.Kind() == reflect.Float64 { + case reflect.Float64: x, err := strconv.ParseFloat(value, 64) if err != nil { logger.Errorf("Dynamic change the configuration in struct {%v} field {%v} error ,error message is {%v}", @@ -147,7 +143,10 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC val.Type().Name(), val.Type().Field(i).Name, perrors.Errorf("the float64 value {%v} from config center is overflow", x)) } } + default: + logger.Warnf("The kind of field {%v} is not supported ", f.Kind().String()) } + } } @@ -180,25 +179,32 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC } if f.Kind() == reflect.Map { - //initiate config - s := reflect.New(f.Type().Elem().Elem()) - prefix := s.MethodByName("Prefix").Call(nil)[0].String() - m := config.GetSubProperty(prefix) - for k := range m { - f.SetMapIndex(reflect.ValueOf(k), reflect.New(f.Type().Elem().Elem())) + if f.Type().Elem().Kind() == reflect.Ptr { + //initiate config + s := reflect.New(f.Type().Elem().Elem()) + prefix := s.MethodByName("Prefix").Call(nil)[0].String() + m := config.GetSubProperty(prefix) + for k := range m { + f.SetMapIndex(reflect.ValueOf(k), reflect.New(f.Type().Elem().Elem())) + } } + //iter := f.MapRange() for _, k := range f.MapKeys() { v := f.MapIndex(k) - if v.Kind() == reflect.Ptr { + switch v.Kind() { + case reflect.Ptr: if v.Elem().Kind() == reflect.Struct { setFieldValue(v.Elem(), k, config) } else { setBaseValue(v.Elem()) } + case reflect.Int64, reflect.String, reflect.Bool, reflect.Float64: + setBaseValue(v) + default: + logger.Warnf("The kind of field {%v} is not supported ", v.Kind().String()) } - } } diff --git a/config/config_loader_test.go b/config/config_loader_test.go index 6e9689c76322686fff0fab585dc08436a07cd55c..cbdc397c283f1e7948b42bbdd59b4f4a985671a6 100644 --- a/config/config_loader_test.go +++ b/config/config_loader_test.go @@ -54,6 +54,7 @@ func TestConfigLoader(t *testing.T) { assert.NotEqual(t, ConsumerConfig{}, GetConsumerConfig()) assert.NotNil(t, providerConfig) assert.NotEqual(t, ProviderConfig{}, GetProviderConfig()) + assert.Equal(t, "soa.com.ikurento.user.UserProvider", GetConsumerConfig().References["UserProvider"].Params["serviceid"]) } func TestLoad(t *testing.T) { diff --git a/config/reference_config.go b/config/reference_config.go index 2c38d8aa4aa31576c94724d4537aa752df2fb96c..835d17f0549045008a996a5756bb3dd772782612 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -38,19 +38,20 @@ import ( type ReferenceConfig struct { context context.Context pxy *proxy.Proxy - InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"` - Check *bool `yaml:"check" json:"check,omitempty" property:"check"` - Url string `yaml:"url" json:"url,omitempty" property:"url"` - Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"` - Protocol string `yaml:"protocol" json:"protocol,omitempty" property:"protocol"` - Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"` - Cluster string `yaml:"cluster" json:"cluster,omitempty" property:"cluster"` - Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"` - Retries int64 `yaml:"retries" json:"retries,omitempty" property:"retries"` - Group string `yaml:"group" json:"group,omitempty" property:"group"` - Version string `yaml:"version" json:"version,omitempty" property:"version"` - Methods []*MethodConfig `yaml:"methods" json:"methods,omitempty" property:"methods"` - async bool `yaml:"async" json:"async,omitempty" property:"async"` + InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"` + Check *bool `yaml:"check" json:"check,omitempty" property:"check"` + Url string `yaml:"url" json:"url,omitempty" property:"url"` + Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"` + Protocol string `yaml:"protocol" json:"protocol,omitempty" property:"protocol"` + Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"` + Cluster string `yaml:"cluster" json:"cluster,omitempty" property:"cluster"` + Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"` + Retries int64 `yaml:"retries" json:"retries,omitempty" property:"retries"` + Group string `yaml:"group" json:"group,omitempty" property:"group"` + Version string `yaml:"version" json:"version,omitempty" property:"version"` + Methods []*MethodConfig `yaml:"methods" json:"methods,omitempty" property:"methods"` + async bool `yaml:"async" json:"async,omitempty" property:"async"` + Params map[string]string `yaml:"params" json:"params,omitempty" property:"params"` invoker protocol.Invoker urls []*common.URL } @@ -143,6 +144,10 @@ func (refconfig *ReferenceConfig) GetRPCService() common.RPCService { func (refconfig *ReferenceConfig) getUrlMap() url.Values { urlMap := url.Values{} + //first set user params + for k, v := range refconfig.Params { + urlMap.Set(k, v) + } urlMap.Set(constant.INTERFACE_KEY, refconfig.InterfaceName) urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10)) urlMap.Set(constant.CLUSTER_KEY, refconfig.Cluster) diff --git a/config/reference_config_test.go b/config/reference_config_test.go index c41e2a16de1cdc347d204cfae9d36b0b54f12808..1a856872a63733866747a481e2a2e5d9295c46af 100644 --- a/config/reference_config_test.go +++ b/config/reference_config_test.go @@ -80,6 +80,9 @@ func doInit() { }, References: map[string]*ReferenceConfig{ "MockService": { + Params: map[string]string{ + "serviceid": "soa.mock", + }, Registry: "shanghai_reg1,shanghai_reg2,hangzhou_reg1,hangzhou_reg2", InterfaceName: "MockService", Protocol: "mock", @@ -125,6 +128,7 @@ func Test_Refer(t *testing.T) { for _, reference := range consumerConfig.References { reference.Refer() + assert.Equal(t, "soa.mock", reference.Params["serviceid"]) assert.NotNil(t, reference.invoker) assert.NotNil(t, reference.pxy) } diff --git a/config/registry_config.go b/config/registry_config.go index 0c6b326a8077de571b4c6254c13f129eb5190b74..1a926b459e598ff313e141a39956dc88cb3daad3 100644 --- a/config/registry_config.go +++ b/config/registry_config.go @@ -37,8 +37,8 @@ type RegistryConfig struct { Group string `yaml:"group" json:"group,omitempty" property:"group"` //for registry Address string `yaml:"address" json:"address,omitempty" property:"address"` - Username string `yaml:"username" json:"address,omitempty" property:"username"` - Password string `yaml:"password" json:"address,omitempty" property:"password"` + Username string `yaml:"username" json:"username,omitempty" property:"username"` + Password string `yaml:"password" json:"password,omitempty" property:"password"` } func (*RegistryConfig) Prefix() string { diff --git a/config/service_config.go b/config/service_config.go index 79a29aa33058dfc47fca282a71ba28292a2b1ff3..1b78c2ef3d6074a82576051f5cca83db42eef04c 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -43,17 +43,18 @@ import ( type ServiceConfig struct { context context.Context - Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"` - Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` //multi protocol support, split by ',' - InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"` - Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"` - Cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty" property:"cluster"` - Loadbalance string `default:"random" yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"` - Group string `yaml:"group" json:"group,omitempty" property:"group"` - Version string `yaml:"version" json:"version,omitempty" property:"version" ` - Methods []*MethodConfig `yaml:"methods" json:"methods,omitempty" property:"methods"` - Warmup string `yaml:"warmup" json:"warmup,omitempty" property:"warmup"` - Retries int64 `yaml:"retries" json:"retries,omitempty" property:"retries"` + Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"` + Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` //multi protocol support, split by ',' + InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"` + Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"` + Cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty" property:"cluster"` + Loadbalance string `default:"random" yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"` + Group string `yaml:"group" json:"group,omitempty" property:"group"` + Version string `yaml:"version" json:"version,omitempty" property:"version" ` + Methods []*MethodConfig `yaml:"methods" json:"methods,omitempty" property:"methods"` + Warmup string `yaml:"warmup" json:"warmup,omitempty" property:"warmup"` + Retries int64 `yaml:"retries" json:"retries,omitempty" property:"retries"` + Params map[string]string `yaml:"params" json:"params,omitempty" property:"params"` unexported *atomic.Bool exported *atomic.Bool rpcService common.RPCService @@ -148,6 +149,10 @@ func (srvconfig *ServiceConfig) Implement(s common.RPCService) { func (srvconfig *ServiceConfig) getUrlMap() url.Values { urlMap := url.Values{} + //first set user params + for k, v := range srvconfig.Params { + urlMap.Set(k, v) + } urlMap.Set(constant.INTERFACE_KEY, srvconfig.InterfaceName) urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10)) urlMap.Set(constant.CLUSTER_KEY, srvconfig.Cluster) diff --git a/config/testdata/consumer_config.yml b/config/testdata/consumer_config.yml index 08ff59f6fc403a0aa31e090fa8f9341a6e11d490..68398623b6a2cbfe9fe9c255d3261c5a59b6af5e 100644 --- a/config/testdata/consumer_config.yml +++ b/config/testdata/consumer_config.yml @@ -42,6 +42,9 @@ references: methods : - name: "GetUser" retries: 3 + params: + "serviceid": + "soa.com.ikurento.user.UserProvider" protocol_conf: dubbo: diff --git a/go.mod b/go.mod index 309be9e00f81c614ea4a887de4ccf05456fdb2cd..ef4c7b2ca8e17c4013f0916964597b43c9ae4615 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,7 @@ module github.com/apache/dubbo-go require ( github.com/dubbogo/getty v1.0.7 + github.com/dubbogo/gost v1.0.0 github.com/dubbogo/hessian2 v1.0.2 github.com/magiconair/properties v1.8.1 github.com/pkg/errors v0.8.1 diff --git a/go.sum b/go.sum index 0a8eb6beea3593059b6ffeaca389e93acba65736..3af6b3eb0d163f358e622769edbe6b856823afac 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dubbogo/getty v1.0.7 h1:5Hg+JwXyCKm9Yr4yJkm98ahhnoa8c2h6br5QJxwQ+YU= github.com/dubbogo/getty v1.0.7/go.mod h1:cRMSuoCmwc5lULFFnYZTxyCfZhObmRTNbS7XRnPNHSo= +github.com/dubbogo/gost v1.0.0 h1:obKvpJYdrIY2BidHYwYoj2E50OtwCDqVVVTcH2nnhAY= +github.com/dubbogo/gost v1.0.0/go.mod h1:R7wZm1DrmrKGr50mBZVcg6C9ekG8aL5hP+sgWcIDwQg= github.com/dubbogo/hessian2 v1.0.2 h1:Ka9Z32ZszGAdCpgrGuZQmwkT0qe1pd3o9r7ERCDnSlQ= github.com/dubbogo/hessian2 v1.0.2/go.mod h1:XFGDn4oSZX26zkcfhkM/fCJrOqwQJxk/xgWW1KMJBKM= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= @@ -35,6 +37,5 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/gostd/container/hashset.go b/gostd/container/hashset.go deleted file mode 100644 index 4be5a7ff1d2944361d3307e06157e1e81df1d8d6..0000000000000000000000000000000000000000 --- a/gostd/container/hashset.go +++ /dev/null @@ -1,87 +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 container - -import ( - "fmt" - "strings" -) - -var itemExists = struct{}{} - -type HashSet struct { - Items map[interface{}]struct{} -} - -func NewSet(values ...interface{}) *HashSet { - set := &HashSet{Items: make(map[interface{}]struct{})} - if len(values) > 0 { - set.Add(values...) - } - return set -} - -func (set *HashSet) Add(items ...interface{}) { - for _, item := range items { - set.Items[item] = itemExists - } -} - -func (set *HashSet) Remove(items ...interface{}) { - for _, item := range items { - delete(set.Items, item) - } -} - -func (set *HashSet) Contains(items ...interface{}) bool { - for _, item := range items { - if _, contains := set.Items[item]; !contains { - return false - } - } - return true -} -func (set *HashSet) Empty() bool { - return set.Size() == 0 -} -func (set *HashSet) Size() int { - return len(set.Items) -} - -func (set *HashSet) Clear() { - set.Items = make(map[interface{}]struct{}) -} - -func (set *HashSet) Values() []interface{} { - values := make([]interface{}, set.Size()) - count := 0 - for item := range set.Items { - values[count] = item - count++ - } - return values -} -func (set *HashSet) String() string { - str := "HashSet\n" - var items []string - for k := range set.Items { - items = append(items, fmt.Sprintf("%v", k)) - } - str += strings.Join(items, ", ") - return str -} diff --git a/gostd/container/hashset_test.go b/gostd/container/hashset_test.go deleted file mode 100644 index 5b371a08e1241ca895c5cd725a9fb13f9d3184bd..0000000000000000000000000000000000000000 --- a/gostd/container/hashset_test.go +++ /dev/null @@ -1,243 +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 container - -import "testing" - -func TestSetNew(t *testing.T) { - set := NewSet(2, 1) - - if actualValue := set.Size(); actualValue != 2 { - t.Errorf("Got %v expected %v", actualValue, 2) - } - if actualValue := set.Contains(1); actualValue != true { - t.Errorf("Got %v expected %v", actualValue, true) - } - if actualValue := set.Contains(2); actualValue != true { - t.Errorf("Got %v expected %v", actualValue, true) - } - if actualValue := set.Contains(3); actualValue != false { - t.Errorf("Got %v expected %v", actualValue, true) - } -} - -func TestSetAdd(t *testing.T) { - set := NewSet() - set.Add() - set.Add(1) - set.Add(2) - set.Add(2, 3) - set.Add() - if actualValue := set.Empty(); actualValue != false { - t.Errorf("Got %v expected %v", actualValue, false) - } - if actualValue := set.Size(); actualValue != 3 { - t.Errorf("Got %v expected %v", actualValue, 3) - } -} - -func TestSetContains(t *testing.T) { - set := NewSet() - set.Add(3, 1, 2) - set.Add(2, 3) - set.Add() - if actualValue := set.Contains(); actualValue != true { - t.Errorf("Got %v expected %v", actualValue, true) - } - if actualValue := set.Contains(1); actualValue != true { - t.Errorf("Got %v expected %v", actualValue, true) - } - if actualValue := set.Contains(1, 2, 3); actualValue != true { - t.Errorf("Got %v expected %v", actualValue, true) - } - if actualValue := set.Contains(1, 2, 3, 4); actualValue != false { - t.Errorf("Got %v expected %v", actualValue, false) - } -} - -func TestSetRemove(t *testing.T) { - set := NewSet() - set.Add(3, 1, 2) - set.Remove() - if actualValue := set.Size(); actualValue != 3 { - t.Errorf("Got %v expected %v", actualValue, 3) - } - set.Remove(1) - if actualValue := set.Size(); actualValue != 2 { - t.Errorf("Got %v expected %v", actualValue, 2) - } - set.Remove(3) - set.Remove(3) - set.Remove() - set.Remove(2) - if actualValue := set.Size(); actualValue != 0 { - t.Errorf("Got %v expected %v", actualValue, 0) - } -} - -func benchmarkContains(b *testing.B, set *HashSet, size int) { - for i := 0; i < b.N; i++ { - for n := 0; n < size; n++ { - set.Contains(n) - } - } -} - -func benchmarkAdd(b *testing.B, set *HashSet, size int) { - for i := 0; i < b.N; i++ { - for n := 0; n < size; n++ { - set.Add(n) - } - } -} - -func benchmarkRemove(b *testing.B, set *HashSet, size int) { - for i := 0; i < b.N; i++ { - for n := 0; n < size; n++ { - set.Remove(n) - } - } -} - -func BenchmarkHashSetContains100(b *testing.B) { - b.StopTimer() - size := 100 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkContains(b, set, size) -} - -func BenchmarkHashSetContains1000(b *testing.B) { - b.StopTimer() - size := 1000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkContains(b, set, size) -} - -func BenchmarkHashSetContains10000(b *testing.B) { - b.StopTimer() - size := 10000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkContains(b, set, size) -} - -func BenchmarkHashSetContains100000(b *testing.B) { - b.StopTimer() - size := 100000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkContains(b, set, size) -} - -func BenchmarkHashSetAdd100(b *testing.B) { - b.StopTimer() - size := 100 - set := NewSet() - b.StartTimer() - benchmarkAdd(b, set, size) -} - -func BenchmarkHashSetAdd1000(b *testing.B) { - b.StopTimer() - size := 1000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkAdd(b, set, size) -} - -func BenchmarkHashSetAdd10000(b *testing.B) { - b.StopTimer() - size := 10000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkAdd(b, set, size) -} - -func BenchmarkHashSetAdd100000(b *testing.B) { - b.StopTimer() - size := 100000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkAdd(b, set, size) -} - -func BenchmarkHashSetRemove100(b *testing.B) { - b.StopTimer() - size := 100 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkRemove(b, set, size) -} - -func BenchmarkHashSetRemove1000(b *testing.B) { - b.StopTimer() - size := 1000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkRemove(b, set, size) -} - -func BenchmarkHashSetRemove10000(b *testing.B) { - b.StopTimer() - size := 10000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkRemove(b, set, size) -} - -func BenchmarkHashSetRemove100000(b *testing.B) { - b.StopTimer() - size := 100000 - set := NewSet() - for n := 0; n < size; n++ { - set.Add(n) - } - b.StartTimer() - benchmarkRemove(b, set, size) -} diff --git a/registry/zookeeper/registry_test.go b/registry/zookeeper/registry_test.go index ba2755fa9923d9e6c11a1908594a176ace458691..168246e1579c26d515bca836a3ad1cf66b26bfcd 100644 --- a/registry/zookeeper/registry_test.go +++ b/registry/zookeeper/registry_test.go @@ -36,13 +36,13 @@ import ( func Test_Register(t *testing.T) { regurl, _ := common.NewURL(context.TODO(), "registry://127.0.0.1:1111", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) - url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithMethods([]string{"GetUser", "AddUser"})) + url, _ := common.NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider", common.WithParamsValue(constant.CLUSTER_KEY, "mock"), common.WithParamsValue("serviceid", "soa.mock"), common.WithMethods([]string{"GetUser", "AddUser"})) ts, reg, err := newMockZkRegistry(®url) defer ts.Stop() err = reg.Register(url) children, _ := reg.client.GetChildren("/dubbo/com.ikurento.user.UserProvider/providers") - assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26category%3Dproviders%26cluster%3Dmock%26dubbo%3Ddubbo-provider-golang-2.6.0%26.*provider", children) + assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26category%3Dproviders%26cluster%3Dmock%26dubbo%3Ddubbo-provider-golang-2.6.0%26.*.serviceid%3Dsoa.mock%26.*provider", children) assert.NoError(t, err) } diff --git a/remoting/zookeeper/listener.go b/remoting/zookeeper/listener.go index af668a1aaf18702b0d7674afda38516d9ab2e3a3..5b9e0a8f824598fd5030bd76eec04adf3e639ed9 100644 --- a/remoting/zookeeper/listener.go +++ b/remoting/zookeeper/listener.go @@ -129,14 +129,14 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string, children []string, li continue } // listen l service node - go func(node string) { + go func(node, childNode string) { logger.Infof("delete zkNode{%s}", node) if l.ListenServiceNodeEvent(node, listener) { - logger.Infof("delete content{%s}", n) + logger.Infof("delete content{%s}", childNode) listener.DataChange(remoting.Event{Path: zkPath, Action: remoting.EventTypeDel}) } logger.Warnf("listenSelf(zk path{%s}) goroutine exit now", zkPath) - }(newNode) + }(newNode, n) } // old node was deleted