Atlas › Test
TestHybridCounter_StartsWithMap
Exact test identity: go.temporal.io/server/service/matching/counter/TestHybridCounter_StartsWithMap
- Package
go.temporal.io/server/service/matching/counter
- Suite / test hierarchy
TestHybridCounter_StartsWithMap
- Test
TestHybridCounter_StartsWithMap
- Introduced at
- TestHybridCounter_StartsWithMap Frontier kind: Test frontier
- Covered ranges
- 12
- Covered lines
- 35
- Covered files
- 2
Covered source
Expand a file to inspect source; the > gutter marks covered lines.
go.temporal.io/server/service/matching/counter/map.go 23 covered LOC · 8 ranges
Open complete file
18
19
// NewMapCounter creates a mapCounter that also tracks the top K entries.
20
>
func NewMapCounter(limit int) *mapCounter {
map.go
21
>
return &mapCounter{
22
>
m: make(map[string]int),
23
>
limit: limit,
24
>
}
25
>
}
26
27
func (m *mapCounter) GetPass(key string, base, inc int64) int64 {
30
}
31
32
>
func (m *mapCounter) getPassWithOverflow(key string, base, inc int64) (int64, bool) {
map.go
33
>
if idx, ok := m.m[key]; ok {
34
prev := m.heap[idx].Count
35
count := max(base, prev+inc)
40
}
41
// not present, fall back to full updateHeap
42
>
count := max(base, inc)
map.go
43
>
return count, m.updateHeap(key, count)
44
}
45
53
}
54
55
>
func (m *mapCounter) updateHeap(key string, count int64) bool {
map.go
56
>
if idx, ok := m.m[key]; ok {
57
// already in heap - update count and fix
58
m.heap[idx].Count = count
61
}
62
63
>
if len(m.heap) < m.limit {
map.go
64
>
// heap not full - add
65
>
m.m[key] = len(m.heap)
66
>
heap.Push(m, TopKEntry{Key: key, Count: count})
67
>
return false
68
>
}
69
70
// heap is full - only add if count > min
81
82
// implements heap.Interface using m.heap
83
>
func (m *mapCounter) Len() int { return len(m.heap) }
map.go
84
>
func (m *mapCounter) Less(i, j int) bool { return m.heap[i].Count < m.heap[j].Count }
map.go
85
func (m *mapCounter) Swap(i, j int) {
86
m.heap[i], m.heap[j] = m.heap[j], m.heap[i]
90
}
91
92
>
func (m *mapCounter) Push(x any) {
map.go
93
>
m.heap = append(m.heap, x.(TopKEntry))
94
>
}
95
96
func (m *mapCounter) Pop() any {
go.temporal.io/server/service/matching/counter/hybrid.go 12 covered LOC · 4 ranges
Open complete file
42
}
43
44
>
func NewHybridCounter(params CounterParams, src rand.Source) *hybridCounter {
hybrid.go
45
>
return &hybridCounter{
46
>
mapCounter: *NewMapCounter(params.MapLimit),
47
>
params: params,
48
>
src: src,
49
>
}
50
>
}
51
52
>
func (h *hybridCounter) GetPass(key string, base int64, inc int64) int64 {
hybrid.go
53
>
if h.cmSketch != nil {
54
p := h.cmSketch.GetPass(key, base, inc)
55
// after migration, continue updating top-K tracker
58
}
59
60
>
p, overflow := h.mapCounter.getPassWithOverflow(key, base, inc)
hybrid.go
61
>
if overflow {
62
h.migrateToCMS()
63
}
65
}
66