當前位置: 首頁>>代碼示例>>Golang>>正文


Golang doozer.New函數代碼示例

本文整理匯總了Golang中github.com/ha/doozer.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Benchmark5DoozerConClientSet

func Benchmark5DoozerConClientSet(b *testing.B) {
	b.StopTimer()
	l := mustListen()
	defer l.Close()
	a := l.Addr().String()
	u := mustListenPacket(a)
	defer u.Close()

	l1 := mustListen()
	defer l1.Close()
	u1 := mustListenPacket(l1.Addr().String())
	defer u1.Close()
	l2 := mustListen()
	defer l2.Close()
	u2 := mustListenPacket(l2.Addr().String())
	defer u2.Close()
	l3 := mustListen()
	defer l3.Close()
	u3 := mustListenPacket(l3.Addr().String())
	defer u3.Close()
	l4 := mustListen()
	defer l4.Close()
	u4 := mustListenPacket(l4.Addr().String())
	defer u4.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 1e8, 3e9)
	go Main("a", "Y", "", doozer.New("a", a), u1, l1, nil, 1e9, 1e8, 3e9)
	go Main("a", "Z", "", doozer.New("a", a), u2, l2, nil, 1e9, 1e8, 3e9)
	go Main("a", "V", "", doozer.New("a", a), u3, l3, nil, 1e9, 1e8, 3e9)
	go Main("a", "W", "", doozer.New("a", a), u4, l4, nil, 1e9, 1e8, 3e9)

	cl := doozer.New("foo", l.Addr().String())
	cl.Set("/ctl/cal/1", store.Missing, nil)
	cl.Set("/ctl/cal/2", store.Missing, nil)
	cl.Set("/ctl/cal/3", store.Missing, nil)
	cl.Set("/ctl/cal/4", store.Missing, nil)

	cls := []*doozer.Client{
		cl,
		doozer.New("foo", l1.Addr().String()),
		doozer.New("foo", l2.Addr().String()),
		doozer.New("foo", l3.Addr().String()),
		doozer.New("foo", l4.Addr().String()),
	}

	c := make(chan bool, b.N)
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		i := i
		go func() {
			cls[i%len(cls)].Set("/test", store.Clobber, nil)
			c <- true
		}()
	}
	for i := 0; i < b.N; i++ {
		<-c
	}
}
開發者ID:kr,項目名稱:doozerd,代碼行數:58,代碼來源:bench_test.go

示例2: TestDoozerWaitSimple

func TestDoozerWaitSimple(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())
	var rev int64 = 1

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	ev, err := cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, []byte("bar"), ev.Body)
	assert.T(t, ev.IsSet())
	rev = ev.Rev + 1

	cl.Set("/test/fun", store.Clobber, []byte("house"))
	ev, err = cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, []byte("house"), ev.Body)
	assert.T(t, ev.IsSet())
	rev = ev.Rev + 1

	cl.Del("/test/foo", store.Clobber)
	ev, err = cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.T(t, ev.IsDel())
}
開發者ID:kr,項目名稱:doozerd,代碼行數:33,代碼來源:peer_test.go

示例3: TestDoozerWalk

func TestDoozerWalk(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))

	info, err := cl.Walk("/test/**", nil, 0, -1)
	assert.Equal(t, nil, err)
	assert.Equal(t, 2, len(info))

	assert.Equal(t, "/test/foo", info[0].Path)
	assert.Equal(t, "bar", string(info[0].Body))
	assert.T(t, info[0].IsSet())

	assert.Equal(t, "/test/fun", info[1].Path)
	assert.Equal(t, "house", string(info[1].Body))
	assert.T(t, info[1].IsSet())
}
開發者ID:kr,項目名稱:doozerd,代碼行數:25,代碼來源:peer_test.go

示例4: TestDoozerWalkWithRev

func TestDoozerWalkWithRev(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	rev, _ := cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))
	cl.Set("/test/fab", store.Clobber, []byte("ulous"))

	w, err := cl.Walk("/test/**", &rev, nil, nil)
	assert.Equal(t, nil, err, err)

	ls := []string{}
	for e := range w.C {
		ls = append(ls, e.Path)
	}

	sort.SortStrings(ls)
	assert.Equal(t, []string{"/test/foo"}, ls)
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:25,代碼來源:peer_test.go

示例5: isCal

// IsCal checks if addr is a CAL in the cluster named name.
// Returns a client if so, nil if not.
func isCal(name, addr string) *doozer.Client {
	c := doozer.New(name, addr)
	v, _, _ := c.Get("/ctl/name", nil)
	if string(v) != name {
		return nil
	}

	var cals []string
	names, err := c.Getdir("/ctl/cal", nil, 0, -1)
	if err != nil {
		panic(err)
	}
	for _, name := range names {
		cals = append(cals, name)
	}

	for _, cal := range cals {
		body, _, err := c.Get("/ctl/cal/"+cal, nil)
		if err != nil || len(body) == 0 {
			continue
		}

		id := string(body)

		v, _, err := c.Get("/ctl/node/"+id+"/addr", nil)
		if err != nil {
			panic(err)
		}
		if string(v) == addr {
			return c
		}
	}

	return nil
}
開發者ID:kr,項目名稱:doozerd,代碼行數:37,代碼來源:boot.go

示例6: TestDoozerGetdirOffsetLimit

func TestDoozerGetdirOffsetLimit(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())
	cl.Set("/test/a", store.Clobber, []byte("1"))
	cl.Set("/test/b", store.Clobber, []byte("2"))
	cl.Set("/test/c", store.Clobber, []byte("3"))
	cl.Set("/test/d", store.Clobber, []byte("4"))

	// The order is arbitrary.  We need to collect them
	// because it's not safe to assume the order.
	w, _ := cl.Getdir("/test", 0, 0, nil)
	ents := make([]string, 0)
	for e := range w.C {
		ents = append(ents, e.Path)
	}

	w, _ = cl.Getdir("/test", 1, 2, nil)
	assert.Equal(t, ents[1], (<-w.C).Path)
	assert.Equal(t, ents[2], (<-w.C).Path)
	assert.Equal(t, (*doozer.Event)(nil), <-w.C)
	assert.T(t, closed(w.C))
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:28,代碼來源:peer_test.go

示例7: TestDoozerWalkWithOffsetAndLimit

func TestDoozerWalkWithOffsetAndLimit(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	cl.Set("/test/a", store.Clobber, []byte("abc"))
	cl.Set("/test/b", store.Clobber, []byte("def"))
	cl.Set("/test/c", store.Clobber, []byte("ghi"))
	cl.Set("/test/d", store.Clobber, []byte("jkl"))

	info, err := cl.Walk("/test/**", nil, 1, 2)
	assert.Equal(t, nil, err)
	assert.Equal(t, 2, len(info))

	assert.Equal(t, "/test/b", info[0].Path)
	assert.Equal(t, "def", string(info[0].Body))
	assert.T(t, info[0].IsSet())

	assert.Equal(t, "/test/c", info[1].Path)
	assert.Equal(t, "ghi", string(info[1].Body))
	assert.T(t, info[1].IsSet())
}
開發者ID:kr,項目名稱:doozerd,代碼行數:27,代碼來源:peer_test.go

示例8: TestDoozerWalk

func TestDoozerWalk(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))

	w, err := cl.Walk("/test/**", nil, nil, nil)
	assert.Equal(t, nil, err, err)

	ev := <-w.C
	assert.NotEqual(t, (*doozer.Event)(nil), ev)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, "bar", string(ev.Body))
	assert.T(t, ev.IsSet())

	ev = <-w.C
	assert.NotEqual(t, (*doozer.Event)(nil), ev)
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, "house", string(ev.Body))
	assert.T(t, ev.IsSet())

	ev = <-w.C
	assert.Tf(t, closed(w.C), "got %v", ev)
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:31,代碼來源:peer_test.go

示例9: TestDoozerGetWithRev

func TestDoozerGetWithRev(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	rev1, err := cl.Set("/x", store.Missing, []byte{'a'})
	assert.Equal(t, nil, err)

	v, rev, err := cl.Get("/x", &rev1) // Use the snapshot.
	assert.Equal(t, nil, err)
	assert.Equal(t, rev1, rev)
	assert.Equal(t, []byte{'a'}, v)

	rev2, err := cl.Set("/x", rev, []byte{'b'})
	assert.Equal(t, nil, err)

	v, rev, err = cl.Get("/x", nil) // Read the new value.
	assert.Equal(t, nil, err)
	assert.Equal(t, rev2, rev)
	assert.Equal(t, []byte{'b'}, v)

	v, rev, err = cl.Get("/x", &rev1) // Read the saved value again.
	assert.Equal(t, nil, err)
	assert.Equal(t, rev1, rev)
	assert.Equal(t, []byte{'a'}, v)
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:31,代碼來源:peer_test.go

示例10: TestDoozerWatchSimple

func TestDoozerWatchSimple(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	w, err := cl.Watch("/test/**", 0)
	assert.Equal(t, nil, err, err)
	defer w.Cancel()

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	ev := <-w.C
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, []byte("bar"), ev.Body)
	assert.T(t, ev.IsSet())

	cl.Set("/test/fun", store.Clobber, []byte("house"))
	ev = <-w.C
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, []byte("house"), ev.Body)
	assert.T(t, ev.IsSet())

	cl.Del("/test/foo", store.Clobber)
	ev = <-w.C
	assert.Equal(t, "/test/foo", ev.Path)
	assert.T(t, ev.IsDel())

	w.Cancel()
	ev = <-w.C
	assert.Tf(t, closed(w.C), "got %v", ev)
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:35,代碼來源:peer_test.go

示例11: TestDoozerWatchWithRev

func TestDoozerWatchWithRev(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	// Create some history
	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))

	// Ask doozer for the history
	w, err := cl.Watch("/test/**", 1)
	assert.Equal(t, nil, err, err)
	defer w.Cancel()

	ev := <-w.C
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, []byte("bar"), ev.Body)
	assert.T(t, ev.IsSet())

	ev = <-w.C
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, []byte("house"), ev.Body)
	assert.T(t, ev.IsSet())
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:29,代碼來源:peer_test.go

示例12: TestDoozerGet

func TestDoozerGet(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	_, err := cl.Set("/x", store.Missing, []byte{'a'})
	assert.Equal(t, nil, err)

	ents, rev, err := cl.Get("/x", nil)
	assert.Equal(t, nil, err)
	assert.NotEqual(t, store.Dir, rev)
	assert.Equal(t, []byte{'a'}, ents)

	//cl.Set("/test/a", store.Missing, []byte{'1'})
	//cl.Set("/test/b", store.Missing, []byte{'2'})
	//cl.Set("/test/c", store.Missing, []byte{'3'})

	//ents, rev, err = cl.Get("/test", 0)
	//sort.SortStrings(ents)
	//assert.Equal(t, store.Dir, rev)
	//assert.Equal(t, nil, err)
	//assert.Equal(t, []string{"a", "b", "c"}, ents)
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:28,代碼來源:peer_test.go

示例13: TestDoozerGetdirOnDir

func TestDoozerGetdirOnDir(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	cl.Set("/test/a", store.Clobber, []byte("1"))
	cl.Set("/test/b", store.Clobber, []byte("2"))
	cl.Set("/test/c", store.Clobber, []byte("3"))

	w, err := cl.Getdir("/test", 0, 0, nil)
	assert.Equal(t, nil, err)

	got := make([]string, 0)
	for e := range w.C {
		got = append(got, e.Path)
	}

	sort.SortStrings(got)
	assert.Equal(t, []string{"a", "b", "c"}, got)
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:25,代碼來源:peer_test.go

示例14: TestDoozerReconnect

func TestDoozerReconnect(t *testing.T) {
	l := mustListen()
	defer l.Close()
	a := l.Addr().String()
	u := mustListenPacket(a)
	defer u.Close()
	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	l1 := mustListen()
	go Main("a", "Y", "", doozer.New("a", a), mustListenPacket(l1.Addr().String()), l1, nil, 1e9, 2e9, 3e9)

	l2 := mustListen()
	go Main("a", "Z", "", doozer.New("a", a), mustListenPacket(l2.Addr().String()), l2, nil, 1e9, 2e9, 3e9)

	c0 := doozer.New("foo", a)

	_, err := c0.Set("/ctl/cal/2", 0, []byte{})
	assert.Equal(t, nil, err)

	_, err = c0.Set("/ctl/cal/3", 0, []byte{})
	assert.Equal(t, nil, err)

	// Wait for the other nodes to become CALs.
	for <-c0.Len < 3 {
		time.Sleep(5e8)
	}

	rev, err := c0.Set("/x", -1, []byte{'a'})
	assert.Equal(t, nil, err, err)

	rev, err = c0.Set("/x", -1, []byte{'b'})
	assert.Equal(t, nil, err)

	l1.Close()

	ents, rev, err := c0.Get("/x", nil)
	assert.Equal(t, nil, err, err)
	assert.NotEqual(t, store.Dir, rev)
	assert.Equal(t, []byte{'b'}, ents)

	rev, err = c0.Set("/x", -1, []byte{'c'})
	assert.Equal(t, nil, err, err)

	rev, err = c0.Set("/x", -1, []byte{'d'})
	assert.Equal(t, nil, err)
}
開發者ID:chrismoos,項目名稱:doozerd,代碼行數:46,代碼來源:peer_test.go

示例15: boot

func boot(name, id, laddr, baddr string) *doozer.Client {
	b := doozer.New("<boot>", baddr)
	cl := lookupAndAttach(b, name)
	if cl == nil {
		return elect(name, id, laddr, b)
	}

	return cl
}
開發者ID:kr,項目名稱:doozerd,代碼行數:9,代碼來源:boot.go


注:本文中的github.com/ha/doozer.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。