diff --git a/common/extension/tps_limit.go b/common/extension/tps_limit.go index 626361e4937879c34c65adba19a3b8451c0edd6a..e789d5b1065add49fcf255a6c4fe3dab808e6d08 100644 --- a/common/extension/tps_limit.go +++ b/common/extension/tps_limit.go @@ -18,20 +18,20 @@ package extension import ( - "github.com/apache/dubbo-go/filter" + "github.com/apache/dubbo-go/filter/impl/tps/intf" ) var ( - tpsLimitStrategy = make(map[string]func(rate int, interval int) filter.TpsLimitStrategy) - tpsLimiter = make(map[string]func() filter.TpsLimiter) - tpsRejectedExecutionHandler = make(map[string]func() filter.RejectedExecutionHandler) + 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) ) -func SetTpsLimiter(name string, creator func() filter.TpsLimiter) { +func SetTpsLimiter(name string, creator func() intf.TpsLimiter) { tpsLimiter[name] = creator } -func GetTpsLimiter(name string) filter.TpsLimiter { +func GetTpsLimiter(name string) intf.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) filter.TpsLimiter { return creator() } -func SetTpsLimitStrategy(name string, creator func(rate int, interval int) filter.TpsLimitStrategy) { +func SetTpsLimitStrategy(name string, creator func(rate int, interval int) intf.TpsLimitStrategy) { tpsLimitStrategy[name] = creator } -func GetTpsLimitStrategyCreator(name string) func(rate int, interval int) filter.TpsLimitStrategy { +func GetTpsLimitStrategyCreator(name string) func(rate int, interval int) intf.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) filter return creator } -func SetTpsRejectedExecutionHandler(name string, creator func() filter.RejectedExecutionHandler) { +func SetTpsRejectedExecutionHandler(name string, creator func() intf.RejectedExecutionHandler) { tpsRejectedExecutionHandler[name] = creator } -func GetTpsRejectedExecutionHandler(name string) filter.RejectedExecutionHandler { +func GetTpsRejectedExecutionHandler(name string) intf.RejectedExecutionHandler { creator, ok := tpsRejectedExecutionHandler[name] if !ok { panic("TpsRejectedExecutionHandler for " + name + " is not existing, make sure you have import the package " + diff --git a/config/testdata/provider_config.yml b/config/testdata/provider_config.yml index 5cbefe08111a048cec1902fbf9563cf78552a730..71e45b9c0e17d0a0f21b4afaeabd1a553469c6dc 100644 --- a/config/testdata/provider_config.yml +++ b/config/testdata/provider_config.yml @@ -29,6 +29,15 @@ services: "UserProvider": registry: "hangzhouzk,shanghaizk" filter: "" + # the name of limiter + tps.limiter: "default" + # the time unit of interval is ms + tps.limit.interval: 60000 + tps.limit.rate: 200 + # the name of strategy + tps.limit.strategy: "slidingWindow" + # the name of RejectedExecutionHandler + tps.limit.rejected.handler: "default" protocol : "dubbo" # equivalent to interface of dubbo.xml interface : "com.ikurento.user.UserProvider" diff --git a/filter/rejected_execution_handler.go b/filter/impl/tps/intf/rejected_execution_handler.go similarity index 70% rename from filter/rejected_execution_handler.go rename to filter/impl/tps/intf/rejected_execution_handler.go index 1773edcbd6d415c57dd1b04e69860831fe831efd..1e0c0938f8e8fb19ae3d1086688a08cbdb896a98 100644 --- a/filter/rejected_execution_handler.go +++ b/filter/impl/tps/intf/rejected_execution_handler.go @@ -14,13 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package filter +package intf import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/protocol" ) +/** + * This implementation only logs the invocation info. + * it always return en error inside the result. + * "UserProvider": + * registry: "hangzhouzk" + * protocol : "dubbo" + * interface : "com.ikurento.user.UserProvider" + * ... # other configuration + * tps.limiter: "method-service" # the name of limiter + * tps.limit.rejected.handler: "name of handler" + * methods: + * - name: "GetUser" + */ type RejectedExecutionHandler interface { RejectedExecution(url common.URL, invocation protocol.Invocation) protocol.Result } diff --git a/filter/tps_limit_strategy.go b/filter/impl/tps/intf/tps_limit_strategy.go similarity index 69% rename from filter/tps_limit_strategy.go rename to filter/impl/tps/intf/tps_limit_strategy.go index 602d20f79caeb6bf8da60de6c08dee5f358c6b8c..ed52daebf66b3aef29e75d39eaa8c10e146e8319 100644 --- a/filter/tps_limit_strategy.go +++ b/filter/impl/tps/intf/tps_limit_strategy.go @@ -15,10 +15,21 @@ * limitations under the License. */ -package filter +package intf /* * please register your implementation by invoking SetTpsLimitStrategy + * "UserProvider": + * registry: "hangzhouzk" + * protocol : "dubbo" + * interface : "com.ikurento.user.UserProvider" + * ... # other configuration + * tps.limiter: "method-service" # the name of limiter + * tps.limit.strategy: "name of implementation" # service-level + * methods: + * - name: "GetUser" + * tps.interval: 3000 + * tps.limit.strategy: "name of implementation" # method-level */ type TpsLimitStrategy interface { IsAllowable() bool diff --git a/filter/tps_limiter.go b/filter/impl/tps/intf/tps_limiter.go similarity index 98% rename from filter/tps_limiter.go rename to filter/impl/tps/intf/tps_limiter.go index 1d2b2341ac7d9b12f75d373909b0baa58bc7295f..d3935c11dec74cc7f4975569280d0825e84a9b6c 100644 --- a/filter/tps_limiter.go +++ b/filter/impl/tps/intf/tps_limiter.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package filter +package intf import ( "github.com/apache/dubbo-go/common" diff --git a/filter/rejected_execution_handler_mock.go b/filter/impl/tps/rejected_execution_handler_mock.go similarity index 99% rename from filter/rejected_execution_handler_mock.go rename to filter/impl/tps/rejected_execution_handler_mock.go index 20c3e575bb3e0e02164a7d4ef01e3db64c6a72c9..55b01f022f8264e70d1b298db7d4d2465fcd6704 100644 --- a/filter/rejected_execution_handler_mock.go +++ b/filter/impl/tps/rejected_execution_handler_mock.go @@ -18,7 +18,7 @@ // Source: rejected_execution_handler.go // Package filter is a generated GoMock package. -package filter +package tps import ( common "github.com/apache/dubbo-go/common" diff --git a/filter/impl/rejected_execution_handler_only_log_impl.go b/filter/impl/tps/rejected_execution_handler_only_log_impl.go similarity index 75% rename from filter/impl/rejected_execution_handler_only_log_impl.go rename to filter/impl/tps/rejected_execution_handler_only_log_impl.go index bc67fa4ec450bcd5651fc0714a8ab7f75cfbe19f..596160f07c3f749097c07dbfd5514492c8f105a2 100644 --- a/filter/impl/rejected_execution_handler_only_log_impl.go +++ b/filter/impl/tps/rejected_execution_handler_only_log_impl.go @@ -15,21 +15,18 @@ * limitations under the License. */ -package impl +package tps import ( "sync" ) -import ( - "github.com/prometheus/common/log" -) - 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" + "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/filter/impl/tps/intf" "github.com/apache/dubbo-go/protocol" ) @@ -46,16 +43,25 @@ var onlyLogHandlerOnce sync.Once /** * This implementation only logs the invocation info. * it always return en error inside the result. + * "UserProvider": + * registry: "hangzhouzk" + * protocol : "dubbo" + * interface : "com.ikurento.user.UserProvider" + * ... # other configuration + * tps.limiter: "method-service" # the name of limiter + * tps.limit.rejected.handler: "default" or "log" + * methods: + * - name: "GetUser" */ type OnlyLogRejectedExecutionHandler struct { } func (handler *OnlyLogRejectedExecutionHandler) RejectedExecution(url common.URL, invocation protocol.Invocation) protocol.Result { - log.Errorf("The invocation was rejected due to over rate limitation. url: %s", url.String()) + logger.Errorf("The invocation was rejected due to over rate limitation. url: %s", url.String()) return &protocol.RPCResult{} } -func GetOnlyLogRejectedExecutionHandler() filter.RejectedExecutionHandler { +func GetOnlyLogRejectedExecutionHandler() intf.RejectedExecutionHandler { onlyLogHandlerOnce.Do(func() { onlyLogHandlerInstance = &OnlyLogRejectedExecutionHandler{} }) diff --git a/filter/impl/rejected_execution_handler_only_log_impl_test.go b/filter/impl/tps/rejected_execution_handler_only_log_impl_test.go similarity index 98% rename from filter/impl/rejected_execution_handler_only_log_impl_test.go rename to filter/impl/tps/rejected_execution_handler_only_log_impl_test.go index da54d8a106338dd4f21f9b01e66b031e3c311e01..beff7e3f2c6295d72c1e8bd6be55e3351f2d912f 100644 --- a/filter/impl/rejected_execution_handler_only_log_impl_test.go +++ b/filter/impl/tps/rejected_execution_handler_only_log_impl_test.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package impl +package tps import ( "net/url" diff --git a/filter/impl/tps_limit_fix_window_strategy_impl.go b/filter/impl/tps/tps_limit_fix_window_strategy_impl.go similarity index 96% rename from filter/impl/tps_limit_fix_window_strategy_impl.go rename to filter/impl/tps/tps_limit_fix_window_strategy_impl.go index 04e79b9b4dbd8ef3ab5dd4959a9311996cd8cf2a..7e4032c684876034be95347e156dc0496e5db1dc 100644 --- a/filter/impl/tps_limit_fix_window_strategy_impl.go +++ b/filter/impl/tps/tps_limit_fix_window_strategy_impl.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package impl +package tps 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" + "github.com/apache/dubbo-go/filter/impl/tps/intf" ) const ( @@ -75,7 +75,7 @@ func (impl *FixedWindowTpsLimitStrategyImpl) IsAllowable() bool { return atomic.AddInt32(&impl.count, 1) <= impl.rate } -func NewFixedWindowTpsLimitStrategyImpl(rate int, interval int) filter.TpsLimitStrategy { +func NewFixedWindowTpsLimitStrategyImpl(rate int, interval int) intf.TpsLimitStrategy { return &FixedWindowTpsLimitStrategyImpl{ rate: int32(rate), interval: int64(interval * 1000), // convert to ns diff --git a/filter/impl/tps_limit_fix_window_strategy_impl_test.go b/filter/impl/tps/tps_limit_fix_window_strategy_impl_test.go similarity index 99% rename from filter/impl/tps_limit_fix_window_strategy_impl_test.go rename to filter/impl/tps/tps_limit_fix_window_strategy_impl_test.go index 55d0b14b75e69b44cf9ebe3a615e1a05c60d4b41..8848a05dde5a079f2e8be07a5ce80a756b4b13fe 100644 --- a/filter/impl/tps_limit_fix_window_strategy_impl_test.go +++ b/filter/impl/tps/tps_limit_fix_window_strategy_impl_test.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package impl +package tps import ( "testing" diff --git a/filter/impl/tps_limit_sliding_window_strategy_impl.go b/filter/impl/tps/tps_limit_sliding_window_strategy_impl.go similarity index 96% rename from filter/impl/tps_limit_sliding_window_strategy_impl.go rename to filter/impl/tps/tps_limit_sliding_window_strategy_impl.go index 726ac197a8957f05cf88ac499179a9995c6c5cd1..3a8db5ab3752bc3fbf22cd16a5810e6d69b37a27 100644 --- a/filter/impl/tps_limit_sliding_window_strategy_impl.go +++ b/filter/impl/tps/tps_limit_sliding_window_strategy_impl.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package impl +package tps import ( "container/list" @@ -25,7 +25,7 @@ import ( import ( "github.com/apache/dubbo-go/common/extension" - "github.com/apache/dubbo-go/filter" + "github.com/apache/dubbo-go/filter/impl/tps/intf" ) func init() { @@ -80,7 +80,7 @@ func (impl *SlidingWindowTpsLimitStrategyImpl) IsAllowable() bool { return false } -func NewSlidingWindowTpsLimitStrategyImpl(rate int, interval int) filter.TpsLimitStrategy { +func NewSlidingWindowTpsLimitStrategyImpl(rate int, interval int) intf.TpsLimitStrategy { return &SlidingWindowTpsLimitStrategyImpl{ rate: rate, interval: int64(interval * 1000), diff --git a/filter/impl/tps_limit_sliding_window_strategy_impl_test.go b/filter/impl/tps/tps_limit_sliding_window_strategy_impl_test.go similarity index 67% rename from filter/impl/tps_limit_sliding_window_strategy_impl_test.go rename to filter/impl/tps/tps_limit_sliding_window_strategy_impl_test.go index 26a9400cdf924bdbc791a4f7f201f4b6503bdbba..1bca13d401efe57585d405514d82fcb801ff3aa8 100644 --- a/filter/impl/tps_limit_sliding_window_strategy_impl_test.go +++ b/filter/impl/tps/tps_limit_sliding_window_strategy_impl_test.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package impl +package tps import ( "testing" @@ -23,23 +23,23 @@ import ( ) import ( - "go.etcd.io/etcd/pkg/testutil" + "github.com/stretchr/testify/assert" ) func TestSlidingWindowTpsLimitStrategyImpl_IsAllowable(t *testing.T) { strategy := NewSlidingWindowTpsLimitStrategyImpl(2, 60000) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertFalse(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.False(t, strategy.IsAllowable()) time.Sleep(time.Duration(2100 * 1000)) - testutil.AssertFalse(t, strategy.IsAllowable()) + assert.False(t, strategy.IsAllowable()) strategy = NewSlidingWindowTpsLimitStrategyImpl(2, 2000) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertFalse(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.False(t, strategy.IsAllowable()) time.Sleep(time.Duration(2100 * 1000)) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertFalse(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.False(t, strategy.IsAllowable()) } diff --git a/filter/tps_limit_strategy_mock.go b/filter/impl/tps/tps_limit_strategy_mock.go similarity index 99% rename from filter/tps_limit_strategy_mock.go rename to filter/impl/tps/tps_limit_strategy_mock.go index 4adf5848d121c6d222f893cf094d6d9401c0e5c9..72c658fb9a5d48b6080900a4645d318dfd2b0c21 100644 --- a/filter/tps_limit_strategy_mock.go +++ b/filter/impl/tps/tps_limit_strategy_mock.go @@ -18,7 +18,7 @@ // Source: tps_limit_strategy.go // Package filter is a generated GoMock package. -package filter +package tps import ( gomock "github.com/golang/mock/gomock" diff --git a/filter/impl/tps_limit_thread_safe_fix_window_strategy_impl.go b/filter/impl/tps/tps_limit_thread_safe_fix_window_strategy_impl.go similarity index 95% rename from filter/impl/tps_limit_thread_safe_fix_window_strategy_impl.go rename to filter/impl/tps/tps_limit_thread_safe_fix_window_strategy_impl.go index e7d592c0bf6a9fe504b8a79185c718b4c1e1fd0e..3541252dbefce3729acc04415b1336dfc702ddfb 100644 --- a/filter/impl/tps_limit_thread_safe_fix_window_strategy_impl.go +++ b/filter/impl/tps/tps_limit_thread_safe_fix_window_strategy_impl.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package impl +package tps import ( "sync" @@ -23,7 +23,7 @@ import ( import ( "github.com/apache/dubbo-go/common/extension" - "github.com/apache/dubbo-go/filter" + "github.com/apache/dubbo-go/filter/impl/tps/intf" ) func init() { @@ -56,7 +56,7 @@ func (impl *ThreadSafeFixedWindowTpsLimitStrategyImpl) IsAllowable() bool { return impl.fixedWindow.IsAllowable() } -func NewThreadSafeFixedWindowTpsLimitStrategyImpl(rate int, interval int) filter.TpsLimitStrategy { +func NewThreadSafeFixedWindowTpsLimitStrategyImpl(rate int, interval int) intf.TpsLimitStrategy { fixedWindowStrategy := NewFixedWindowTpsLimitStrategyImpl(rate, interval).(*FixedWindowTpsLimitStrategyImpl) return &ThreadSafeFixedWindowTpsLimitStrategyImpl{ fixedWindow: fixedWindowStrategy, diff --git a/filter/impl/tps_limit_thread_safe_fix_window_strategy_impl_test.go b/filter/impl/tps/tps_limit_thread_safe_fix_window_strategy_impl_test.go similarity index 69% rename from filter/impl/tps_limit_thread_safe_fix_window_strategy_impl_test.go rename to filter/impl/tps/tps_limit_thread_safe_fix_window_strategy_impl_test.go index e41dd62f2c4b1c381ce9dc38f6434ced1d987893..72cd4800de17e512d1b2429a95687315329322ad 100644 --- a/filter/impl/tps_limit_thread_safe_fix_window_strategy_impl_test.go +++ b/filter/impl/tps/tps_limit_thread_safe_fix_window_strategy_impl_test.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package impl +package tps import ( "testing" @@ -23,21 +23,21 @@ import ( ) import ( - "github.com/coreos/etcd/pkg/testutil" + "github.com/stretchr/testify/assert" ) func TestThreadSafeFixedWindowTpsLimitStrategyImpl_IsAllowable(t *testing.T) { strategy := NewThreadSafeFixedWindowTpsLimitStrategyImpl(2, 60000) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertFalse(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.False(t, strategy.IsAllowable()) strategy = NewThreadSafeFixedWindowTpsLimitStrategyImpl(2, 2000) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertFalse(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.False(t, strategy.IsAllowable()) time.Sleep(time.Duration(2100 * 1000)) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertTrue(t, strategy.IsAllowable()) - testutil.AssertFalse(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.True(t, strategy.IsAllowable()) + assert.False(t, strategy.IsAllowable()) } diff --git a/filter/impl/tps_limiter_method_service_impl.go b/filter/impl/tps/tps_limiter_method_service_impl.go similarity index 96% rename from filter/impl/tps_limiter_method_service_impl.go rename to filter/impl/tps/tps_limiter_method_service_impl.go index 23cd64f5c4bbd1ad27d5116b4e23eea6cbbfef54..01d9f6564a25ad08d188519e75a477a312ec0a31 100644 --- a/filter/impl/tps_limiter_method_service_impl.go +++ b/filter/impl/tps/tps_limiter_method_service_impl.go @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package impl +package tps 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" + "github.com/apache/dubbo-go/filter/impl/tps/intf" "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.(filter.TpsLimitStrategy).IsAllowable() + return limitState.(intf.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.(filter.TpsLimitStrategy).IsAllowable() + return limitState.(intf.TpsLimitStrategy).IsAllowable() } func getLimitConfig(methodLevelConfig string, @@ -178,7 +178,7 @@ func getLimitConfig(methodLevelConfig string, var methodServiceTpsLimiterInstance *MethodServiceTpsLimiterImpl var methodServiceTpsLimiterOnce sync.Once -func GetMethodServiceTpsLimiter() filter.TpsLimiter { +func GetMethodServiceTpsLimiter() intf.TpsLimiter { methodServiceTpsLimiterOnce.Do(func() { methodServiceTpsLimiterInstance = &MethodServiceTpsLimiterImpl{ tpsState: concurrent.NewMap(), diff --git a/filter/impl/tps_limiter_method_service_impl_test.go b/filter/impl/tps/tps_limiter_method_service_impl_test.go similarity index 93% rename from filter/impl/tps_limiter_method_service_impl_test.go rename to filter/impl/tps/tps_limiter_method_service_impl_test.go index c0beee9cf39a245d353cd4c7982ed683c6bf627c..8a6fa8398dae9aaa3a7c58422d669b8ab16c55e1 100644 --- a/filter/impl/tps_limiter_method_service_impl_test.go +++ b/filter/impl/tps/tps_limiter_method_service_impl_test.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package impl +package tps 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" + "github.com/apache/dubbo-go/filter/impl/tps/intf" "github.com/apache/dubbo-go/protocol/invocation" ) @@ -46,9 +46,9 @@ func TestMethodServiceTpsLimiterImpl_IsAllowable_Only_Service_Level(t *testing.T common.WithParamsValue(constant.INTERFACE_KEY, methodName), common.WithParamsValue(constant.TPS_LIMIT_RATE_KEY, "20")) - mockStrategyImpl := filter.NewMockTpsLimitStrategy(ctrl) + mockStrategyImpl := NewMockTpsLimitStrategy(ctrl) mockStrategyImpl.EXPECT().IsAllowable().Return(true).Times(1) - extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) filter.TpsLimitStrategy { + extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) intf.TpsLimitStrategy { assert.Equal(t, 20, rate) assert.Equal(t, 60000, interval) return mockStrategyImpl @@ -93,9 +93,9 @@ func TestMethodServiceTpsLimiterImpl_IsAllowable_Method_Level_Override(t *testin common.WithParamsValue(methodConfigPrefix+constant.TPS_LIMIT_STRATEGY_KEY, "default"), ) - mockStrategyImpl := filter.NewMockTpsLimitStrategy(ctrl) + mockStrategyImpl := NewMockTpsLimitStrategy(ctrl) mockStrategyImpl.EXPECT().IsAllowable().Return(true).Times(1) - extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) filter.TpsLimitStrategy { + extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) intf.TpsLimitStrategy { assert.Equal(t, 40, rate) assert.Equal(t, 7000, interval) return mockStrategyImpl @@ -121,9 +121,9 @@ func TestMethodServiceTpsLimiterImpl_IsAllowable_Both_Method_And_Service(t *test common.WithParamsValue(methodConfigPrefix+constant.TPS_LIMIT_RATE_KEY, "40"), ) - mockStrategyImpl := filter.NewMockTpsLimitStrategy(ctrl) + mockStrategyImpl := NewMockTpsLimitStrategy(ctrl) mockStrategyImpl.EXPECT().IsAllowable().Return(true).Times(1) - extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) filter.TpsLimitStrategy { + extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, func(rate int, interval int) intf.TpsLimitStrategy { assert.Equal(t, 40, rate) assert.Equal(t, 3000, interval) return mockStrategyImpl diff --git a/filter/tps_limiter_mock.go b/filter/impl/tps/tps_limiter_mock.go similarity index 99% rename from filter/tps_limiter_mock.go rename to filter/impl/tps/tps_limiter_mock.go index 5fbf7176147a1168164762657799f6c903d196a7..a247bf14daf947628cb793c913f701769e0ad4ef 100644 --- a/filter/tps_limiter_mock.go +++ b/filter/impl/tps/tps_limiter_mock.go @@ -18,7 +18,7 @@ // Source: tps_limiter.go // Package filter is a generated GoMock package. -package filter +package tps import ( common "github.com/apache/dubbo-go/common" diff --git a/filter/impl/tps_limit_filter_test.go b/filter/impl/tps_limit_filter_test.go index 45ce2a5e6d5c90444ea2aff061e5d08fd0da7fd6..18a72ba9e97ca8c423965929c28b317982a7143d 100644 --- a/filter/impl/tps_limit_filter_test.go +++ b/filter/impl/tps_limit_filter_test.go @@ -31,7 +31,8 @@ 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" + "github.com/apache/dubbo-go/filter/impl/tps" + "github.com/apache/dubbo-go/filter/impl/tps/intf" "github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol/invocation" ) @@ -53,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 := filter.NewMockTpsLimiter(ctrl) + mockLimiter := tps.NewMockTpsLimiter(ctrl) mockLimiter.EXPECT().IsAllowable(gomock.Any(), gomock.Any()).Return(true).Times(1) - extension.SetTpsLimiter(constant.DEFAULT_KEY, func() filter.TpsLimiter { + extension.SetTpsLimiter(constant.DEFAULT_KEY, func() intf.TpsLimiter { return mockLimiter }) @@ -74,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 := filter.NewMockTpsLimiter(ctrl) + mockLimiter := tps.NewMockTpsLimiter(ctrl) mockLimiter.EXPECT().IsAllowable(gomock.Any(), gomock.Any()).Return(false).Times(1) - extension.SetTpsLimiter(constant.DEFAULT_KEY, func() filter.TpsLimiter { + extension.SetTpsLimiter(constant.DEFAULT_KEY, func() intf.TpsLimiter { return mockLimiter }) mockResult := &protocol.RPCResult{} - mockRejectedHandler := filter.NewMockRejectedExecutionHandler(ctrl) + mockRejectedHandler := tps.NewMockRejectedExecutionHandler(ctrl) mockRejectedHandler.EXPECT().RejectedExecution(gomock.Any(), gomock.Any()).Return(mockResult).Times(1) - extension.SetTpsRejectedExecutionHandler(constant.DEFAULT_KEY, func() filter.RejectedExecutionHandler { + extension.SetTpsRejectedExecutionHandler(constant.DEFAULT_KEY, func() intf.RejectedExecutionHandler { return mockRejectedHandler })