示例#1
0
func TestJobSinkStoresOneEvent(t *testing.T) {
	jobSeqs := []testutil.JobsCPUUsage{
		[]testutil.InstanceCPUUsage{
			[]float64{.20},
		},
	}

	iStates, err := testutil.GenerateJobCPUEvents(jobSeqs)
	if err != nil {
		t.Fatal(err)
	}

	js := NewDefaultJobSink()

	js.SetJobState(iStates[0])
	jobState := js.GetJobState("job-fqn-0")

	instance, ok := jobState.InstanceStates[iStates[0].InstanceUUID]
	if !ok {
		t.Fatalf("Expected jobState to contain InstanceUUID: %q", iStates[0].InstanceUUID)
	}

	if len(instance) != 1 {
		t.Fatalf("Expected slice of length 1")
	}

	if !reflect.DeepEqual(iStates[0], instance[0]) {
		t.Fatalf("Input state %+v != output state %+v", iStates[0], instance[0])
	}
}
示例#2
0
func TestJobSinkStoresTwoEvents(t *testing.T) {
	jobSeqs := []testutil.JobsCPUUsage{
		[]testutil.InstanceCPUUsage{
			[]float64{.20, .30}},
	}

	iStates, err := testutil.GenerateJobCPUEvents(jobSeqs)
	if err != nil {
		t.Fatal(err)
	}

	js := NewDefaultJobSink()

	for _, iState := range iStates {
		js.SetJobState(iState)
	}

	jobState := js.GetJobState("job-fqn-0")

	instance, ok := jobState.InstanceStates["instance-uuid-0"]
	if !ok {
		t.Fatalf("Expected instance %q to be present in JobState", "instance-uuid-0")
	}

	expectedCPU := []float64{20, 30}

	for i, iState := range instance {
		if expectedCPU[i] != iState.CPU {
			t.Fatalf("Expected CPU to be %f, got %f", expectedCPU[i], iState.CPU)
		}
	}

}