示例#1
0
func TestTaskManagerProviderPriority(t *testing.T) {
	tm := kamaji.NewTaskManager()
	job0 := kamaji.NewJob("JOB0")
	job0.SetPrio(0)
	job1 := kamaji.NewJob("JOB0")
	job1.SetPrio(1)
	task0 := kamaji.NewTask("TASK0", job0, []string{})
	_ = kamaji.NewCommand("0", task0)
	tm.AddJob(job0)
	task1 := kamaji.NewTask("TASK1", job1, []string{})
	_ = kamaji.NewCommand("1", task1)
	tm.AddJob(job1)
	tm.Start()
	defer tm.Stop()
	expected := []string{"1", "0"}
	var got []string
	for _ = range tm.Jobs {
		command := <-tm.NextCommand
		got = append(got, command.Name)
	}
	if !testEq(expected, got) {
		t.Errorf("Expected %+v got %+v.", expected, got)
	}
	got = got[:0]
	tm.ResetProvider()
	for _ = range tm.Jobs {
		command := <-tm.NextCommand
		got = append(got, command.Name)
	}
	if !testEq(expected, got) {
		t.Errorf("After reset. Expected %+v got %+v.", expected, got)
	}
}
示例#2
0
func TestJobState(t *testing.T) {
	job_count := 10
	task_count := 2
	command_count := 10
	var jobs []*kamaji.Job
	for i := 1; i < job_count+1; i++ {
		job := kamaji.NewJob(fmt.Sprintf("Job %d", i))
		job.SetPrio(10)
		for j := 0; j < task_count; j++ {
			task := kamaji.NewTask(fmt.Sprintf("Task %d", j), job, []string{})
			for k := 0; k < command_count; k++ {
				_ = kamaji.NewCommand(fmt.Sprintf("Command %d", k), task)
			}
		}
		jobs = append(jobs, job)
	}
	stateSequence := []string{"ready", "start", "finish"}
	var wg sync.WaitGroup
	for _, state := range stateSequence {
		for _, job := range jobs {
			if job.GetPrio() != 10 {
				t.Logf("Prio Expected: 10 got %d", job.GetPrio())
			}
			wg.Add(1)
			go changeState(job, state, t, &wg)
		}
		time.Sleep(time.Millisecond * 10)
	}
	wg.Wait()
}
示例#3
0
func TestTaskManagerProviderOrder(t *testing.T) {
	tm := kamaji.NewTaskManager()
	job := kamaji.NewJob("JOB")
	task := kamaji.NewTask("TASK", job, []string{})
	_ = kamaji.NewCommand("0", task)
	_ = kamaji.NewCommand("1", task)
	_ = kamaji.NewCommand("2", task)
	_ = kamaji.NewCommand("3", task)
	_ = kamaji.NewCommand("4", task)
	_ = kamaji.NewCommand("5", task)
	tm.AddJob(job)
	tm.Start()
	defer tm.Stop()
	expected := []string{"0", "1", "2", "3", "4", "5"}
	var got []string
	for _ = range task.Commands {
		command := <-tm.NextCommand
		got = append(got, command.Name)
	}
	if !testEq(expected, got) {
		t.Errorf("Expected %+v got %+v.", expected, got)
	}
	got = got[:0]
	tm.ResetProvider()
	for _ = range task.Commands {
		command := <-tm.NextCommand
		got = append(got, command.Name)
	}
	if !testEq(expected, got) {
		t.Errorf("After reset. Expected %+v got %+v.", expected, got)
	}
}
示例#4
0
func TestDispatcher(t *testing.T) {
	fmt.Println("Starting")
	lm := kamaji.NewLicenseManager()
	nm := kamaji.NewNodeManager("", 6666)
	go nm.Start()
	tm := kamaji.NewTaskManager()
	d := kamaji.NewDispatcher(lm, nm, tm)
	job_count := 10
	task_count := 5
	command_count := 20
	for i := 0; i < job_count; i++ {
		job := kamaji.NewJob(fmt.Sprintf("Job %d", i))
		for j := 0; j < task_count; j++ {
			task := kamaji.NewTask(fmt.Sprintf("Task %d", j), job, []string{})
			for k := 0; k < command_count; k++ {
				_ = kamaji.NewCommand(fmt.Sprintf("Command %d", k), task)
			}
		}
		tm.AddJob(job)
	}
	go d.Start()

	client_count := 1
	fmt.Println("Starting: ", client_count, " clients.")
	quit := make(chan bool, client_count)
	for i := 0; i < client_count; i++ {
		go cli(i, quit)
		time.Sleep(time.Millisecond * 2)
	}
	time.Sleep(time.Second)
	for i := 0; i < client_count; i++ {
		quit <- true
	}
}
示例#5
0
func main() {
	fmt.Println("Starting")
	// Create all managers
	lm := kamaji.NewLicenseManager()
	lm.AddLicense("maya", 4)
	lm.AddLicense("nuke", 4)
	nm := kamaji.NewNodeManager("", 1314)
	tm := kamaji.NewTaskManager()
	d := kamaji.NewDispatcher(lm, nm, tm)
	s := kamaji.NewService("", 8080, lm, nm, tm)
	// Create signal handler
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for sig := range c {
			switch sig {
			case os.Interrupt:
				fmt.Printf("\nCatched Interupt Signal, Cleaning up\n")
				d.Stop()
			}
		}
	}()

	// Create Test Jobs
	job_count := 10
	task_count := 2
	command_count := 50
	for i := 1; i < job_count+1; i++ {
		lic_name := "maya"
		if i > 6 {
			lic_name = "nuke"
		}
		job := kamaji.NewJob(fmt.Sprintf("Job %d | %s", i, lic_name))
		for j := 0; j < task_count; j++ {
			task := kamaji.NewTask(fmt.Sprintf("Task %d [%s]", j, lic_name), job, []string{lic_name})
			for k := 0; k < command_count; k++ {
				_ = kamaji.NewCommand(fmt.Sprintf("Command %d", k), task)
			}
		}
		tm.AddJob(job)
	}
	go nm.Start()
	defer nm.Stop()
	go tm.Start()
	defer tm.Stop()
	go s.Start()
	defer s.Stop()
	d.Start()
}
示例#6
0
func TestTaskManagerGetById(t *testing.T) {
	tm := kamaji.NewTaskManager()
	job := kamaji.NewJob("JOB")
	task := kamaji.NewTask("TASK", job, []string{})
	command := kamaji.NewCommand("1", task)
	tm.AddJob(job)
	q_job := tm.GetJobFromId(job.ID.String())
	if q_job.ID.String() != job.ID.String() {
		t.Logf("Expected %s, got %s", job.ID, q_job.ID)
	}

	q_cmd := tm.GetCommandsFromId(command.ID.String())
	if q_cmd.ID.String() != command.ID.String() {
		t.Logf("Expected %s, got %s", command.ID, q_cmd.ID)
	}
}
示例#7
0
func fillTaskManager(tm *kamaji.TaskManager, job_count int, task_count int, command_count int) {
	// Create Test Jobs
	for i := 1; i < job_count+1; i++ {
		lic_name := "maya"
		if i > 6 {
			lic_name = "nuke"
		}
		job := kamaji.NewJob(fmt.Sprintf("Job %d | %s", i, lic_name))
		for j := 0; j < task_count; j++ {
			task := kamaji.NewTask(fmt.Sprintf("Task %d [%s]", j, lic_name), job, []string{lic_name})
			for k := 0; k < command_count; k++ {
				_ = kamaji.NewCommand(fmt.Sprintf("Command %d", k), task)
			}
		}
		tm.AddJob(job)
	}
}
示例#8
0
func TestTaskStates(t *testing.T) {
	job := kamaji.NewJob("Test Job 01")
	task := kamaji.NewTask("Test Task 01", job, []string{})
	t.Logf("Task: %s is %s", task.Name, task.State)
	/*
	   err := task.FSM.Event("start")
	   if err != nil {
	       t.Log(err)
	   }
	   t.Logf("Task: %s is %s", task.Name, task.State)
	   err = task.FSM.Event("start")
	   if err != nil {
	       t.Log(err)
	   }
	   t.Logf("Task: %s is %s", task.Name, task.State)
	   err = task.FSM.Event("stop")
	   if err != nil {
	       t.Log(err)
	   }
	   t.Logf("Task: %s is %s", task.Name, task.State)
	*/
}