1 Star 0 Fork 0

摆渡村村长/cluster-timewheel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
timewheel_test.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
package timewheel
import (
"fmt"
"testing"
)
func TestOrderListAdd(t *testing.T) {
list := NewOrderList()
list.Add(&Target{
Id: "1",
Circle: 1,
})
list.Add(&Target{
Id: "2",
Circle: 4,
})
list.Add(&Target{
Id: "3",
Circle: 2,
})
list.Add(&Target{
Id: "4",
Circle: 3,
})
// id: 1,3,4,2
list.Foreach(func(task *Target) {
fmt.Println(task.Id)
})
}
func TestOrderListRemove(t *testing.T) {
list := NewOrderList()
list.Add(&Target{
Id: "1",
Circle: 1,
})
list.Add(&Target{
Id: "2",
Circle: 4,
})
list.Add(&Target{
Id: "3",
Circle: 2,
})
list.Add(&Target{
Id: "4",
Circle: 3,
})
// id: 1,3,4,2
list.Foreach(func(task *Target) {
fmt.Println(task.Id)
})
list.Remove(&Target{
Id: "3",
Circle: 2,
})
fmt.Println("remove after")
list.Foreach(func(task *Target) {
fmt.Println(task.Id)
})
}
func TestOrderListConsumer(t *testing.T) {
list := NewOrderList()
list.Add(&Target{
Id: "1",
Circle: 1,
})
list.Add(&Target{
Id: "2",
Circle: 4,
})
list.Add(&Target{
Id: "3",
Circle: 2,
})
list.Add(&Target{
Id: "4",
Circle: 3,
})
// id: 1,3,4,2
list.Foreach(func(task *Target) {
fmt.Println(task.Id)
})
fmt.Println("consumer ing")
list.Consumer(func(task *Target) bool {
fmt.Println(task.Id)
if task.Id == "2" {
return false
}
return true
})
fmt.Println("consumer after")
list.Foreach(func(task *Target) {
fmt.Println(task.Id)
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/burybell/cluster-timewheel.git
git@gitee.com:burybell/cluster-timewheel.git
burybell
cluster-timewheel
cluster-timewheel
master

搜索帮助