2015-08-13 17:05:54 +00:00
|
|
|
package scheduler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/mock"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLimitIterator(t *testing.T) {
|
2015-08-13 18:33:58 +00:00
|
|
|
_, ctx := testContext(t)
|
2015-08-13 17:05:54 +00:00
|
|
|
nodes := []*RankedNode{
|
|
|
|
&RankedNode{
|
|
|
|
Node: mock.Node(),
|
|
|
|
Score: 1,
|
|
|
|
},
|
|
|
|
&RankedNode{
|
|
|
|
Node: mock.Node(),
|
|
|
|
Score: 2,
|
|
|
|
},
|
|
|
|
&RankedNode{
|
|
|
|
Node: mock.Node(),
|
|
|
|
Score: 3,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
static := NewStaticRankIterator(ctx, nodes)
|
|
|
|
|
|
|
|
limit := NewLimitIterator(ctx, static, 2)
|
|
|
|
|
2015-08-13 19:02:42 +00:00
|
|
|
out := collectRanked(limit)
|
2015-08-13 17:05:54 +00:00
|
|
|
if len(out) != 2 {
|
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
|
|
|
if out[0] != nodes[0] && out[1] != nodes[1] {
|
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMaxScoreIterator(t *testing.T) {
|
2015-08-13 18:33:58 +00:00
|
|
|
_, ctx := testContext(t)
|
2015-08-13 17:05:54 +00:00
|
|
|
nodes := []*RankedNode{
|
|
|
|
&RankedNode{
|
|
|
|
Node: mock.Node(),
|
|
|
|
Score: 1,
|
|
|
|
},
|
|
|
|
&RankedNode{
|
|
|
|
Node: mock.Node(),
|
|
|
|
Score: 2,
|
|
|
|
},
|
|
|
|
&RankedNode{
|
|
|
|
Node: mock.Node(),
|
|
|
|
Score: 3,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
static := NewStaticRankIterator(ctx, nodes)
|
|
|
|
|
|
|
|
max := NewMaxScoreIterator(ctx, static)
|
|
|
|
|
2015-08-13 19:02:42 +00:00
|
|
|
out := collectRanked(max)
|
2015-08-13 17:05:54 +00:00
|
|
|
if len(out) != 1 {
|
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
|
|
|
if out[0] != nodes[2] {
|
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
|
|
|
}
|