Ejemplo n.º 1
0
func TestStatusUpdateMessageHandling(t *testing.T) {
	sched := NewMesosScheduler()
	sched.StatusUpdate = func(schedDriver *SchedulerDriver, taskStatus *mesos.TaskStatus) {
		if taskStatus.GetState() != mesos.TaskState(mesos.TaskState_TASK_RUNNING) {
			log.Fatal("Scheduler.StatusUpdate expected State value not received.")
		}

		if string(taskStatus.GetData()) != "World!" {
			log.Fatal("Scheduler.StatusUpdate expected Status.Data not received.")
		}
	}

	msg := &mesos.StatusUpdateMessage{
		Update: &mesos.StatusUpdate{
			FrameworkId: &mesos.FrameworkID{Value: proto.String("test-framework-1")},
			Status: &mesos.TaskStatus{
				TaskId:  &mesos.TaskID{Value: proto.String("test-task-1")},
				State:   mesos.TaskState(mesos.TaskState_TASK_RUNNING).Enum(),
				Message: proto.String("Hello"),
				Data:    []byte("World!"),
			},
			Timestamp: proto.Float64(1234567.2),
			Uuid:      []byte("abcd-efg1-2345-6789-abcd-efg1"),
		},
	}

	driver, err := NewSchedDriver(sched, &mesos.FrameworkInfo{}, "localhost:0")
	if err != nil {
		t.Fatal(err)
	}
	driver.schedMsgQ <- msg
}
Ejemplo n.º 2
0
func TestStatusUpdateMessage(t *testing.T) {
	eventQ := make(chan interface{})
	go func() {
		for msg := range eventQ {
			val, ok := msg.(*mesos.StatusUpdateMessage)
			if !ok {
				t.Fatal("Failed to receive msg of type StatusUpdateMessage")
			}

			if val.Update.FrameworkId.GetValue() != "test-framework-1" {
				t.Fatal("Expected StatusUpdateMessage.FramewId not received.")
			}

			if val.Update.Status.GetState() != mesos.TaskState(mesos.TaskState_TASK_RUNNING) {
				t.Fatal("Expected StatusUpdateMessage.Update.Status.State not received.")
			}

			if string(val.Update.Status.GetData()) != "World!" {
				t.Fatal("Expected StatusUpdateMessage.Update.Message not received.")
			}

		}
	}()

	proc, err := newSchedulerProcess(eventQ)
	if err != nil {
		t.Fatal(err)
	}
	proc.started = true
	proc.aborted = false

	msg := &mesos.StatusUpdateMessage{
		Update: &mesos.StatusUpdate{
			FrameworkId: &mesos.FrameworkID{Value: proto.String("test-framework-1")},
			Status: &mesos.TaskStatus{
				TaskId:  &mesos.TaskID{Value: proto.String("test-task-1")},
				State:   mesos.TaskState(mesos.TaskState_TASK_RUNNING).Enum(),
				Message: proto.String("Hello"),
				Data:    []byte("World!"),
			},
			Timestamp: proto.Float64(1234567.2),
			Uuid:      []byte("abcd-efg1-2345-6789-abcd-efg1"),
		},
	}
	data, err := proto.Marshal(msg)
	if err != nil {
		t.Fatalf("Unable to marshal StatusUpdateMessage, %v", err)
	}

	req := buildHttpRequest(t, "StatusUpdateMessage", data)
	resp := httptest.NewRecorder()

	proc.ServeHTTP(resp, req)

	if resp.Code != http.StatusAccepted {
		t.Fatalf("Expecting server status %d but got status %d", http.StatusAccepted, resp.Code)
	}
}
Ejemplo n.º 3
0
func TestNewTaskStatus(t *testing.T) {
	status := NewTaskStatus(NewTaskID("task-1"), mesos.TaskState_TASK_RUNNING)
	if status == nil {
		t.Fatal("Not creating protobuf object TaskStatus")
	}
	if status.GetTaskId().GetValue() != "task-1" {
		t.Fatal("Protobuf object TaskStatus.TaskId missing.")
	}
	if status.GetState() != mesos.TaskState(mesos.TaskState_TASK_RUNNING) {
		t.Fatal("Protobuf object TaskStatus.State missing.")
	}
}
Ejemplo n.º 4
0
func NewTaskStatus(taskId *mesos.TaskID, state mesos.TaskState) *mesos.TaskStatus {
	return &mesos.TaskStatus{
		TaskId: taskId,
		State:  mesos.TaskState(state).Enum(),
	}
}