forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_job_supervisor.go
120 lines (94 loc) · 2.33 KB
/
fake_job_supervisor.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
package fakes
import (
boshalert "github.com/cloudfoundry/bosh-agent/agent/alert"
boshjobsuper "github.com/cloudfoundry/bosh-agent/jobsupervisor"
"sync"
)
type FakeJobSupervisor struct {
Reloaded bool
ReloadErr error
AddJobArgs []AddJobArgs
RemovedAllJobs bool
RemovedAllJobsErr error
Started bool
StartErr error
Stopped bool
StopErr error
StoppedAndWaited bool
Unmonitored bool
UnmonitorErr error
StatusStatus string
ProcessesStatus []boshjobsuper.Process
ProcessesError error
JobFailureAlert *boshalert.MonitAlert
HealthRecorded int
HealthRecordedMutex sync.Mutex
}
type AddJobArgs struct {
Name string
Index int
ConfigPath string
}
func NewFakeJobSupervisor() *FakeJobSupervisor {
return &FakeJobSupervisor{}
}
func NewFakeJobSupervisorWithArgs() *FakeJobSupervisor {
return &FakeJobSupervisor{}
}
func (m *FakeJobSupervisor) Reload() error {
m.Reloaded = true
return m.ReloadErr
}
func (m *FakeJobSupervisor) AddJob(jobName string, jobIndex int, configPath string) error {
args := AddJobArgs{
Name: jobName,
Index: jobIndex,
ConfigPath: configPath,
}
m.AddJobArgs = append(m.AddJobArgs, args)
return nil
}
func (m *FakeJobSupervisor) RemoveAllJobs() error {
m.RemovedAllJobs = true
return m.RemovedAllJobsErr
}
func (m *FakeJobSupervisor) Start() error {
m.Started = true
return m.StartErr
}
func (m *FakeJobSupervisor) Stop() error {
m.Stopped = true
return m.StopErr
}
func (m *FakeJobSupervisor) StopAndWait() error {
m.Stopped = true
m.StoppedAndWaited = true
return m.StopErr
}
func (m *FakeJobSupervisor) Unmonitor() error {
m.Unmonitored = true
return m.UnmonitorErr
}
func (m *FakeJobSupervisor) Status() string {
return m.StatusStatus
}
func (m *FakeJobSupervisor) Processes() ([]boshjobsuper.Process, error) {
return m.ProcessesStatus, m.ProcessesError
}
func (m *FakeJobSupervisor) MonitorJobFailures(handler boshjobsuper.JobFailureHandler) error {
if m.JobFailureAlert != nil {
return handler(*m.JobFailureAlert)
}
return nil
}
func (m *FakeJobSupervisor) HealthRecorder(status string) {
m.HealthRecordedMutex.Lock()
m.HealthRecorded += 1
m.HealthRecordedMutex.Unlock()
}
func (m *FakeJobSupervisor) GetHealthRecorded() int {
m.HealthRecordedMutex.Lock()
value := m.HealthRecorded
m.HealthRecordedMutex.Unlock()
return value
}