Skip to content

Commit

Permalink
Fix format of comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kateryna Nezdolii <[email protected]>
  • Loading branch information
Kateryna Nezdolii committed Jan 5, 2021
1 parent 610d3a0 commit 850b608
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/limiter/base_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (this *BaseRateLimiter) IsOverLimitWithLocalCache(key string) bool {
return false
}

//Generates response descriptor status based on cache key, over the limit with local cache, over the limit and
// Generates response descriptor status based on cache key, over the limit with local cache, over the limit and
// near the limit thresholds. Thresholds are checked in order and are mutually exclusive.
func (this *BaseRateLimiter) GetResponseDescriptorStatus(key string, limitInfo *LimitInfo,
isOverLimitWithLocalCache bool, hitsAddend uint32) *pb.RateLimitResponse_DescriptorStatus {
Expand Down
4 changes: 2 additions & 2 deletions src/memcached/cache_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (this *rateLimitMemcacheImpl) DoLimit(
continue
}

//Check if key is over the limit in local cache
// Check if key is over the limit in local cache.
if this.baseRateLimiter.IsOverLimitWithLocalCache(cacheKey.Key) {
isOverLimitWithLocalCache[i] = true
logger.Debugf("cache key is over the limit: %s", cacheKey.Key)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (this *rateLimitMemcacheImpl) increaseAsync(cacheKeys []limiter.CacheKey, i
expirationSeconds += this.jitterRand.Int63n(this.expirationJitterMaxSeconds)
}

// Need to add instead of increment
// Need to add instead of increment.
err = this.client.Add(&memcache.Item{
Key: cacheKey.Key,
Value: []byte(strconv.FormatUint(hitsAddend, 10)),
Expand Down
2 changes: 1 addition & 1 deletion src/redis/fixed_cache_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (this *fixedRateLimitCacheImpl) DoLimit(
continue
}

//Check if key is over the limit in local cache
// Check if key is over the limit in local cache.
if this.baseRateLimiter.IsOverLimitWithLocalCache(cacheKey.Key) {
isOverLimitWithLocalCache[i] = true
logger.Debugf("cache key is over the limit: %s", cacheKey.Key)
Expand Down
10 changes: 5 additions & 5 deletions test/limiter/base_limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestOverLimitWithLocalCache(t *testing.T) {
localCache := freecache.NewCache(100)
localCache.Set([]byte("key"), []byte("value"), 100)
baseRateLimit := limiter.NewBaseRateLimit(nil, nil, 3600, localCache, 0.8)
//returns true, as local cache contains over limit value for the key
// Returns true, as local cache contains over limit value for the key.
assert.Equal(true, baseRateLimit.IsOverLimitWithLocalCache("key"))
}

Expand All @@ -48,11 +48,11 @@ func TestNoOverLimitWithLocalCache(t *testing.T) {
controller := gomock.NewController(t)
defer controller.Finish()
baseRateLimit := limiter.NewBaseRateLimit(nil, nil, 3600, nil, 0.8)
//returns false, as local cache is nil
// Returns false, as local cache is nil.
assert.Equal(false, baseRateLimit.IsOverLimitWithLocalCache("domain_key_value_1234"))
localCache := freecache.NewCache(100)
baseRateLimitWithLocalCache := limiter.NewBaseRateLimit(nil, nil, 3600, localCache, 0.8)
//returns false, as local cache does not contain value for cache key
// Returns false, as local cache does not contain value for cache key.
assert.Equal(false, baseRateLimitWithLocalCache.IsOverLimitWithLocalCache("domain_key_value_1234"))
}

Expand All @@ -76,7 +76,7 @@ func TestGetResponseStatusOverLimitWithLocalCache(t *testing.T) {
baseRateLimit := limiter.NewBaseRateLimit(timeSource, nil, 3600, nil, 0.8)
limits := []*config.RateLimit{config.NewRateLimit(5, pb.RateLimitResponse_RateLimit_SECOND, "key_value", statsStore)}
limitInfo := limiter.NewRateLimitInfo(limits[0], 2, 6, 4, 5)
//as `isOverLimitWithLocalCache` is passed as `true`, immediate response is returned with no checks of the limits
// As `isOverLimitWithLocalCache` is passed as `true`, immediate response is returned with no checks of the limits.
responseStatus := baseRateLimit.GetResponseDescriptorStatus("key", limitInfo, true, 2)
assert.Equal(pb.RateLimitResponse_OVER_LIMIT, responseStatus.GetCode())
assert.Equal(uint32(0), responseStatus.GetLimitRemaining())
Expand All @@ -101,7 +101,7 @@ func TestGetResponseStatusOverLimit(t *testing.T) {
assert.Equal(uint32(0), responseStatus.GetLimitRemaining())
assert.Equal(limits[0].Limit, responseStatus.GetCurrentLimit())
result, _ := localCache.Get([]byte("key"))
//local cache should have been populated with over the limit key
// Local cache should have been populated with over the limit key.
assert.Equal("", string(result))
assert.Equal(uint64(2), limits[0].Stats.OverLimit.Value())
assert.Equal(uint64(1), limits[0].Stats.NearLimit.Value())
Expand Down

0 comments on commit 850b608

Please sign in to comment.