forked from DataDog/kafka-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimits_test.go
More file actions
92 lines (74 loc) · 1.73 KB
/
Copy pathlimits_test.go
File metadata and controls
92 lines (74 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"testing"
"github.com/DataDog/kafka-kit/v4/kafkametrics"
)
func TestNewLimits(t *testing.T) {
c := NewLimitsConfig{}
c.Minimum = -1 // Invalid.
_, err := NewLimits(c)
if err == nil {
t.Error("Expected non-nil error")
}
c.Minimum = 10
c.SourceMaximum = 120 // Invalid.
_, err = NewLimits(c)
if err == nil {
t.Error("Expected non-nil error")
}
c.SourceMaximum = 80
c.DestinationMaximum = 80
_, err = NewLimits(c)
if err != nil {
t.Errorf("Unexpected error: %s\n", err.Error())
}
c.DestinationMaximum = 120 // Invalid.
_, err = NewLimits(c)
if err == nil {
t.Error("Expected non-nil error")
}
}
func TestReplicationHeadroom(t *testing.T) {
c := NewLimitsConfig{
Minimum: 10,
SourceMaximum: 80,
DestinationMaximum: 60,
CapacityMap: map[string]float64{
"stub": 100,
},
}
l, _ := NewLimits(c)
b := &kafkametrics.Broker{
InstanceType: "stub",
}
// Test leader values.
// [current utilization, current throttle, expected headroom]
expected := [][3]float64{
{70, 0, 24},
{80, 70, 72},
{110, 70, 40},
{200, 70, 10},
}
for n, params := range expected {
b.NetTX = params[0]
h, _ := l.replicationHeadroom(b, "leader", params[1])
if h != params[2] {
t.Errorf("[test index %d] Expected headroom value of %f, got %f\n", n, params[2], h)
}
}
// Test follower values.
// [current utilization, current throttle, expected headroom]
expected = [][3]float64{
{70, 0, 18},
{80, 70, 54},
{110, 70, 30},
{200, 70, 10},
}
for n, params := range expected {
b.NetRX = params[0]
h, _ := l.replicationHeadroom(b, "follower", params[1])
if h != params[2] {
t.Errorf("[test index %d] Expected headroom value of %f, got %f\n", n, params[2], h)
}
}
}