Skip to content
Snippets Groups Projects
Commit 44a71ec3 authored by AlexStocks's avatar AlexStocks
Browse files

Merge branch 'develop'

parents 559efc95 e8a65461
No related branches found
No related tags found
No related merge requests found
Showing
with 95 additions and 54 deletions
......@@ -79,8 +79,10 @@ type rest struct {
func (bi *MockInvoker) Invoke(c context.Context, invocation protocol.Invocation) protocol.Result {
count++
var success bool
var err error = nil
var (
success bool
err error
)
if count >= bi.successCount {
success = true
} else {
......
......@@ -42,8 +42,8 @@ var (
failsafeUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)
// register_failsafe register failsafeCluster to cluster extension.
func register_failsafe(t *testing.T, invoker *mock.MockInvoker) protocol.Invoker {
// registerFailsafe register failsafeCluster to cluster extension.
func registerFailsafe(t *testing.T, invoker *mock.MockInvoker) protocol.Invoker {
extension.SetLoadbalance("random", loadbalance.NewRandomLoadBalance)
failsafeCluster := NewFailsafeCluster()
......@@ -62,7 +62,7 @@ func Test_FailSafeInvokeSuccess(t *testing.T) {
defer ctrl.Finish()
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failsafe(t, invoker)
clusterInvoker := registerFailsafe(t, invoker)
invoker.EXPECT().GetUrl().Return(failsafeUrl).AnyTimes()
......@@ -81,7 +81,7 @@ func Test_FailSafeInvokeFail(t *testing.T) {
defer ctrl.Finish()
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failsafe(t, invoker)
clusterInvoker := registerFailsafe(t, invoker)
invoker.EXPECT().GetUrl().Return(failsafeUrl).AnyTimes()
......
......@@ -19,7 +19,6 @@ package cluster_impl
import (
"context"
"errors"
"fmt"
"time"
)
......@@ -45,6 +44,7 @@ func newForkingClusterInvoker(directory cluster.Directory) protocol.Invoker {
}
}
// Invoke ...
func (invoker *forkingClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
err := invoker.checkWhetherDestroyed()
if err != nil {
......@@ -87,14 +87,18 @@ func (invoker *forkingClusterInvoker) Invoke(ctx context.Context, invocation pro
rsps, err := resultQ.Poll(1, time.Millisecond*time.Duration(timeouts))
if err != nil {
return &protocol.RPCResult{
Err: errors.New(fmt.Sprintf("failed to forking invoke provider %v, but no luck to perform the invocation. Last error is: %s", selected, err.Error()))}
Err: fmt.Errorf("failed to forking invoke provider %v, "+
"but no luck to perform the invocation. Last error is: %v", selected, err),
}
}
if len(rsps) == 0 {
return &protocol.RPCResult{Err: errors.New(fmt.Sprintf("failed to forking invoke provider %v, but no resp", selected))}
return &protocol.RPCResult{Err: fmt.Errorf("failed to forking invoke provider %v, but no resp", selected)}
}
result, ok := rsps[0].(protocol.Result)
if !ok {
return &protocol.RPCResult{Err: errors.New(fmt.Sprintf("failed to forking invoke provider %v, but not legal resp", selected))}
return &protocol.RPCResult{Err: fmt.Errorf("failed to forking invoke provider %v, but not legal resp", selected)}
}
return result
}
......@@ -22,7 +22,7 @@ import (
"github.com/apache/dubbo-go/protocol"
)
// Extension - Directory
// Directory: Extension - Directory
type Directory interface {
common.Node
List(invocation protocol.Invocation) []protocol.Invoker
......
......@@ -21,7 +21,7 @@ import (
"github.com/apache/dubbo-go/protocol"
)
// Extension - LoadBalance
// LoadBalance: Extension - LoadBalance
type LoadBalance interface {
Select([]protocol.Invoker, protocol.Invocation) protocol.Invoker
}
......@@ -36,9 +36,12 @@ import (
)
const (
// ConsistentHash ...
ConsistentHash = "consistenthash"
HashNodes = "hash.nodes"
HashArguments = "hash.arguments"
// HashNodes ...
HashNodes = "hash.nodes"
// HashArguments ...
HashArguments = "hash.arguments"
)
var (
......
......@@ -28,6 +28,7 @@ import (
)
const (
// LeastActive ...
LeastActive = "leastactive"
)
......@@ -53,12 +54,12 @@ func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation
}
var (
leastActive int32 = -1 // The least active value of all invokers
totalWeight int64 = 0 // The number of invokers having the same least active value (LEAST_ACTIVE)
firstWeight int64 = 0 // Initial value, used for comparison
leastIndexes = make([]int, count) // The index of invokers having the same least active value (LEAST_ACTIVE)
leastCount = 0 // The number of invokers having the same least active value (LEAST_ACTIVE)
sameWeight = true // Every invoker has the same weight value?
leastActive int32 = -1 // The least active value of all invokers
totalWeight int64 // The number of invokers having the same least active value (LEAST_ACTIVE)
firstWeight int64 // Initial value, used for comparison
leastCount int // The number of invokers having the same least active value (LEAST_ACTIVE)
leastIndexes = make([]int, count) // The index of invokers having the same least active value (LEAST_ACTIVE)
sameWeight = true // Every invoker has the same weight value?
)
for i := 0; i < count; i++ {
......
......@@ -31,16 +31,19 @@ import (
)
const (
// RoundRobin ...
RoundRobin = "roundrobin"
// COMPLETE ...
COMPLETE = 0
// UPDATING ...
UPDATING = 1
)
var (
methodWeightMap sync.Map // [string]invokers
state int32 = COMPLETE // update lock acquired ?
recyclePeriod int64 = 60 * time.Second.Nanoseconds()
methodWeightMap sync.Map // [string]invokers
state = int32(COMPLETE) // update lock acquired ?
recyclePeriod = 60 * time.Second.Nanoseconds()
)
func init() {
......
......@@ -37,9 +37,12 @@ import (
)
const (
//ROUTE_PATTERN: route pattern regex
ROUTE_PATTERN = `([&!=,]*)\\s*([^&!=,\\s]+)`
FORCE = "force"
PRIORITY = "priority"
// FORCE ...
FORCE = "force"
// PRIORITY ...
PRIORITY = "priority"
)
//ConditionRouter condition router struct
......@@ -104,7 +107,7 @@ func newConditionRouter(url *common.URL) (*ConditionRouter, error) {
}, nil
}
//Router determine the target server list.
//Route: Router determine the target server list.
func (c *ConditionRouter) Route(invokers []protocol.Invoker, url common.URL, invocation protocol.Invocation) []protocol.Invoker {
if len(invokers) == 0 {
return invokers
......@@ -212,7 +215,7 @@ func parseRule(rule string) (map[string]MatchPair, error) {
return condition, nil
}
//
//MatchWhen MatchWhen
func (c *ConditionRouter) MatchWhen(url common.URL, invocation protocol.Invocation) (bool, error) {
condition, err := MatchCondition(c.WhenCondition, &url, nil, invocation)
return len(c.WhenCondition) == 0 || condition, err
......@@ -245,15 +248,15 @@ func MatchCondition(pairs map[string]MatchPair, url *common.URL, param *common.U
if len(sampleValue) > 0 {
if !matchPair.isMatch(sampleValue, param) {
return false, nil
} else {
result = true
}
result = true
} else {
if !(matchPair.Matches.Empty()) {
return false, nil
} else {
result = true
}
result = true
}
}
return result, nil
......
......@@ -95,13 +95,17 @@ var count int
func (bi *MockInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
count++
var success bool
var err error = nil
var (
success bool
err error = nil
)
if count >= bi.successCount {
success = true
} else {
err = perrors.New("error")
}
result := &protocol.RPCResult{Err: err, Rest: rest{tried: count, success: success}}
return result
}
......
......@@ -27,6 +27,7 @@ import (
"github.com/apache/dubbo-go/config_center"
)
// Environment:
// There is dubbo.properties file and application level config center configuration which higner than normal config center in java. So in java the
// configuration sequence will be config center > application level config center > dubbo.properties > spring bean configuration.
// But in go, neither the dubbo.properties file or application level config center configuration will not support for the time being.
......
......@@ -18,7 +18,10 @@
package constant
const (
// CONF_CONSUMER_FILE_PATH ...
CONF_CONSUMER_FILE_PATH = "CONF_CONSUMER_FILE_PATH"
// CONF_PROVIDER_FILE_PATH ...
CONF_PROVIDER_FILE_PATH = "CONF_PROVIDER_FILE_PATH"
APP_LOG_CONF_FILE = "APP_LOG_CONF_FILE"
// APP_LOG_CONF_FILE ...
APP_LOG_CONF_FILE = "APP_LOG_CONF_FILE"
)
......@@ -18,7 +18,10 @@
package constant
const (
// Version: apache/dubbo-go version
Version = "1.3.0"
Name = "dubbogo"
DATE = "2020/01/12"
// Name: module name
Name = "dubbogo"
// Date: release date
DATE = "2020/01/12"
)
......@@ -22,7 +22,10 @@ import (
"github.com/apache/dubbo-go/config_center"
)
const DefaultKey = "default"
const (
// DefaultKey ...
DefaultKey = "default"
)
type getConfiguratorFunc func(url *common.URL) config_center.Configurator
......
......@@ -26,7 +26,7 @@ var (
)
/**
* you should not make any assumption about the order.
* AddCustomShutdownCallback: you should not make any assumption about the order.
* For example, if you have more than one callbacks, and you wish the order is:
* callback1()
* callback2()
......
......@@ -22,12 +22,12 @@ import (
)
var (
proxy_factories = make(map[string]func(...proxy.Option) proxy.ProxyFactory)
proxyFactories = make(map[string]func(...proxy.Option) proxy.ProxyFactory)
)
// SetProxyFactory ...
func SetProxyFactory(name string, f func(...proxy.Option) proxy.ProxyFactory) {
proxy_factories[name] = f
proxyFactories[name] = f
}
// GetProxyFactory ...
......@@ -35,8 +35,8 @@ func GetProxyFactory(name string) proxy.ProxyFactory {
if name == "" {
name = "default"
}
if proxy_factories[name] == nil {
if proxyFactories[name] == nil {
panic("proxy factory for " + name + " is not existing, make sure you have import the package.")
}
return proxy_factories[name]()
return proxyFactories[name]()
}
......@@ -51,7 +51,7 @@ func NewProxy(invoke protocol.Invoker, callBack interface{}, attachments map[str
}
}
// proxy implement
// Implement: proxy implement
// In consumer, RPCService like:
// type XxxProvider struct {
// Yyy func(ctx context.Context, args []interface{}, rsp *Zzz) error
......
......@@ -34,19 +34,21 @@ import (
"github.com/apache/dubbo-go/common/logger"
)
// rpc service interface
// RPCService: rpc service interface
type RPCService interface {
Reference() string // rpc service id or reference id
// Reference:
// rpc service id or reference id
Reference() string
}
//AsyncCallbackService callback interface for async
type AsyncCallbackService interface {
CallBack(response CallbackResponse) // callback
// Callback: callback
CallBack(response CallbackResponse)
}
//CallbackResponse for different protocol
type CallbackResponse interface {
}
type CallbackResponse interface{}
//AsyncCallback async callback method
type AsyncCallback func(response CallbackResponse)
......@@ -55,7 +57,10 @@ type AsyncCallback func(response CallbackResponse)
// func MethodMapper() map[string][string] {
// return map[string][string]{}
// }
const METHOD_MAPPER = "MethodMapper"
const (
// METHOD_MAPPER ...
METHOD_MAPPER = "MethodMapper"
)
var (
// Precompute the reflect type for error. Can't use error directly
......@@ -63,6 +68,7 @@ var (
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
// todo: lowerecas?
// ServiceMap ...
ServiceMap = &serviceMap{
serviceMap: make(map[string]map[string]*Service),
}
......
......@@ -122,9 +122,8 @@ func TestServiceMap_UnRegister(t *testing.T) {
func TestMethodType_SuiteContext(t *testing.T) {
mt := &MethodType{ctxType: reflect.TypeOf(context.TODO())}
c := context.TODO()
c = context.WithValue(c, "key", "value")
assert.Equal(t, reflect.ValueOf(c), mt.SuiteContext(c))
ctx := context.WithValue(context.Background(), "key", "value")
assert.Equal(t, reflect.ValueOf(ctx), mt.SuiteContext(ctx))
assert.Equal(t, reflect.Zero(mt.ctxType), mt.SuiteContext(nil))
}
......
......@@ -45,17 +45,23 @@ import (
// dubbo role type
/////////////////////////////////
// role constant
const (
// CONSUMER ...
CONSUMER = iota
// CONFIGURATOR ...
CONFIGURATOR
// ROUTER ...
ROUTER
// PROVIDER ...
PROVIDER
)
var (
// DubboNodes ...
DubboNodes = [...]string{"consumers", "configurators", "routers", "providers"}
DubboRole = [...]string{"consumer", "", "", "provider"}
// DubboRole ...
DubboRole = [...]string{"consumer", "", "", "provider"}
)
// RoleType ...
......@@ -428,7 +434,7 @@ func (c URL) GetRawParam(key string) string {
}
}
// GetParamBool
// GetParamBool ...
func (c URL) GetParamBool(s string, d bool) bool {
var r bool
......
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