73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package platformapi
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
)
|
|
|
|
func TestLimitSpeed(t *testing.T) {
|
|
limiter := New(map[string]*LimiterConfig{
|
|
"limited1persecond": &LimiterConfig{
|
|
MaxAccessCount: 1,
|
|
TimeGapMilliSecond: 1000,
|
|
},
|
|
"limited10per10second": &LimiterConfig{
|
|
MaxAccessCount: 10,
|
|
TimeGapMilliSecond: 10 * 1000,
|
|
},
|
|
}, &LimiterConfig{
|
|
MaxAccessCount: 1,
|
|
TimeGapMilliSecond: 2000,
|
|
})
|
|
|
|
utils.CallFuncAsync(func() {
|
|
count := 0
|
|
for {
|
|
limiter.AccessAPI("limited1persecond", "")
|
|
fmt.Printf("limited1persecond, time:%s, count:%d\n", time.Now().Format("2006-01-02 15:04:05.00000"), count)
|
|
count++
|
|
}
|
|
})
|
|
utils.CallFuncAsync(func() {
|
|
count := 0
|
|
for {
|
|
limiter.AccessAPI("limited10per10second", "")
|
|
fmt.Printf("limited10per10second, time:%s, count:%d\n", time.Now().Format("2006-01-02 15:04:05.00000"), count)
|
|
count++
|
|
}
|
|
})
|
|
utils.CallFuncAsync(func() {
|
|
count := 0
|
|
for {
|
|
limiter.AccessAPI("otherAPI", "")
|
|
fmt.Printf("otherAPI, time:%s, count:%d\n", time.Now().Format("2006-01-02 15:04:05.00000"), count)
|
|
count++
|
|
}
|
|
})
|
|
time.Sleep(30 * time.Second)
|
|
}
|
|
|
|
func Test_store(b *testing.T) {
|
|
tempTagList := []int{1, 2, 3, 9, 5, 4}
|
|
sort.Slice(tempTagList, func(i, j int) bool {
|
|
if tempTagList[i] > tempTagList[j] {
|
|
return false
|
|
}
|
|
return true
|
|
})
|
|
fmt.Println(tempTagList)
|
|
}
|
|
|
|
func Test_string_byte(t *testing.T) {
|
|
aa := `<b>%s</b><b>1111111111111111111</b>`
|
|
bb := strings.Replace(aa, "<b>", "<hb>", -1)
|
|
cc := strings.Replace(bb, "</b>", "</hb>", -1)
|
|
fmt.Println("bb===========", bb)
|
|
fmt.Println("cc===========", cc)
|
|
}
|