Skip to content
Snippets Groups Projects
Unverified Commit e11faed2 authored by watermelon's avatar watermelon Committed by GitHub
Browse files

Merge pull request #871 from kedadiannao220/bugfix

Fix Warnings: incorrect conversion between integer type #857
parents a2a2b0b3 de301c79
Branches
Tags
No related merge requests found
...@@ -56,7 +56,7 @@ func (invoker *forkingClusterInvoker) Invoke(ctx context.Context, invocation pro ...@@ -56,7 +56,7 @@ func (invoker *forkingClusterInvoker) Invoke(ctx context.Context, invocation pro
} }
var selected []protocol.Invoker var selected []protocol.Invoker
forks := int(invoker.GetUrl().GetParamInt(constant.FORKS_KEY, constant.DEFAULT_FORKS)) forks := invoker.GetUrl().GetParamByIntValue(constant.FORKS_KEY, constant.DEFAULT_FORKS)
timeouts := invoker.GetUrl().GetParamInt(constant.TIMEOUT_KEY, constant.DEFAULT_TIMEOUT) timeouts := invoker.GetUrl().GetParamInt(constant.TIMEOUT_KEY, constant.DEFAULT_TIMEOUT)
if forks < 0 || forks > len(invokers) { if forks < 0 || forks > len(invokers) {
selected = invokers selected = invokers
......
...@@ -105,7 +105,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string, ...@@ -105,7 +105,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
selector.virtualInvokers = make(map[uint32]protocol.Invoker) selector.virtualInvokers = make(map[uint32]protocol.Invoker)
selector.hashCode = hashCode selector.hashCode = hashCode
url := invokers[0].GetUrl() url := invokers[0].GetUrl()
selector.replicaNum = int(url.GetMethodParamInt(methodName, HashNodes, 160)) selector.replicaNum = url.GetMethodParamIntValue(methodName, HashNodes, 160)
indices := re.Split(url.GetMethodParam(methodName, HashArguments, "0"), -1) indices := re.Split(url.GetMethodParam(methodName, HashArguments, "0"), -1)
for _, index := range indices { for _, index := range indices {
i, err := strconv.Atoi(index) i, err := strconv.Atoi(index)
......
...@@ -96,6 +96,7 @@ func (c *DefaultHealthChecker) getCircuitBreakerSleepWindowTime(status *protocol ...@@ -96,6 +96,7 @@ func (c *DefaultHealthChecker) getCircuitBreakerSleepWindowTime(status *protocol
return int64(sleepWindow) return int64(sleepWindow)
} }
// GetRequestSuccessiveFailureThreshold return the requestSuccessiveFailureThreshold bound to this DefaultHealthChecker // GetRequestSuccessiveFailureThreshold return the requestSuccessiveFailureThreshold bound to this DefaultHealthChecker
func (c *DefaultHealthChecker) GetRequestSuccessiveFailureThreshold() int32 { func (c *DefaultHealthChecker) GetRequestSuccessiveFailureThreshold() int32 {
return c.requestSuccessiveFailureThreshold return c.requestSuccessiveFailureThreshold
...@@ -114,8 +115,8 @@ func (c *DefaultHealthChecker) GetOutStandingRequestCountLimit() int32 { ...@@ -114,8 +115,8 @@ func (c *DefaultHealthChecker) GetOutStandingRequestCountLimit() int32 {
// NewDefaultHealthChecker constructs a new DefaultHealthChecker based on the url // NewDefaultHealthChecker constructs a new DefaultHealthChecker based on the url
func NewDefaultHealthChecker(url *common.URL) router.HealthChecker { func NewDefaultHealthChecker(url *common.URL) router.HealthChecker {
return &DefaultHealthChecker{ return &DefaultHealthChecker{
outStandingRequestConutLimit: int32(url.GetParamInt(constant.OUTSTANDING_REQUEST_COUNT_LIMIT_KEY, math.MaxInt32)), outStandingRequestConutLimit: url.GetParamInt32(constant.OUTSTANDING_REQUEST_COUNT_LIMIT_KEY, math.MaxInt32),
requestSuccessiveFailureThreshold: int32(url.GetParamInt(constant.SUCCESSIVE_FAILED_REQUEST_THRESHOLD_KEY, constant.DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF)), requestSuccessiveFailureThreshold: url.GetParamInt32(constant.SUCCESSIVE_FAILED_REQUEST_THRESHOLD_KEY, constant.DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF),
circuitTrippedTimeoutFactor: int32(url.GetParamInt(constant.CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY, constant.DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR)), circuitTrippedTimeoutFactor: url.GetParamInt32(constant.CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY, constant.DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR),
} }
} }
...@@ -484,22 +484,49 @@ func (c URL) GetParamBool(key string, d bool) bool { ...@@ -484,22 +484,49 @@ func (c URL) GetParamBool(key string, d bool) bool {
return r return r
} }
// GetParamInt gets int value by @key // GetParamInt gets int64 value by @key
func (c URL) GetParamInt(key string, d int64) int64 { func (c URL) GetParamInt(key string, d int64) int64 {
r, err := strconv.Atoi(c.GetParam(key, "")) r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 64)
if r == 0 || err != nil { if err != nil {
return d
}
return r
}
// GetParamInt32 gets int32 value by @key
func (c URL) GetParamInt32(key string, d int32) int32 {
r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 32)
if err != nil {
return d return d
} }
return int64(r) return int32(r)
}
// GetParamByIntValue gets int value by @key
func (c URL) GetParamByIntValue(key string, d int) int {
r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 0)
if err != nil {
return d
}
return int(r)
} }
// GetMethodParamInt gets int method param // GetMethodParamInt gets int method param
func (c URL) GetMethodParamInt(method string, key string, d int64) int64 { func (c URL) GetMethodParamInt(method string, key string, d int64) int64 {
r, err := strconv.Atoi(c.GetParam("methods."+method+"."+key, "")) r, err := strconv.ParseInt(c.GetParam("methods."+method+"."+key, ""), 10, 64)
if r == 0 || err != nil { if err != nil {
return d
}
return r
}
// GetMethodParamIntValue gets int method param
func (c URL) GetMethodParamIntValue(method string, key string, d int) int {
r, err := strconv.ParseInt(c.GetParam("methods."+method+"."+key, ""), 10, 0)
if err != nil {
return d return d
} }
return int64(r) return int(r)
} }
// GetMethodParamInt64 gets int64 method param // GetMethodParamInt64 gets int64 method param
......
...@@ -167,10 +167,22 @@ func TestURLGetParam(t *testing.T) { ...@@ -167,10 +167,22 @@ func TestURLGetParam(t *testing.T) {
func TestURLGetParamInt(t *testing.T) { func TestURLGetParamInt(t *testing.T) {
params := url.Values{} params := url.Values{}
params.Set("key", "3") params.Set("key", "")
u := URL{baseUrl: baseUrl{params: params}} u := URL{baseUrl: baseUrl{params: params}}
v := u.GetParamInt("key", 1) v := u.GetParamInt("key", 1)
assert.Equal(t, int64(3), v) assert.Equal(t, int64(1), v)
u = URL{}
v = u.GetParamInt("key", 1)
assert.Equal(t, int64(1), v)
}
func TestURLGetParamIntValue(t *testing.T) {
params := url.Values{}
params.Set("key", "0")
u := URL{baseUrl: baseUrl{params: params}}
v := u.GetParamInt("key", 1)
assert.Equal(t, int64(0), v)
u = URL{} u = URL{}
v = u.GetParamInt("key", 1) v = u.GetParamInt("key", 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment