Skip to content

Commit

Permalink
Merge pull request #871 from kedadiannao220/bugfix
Browse files Browse the repository at this point in the history
Fix Warnings: incorrect conversion between integer type #857
  • Loading branch information
watermelo authored Nov 12, 2020
2 parents a2a2b0b + de301c7 commit e11faed
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cluster/cluster_impl/forking_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (invoker *forkingClusterInvoker) Invoke(ctx context.Context, invocation pro
}

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)
if forks < 0 || forks > len(invokers) {
selected = invokers
Expand Down
2 changes: 1 addition & 1 deletion cluster/loadbalance/consistent_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
selector.virtualInvokers = make(map[uint32]protocol.Invoker)
selector.hashCode = hashCode
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)
for _, index := range indices {
i, err := strconv.Atoi(index)
Expand Down
7 changes: 4 additions & 3 deletions cluster/router/healthcheck/default_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (c *DefaultHealthChecker) getCircuitBreakerSleepWindowTime(status *protocol
return int64(sleepWindow)
}


// GetRequestSuccessiveFailureThreshold return the requestSuccessiveFailureThreshold bound to this DefaultHealthChecker
func (c *DefaultHealthChecker) GetRequestSuccessiveFailureThreshold() int32 {
return c.requestSuccessiveFailureThreshold
Expand All @@ -114,8 +115,8 @@ func (c *DefaultHealthChecker) GetOutStandingRequestCountLimit() int32 {
// NewDefaultHealthChecker constructs a new DefaultHealthChecker based on the url
func NewDefaultHealthChecker(url *common.URL) router.HealthChecker {
return &DefaultHealthChecker{
outStandingRequestConutLimit: int32(url.GetParamInt(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)),
circuitTrippedTimeoutFactor: int32(url.GetParamInt(constant.CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY, constant.DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR)),
outStandingRequestConutLimit: url.GetParamInt32(constant.OUTSTANDING_REQUEST_COUNT_LIMIT_KEY, math.MaxInt32),
requestSuccessiveFailureThreshold: url.GetParamInt32(constant.SUCCESSIVE_FAILED_REQUEST_THRESHOLD_KEY, constant.DEFAULT_SUCCESSIVE_FAILED_REQUEST_MAX_DIFF),
circuitTrippedTimeoutFactor: url.GetParamInt32(constant.CIRCUIT_TRIPPED_TIMEOUT_FACTOR_KEY, constant.DEFAULT_CIRCUIT_TRIPPED_TIMEOUT_FACTOR),
}
}
41 changes: 34 additions & 7 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,22 +484,49 @@ func (c URL) GetParamBool(key string, d bool) bool {
return r
}

// GetParamInt gets int value by @key
// GetParamInt gets int64 value by @key
func (c URL) GetParamInt(key string, d int64) int64 {
r, err := strconv.Atoi(c.GetParam(key, ""))
if r == 0 || err != nil {
r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 64)
if err != nil {
return d
}
return int64(r)
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 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
func (c URL) GetMethodParamInt(method string, key string, d int64) int64 {
r, err := strconv.Atoi(c.GetParam("methods."+method+"."+key, ""))
if r == 0 || err != nil {
r, err := strconv.ParseInt(c.GetParam("methods."+method+"."+key, ""), 10, 64)
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 int64(r)
return int(r)
}

// GetMethodParamInt64 gets int64 method param
Expand Down
16 changes: 14 additions & 2 deletions common/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,22 @@ func TestURLGetParam(t *testing.T) {

func TestURLGetParamInt(t *testing.T) {
params := url.Values{}
params.Set("key", "3")
params.Set("key", "")
u := URL{baseUrl: baseUrl{params: params}}
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{}
v = u.GetParamInt("key", 1)
Expand Down

0 comments on commit e11faed

Please sign in to comment.