Skip to content
Snippets Groups Projects
Commit d84daf93 authored by cvictory's avatar cvictory
Browse files

Fix review Issue: rename the struct and remove some code.

parent 872b4eb9
No related branches found
No related tags found
No related merge requests found
...@@ -290,7 +290,7 @@ func isInvokersChanged(left []protocol.Invoker, right []protocol.Invoker) bool { ...@@ -290,7 +290,7 @@ func isInvokersChanged(left []protocol.Invoker, right []protocol.Invoker) bool {
rurl := r.GetUrl() rurl := r.GetUrl()
for _, l := range left { for _, l := range left {
lurl := l.GetUrl() lurl := l.GetUrl()
if common.GetURLTool().CompareURLEqual(&lurl, &rurl, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY) { if common.GetURLComparator().CompareURLEqual(&lurl, &rurl, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY) {
found = true found = true
break break
} }
......
...@@ -17,50 +17,30 @@ ...@@ -17,50 +17,30 @@
package common package common
import "sync" var urlComparator URLComparator
var urlTool URLTool
var lock sync.Mutex
// Define some func for URL, such as comparison of URL. // Define some func for URL, such as comparison of URL.
// Your can define your own implements, and invoke SetURLTool for high priority. // Your can define your own implements, and invoke SetURLComparator.
type URLTool interface { type URLComparator interface {
// The higher of the number, the higher of the priority.
Priority() uint8
// comparison of two URL, excluding some params
CompareURLEqual(*URL, *URL, ...string) bool CompareURLEqual(*URL, *URL, ...string) bool
} }
func SetURLTool(tool URLTool) { func SetURLComparator(comparator URLComparator) {
lock.Lock() urlComparator = comparator
defer lock.Unlock()
if urlTool == nil {
urlTool = tool
return
}
if urlTool.Priority() < tool.Priority() {
urlTool = tool
}
} }
func GetURLTool() URLTool { func GetURLComparator() URLComparator {
return urlTool return urlComparator
} }
// Config default urlTools. // Config default defaultURLComparator.
func init() { func init() {
SetURLTool(defaultURLTool{}) SetURLComparator(defaultURLComparator{})
}
type defaultURLTool struct {
} }
// default priority is 16. type defaultURLComparator struct {
func (defaultURLTool) Priority() uint8 {
//default is 16.
return 16
} }
// default comparison implements // default comparison implements
func (defaultURLTool) CompareURLEqual(l *URL, r *URL, execludeParam ...string) bool { func (defaultURLComparator) CompareURLEqual(l *URL, r *URL, excludeParam ...string) bool {
return IsEquals(*l, *r, execludeParam...) return IsEquals(*l, *r, excludeParam...)
} }
...@@ -34,8 +34,8 @@ func TestDefaultURLTool(t *testing.T) { ...@@ -34,8 +34,8 @@ func TestDefaultURLTool(t *testing.T) {
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=155650979798") "side=provider&timeout=3000&timestamp=155650979798")
assert.False(t, GetURLTool().CompareURLEqual(&url1, &url2)) assert.False(t, GetURLComparator().CompareURLEqual(&url1, &url2))
assert.True(t, GetURLTool().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY)) assert.True(t, GetURLComparator().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
} }
func TestNewCustomURLTool(t *testing.T) { func TestNewCustomURLTool(t *testing.T) {
...@@ -49,10 +49,10 @@ func TestNewCustomURLTool(t *testing.T) { ...@@ -49,10 +49,10 @@ func TestNewCustomURLTool(t *testing.T) {
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000&timestamp=155650979798") "side=provider&timeout=3000&timestamp=155650979798")
assert.True(t, GetURLTool().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY)) assert.True(t, GetURLComparator().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
SetURLTool(customURLTool{}) SetURLComparator(customURLTool{})
assert.False(t, GetURLTool().CompareURLEqual(&url1, &url2)) assert.False(t, GetURLComparator().CompareURLEqual(&url1, &url2))
assert.False(t, GetURLTool().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY)) assert.False(t, GetURLComparator().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
url1, _ = NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" + url1, _ = NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&" +
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
...@@ -64,11 +64,11 @@ func TestNewCustomURLTool(t *testing.T) { ...@@ -64,11 +64,11 @@ func TestNewCustomURLTool(t *testing.T) {
"environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&" +
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&" +
"side=provider&timeout=3000") "side=provider&timeout=3000")
assert.True(t, GetURLTool().CompareURLEqual(&url1, &url2)) assert.True(t, GetURLComparator().CompareURLEqual(&url1, &url2))
assert.True(t, GetURLTool().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY)) assert.True(t, GetURLComparator().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
SetURLTool(customURLTool{}) SetURLComparator(customURLTool{})
assert.True(t, GetURLTool().CompareURLEqual(&url1, &url2)) assert.True(t, GetURLComparator().CompareURLEqual(&url1, &url2))
assert.True(t, GetURLTool().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY)) assert.True(t, GetURLComparator().CompareURLEqual(&url1, &url2, constant.TIMESTAMP_KEY, constant.REMOTE_TIMESTAMP_KEY))
} }
// just for no timestamp, it depend on write data. // just for no timestamp, it depend on write data.
......
...@@ -304,7 +304,7 @@ func (dir *RegistryDirectory) cacheInvoker(url *common.URL) protocol.Invoker { ...@@ -304,7 +304,7 @@ func (dir *RegistryDirectory) cacheInvoker(url *common.URL) protocol.Invoker {
// if cached invoker has the same URL with the new URL, then no need to re-refer, and no need to destroy // if cached invoker has the same URL with the new URL, then no need to re-refer, and no need to destroy
// the old invoker. // the old invoker.
urlTmp := cacheInvoker.(protocol.Invoker).GetUrl() urlTmp := cacheInvoker.(protocol.Invoker).GetUrl()
if common.GetURLTool().CompareURLEqual(newUrl, &urlTmp) { if common.GetURLComparator().CompareURLEqual(newUrl, &urlTmp) {
return nil return nil
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment