forked from cloudfoundry-attic/app-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_app_manager_bbs.go
130 lines (104 loc) · 3.71 KB
/
fake_app_manager_bbs.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
122
123
124
125
126
127
128
129
130
package fake_bbs
import (
"sync"
"github.com/cloudfoundry-incubator/runtime-schema/models"
)
type FakeAppManagerBBS struct {
FileServerGetter
DesiredLRPChangeChan chan models.DesiredLRPChange
DesiredLRPStopChan chan bool
DesiredLRPErrChan chan error
stopLRPInstances []models.StopLRPInstance
StopLRPInstanceErr error
desiredLRPs []models.DesiredLRP
DesireLRPErr error
removeDesiredLRPProcessGuids []string
removeDesiredLRPProcessGuidsErr error
ActualLRPs []models.ActualLRP
ActualLRPsErr error
lrpStartAuctions []models.LRPStartAuction
LRPStartAuctionErr error
WhenRequestingLRPStartAuctions func(lrp models.LRPStartAuction) error
lrpStopAuctions []models.LRPStopAuction
LRPStopAuctionErr error
WhenRequestingLRPStopAuctions func(lrp models.LRPStopAuction) error
sync.RWMutex
}
func NewFakeAppManagerBBS() *FakeAppManagerBBS {
return &FakeAppManagerBBS{
DesiredLRPChangeChan: make(chan models.DesiredLRPChange, 1),
DesiredLRPStopChan: make(chan bool),
DesiredLRPErrChan: make(chan error),
WhenRequestingLRPStartAuctions: nil,
WhenRequestingLRPStopAuctions: nil,
}
}
func (fakeBBS *FakeAppManagerBBS) DesireLRP(lrp models.DesiredLRP) error {
fakeBBS.Lock()
defer fakeBBS.Unlock()
fakeBBS.desiredLRPs = append(fakeBBS.desiredLRPs, lrp)
return fakeBBS.DesireLRPErr
}
func (fakeBBS *FakeAppManagerBBS) DesiredLRPs() []models.DesiredLRP {
fakeBBS.RLock()
defer fakeBBS.RUnlock()
return fakeBBS.desiredLRPs
}
func (fakeBBS *FakeAppManagerBBS) WatchForDesiredLRPChanges() (<-chan models.DesiredLRPChange, chan<- bool, <-chan error) {
return fakeBBS.DesiredLRPChangeChan, fakeBBS.DesiredLRPStopChan, fakeBBS.DesiredLRPErrChan
}
func (fakeBBS *FakeAppManagerBBS) RequestLRPStartAuction(lrp models.LRPStartAuction) error {
fakeBBS.Lock()
defer fakeBBS.Unlock()
if fakeBBS.WhenRequestingLRPStartAuctions != nil {
return fakeBBS.WhenRequestingLRPStartAuctions(lrp)
}
fakeBBS.lrpStartAuctions = append(fakeBBS.lrpStartAuctions, lrp)
return fakeBBS.LRPStartAuctionErr
}
func (fakeBBS *FakeAppManagerBBS) GetLRPStartAuctions() []models.LRPStartAuction {
fakeBBS.RLock()
defer fakeBBS.RUnlock()
return fakeBBS.lrpStartAuctions
}
func (fakeBBS *FakeAppManagerBBS) RequestLRPStopAuction(lrp models.LRPStopAuction) error {
fakeBBS.Lock()
defer fakeBBS.Unlock()
if fakeBBS.WhenRequestingLRPStopAuctions != nil {
return fakeBBS.WhenRequestingLRPStopAuctions(lrp)
}
fakeBBS.lrpStopAuctions = append(fakeBBS.lrpStopAuctions, lrp)
return fakeBBS.LRPStopAuctionErr
}
func (fakeBBS *FakeAppManagerBBS) GetLRPStopAuctions() []models.LRPStopAuction {
fakeBBS.RLock()
defer fakeBBS.RUnlock()
return fakeBBS.lrpStopAuctions
}
func (fakeBBS *FakeAppManagerBBS) RequestStopLRPInstance(lrp models.StopLRPInstance) error {
fakeBBS.Lock()
defer fakeBBS.Unlock()
fakeBBS.stopLRPInstances = append(fakeBBS.stopLRPInstances, lrp)
return fakeBBS.StopLRPInstanceErr
}
func (fakeBBS *FakeAppManagerBBS) GetStopLRPInstances() []models.StopLRPInstance {
fakeBBS.RLock()
defer fakeBBS.RUnlock()
return fakeBBS.stopLRPInstances
}
func (fakeBBS *FakeAppManagerBBS) GetActualLRPsByProcessGuid(string) ([]models.ActualLRP, error) {
fakeBBS.RLock()
defer fakeBBS.RUnlock()
return fakeBBS.ActualLRPs, fakeBBS.ActualLRPsErr
}
func (fakeBBS *FakeAppManagerBBS) RemoveDesiredLRPByProcessGuid(processGuid string) error {
fakeBBS.Lock()
defer fakeBBS.Unlock()
fakeBBS.removeDesiredLRPProcessGuids = append(fakeBBS.removeDesiredLRPProcessGuids, processGuid)
return fakeBBS.removeDesiredLRPProcessGuidsErr
}
func (fakeBBS *FakeAppManagerBBS) GetRemovedDesiredLRPProcessGuids() []string {
fakeBBS.RLock()
defer fakeBBS.RUnlock()
return fakeBBS.removeDesiredLRPProcessGuids
}