Ejemplo n.º 1
0
// Worker should register its address in etcd so that others can find him.
func TestWorkerSetupEtcd(t *testing.T) {
	job := "TestWorkerSetupEtcd"
	id := uint64(1)
	etcdClient := etcd.NewClient([]string{"http://localhost:4001"})
	w := &worker{
		job:        job,
		etcdClient: etcdClient,
		listener:   createListener(t),
		id:         id,
	}
	w.setupEtcd()
	resp, err := etcdClient.Get(etcdutil.WorkerPath(job, id), false, false)
	if err != nil {
		t.Fatalf("etcdClient.Get failed: %v", err)
	}
	addr := w.listener.Addr().String()
	if resp.Node.Value != addr {
		t.Fatalf("Wrong address on etcd: want = %s, get = %s", addr, resp.Node.Value)
	}
}
Ejemplo n.º 2
0
func (w *worker) setupEtcd() {
	// register worker's addr
	w.etcdClient.Set(etcdutil.WorkerPath(w.job, w.id), w.listener.Addr().String(), 0)
}