예제 #1
0
파일: config.go 프로젝트: nkuacac/pat
	config.BoolVar(&params.useRedis, "use-redis-store", false, "True if redis should be used (requires the -redis-host, -redis-port and -redis-password arguments)")
	redis.DescribeParameters(config)
}

func WithStore(fn func(store laboratory.Store) error) error {
	if params.useRedis {
		return WithRedisConnection(func(conn redis.Conn) error {
			store, err := RedisStoreFactory(conn)
			if err != nil {
				return err
			}

			return fn(store)
		})
	} else {
		return fn(CsvStoreFactory(params.csvDir))
	}
}

var WithRedisConnection = func(fn func(conn redis.Conn) error) error {
	return redis.WithRedisConnection(fn)
}

var RedisStoreFactory = func(conn redis.Conn) (laboratory.Store, error) {
	return NewRedisStore(conn)
}

var CsvStoreFactory = func(dir string) laboratory.Store {
	return NewCsvStore(dir, workloads.DefaultWorkloadList())
}
예제 #2
0
파일: server_test.go 프로젝트: nkuacac/pat
				flags.Parse([]string{})
			})

			It("Uses the env variable", func() {
				Ω(listen).Should(Equal(":1234"))
			})
		})
	})

	It("Uses config to get CSV output directory", func() {
		http.DefaultServeMux = http.NewServeMux()
		c := config.NewConfig()
		tempDir := filepath.Join(os.TempDir(), "foo")
		InitCommandLineFlags(c)
		c.Parse([]string{"-csv-dir", tempDir})
		csvs := store.NewCsvStore(tempDir, workloads.DefaultWorkloadList())
		ch := make(chan *Sample)
		go func() { ch <- &Sample{}; ch <- &Sample{}; close(ch) }()
		csvs.Writer("1234")(ch)
		Serve()
		json := get("/experiments/1234")
		Ω(json["Items"]).Should(HaveLen(2))
		os.RemoveAll(tempDir)
	})

	It("Returns empty experiments as [] not null", func() {
		json := get("/experiments/empty")
		Ω(json["Items"]).ShouldNot(BeNil())
	})

	It("lists experiments", func() {
예제 #3
0
파일: config.go 프로젝트: nkuacac/pat
func configure(worker Worker) Worker {
	workloadList := WorkloadListFactory()
	workloadList.DescribeWorkloads(worker)
	return worker
}

type WorkloadDescriber interface {
	DescribeWorkloads(worker workloads.WorkloadAdder)
}

var WithRedisConnection = func(fn func(conn redis.Conn) error) error {
	return redis.WithRedisConnection(fn)
}

var LocalWorkerFactory = func() *LocalWorker {
	return NewLocalWorker()
}

var RedisWorkerFactory = func(conn redis.Conn) Worker {
	return NewRedisWorker(conn)
}

var SlaveFactory = func(conn redis.Conn, delegate Worker) io.Closer {
	return StartSlave(conn, delegate)
}

var WorkloadListFactory = func() WorkloadDescriber {
	return workloads.DefaultWorkloadList()
}