コード例 #1
0
func TestHandleDemandChange(t *testing.T) {
	tasks = make(map[string]demand.Task)
	tasks["priority1"] = demand.Task{
		FamilyName: "p1family",
		Demand:     4,
		Requested:  0,
	}

	tasks["priority2"] = demand.Task{
		FamilyName: "p2family",
		Demand:     3,
		Requested:  0,
	}

	// We might see our own task when we look at Docker, we shouldn't be scaling it!
	tasks["force12"] = demand.Task{
		FamilyName: "force12",
		Demand:     1,
		Requested:  1,
	}

	di := rng.NewDemandModel(3, 9)
	s := toy_scheduler.NewScheduler()

	ready := make(chan struct{}, 1)

	for i := 0; i < 5; i++ {
		err := handleDemandChange(di, s, ready, tasks)
		<-ready
		if err != nil {
			t.Fatalf("handleDemandChange failed")
		}
		log.Println(tasks)
	}
}
コード例 #2
0
ファイル: settings.go プロジェクト: philpearl/force12
func get_demand_input(st settings) (demand.Input, error) {
	var di demand.Input

	switch st.demandModelType {
	case "CONSUL":
		return nil, fmt.Errorf("Demand metric from Consul not yet supported")
	case "RNG":
		log.Println("Random demand generation")
		di = rng.NewDemandModel(st.demandDelta, st.maxContainers)
	default:
		return nil, fmt.Errorf("Bad value for F12_DEMAND_MODEL: %s", st.demandModelType)
	}

	return di, nil
}
コード例 #3
0
func TestDemandUpdate(t *testing.T) {
	var demandchange bool

	tasks = make(map[string]demand.Task)
	tasks["priority1"] = demand.Task{
		FamilyName: "p1family",
		Demand:     3,
		Requested:  0,
	}

	tasks["priority2"] = demand.Task{
		FamilyName: "p2family",
		Demand:     5,
		Requested:  0,
	}

	di := rng.NewDemandModel(4, 10)

	demandchange, _ = update(di, tasks)
	if !demandchange {
		// Note this test relies on us not seeding random numbers. Not very nice but OK for our purposes.
		t.Fatalf("Expected demand to have changed but it didn't")
	}
}