Skip to content

Commit

Permalink
fix(proto): fix getting attributes issue (#1968)
Browse files Browse the repository at this point in the history
RPCInvocation::GetAttributeWithDefaultValue() has a typo which couldn't
get attributes correctly, this PR fixes that issue.

Signed-off-by: Xuewei Niu <justxuewei@apache.org>
  • Loading branch information
justxuewei authored and jasondeng1997 committed Aug 17, 2022
1 parent 7b99da6 commit 08af2cc
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 263 deletions.
2 changes: 1 addition & 1 deletion protocol/invocation/rpcinvocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (r *RPCInvocation) GetAttributeWithDefaultValue(key string, defaultValue in
if r.attributes == nil {
return defaultValue
}
if value, ok := r.attachments[key]; ok {
if value, ok := r.attributes[key]; ok {
return value
}
return defaultValue
Expand Down
40 changes: 40 additions & 0 deletions registry/polaris/core_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package polaris

import (
"dubbo.apache.org/dubbo-go/v3/remoting"
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/model"
"github.com/stretchr/testify/assert"
"sync"
"testing"
)

func TestPolarisServiceWatcher_AddSubscriber(t *testing.T) {
type fields struct {
consumer api.ConsumerAPI
subscribeParam *api.WatchServiceRequest
lock *sync.RWMutex
subscribers []subscriber
execOnce *sync.Once
}
type args struct {
subscriber func(remoting.EventType, []model.Instance)
}
var tests []struct {
name string
fields fields
args args
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
watcher := &PolarisServiceWatcher{
subscribeParam: &newParam,
consumer: newConsumer,
lock: &sync.RWMutex{},
subscribers: make([]subscriber, 0),
execOnce: &sync.Once{},
}
assert.Empty(t, watcher)
})
}
}
1 change: 1 addition & 0 deletions registry/polaris/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func NewPolarisListener(url *common.URL) (*polarisListener, error) {
events: gxchan.NewUnboundedChan(32),
closeCh: make(chan struct{}),
}

return listener, nil
}

Expand Down
19 changes: 19 additions & 0 deletions registry/polaris/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
)

var localIP = ""
var newParam api.WatchServiceRequest
var newConsumer api.ConsumerAPI

const (
RegistryConnDelay = 3
Expand Down Expand Up @@ -163,15 +165,32 @@ func (pr *polarisRegistry) Subscribe(url *common.URL, notifyListener registry.No
continue
}

watcher := &PolarisServiceWatcher{
subscribeParam: &newParam,
consumer: newConsumer,
lock: &sync.RWMutex{},
subscribers: make([]subscriber, 0),
execOnce: &sync.Once{},
}

watcher, err = newPolarisWatcher(&newParam, newConsumer)
if err != nil {
logger.Warnf("getwatcher() = err:%v", perrors.WithStack(err))
<-time.After(time.Duration(RegistryConnDelay) * time.Second)
continue
}
for {

serviceEvent, err := listener.Next()

if err != nil {
logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err))
listener.Close()
return err
}
logger.Infof("update begin, service event: %v", serviceEvent.String())
notifyListener.Notify(serviceEvent)
watcher.startWatch()
}
}
}
Expand Down
58 changes: 58 additions & 0 deletions registry/polaris/registry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package polaris

import (
"dubbo.apache.org/dubbo-go/v3/common"
"github.com/polarismesh/polaris-go/api"
"reflect"
"sync"
"testing"
)

func Test_createDeregisterParam(t *testing.T) {
type args struct {
url *common.URL
serviceName string
}
tests := []struct {
name string
args args
want *api.InstanceDeRegisterRequest
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := createDeregisterParam(tt.args.url, tt.args.serviceName); !reflect.DeepEqual(got, tt.want) {
t.Errorf("createDeregisterParam() = %v, want %v", got, tt.want)
}
})
}
}

func Test_polarisRegistry_Destroy(t *testing.T) {
type fields struct {
url *common.URL
provider api.ProviderAPI
lock *sync.RWMutex
registryUrls map[string]*PolarisHeartbeat
listenerLock *sync.RWMutex
}
tests := []struct {
name string
fields fields
}{
{
name: "Test_polarisRegistry_Destroy",
fields: fields{
url: nil,
provider: nil,
registryUrls: nil,
},
},
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
})
}
}
Loading

0 comments on commit 08af2cc

Please sign in to comment.