forked from linkedin/Iris-message-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregationManager_test.go
104 lines (82 loc) · 2.65 KB
/
aggregationManager_test.go
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
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"sync"
"testing"
"time"
uuid "github.com/satori/go.uuid"
)
func TesttriggerAggregationMessages(t *testing.T) {
logger := NewLogger("tests", "", false)
defer logger.RedirectStdLogger()()
defer logger.Close()
quit := make(chan int)
var mainWg sync.WaitGroup
var appConfig Config
aggregationManager := NewAggregationManager(irisClient, &appConfig, logger.Clone("aggregationManager"), quit, &mainWg, nil)
planAggregationRespItem := PlanAggregationResp{
PlanID: 123,
PlanName: "plan1",
ThresholdWindow: 1,
ThresholdCount: 2,
AggregationWindow: 1,
AggregationReset: 1,
}
planAggSettingResp := []PlanAggregationResp{
planAggregationRespItem,
}
aggregationManager.updateSettings(planAggSettingResp)
var got, want int
got = len(aggregationManager.planAggregationMap)
want = 1
if got != want {
t.Fatalf("len(authMap) = %d; want %d", got, want)
}
aggregationManager.countIncident("plan1")
batchID, triggerBool := aggregationManager.checkAggregation("plan1")
var defaultUUID uuid.UUID
if triggerBool != false {
t.Fatalf("triggerBool = %+v; want %+v", triggerBool, false)
}
if batchID != defaultUUID {
t.Fatalf("batchID = %+v; want %+v", batchID, uuid.UUID{})
}
aggregationManager.countIncident("plan1")
batchID, triggerBool = aggregationManager.checkAggregation("plan1")
if triggerBool != false {
t.Fatalf("triggerBool = %+v; want %+v", triggerBool, false)
}
if batchID != defaultUUID {
t.Fatalf("batchID = %+v; want %+v", batchID, uuid.UUID{})
}
aggregationManager.countIncident("plan1")
batchID, triggerBool = aggregationManager.checkAggregation("plan1")
// aggregation is triggered
if triggerBool != true {
t.Fatalf("triggerBool = %+v; want %+v", triggerBool, false)
}
if batchID == defaultUUID {
t.Fatalf("batchID = %+v; want %+v", batchID, uuid.UUID{})
}
// aggregation is still in effect but not freshly triggered
aggregationManager.countIncident("plan1")
batchID, triggerBool = aggregationManager.checkAggregation("plan1")
if triggerBool != false {
t.Fatalf("triggerBool = %+v; want %+v", triggerBool, false)
}
if batchID == defaultUUID {
t.Fatalf("batchID = %+v; want %+v", batchID, uuid.UUID{})
}
// wait so that aggregationwindow expires
time.Sleep(1 * time.Second)
// reset aggregation
aggregationManager.resetAggregation()
aggregationManager.countIncident("plan1")
batchID, triggerBool = aggregationManager.checkAggregation("plan1")
// plan is no longer under aggregation
if triggerBool != false {
t.Fatalf("triggerBool = %+v; want %+v", triggerBool, false)
}
if batchID != defaultUUID {
t.Fatalf("batchID = %+v; want %+v", batchID, uuid.UUID{})
}
}