scheduler: allow StaticIterator to update base set

This commit is contained in:
Armon Dadgar
2015-09-07 11:26:16 -07:00
parent 49488ecdba
commit 831848bf5e
2 changed files with 23 additions and 0 deletions

View File

@@ -62,6 +62,12 @@ func (iter *StaticIterator) Reset() {
iter.seen = 0
}
func (iter *StaticIterator) SetNodes(nodes []*structs.Node) {
iter.nodes = nodes
iter.offset = 0
iter.seen = 0
}
// NewRandomIterator constructs a static iterator from a list of nodes
// after applying the Fisher-Yates algorithm for a random shuffle. This
// is applied in-place

View File

@@ -39,6 +39,23 @@ func TestStaticIterator_Reset(t *testing.T) {
}
}
func TestStaticIterator_SetNodes(t *testing.T) {
_, ctx := testContext(t)
var nodes []*structs.Node
for i := 0; i < 3; i++ {
nodes = append(nodes, mock.Node())
}
static := NewStaticIterator(ctx, nodes)
newNodes := []*structs.Node{mock.Node()}
static.SetNodes(newNodes)
out := collectFeasible(static)
if !reflect.DeepEqual(out, newNodes) {
t.Fatalf("bad: %#v", out)
}
}
func TestRandomIterator(t *testing.T) {
_, ctx := testContext(t)
var nodes []*structs.Node