-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprophet_coordinator_test.go
72 lines (58 loc) · 1.82 KB
/
prophet_coordinator_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
package prophet
import (
"testing"
)
type testScheduler struct{}
func (s *testScheduler) Name() string { return "test-scheduler" }
func (s *testScheduler) ResourceKind() ResourceKind { return LeaderKind }
func (s *testScheduler) ResourceLimit() uint64 { return 0 }
func (s *testScheduler) Prepare(rt *Runtime) error { return nil }
func (s *testScheduler) Cleanup(rt *Runtime) {}
func (s *testScheduler) Schedule(rt *Runtime) Operator { return nil }
type testOperator struct {
id uint64
kind ResourceKind
}
func newTestOperator(id uint64, kind ResourceKind) Operator {
return &testOperator{
id: id,
kind: kind,
}
}
func (op *testOperator) ResourceID() uint64 { return op.id }
func (op *testOperator) ResourceKind() ResourceKind { return op.kind }
func (op *testOperator) Do(target *ResourceRuntime) (*resourceHeartbeatRsp, bool) { return nil, false }
func TestAddScheduler(t *testing.T) {
cfg := &Cfg{}
cfg.adujst()
runner := NewRunner()
sch := &testScheduler{}
c := newCoordinator(cfg, runner, newRuntime(nil))
c.addScheduler(sch)
if _, ok := c.schedulers[sch.Name()]; !ok {
t.Error("add scheduler failed")
}
}
func TestAddAndGetOperator(t *testing.T) {
cfg := &Cfg{}
cfg.adujst()
runner := NewRunner()
c := newCoordinator(cfg, runner, newRuntime(nil))
if !c.addOperator(newTestOperator(1, LeaderKind)) {
t.Errorf("add operator failed")
}
if nil == c.getOperator(1) {
t.Errorf("get operator failed")
}
}
func TestRemoveOperator(t *testing.T) {
cfg := &Cfg{}
cfg.adujst()
runner := NewRunner()
c := newCoordinator(cfg, runner, newRuntime(nil))
c.addOperator(newTestOperator(1, LeaderKind))
c.removeOperator(c.getOperator(1))
if nil != c.getOperator(1) {
t.Errorf("remove operator failed")
}
}