Example #1
0
// etcd needs to be initialized beforehand
func TestControllerInitEtcdLayout(t *testing.T) {
	etcdClient := etcd.NewClient([]string{"http://localhost:4001"})

	tests := []struct {
		name          string
		numberOfTasks uint64
	}{
		{"test-1", 2},
		{"test-2", 4},
	}

	for i, tt := range tests {
		c := New(tt.name, etcdClient, tt.numberOfTasks, []string{"Parents", "Children"})
		c.InitEtcdLayout()

		for taskID := uint64(0); taskID < tt.numberOfTasks; taskID++ {
			key := etcdutil.FreeTaskPath(c.name, strconv.FormatUint(taskID, 10))
			if _, err := etcdClient.Get(key, false, false); err != nil {
				t.Errorf("task %d: etcdClient.Get %v failed: %v", i, key, err)
			}
			key = etcdutil.MetaPath(c.name, taskID)
			if _, err := etcdClient.Get(key, false, false); err != nil {
				t.Errorf("task %d: etcdClient.Get %v failed: %v", i, key, err)
			}
		}

		c.DestroyEtcdLayout()
	}
}
Example #2
0
func (c *Controller) InitEtcdLayout() error {
	// Initilize the job epoch to 0
	etcdutil.MustCreate(c.etcdclient, c.logger, etcdutil.EpochPath(c.name), "0", 0)
	c.setupWatchOnJobStatus()
	// initiate etcd data layout for tasks
	// currently it creates as many unassigned tasks as task masters.
	for i := uint64(0); i < c.numOfTasks; i++ {
		key := etcdutil.FreeTaskPath(c.name, strconv.FormatUint(i, 10))
		etcdutil.MustCreate(c.etcdclient, c.logger, key, "", 0)
		key = etcdutil.MetaPath(c.name, i)
		etcdutil.MustCreate(c.etcdclient, c.logger, key, "", 0)
	}
	return nil
}