-
Notifications
You must be signed in to change notification settings - Fork 199
/
throttlerStub.go
65 lines (52 loc) · 1.17 KB
/
throttlerStub.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
package mock
import "sync"
// ThrottlerStub -
type ThrottlerStub struct {
CanProcessCalled func() bool
StartProcessingCalled func()
EndProcessingCalled func()
mutState sync.RWMutex
startWasCalled bool
endWasCalled bool
}
// CanProcess -
func (ts *ThrottlerStub) CanProcess() bool {
if ts.CanProcessCalled != nil {
return ts.CanProcessCalled()
}
return true
}
// StartProcessing -
func (ts *ThrottlerStub) StartProcessing() {
ts.mutState.Lock()
ts.startWasCalled = true
ts.mutState.Unlock()
if ts.StartProcessingCalled != nil {
ts.StartProcessingCalled()
}
}
// EndProcessing -
func (ts *ThrottlerStub) EndProcessing() {
ts.mutState.Lock()
ts.endWasCalled = true
ts.mutState.Unlock()
if ts.EndProcessingCalled != nil {
ts.EndProcessingCalled()
}
}
// StartWasCalled -
func (ts *ThrottlerStub) StartWasCalled() bool {
ts.mutState.RLock()
defer ts.mutState.RUnlock()
return ts.startWasCalled
}
// EndWasCalled -
func (ts *ThrottlerStub) EndWasCalled() bool {
ts.mutState.RLock()
defer ts.mutState.RUnlock()
return ts.endWasCalled
}
// IsInterfaceNil -
func (ts *ThrottlerStub) IsInterfaceNil() bool {
return ts == nil
}