Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: HunDunDM <[email protected]>
  • Loading branch information
HunDunDM committed Sep 14, 2022
1 parent 1499df2 commit ff558a0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/statistics/hot_peer_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (

"github.com/docker/go-units"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/stretchr/testify/require"
"github.com/tikv/pd/pkg/movingaverage"
"github.com/tikv/pd/pkg/typeutil"
"github.com/tikv/pd/server/core"
)

Expand Down Expand Up @@ -633,6 +635,37 @@ func TestUnstableData(t *testing.T) {
}
}

func TestHotPeerCacheTopN(t *testing.T) {
re := require.New(t)

cache := NewHotPeerCache(Write)
now := time.Now()
for id := uint64(99); id > 0; id-- {
meta := &metapb.Region{
Id: id,
Peers: []*metapb.Peer{{Id: id, StoreId: 1}},
}
region := core.NewRegionInfo(meta, meta.Peers[0], core.SetWrittenBytes(id*6000), core.SetWrittenKeys(id*6000), core.SetWrittenQuery(id*6000))
for i := 0; i < 10; i++ {
start := uint64(now.Add(time.Minute * time.Duration(i)).Unix())
end := uint64(now.Add(time.Minute * time.Duration(i+1)).Unix())
newRegion := region.Clone(core.WithInterval(&pdpb.TimeInterval{
StartTimestamp: start,
EndTimestamp: end,
}))
newPeer := core.NewPeerInfo(meta.Peers[0], region.GetLoads(), end-start)
stat := cache.checkPeerFlow(newPeer, newRegion)
if stat != nil {
cache.updateStat(stat)
}
}
}

re.Contains(cache.peersOfStore, uint64(1))
println(cache.peersOfStore[1].GetTopNMin(ByteDim).(*HotPeerStat).GetLoad(ByteDim))
re.True(typeutil.Float64Equal(4000, cache.peersOfStore[1].GetTopNMin(ByteDim).(*HotPeerStat).GetLoad(ByteDim)))
}

func BenchmarkCheckRegionFlow(b *testing.B) {
cache := NewHotPeerCache(Read)
region := buildRegion(Read, 3, 10)
Expand Down

0 comments on commit ff558a0

Please sign in to comment.