Skip to content
Snippets Groups Projects
Commit 34f946ca authored by Ming Deng's avatar Ming Deng
Browse files

Fix review

parent d170af16
No related branches found
No related tags found
No related merge requests found
Showing
with 50 additions and 50 deletions
.DS_Store 0 → 100644
File added
......@@ -18,20 +18,20 @@
package extension
import (
"github.com/apache/dubbo-go/filter/impl/tps/intf"
"github.com/apache/dubbo-go/filter/impl/tps"
)
var (
tpsLimitStrategy = make(map[string]func(rate int, interval int) intf.TpsLimitStrategy)
tpsLimiter = make(map[string]func() intf.TpsLimiter)
tpsRejectedExecutionHandler = make(map[string]func() intf.RejectedExecutionHandler)
tpsLimitStrategy = make(map[string]func(rate int, interval int) tps.TpsLimitStrategy)
tpsLimiter = make(map[string]func() tps.TpsLimiter)
tpsRejectedExecutionHandler = make(map[string]func() tps.RejectedExecutionHandler)
)
func SetTpsLimiter(name string, creator func() intf.TpsLimiter) {
func SetTpsLimiter(name string, creator func() tps.TpsLimiter) {
tpsLimiter[name] = creator
}
func GetTpsLimiter(name string) intf.TpsLimiter {
func GetTpsLimiter(name string) tps.TpsLimiter {
creator, ok := tpsLimiter[name]
if !ok {
panic("TpsLimiter for " + name + " is not existing, make sure you have import the package " +
......@@ -40,11 +40,11 @@ func GetTpsLimiter(name string) intf.TpsLimiter {
return creator()
}
func SetTpsLimitStrategy(name string, creator func(rate int, interval int) intf.TpsLimitStrategy) {
func SetTpsLimitStrategy(name string, creator func(rate int, interval int) tps.TpsLimitStrategy) {
tpsLimitStrategy[name] = creator
}
func GetTpsLimitStrategyCreator(name string) func(rate int, interval int) intf.TpsLimitStrategy {
func GetTpsLimitStrategyCreator(name string) func(rate int, interval int) tps.TpsLimitStrategy {
creator, ok := tpsLimitStrategy[name]
if !ok {
panic("TpsLimitStrategy for " + name + " is not existing, make sure you have import the package " +
......@@ -53,11 +53,11 @@ func GetTpsLimitStrategyCreator(name string) func(rate int, interval int) intf.T
return creator
}
func SetTpsRejectedExecutionHandler(name string, creator func() intf.RejectedExecutionHandler) {
func SetTpsRejectedExecutionHandler(name string, creator func() tps.RejectedExecutionHandler) {
tpsRejectedExecutionHandler[name] = creator
}
func GetTpsRejectedExecutionHandler(name string) intf.RejectedExecutionHandler {
func GetTpsRejectedExecutionHandler(name string) tps.RejectedExecutionHandler {
creator, ok := tpsRejectedExecutionHandler[name]
if !ok {
panic("TpsRejectedExecutionHandler for " + name + " is not existing, make sure you have import the package " +
......
......@@ -18,7 +18,7 @@
// Source: rejected_execution_handler.go
// Package filter is a generated GoMock package.
package tps
package impl
import (
common "github.com/apache/dubbo-go/common"
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"sync"
......@@ -26,7 +26,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/filter/impl/tps/intf"
"github.com/apache/dubbo-go/filter/impl/tps"
"github.com/apache/dubbo-go/protocol"
)
......@@ -61,7 +61,7 @@ func (handler *OnlyLogRejectedExecutionHandler) RejectedExecution(url common.URL
return &protocol.RPCResult{}
}
func GetOnlyLogRejectedExecutionHandler() intf.RejectedExecutionHandler {
func GetOnlyLogRejectedExecutionHandler() tps.RejectedExecutionHandler {
onlyLogHandlerOnce.Do(func() {
onlyLogHandlerInstance = &OnlyLogRejectedExecutionHandler{}
})
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"net/url"
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"sync/atomic"
......@@ -24,7 +24,7 @@ import (
import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter/impl/tps/intf"
"github.com/apache/dubbo-go/filter/impl/tps"
)
const (
......@@ -75,7 +75,7 @@ func (impl *FixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
return atomic.AddInt32(&impl.count, 1) <= impl.rate
}
func NewFixedWindowTpsLimitStrategyImpl(rate int, interval int) intf.TpsLimitStrategy {
func NewFixedWindowTpsLimitStrategyImpl(rate int, interval int) tps.TpsLimitStrategy {
return &FixedWindowTpsLimitStrategyImpl{
rate: int32(rate),
interval: int64(interval * 1000), // convert to ns
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"testing"
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"container/list"
......@@ -25,7 +25,7 @@ import (
import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter/impl/tps/intf"
"github.com/apache/dubbo-go/filter/impl/tps"
)
func init() {
......@@ -80,7 +80,7 @@ func (impl *SlidingWindowTpsLimitStrategyImpl) IsAllowable() bool {
return false
}
func NewSlidingWindowTpsLimitStrategyImpl(rate int, interval int) intf.TpsLimitStrategy {
func NewSlidingWindowTpsLimitStrategyImpl(rate int, interval int) tps.TpsLimitStrategy {
return &SlidingWindowTpsLimitStrategyImpl{
rate: rate,
interval: int64(interval * 1000),
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"testing"
......
......@@ -18,7 +18,7 @@
// Source: tps_limit_strategy.go
// Package filter is a generated GoMock package.
package tps
package impl
import (
gomock "github.com/golang/mock/gomock"
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"sync"
......@@ -23,7 +23,7 @@ import (
import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter/impl/tps/intf"
"github.com/apache/dubbo-go/filter/impl/tps"
)
func init() {
......@@ -56,7 +56,7 @@ func (impl *ThreadSafeFixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
return impl.fixedWindow.IsAllowable()
}
func NewThreadSafeFixedWindowTpsLimitStrategyImpl(rate int, interval int) intf.TpsLimitStrategy {
func NewThreadSafeFixedWindowTpsLimitStrategyImpl(rate int, interval int) tps.TpsLimitStrategy {
fixedWindowStrategy := NewFixedWindowTpsLimitStrategyImpl(rate, interval).(*FixedWindowTpsLimitStrategyImpl)
return &ThreadSafeFixedWindowTpsLimitStrategyImpl{
fixedWindow: fixedWindowStrategy,
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"testing"
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tps
package impl
import (
"fmt"
......@@ -30,7 +30,7 @@ import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter/impl/tps/intf"
"github.com/apache/dubbo-go/filter/impl/tps"
"github.com/apache/dubbo-go/protocol"
)
......@@ -127,7 +127,7 @@ func (limiter MethodServiceTpsLimiterImpl) IsAllowable(url common.URL, invocatio
limitState, found := limiter.tpsState.Load(limitTarget)
if found {
return limitState.(intf.TpsLimitStrategy).IsAllowable()
return limitState.(tps.TpsLimitStrategy).IsAllowable()
}
limitRate := getLimitConfig(methodLimitRateConfig, url, invocation,
......@@ -149,7 +149,7 @@ func (limiter MethodServiceTpsLimiterImpl) IsAllowable(url common.URL, invocatio
url.GetParam(constant.TPS_LIMIT_STRATEGY_KEY, constant.DEFAULT_KEY))
limitStateCreator := extension.GetTpsLimitStrategyCreator(limitStrategyConfig)
limitState, _ = limiter.tpsState.LoadOrStore(limitTarget, limitStateCreator(int(limitRate), int(limitInterval)))
return limitState.(intf.TpsLimitStrategy).IsAllowable()
return limitState.(tps.TpsLimitStrategy).IsAllowable()
}
func getLimitConfig(methodLevelConfig string,
......@@ -178,7 +178,7 @@ func getLimitConfig(methodLevelConfig string,
var methodServiceTpsLimiterInstance *MethodServiceTpsLimiterImpl
var methodServiceTpsLimiterOnce sync.Once
func GetMethodServiceTpsLimiter() intf.TpsLimiter {
func GetMethodServiceTpsLimiter() tps.TpsLimiter {
methodServiceTpsLimiterOnce.Do(func() {
methodServiceTpsLimiterInstance = &MethodServiceTpsLimiterImpl{
tpsState: concurrent.NewMap(),
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package impl
import (
"net/url"
......@@ -30,7 +30,7 @@ import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter/impl/tps/intf"
"github.com/apache/dubbo-go/filter/impl/tps"
"github.com/apache/dubbo-go/protocol/invocation"
)
......@@ -48,7 +48,7 @@ func TestMethodServiceTpsLimiterImpl_IsAllowable_Only_Service_Level(t *testing.T
mockStrategyImpl := NewMockTpsLimitStrategy(ctrl)
mockStrategyImpl.EXPECT().IsAllowable().Return(true).Times(1)
extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) intf.TpsLimitStrategy {
extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) tps.TpsLimitStrategy {
assert.Equal(t, 20, rate)
assert.Equal(t, 60000, interval)
return mockStrategyImpl
......@@ -95,7 +95,7 @@ func TestMethodServiceTpsLimiterImpl_IsAllowable_Method_Level_Override(t *testin
mockStrategyImpl := NewMockTpsLimitStrategy(ctrl)
mockStrategyImpl.EXPECT().IsAllowable().Return(true).Times(1)
extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) intf.TpsLimitStrategy {
extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) tps.TpsLimitStrategy {
assert.Equal(t, 40, rate)
assert.Equal(t, 7000, interval)
return mockStrategyImpl
......@@ -123,7 +123,7 @@ func TestMethodServiceTpsLimiterImpl_IsAllowable_Both_Method_And_Service(t *test
mockStrategyImpl := NewMockTpsLimitStrategy(ctrl)
mockStrategyImpl.EXPECT().IsAllowable().Return(true).Times(1)
extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) intf.TpsLimitStrategy {
extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) tps.TpsLimitStrategy {
assert.Equal(t, 40, rate)
assert.Equal(t, 3000, interval)
return mockStrategyImpl
......
......@@ -18,7 +18,7 @@
// Source: tps_limiter.go
// Package filter is a generated GoMock package.
package tps
package impl
import (
common "github.com/apache/dubbo-go/common"
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package intf
package tps
import (
"github.com/apache/dubbo-go/common"
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package intf
package tps
/*
* please register your implementation by invoking SetTpsLimitStrategy
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package intf
package tps
import (
"github.com/apache/dubbo-go/common"
......
......@@ -21,7 +21,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter"
_ "github.com/apache/dubbo-go/filter/impl/tps"
_ "github.com/apache/dubbo-go/filter/impl/tps/impl"
"github.com/apache/dubbo-go/protocol"
)
......
......@@ -32,7 +32,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/filter/impl/tps"
"github.com/apache/dubbo-go/filter/impl/tps/intf"
"github.com/apache/dubbo-go/filter/impl/tps/impl"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/invocation"
)
......@@ -54,9 +54,9 @@ func TestTpsLimitFilter_Invoke_With_No_TpsLimiter(t *testing.T) {
func TestGenericFilter_Invoke_With_Default_TpsLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockLimiter := tps.NewMockTpsLimiter(ctrl)
mockLimiter := impl.NewMockTpsLimiter(ctrl)
mockLimiter.EXPECT().IsAllowable(gomock.Any(), gomock.Any()).Return(true).Times(1)
extension.SetTpsLimiter(constant.DEFAULT_KEY, func() intf.TpsLimiter {
extension.SetTpsLimiter(constant.DEFAULT_KEY, func() tps.TpsLimiter {
return mockLimiter
})
......@@ -75,17 +75,17 @@ func TestGenericFilter_Invoke_With_Default_TpsLimiter(t *testing.T) {
func TestGenericFilter_Invoke_With_Default_TpsLimiter_Not_Allow(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockLimiter := tps.NewMockTpsLimiter(ctrl)
mockLimiter := impl.NewMockTpsLimiter(ctrl)
mockLimiter.EXPECT().IsAllowable(gomock.Any(), gomock.Any()).Return(false).Times(1)
extension.SetTpsLimiter(constant.DEFAULT_KEY, func() intf.TpsLimiter {
extension.SetTpsLimiter(constant.DEFAULT_KEY, func() tps.TpsLimiter {
return mockLimiter
})
mockResult := &protocol.RPCResult{}
mockRejectedHandler := tps.NewMockRejectedExecutionHandler(ctrl)
mockRejectedHandler := impl.NewMockRejectedExecutionHandler(ctrl)
mockRejectedHandler.EXPECT().RejectedExecution(gomock.Any(), gomock.Any()).Return(mockResult).Times(1)
extension.SetTpsRejectedExecutionHandler(constant.DEFAULT_KEY, func() intf.RejectedExecutionHandler {
extension.SetTpsRejectedExecutionHandler(constant.DEFAULT_KEY, func() tps.RejectedExecutionHandler {
return mockRejectedHandler
})
......
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