Skip to content
Snippets Groups Projects
Commit 9e17bad7 authored by zhanghuiren's avatar zhanghuiren
Browse files

Merge remote-tracking branch 'upstream/develop' into dev

parents 9be788c9 c8f57d96
No related branches found
No related tags found
No related merge requests found
Showing
with 48 additions and 49 deletions
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package impl
package filter
import (
"net/url"
......@@ -31,8 +31,8 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/config"
filterCommon "github.com/apache/dubbo-go/filter/common"
"github.com/apache/dubbo-go/filter/common/impl"
"github.com/apache/dubbo-go/filter"
common2 "github.com/apache/dubbo-go/filter/common"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/invocation"
)
......@@ -66,8 +66,8 @@ func TestGenericFilter_Invoke(t *testing.T) {
assert.True(t, shutdownFilter.rejectNewRequest())
result = shutdownFilter.OnResponse(nil, protocol.NewBaseInvoker(*invokeUrl), invoc)
rejectHandler := &impl.OnlyLogRejectedExecutionHandler{}
extension.SetRejectedExecutionHandler("mock", func() filterCommon.RejectedExecutionHandler {
rejectHandler := &common2.OnlyLogRejectedExecutionHandler{}
extension.SetRejectedExecutionHandler("mock", func() filter.RejectedExecutionHandler {
return rejectHandler
})
assert.True(t, providerConfig.ShutdownConfig.RequestsFinished)
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package impl
package filter
import (
"fmt"
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package impl
package filter
import (
"regexp"
......
......@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package impl
package filter
import (
"strings"
......
......@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package impl
package filter
import (
"net/url"
......
......@@ -15,15 +15,15 @@
* limitations under the License.
*/
package impl
package filter
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"
_ "github.com/apache/dubbo-go/filter/common/impl"
_ "github.com/apache/dubbo-go/filter/impl/tps/impl"
_ "github.com/apache/dubbo-go/filter/common"
_ "github.com/apache/dubbo-go/filter/tps"
"github.com/apache/dubbo-go/protocol"
)
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package impl
package filter
import (
"net/url"
......@@ -23,6 +23,9 @@ import (
)
import (
"github.com/apache/dubbo-go/filter"
common2 "github.com/apache/dubbo-go/filter/common"
"github.com/apache/dubbo-go/filter/tps"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)
......@@ -31,10 +34,6 @@ import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
filterCommon "github.com/apache/dubbo-go/filter/common"
filterCommonImpl "github.com/apache/dubbo-go/filter/common/impl"
"github.com/apache/dubbo-go/filter/impl/tps"
"github.com/apache/dubbo-go/filter/impl/tps/impl"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/invocation"
)
......@@ -56,9 +55,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 := impl.NewMockTpsLimiter(ctrl)
mockLimiter := tps.NewMockTpsLimiter(ctrl)
mockLimiter.EXPECT().IsAllowable(gomock.Any(), gomock.Any()).Return(true).Times(1)
extension.SetTpsLimiter(constant.DEFAULT_KEY, func() tps.TpsLimiter {
extension.SetTpsLimiter(constant.DEFAULT_KEY, func() filter.TpsLimiter {
return mockLimiter
})
......@@ -77,17 +76,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 := impl.NewMockTpsLimiter(ctrl)
mockLimiter := tps.NewMockTpsLimiter(ctrl)
mockLimiter.EXPECT().IsAllowable(gomock.Any(), gomock.Any()).Return(false).Times(1)
extension.SetTpsLimiter(constant.DEFAULT_KEY, func() tps.TpsLimiter {
extension.SetTpsLimiter(constant.DEFAULT_KEY, func() filter.TpsLimiter {
return mockLimiter
})
mockResult := &protocol.RPCResult{}
mockRejectedHandler := filterCommonImpl.NewMockRejectedExecutionHandler(ctrl)
mockRejectedHandler := common2.NewMockRejectedExecutionHandler(ctrl)
mockRejectedHandler.EXPECT().RejectedExecution(gomock.Any(), gomock.Any()).Return(mockResult).Times(1)
extension.SetRejectedExecutionHandler(constant.DEFAULT_KEY, func() filterCommon.RejectedExecutionHandler {
extension.SetRejectedExecutionHandler(constant.DEFAULT_KEY, func() filter.RejectedExecutionHandler {
return mockRejectedHandler
})
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package common
package filter
import (
"github.com/apache/dubbo-go/common"
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package impl
package tps
import (
"sync/atomic"
......@@ -25,7 +25,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"
"github.com/apache/dubbo-go/filter"
)
const (
......@@ -79,7 +79,7 @@ func (impl *FixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
type fixedWindowStrategyCreator struct{}
func (creator *fixedWindowStrategyCreator) Create(rate int, interval int) tps.TpsLimitStrategy {
func (creator *fixedWindowStrategyCreator) Create(rate int, interval int) filter.TpsLimitStrategy {
return &FixedWindowTpsLimitStrategyImpl{
rate: int32(rate),
interval: int64(interval) * int64(time.Millisecond), // convert to ns
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package impl
package tps
import (
"testing"
......
......@@ -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/impl/tps"
"github.com/apache/dubbo-go/filter"
)
func init() {
......@@ -82,7 +82,7 @@ func (impl *SlidingWindowTpsLimitStrategyImpl) IsAllowable() bool {
type slidingWindowStrategyCreator struct{}
func (creator *slidingWindowStrategyCreator) Create(rate int, interval int) tps.TpsLimitStrategy {
func (creator *slidingWindowStrategyCreator) Create(rate int, interval int) filter.TpsLimitStrategy {
return &SlidingWindowTpsLimitStrategyImpl{
rate: rate,
interval: int64(interval) * int64(time.Millisecond),
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package impl
package tps
import (
"testing"
......
......@@ -18,7 +18,7 @@
// Source: tps_limit_strategy.go
// Package filter is a generated GoMock package.
package impl
package tps
import (
gomock "github.com/golang/mock/gomock"
......
......@@ -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/impl/tps"
"github.com/apache/dubbo-go/filter"
)
func init() {
......@@ -62,7 +62,7 @@ type threadSafeFixedWindowStrategyCreator struct {
fixedWindowStrategyCreator *fixedWindowStrategyCreator
}
func (creator *threadSafeFixedWindowStrategyCreator) Create(rate int, interval int) tps.TpsLimitStrategy {
func (creator *threadSafeFixedWindowStrategyCreator) Create(rate int, interval int) filter.TpsLimitStrategy {
fixedWindowStrategy := creator.fixedWindowStrategyCreator.Create(rate, interval).(*FixedWindowTpsLimitStrategyImpl)
return &ThreadSafeFixedWindowTpsLimitStrategyImpl{
fixedWindow: fixedWindowStrategy,
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package impl
package tps
import (
"testing"
......
......@@ -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/impl/tps"
"github.com/apache/dubbo-go/filter"
"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.(tps.TpsLimitStrategy).IsAllowable()
return limitState.(filter.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.Create(int(limitRate), int(limitInterval)))
return limitState.(tps.TpsLimitStrategy).IsAllowable()
return limitState.(filter.TpsLimitStrategy).IsAllowable()
}
func getLimitConfig(methodLevelConfig string,
......@@ -178,7 +178,7 @@ func getLimitConfig(methodLevelConfig string,
var methodServiceTpsLimiterInstance *MethodServiceTpsLimiterImpl
var methodServiceTpsLimiterOnce sync.Once
func GetMethodServiceTpsLimiter() tps.TpsLimiter {
func GetMethodServiceTpsLimiter() filter.TpsLimiter {
methodServiceTpsLimiterOnce.Do(func() {
methodServiceTpsLimiterInstance = &MethodServiceTpsLimiterImpl{
tpsState: concurrent.NewMap(),
......
......@@ -15,13 +15,14 @@
* limitations under the License.
*/
package impl
package tps
import (
"net/url"
"testing"
)
import (
"github.com/apache/dubbo-go/filter"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)
......@@ -30,7 +31,6 @@ 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"
"github.com/apache/dubbo-go/protocol/invocation"
)
......@@ -144,10 +144,10 @@ type mockStrategyCreator struct {
rate int
interval int
t *testing.T
strategy tps.TpsLimitStrategy
strategy filter.TpsLimitStrategy
}
func (creator *mockStrategyCreator) Create(rate int, interval int) tps.TpsLimitStrategy {
func (creator *mockStrategyCreator) Create(rate int, interval int) filter.TpsLimitStrategy {
assert.Equal(creator.t, creator.rate, rate)
assert.Equal(creator.t, creator.interval, interval)
return creator.strategy
......
......@@ -18,7 +18,7 @@
// Source: tps_limiter.go
// Package filter is a generated GoMock package.
package impl
package tps
import (
reflect "reflect"
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package filter
/*
* please register your implementation by invoking SetTpsLimitStrategy
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package tps
package filter
import (
"github.com/apache/dubbo-go/common"
......
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