当前位置: 首页>>代码示例>>Golang>>正文


Golang store.New函数代码示例

本文整理汇总了Golang中github.com/soundcloud/doozerd/store.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Benchmark5DoozerClientSet

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

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

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

	cl := dial(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)

	// make sure all the peers have started up
	dial(l1.Addr().String()).Set("/foo", store.Clobber, nil)
	dial(l2.Addr().String()).Set("/foo", store.Clobber, nil)
	dial(l3.Addr().String()).Set("/foo", store.Clobber, nil)
	dial(l4.Addr().String()).Set("/foo", store.Clobber, nil)

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		cl.Set("/test", store.Clobber, nil)
	}
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:48,代码来源:bench_test.go

示例2: TestDoozerWaitWithRev

func TestDoozerWaitWithRev(t *testing.T) {
	var (
		l  = mustListen()
		u  = mustListenUDP(l.Addr().String())
		st = store.New(store.DefaultInitialRev)
	)
	defer l.Close()
	defer u.Close()

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

	cl := dial(l.Addr().String())

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

	ev, err := cl.Wait("/test/**", 1)
	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

	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())
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:30,代码来源:peer_test.go

示例3: TestDoozerWaitSimple

func TestDoozerWaitSimple(t *testing.T) {
	var (
		l  = mustListen()
		st = store.New(store.DefaultInitialRev)
	)
	defer l.Close()

	go Main("a", "X", nil, l, nil, st, 1e6)

	cl := dial(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:soundcloud,项目名称:doozerd,代码行数:34,代码来源:solo_test.go

示例4: Benchmark1DoozerConClientSet

func Benchmark1DoozerConClientSet(b *testing.B) {
	var (
		l  = mustListen()
		a  = l.Addr().String()
		u  = mustListenUDP(a)
		st = store.New(store.DefaultInitialRev)
	)
	defer l.Close()
	defer u.Close()
	b.StopTimer()

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

	cl := dial(l.Addr().String())

	c := make(chan bool, b.N)
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		go func() {
			cl.Set("/test", store.Clobber, nil)
			c <- true
		}()
	}
	for i := 0; i < b.N; i++ {
		<-c
	}
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:27,代码来源:bench_test.go

示例5: TestManagerFilterPropSeqn

func TestManagerFilterPropSeqn(t *testing.T) {
	ps := make(chan int64, 100)
	st := store.New(store.DefaultInitialRev)
	defer close(st.Ops)

	m := &Manager{
		DefRev: 2,
		Alpha:  1,
		Self:   "b",
		PSeqn:  ps,
		Store:  st,
	}
	go m.Run()

	st.Ops <- store.Op{1, store.MustEncodeSet("/ctl/cal/0", "a", 0)}
	st.Ops <- store.Op{2, store.MustEncodeSet("/ctl/cal/1", "b", 0)}
	st.Ops <- store.Op{3, store.Nop}
	st.Ops <- store.Op{4, store.Nop}
	assert.Equal(t, int64(3), <-ps)
	assert.Equal(t, int64(5), <-ps)

	st.Ops <- store.Op{5, store.Nop}
	st.Ops <- store.Op{6, store.Nop}
	assert.Equal(t, int64(7), <-ps)
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:25,代码来源:manager_test.go

示例6: TestManagerEvent

func TestManagerEvent(t *testing.T) {
	const alpha = 2
	runs := make(map[int64]*run)
	st := store.New(store.DefaultInitialRev)
	defer close(st.Ops)

	st.Ops <- store.Op{
		Seqn: 1,
		Mut:  store.MustEncodeSet(node+"/a/addr", "1.2.3.4:5", 0),
	}

	st.Ops <- store.Op{
		Seqn: 2,
		Mut:  store.MustEncodeSet(cal+"/1", "a", 0),
	}

	ch, err := st.Wait(store.Any, 2)
	if err != nil {
		panic(err)
	}

	x, _ := net.ResolveUDPAddr("udp", "1.2.3.4:5")
	pseqn := make(chan int64, 1)
	m := &Manager{
		Alpha: alpha,
		Self:  "a",
		PSeqn: pseqn,
		Ops:   st.Ops,
		Out:   make(chan Packet),
		run:   runs,
	}
	m.event(<-ch)

	exp := &run{
		self:  "a",
		seqn:  2 + alpha,
		cals:  []string{"a"},
		addr:  []*net.UDPAddr{x},
		ops:   st.Ops,
		out:   m.Out,
		bound: initialWaitBound,
	}
	exp.c = coordinator{
		crnd: 1,
		size: 1,
		quor: exp.quorum(),
	}
	exp.l = learner{
		round:  1,
		size:   1,
		quorum: int64(exp.quorum()),
		votes:  map[string]int64{},
		voted:  []bool{false},
	}

	assert.Equal(t, 1, len(runs))
	assert.Equal(t, exp, runs[exp.seqn])
	assert.Equal(t, exp.seqn, <-pseqn)
	assert.Equal(t, exp.seqn+1, m.next)
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:60,代码来源:manager_test.go

示例7: TestManagerPacketProcessing

func TestManagerPacketProcessing(t *testing.T) {
	st := store.New(store.DefaultInitialRev)
	defer close(st.Ops)
	in := make(chan Packet)
	out := make(chan Packet, 100)
	var m Manager
	m.run = make(map[int64]*run)
	m.Alpha = 1
	m.Store = st
	m.In = in
	m.Out = out
	m.Ops = st.Ops

	st.Ops <- store.Op{1, store.MustEncodeSet(node+"/a/addr", "1.2.3.4:5", 0)}
	st.Ops <- store.Op{2, store.MustEncodeSet("/ctl/cal/0", "a", 0)}
	m.event(<-mustWait(st, 2))

	addr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:9999")
	recvPacket(&m.packet, Packet{
		Addr: addr,
		Msg:  Msg{Seqn: proto.Int64(2), Cmd: learn, Value: []byte("foo")},
	})
	m.pump()
	assert.Equal(t, 0, m.packet.Len())
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:25,代码来源:manager_test.go

示例8: TestDoozerGetdirOffsetLimit

func TestDoozerGetdirOffsetLimit(t *testing.T) {
	var (
		l  = mustListen()
		u  = mustListenUDP(l.Addr().String())
		st = store.New(store.DefaultInitialRev)
	)
	defer l.Close()
	defer u.Close()

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

	cl := dial(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"))

	rev, err := cl.Rev()
	if err != nil {
		panic(err)
	}

	names, err := cl.Getdir("/test", rev, 1, 2)
	assert.Equal(t, nil, err)
	assert.Equal(t, []string{"b", "c"}, names)
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:26,代码来源:peer_test.go

示例9: TestDoozerGet

func TestDoozerGet(t *testing.T) {
	var (
		l  = mustListen()
		u  = mustListenUDP(l.Addr().String())
		st = store.New(store.DefaultInitialRev)
	)

	defer l.Close()
	defer u.Close()

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

	cl := dial(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:soundcloud,项目名称:doozerd,代码行数:32,代码来源:peer_test.go

示例10: TestDoozerStat

func TestDoozerStat(t *testing.T) {
	var (
		l  = mustListen()
		u  = mustListenUDP(l.Addr().String())
		st = store.New(store.DefaultInitialRev)
	)
	defer l.Close()
	defer u.Close()

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

	cl := dial(l.Addr().String())

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

	ln, rev, err := cl.Stat("/test", nil)
	assert.Equal(t, nil, err)
	assert.Equal(t, store.Dir, rev)
	assert.Equal(t, int(2), ln)

	ln, rev, err = cl.Stat("/test/fun", nil)
	assert.Equal(t, nil, err)
	assert.Equal(t, setRev, rev)
	assert.Equal(t, int(5), ln)
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:26,代码来源:peer_test.go

示例11: TestDoozerGetWithRev

func TestDoozerGetWithRev(t *testing.T) {
	var (
		l  = mustListen()
		st = store.New(store.DefaultInitialRev)
	)
	defer l.Close()

	go Main("a", "X", nil, l, nil, st, 1e6)

	cl := dial(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:soundcloud,项目名称:doozerd,代码行数:32,代码来源:solo_test.go

示例12: TestConsensusOne

func TestConsensusOne(t *testing.T) {
	self := "test"
	const alpha = 1
	st := store.New(store.DefaultInitialRev)

	st.Ops <- store.Op{1, store.MustEncodeSet("/ctl/node/"+self+"/addr", "1.2.3.4:5", 0)}
	st.Ops <- store.Op{2, store.MustEncodeSet("/ctl/cal/1", self, 0)}
	<-st.Seqns

	in := make(chan Packet)
	out := make(chan Packet)
	seqns := make(chan int64, alpha)
	props := make(chan *Prop)

	m := &Manager{
		Self:   self,
		DefRev: 2,
		Alpha:  alpha,
		In:     in,
		Out:    out,
		Ops:    st.Ops,
		PSeqn:  seqns,
		Props:  props,
		TFill:  10e9,
		Store:  st,
		Ticker: time.Tick(10e6),
	}
	go m.Run()

	go func() {
		for o := range out {
			in <- o
		}
	}()

	n := <-seqns
	w, err := st.Wait(store.Any, n)
	if err != nil {
		panic(err)
	}
	props <- &Prop{n, []byte("foo")}
	e := <-w

	exp := store.Event{
		Seqn: 3,
		Path: "/ctl/err",
		Body: "bad mutation",
		Rev:  3,
		Mut:  "foo",
		Err:  errors.New("bad mutation"),
	}

	e.Getter = nil
	assert.Equal(t, exp, e)
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:55,代码来源:consensus_test.go

示例13: TestGetCalsPartial

func TestGetCalsPartial(t *testing.T) {
	st := store.New(store.DefaultInitialRev)
	defer close(st.Ops)

	st.Ops <- store.Op{Seqn: 1, Mut: store.MustEncodeSet(cal+"/1", "a", 0)}
	st.Ops <- store.Op{Seqn: 2, Mut: store.MustEncodeSet(cal+"/2", "", 0)}
	st.Ops <- store.Op{Seqn: 3, Mut: store.MustEncodeSet(cal+"/3", "", 0)}
	<-st.Seqns

	assert.Equal(t, []string{"a"}, getCals(st))
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:11,代码来源:manager_test.go

示例14: TestDoozerNop

func TestDoozerNop(t *testing.T) {
	var (
		l  = mustListen()
		st = store.New(store.DefaultInitialRev)
	)
	defer l.Close()

	go Main("a", "X", nil, l, nil, st, 1e6)

	cl := dial(l.Addr().String())
	err := cl.Nop()
	assert.Equal(t, nil, err)
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:13,代码来源:solo_test.go

示例15: TestGetAddrs

func TestGetAddrs(t *testing.T) {
	st := store.New(store.DefaultInitialRev)
	defer close(st.Ops)

	st.Ops <- store.Op{1, store.MustEncodeSet(node+"/1/addr", "1.2.3.4:5", 0)}
	st.Ops <- store.Op{2, store.MustEncodeSet(node+"/2/addr", "2.3.4.5:6", 0)}
	st.Ops <- store.Op{3, store.MustEncodeSet(node+"/3/addr", "3.4.5.6:7", 0)}
	<-st.Seqns

	x, _ := net.ResolveUDPAddr("udp", "1.2.3.4:5")
	y, _ := net.ResolveUDPAddr("udp", "2.3.4.5:6")
	z, _ := net.ResolveUDPAddr("udp", "3.4.5.6:7")
	addrs := getAddrs(st, []string{"1", "2", "3"})
	assert.Equal(t, []*net.UDPAddr{x, y, z}, addrs)
}
开发者ID:soundcloud,项目名称:doozerd,代码行数:15,代码来源:manager_test.go


注:本文中的github.com/soundcloud/doozerd/store.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。