Skip to content
Snippets Groups Projects
Commit ab8603a0 authored by flycash's avatar flycash
Browse files

Fix review and test

parent 492a1788
No related branches found
No related tags found
No related merge requests found
......@@ -143,19 +143,34 @@ const (
)
const (
CONSUMER_SIGN_FILTER = "sign"
PROVIDER_AUTH_FILTER = "auth"
SERVICE_AUTH_KEY = "auth"
AUTHENTICATOR_KEY = "authenticator"
DEFAULT_AUTHENTICATOR = "accesskeys"
DEFAULT_ACCESS_KEY_STORAGE = "urlstorage"
ACCESS_KEY_STORAGE_KEY = "accessKey.storage"
REQUEST_TIMESTAMP_KEY = "timestamp"
REQUEST_SIGNATURE_KEY = "signature"
AK_KEY = "ak"
SIGNATURE_STRING_FORMAT = "%s#%s#%s#%s"
// name of consumer sign filter
CONSUMER_SIGN_FILTER = "sign"
// name of consumer sign filter
PROVIDER_AUTH_FILTER = "auth"
// name of service filter
SERVICE_AUTH_KEY = "auth"
// key of authenticator
AUTHENTICATOR_KEY = "authenticator"
// name of default authenticator
DEFAULT_AUTHENTICATOR = "accesskeys"
// name of default url storage
DEFAULT_ACCESS_KEY_STORAGE = "urlstorage"
// key of storage
ACCESS_KEY_STORAGE_KEY = "accessKey.storage"
// key of request timestamp
REQUEST_TIMESTAMP_KEY = "timestamp"
// key of request signature
REQUEST_SIGNATURE_KEY = "signature"
// AK key
AK_KEY = "ak"
// signature format
SIGNATURE_STRING_FORMAT = "%s#%s#%s#%s"
// key whether enable signature
PARAMTER_SIGNATURE_ENABLE_KEY = "param.sign"
CONSUMER = "consumer"
ACCESS_KEY_ID_KEY = "accessKeyId"
SECRET_ACCESS_KEY_KEY = "secretAccessKey"
// consumer
CONSUMER = "consumer"
// key of access key id
ACCESS_KEY_ID_KEY = "accessKeyId"
// key of secret access key
SECRET_ACCESS_KEY_KEY = "secretAccessKey"
)
......@@ -22,5 +22,7 @@ import (
)
var (
// The value will be 10^6
// 1ms = 10^6ns
MsToNanoRate = int64(time.Millisecond / time.Nanosecond)
)
......@@ -9,10 +9,13 @@ var (
accesskeyStorages = make(map[string]func() filter.AccessKeyStorage)
)
// SetAuthenticator put the fcn into map with name
func SetAuthenticator(name string, fcn func() filter.Authenticator) {
authenticators[name] = fcn
}
// GetAuthenticator find the Authenticator with name
// if not found, it will panic
func GetAuthenticator(name string) filter.Authenticator {
if authenticators[name] == nil {
panic("authenticator for " + name + " is not existing, make sure you have import the package.")
......@@ -20,10 +23,13 @@ func GetAuthenticator(name string) filter.Authenticator {
return authenticators[name]()
}
// SetAccesskeyStorages will set the fcn into map with this name
func SetAccesskeyStorages(name string, fcn func() filter.AccessKeyStorage) {
accesskeyStorages[name] = fcn
}
// GetAccesskeyStorages find the storage with the name.
// If not found, it will panic.
func GetAccesskeyStorages(name string) filter.AccessKeyStorage {
if accesskeyStorages[name] == nil {
panic("accesskeyStorages for " + name + " is not existing, make sure you have import the package.")
......
......@@ -46,10 +46,6 @@ type nacosClientFacade interface {
common.Node
}
func timeSecondDuration(sec int) time.Duration {
return time.Duration(sec) * time.Second
}
// HandleClientRestart Restart client handler
func HandleClientRestart(r nacosClientFacade) {
var (
......@@ -79,7 +75,7 @@ LOOP:
case <-r.GetDone():
logger.Warnf("(NacosProviderRegistry)reconnectZkRegistry goroutine exit now...")
break LOOP
case <-getty.GetTimeWheel().After(timeSecondDuration(failTimes * connDelay)): // Prevent crazy reconnection nacos.
case <-getty.GetTimeWheel().After(time.Duration(failTimes*connDelay) * time.Second): // Prevent crazy reconnection nacos.
}
err = ValidateNacosClient(r, WithNacosName(nacosName))
logger.Infof("NacosProviderRegistry.validateNacosClient(nacosAddr{%s}) = error{%#v}",
......
......@@ -41,10 +41,10 @@ func TestRestInvoker_Invoke(t *testing.T) {
// Refer
proto := GetRestProtocol()
defer proto.Destroy()
url, err := common.NewURL(context.Background(), "rest://127.0.0.1:8877/com.ikurento.user.UserProvider?anyhost=true&"+
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+
"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&"+
url, err := common.NewURL("rest://127.0.0.1:8877/com.ikurento.user.UserProvider?anyhost=true&" +
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"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&" +
"side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err)
_, err = common.ServiceMap.Register(url.Protocol, &UserProvider{})
......
......@@ -40,10 +40,10 @@ import (
func TestRestProtocol_Refer(t *testing.T) {
// Refer
proto := GetRestProtocol()
url, err := common.NewURL(context.Background(), "rest://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&"+
"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&"+
url, err := common.NewURL("rest://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&" +
"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&" +
"side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err)
con := config.ConsumerConfig{
......@@ -73,10 +73,10 @@ func TestRestProtocol_Refer(t *testing.T) {
func TestRestProtocol_Export(t *testing.T) {
// Export
proto := GetRestProtocol()
url, err := common.NewURL(context.Background(), "rest://127.0.0.1:8888/com.ikurento.user.UserProvider?anyhost=true&"+
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+
"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&"+
url, err := common.NewURL("rest://127.0.0.1:8888/com.ikurento.user.UserProvider?anyhost=true&" +
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&" +
"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&" +
"side=provider&timeout=3000&timestamp=1556509797245")
assert.NoError(t, err)
_, err = common.ServiceMap.Register(url.Protocol, &UserProvider{})
......
......@@ -69,11 +69,20 @@ func init() {
*/
type FacadeBasedRegistry interface {
Registry
// CreatePath create the path in the registry
CreatePath(string) error
// DoRegister actually do the register job
DoRegister(string, string) error
// DoSubscribe actually subscribe the URL
DoSubscribe(conf *common.URL) (Listener, error)
// CloseAndNilClient close the client and then reset the client in registry to nil
// you should notice that this method will be invoked inside a lock.
// So you should implement this method as light weighted as you can.
CloseAndNilClient()
// CloseListener close listeners
CloseListener()
// InitListeners init listeners
InitListeners()
}
......@@ -345,9 +354,9 @@ func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener)
// closeRegisters close and remove registry client and reset services map
func (r *BaseRegistry) closeRegisters() {
logger.Infof("begin to close provider client")
r.cltLock.Lock()
defer r.cltLock.Unlock()
logger.Infof("begin to close provider client")
// Close and remove(set to nil) the registry client
r.facadeBasedRegistry.CloseAndNilClient()
// reset the services map
......
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