open-nomad/nomad/drainer/drain_testing.go

46 lines
915 B
Go
Raw Normal View History

2018-03-08 23:08:23 +00:00
package drainer
2018-03-03 01:15:38 +00:00
import (
"sync"
"github.com/hashicorp/nomad/nomad/structs"
)
type MockNodeTrackerEvent struct {
NodeUpdate *structs.Node
NodeRemove string
}
type MockNodeTracker struct {
Nodes map[string]*structs.Node
Events []*MockNodeTrackerEvent
sync.Mutex
}
func NewMockNodeTracker() *MockNodeTracker {
return &MockNodeTracker{
Nodes: make(map[string]*structs.Node),
Events: make([]*MockNodeTrackerEvent, 0, 16),
}
}
2018-03-06 18:12:17 +00:00
func (m *MockNodeTracker) TrackedNodes() map[string]*structs.Node {
2018-03-03 01:15:38 +00:00
m.Lock()
defer m.Unlock()
2018-03-06 18:12:17 +00:00
return m.Nodes
2018-03-03 01:15:38 +00:00
}
func (m *MockNodeTracker) Remove(nodeID string) {
m.Lock()
defer m.Unlock()
delete(m.Nodes, nodeID)
m.Events = append(m.Events, &MockNodeTrackerEvent{NodeRemove: nodeID})
}
func (m *MockNodeTracker) Update(node *structs.Node) {
m.Lock()
defer m.Unlock()
m.Nodes[node.ID] = node
m.Events = append(m.Events, &MockNodeTrackerEvent{NodeUpdate: node})
}