-
Notifications
You must be signed in to change notification settings - Fork 7
/
supervisor_internal_test.go
121 lines (81 loc) · 1.88 KB
/
supervisor_internal_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package streams
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type ctxKey int
func TestSupervisor_WithContext(t *testing.T) {
ctx := context.WithValue(context.Background(), ctxKey(1), "test")
supervisor := &supervisor{}
supervisor.WithContext(ctx)
assert.Equal(t, ctx, supervisor.ctx)
}
func TestSupervisor_WithMonitor(t *testing.T) {
mon := &fakeMonitor{}
supervisor := &supervisor{}
supervisor.WithMonitor(mon)
assert.Equal(t, mon, supervisor.mon)
}
func TestSupervisor_WithPumps(t *testing.T) {
supervisor := &supervisor{}
pump := &fakePump{}
processor := &fakeProcessor{}
node := newFakeNode(processor)
input := map[Node]Pump{
node: pump,
}
expected := map[Processor]Pump{
processor: pump,
}
supervisor.WithPumps(input)
assert.Equal(t, expected, supervisor.pumps)
}
func TestSupervisor_Commit_CommitPending(t *testing.T) {
supervisor := &supervisor{}
supervisor.commitMu.Lock()
err := supervisor.Commit(nil)
assert.NoError(t, err)
}
type fakeMonitor struct{}
func (*fakeMonitor) Processed(name string, l time.Duration, bp float64) {}
func (*fakeMonitor) Committed(l time.Duration) {}
func (*fakeMonitor) Close() error {
return nil
}
type fakePump struct{}
func (*fakePump) Lock() {}
func (*fakePump) Unlock() {}
func (*fakePump) Accept(Message) error {
return nil
}
func (*fakePump) Stop() {
}
func (*fakePump) Close() error {
return nil
}
type fakeProcessor struct{}
func (*fakeProcessor) WithPipe(Pipe) {}
func (*fakeProcessor) Process(Message) error {
return nil
}
func (*fakeProcessor) Close() error {
return nil
}
type fakeNode struct {
p Processor
}
func newFakeNode(p Processor) *fakeNode {
return &fakeNode{p: p}
}
func (*fakeNode) Name() string {
return ""
}
func (*fakeNode) AddChild(n Node) {}
func (*fakeNode) Children() []Node {
return nil
}
func (n *fakeNode) Processor() Processor {
return n.p
}