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


Golang store.New函數代碼示例

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


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

示例1: TestSession

func TestSession(t *testing.T) {
	st := store.New()
	defer close(st.Ops)
	fp := &test.FakeProposer{Store: st}
	go Clean(st, fp)

	ch := make(chan store.Event, 100)
	go func(c <-chan store.Event) {
		for e := range c {
			ch <- e
		}
		close(ch)
	}(st.Watch("/session/*"))

	// check-in with less than a nanosecond to live
	body := strconv.Itoa64(time.Nanoseconds() + 1)
	fp.Propose(store.MustEncodeSet("/session/a", body, store.Clobber))

	// Throw away the set
	assert.T(t, (<-ch).IsSet())

	ev := <-ch
	assert.T(t, ev.IsDel())
	assert.Equal(t, "/session/a", ev.Path)
}
開發者ID:andradeandrey,項目名稱:doozer,代碼行數:25,代碼來源:session_test.go

示例2: TestManagerEvent

func TestManagerEvent(t *testing.T) {
	const alpha = 2
	runs := make(map[int64]*run)
	st := store.New()
	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:piston,項目名稱:doozerd,代碼行數:60,代碼來源:manager_test.go

示例3: TestManagerProposeFill

func TestManagerProposeFill(t *testing.T) {
	props := make(chan *Prop)
	q := new(vector.Vector)

	st := store.New()
	out := make(chan Packet, 100)
	cfg := &Config{
		Self:   "a",
		Store:  st,
		Out:    out,
		DefRev: 2,
		Alpha:  1,
		Props:  props,
	}
	m := NewManager(cfg)
	m.run = map[int64]*run{
		6: &run{seqn: 6, cals: []string{"a", "b", "c"}},
		7: &run{seqn: 7, cals: []string{"a", "b", "c"}},
		8: &run{seqn: 8, cals: []string{"a", "b", "c"}},
	}
	exp := vector.Vector{
		trigger{123, 7},
		trigger{123, 8},
	}
	m.propose(q, &Prop{Seqn: 9, Mut: []byte("foo")}, 123)
	assert.Equal(t, exp, m.fill)
}
開發者ID:thaingo,項目名稱:doozerd,代碼行數:27,代碼來源:manager_test.go

示例4: TestMemberSimple

func TestMemberSimple(t *testing.T) {
	st := store.New()
	defer close(st.Ops)
	fp := &test.FakeProposer{Store: st}
	c := make(chan string)
	go Clean(c, fp.Store, fp)

	fp.Propose([]byte(store.MustEncodeSet("/ctl/node/a/x", "a", store.Missing)))
	fp.Propose([]byte(store.MustEncodeSet("/ctl/node/a/y", "b", store.Missing)))
	fp.Propose([]byte(store.MustEncodeSet("/ctl/node/a/addr", "1.2.3.4", store.Missing)))
	fp.Propose([]byte(store.MustEncodeSet("/ctl/cal/0", "a", store.Missing)))

	calCh := fp.Watch(store.MustCompileGlob("/ctl/cal/0"))
	nodeCh := fp.Watch(store.MustCompileGlob("/ctl/node/a/?"))

	// indicate that this peer is inactive
	go func() { c <- "1.2.3.4" }()

	ev := <-calCh
	assert.T(t, ev.IsSet())
	assert.Equal(t, "", ev.Body)

	cs := []int{}

	ev = <-nodeCh
	assert.T(t, ev.IsDel())
	cs = append(cs, int(ev.Path[len(ev.Path)-1]))

	ev = <-nodeCh
	assert.T(t, ev.IsDel())
	cs = append(cs, int(ev.Path[len(ev.Path)-1]))

	sort.SortInts(cs)
	assert.Equal(t, []int{'x', 'y'}, cs)
}
開發者ID:kr,項目名稱:doozerd,代碼行數:35,代碼來源:member_test.go

示例5: TestManagerTickQueue

func TestManagerTickQueue(t *testing.T) {
	ticker := make(chan int64)
	st := store.New()
	defer close(st.Ops)
	in := make(chan Packet)
	cfg := &Config{
		Alpha:  1,
		Store:  st,
		In:     in,
		Ticker: ticker,
		Out:    make(chan Packet, 100),
	}
	m := NewManager(cfg)
	st.Ops <- store.Op{
		Seqn: 1,
		Mut:  store.MustEncodeSet(node+"/a/addr", "x", 0),
	}
	for (<-m.Stats).Runs < 1 {
	}

	// get it to tick for seqn 2
	in <- Packet{Data: mustMarshal(&msg{Seqn: proto.Int64(2), Cmd: propose})}
	assert.Equal(t, 1, (<-m.Stats).WaitTicks)

	ticker <- time.Nanoseconds() + initialWaitBound*2
	assert.Equal(t, int64(1), (<-m.Stats).TotalTicks)
}
開發者ID:thaingo,項目名稱:doozerd,代碼行數:27,代碼來源:manager_test.go

示例6: TestManagerDeletesSuccessfulRun

func TestManagerDeletesSuccessfulRun(t *testing.T) {
	st := store.New()
	defer close(st.Ops)
	in := make(chan Packet)
	out := make(chan Packet, 100)
	cfg := &Config{
		Alpha: 1,
		Store: st,
		In:    in,
		Out:   out,
		Ops:   st.Ops,
	}
	m := NewManager(cfg)

	st.Ops <- store.Op{
		Seqn: 1,
		Mut:  store.MustEncodeSet(node+"/a/addr", "x", 0),
	}
	for (<-m.Stats).TotalRuns < 1 {
	}

	in <- Packet{
		Data: mustMarshal(&msg{Seqn: proto.Int64(2), Cmd: learn, Value: []byte("foo")}),
		Addr: "127.0.0.1:9999",
	}
	for (<-m.Stats).TotalRuns < 2 {
	}
	assert.Equal(t, 1, (<-m.Stats).Runs)
}
開發者ID:thaingo,項目名稱:doozerd,代碼行數:29,代碼來源:manager_test.go

示例7: TestManagerFilterPropSeqn

func TestManagerFilterPropSeqn(t *testing.T) {
	ps := make(chan int64, 100)
	st := store.New()
	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:piston,項目名稱:doozerd,代碼行數:25,代碼來源:manager_test.go

示例8: TestRegistrarEmptySlot

func TestRegistrarEmptySlot(t *testing.T) {
	st := store.New()
	rg := NewRegistrar(st, 0, 2)
	go func() {
		(st.Ops <- store.Op{3, mustEncodeSet(slotDir+"0", "c")})
		(st.Ops <- store.Op{2, mustEncodeSet(slotDir+"1", "")})
		(st.Ops <- store.Op{1, mustEncodeSet(slotDir+"2", "a")})
	}()
開發者ID:andradeandrey,項目名稱:doozer,代碼行數:8,代碼來源:registrar_test.go

示例9: TestRegistrarMembers

func TestRegistrarMembers(t *testing.T) {
	st := store.New()
	rg := NewRegistrar(st, 0, 2)
	go func() {
		(st.Ops <- store.Op{3, mustEncodeSet(membersKey+"/c", "1")})
		(st.Ops <- store.Op{2, mustEncodeSet(membersKey+"/b", "1")})
		(st.Ops <- store.Op{1, mustEncodeSet(membersKey+"/a", "1")})
	}()
開發者ID:andradeandrey,項目名稱:doozer,代碼行數:8,代碼來源:registrar_test.go

示例10: TestAddRun

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

	st.Ops <- store.Op{
		Seqn: 1,
		Mut:  store.MustEncodeSet(node+"/a/addr", "x", 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)
	}

	pseqn := make(chan int64, 1)
	c := &Config{
		Alpha: alpha,
		Self:  "a",
		PSeqn: pseqn,
		Ops:   st.Ops,
		Out:   make(chan Packet),
	}
	m := &Manager{cfg: *c, run: runs}
	got := m.addRun(<-ch)

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

	assert.Equal(t, exp, got)
	assert.Equal(t, exp, runs[got.seqn])
	assert.Equal(t, 1, len(runs))
	assert.Equal(t, exp.seqn, <-pseqn)
}
開發者ID:thaingo,項目名稱:doozerd,代碼行數:58,代碼來源:manager_test.go

示例11: selfRefNewManager

func selfRefNewManager(self string, alpha int) (*Manager, *store.Store) {
	p := make(FakePutterFrom, 1)
	st := store.New()
	st.Ops <- store.Op{1, mustEncodeSet(membersDir+"a", "x")}
	st.Ops <- store.Op{2, mustEncodeSet(slotDir+"0", "a")}
	m := NewManager(self, alpha, st, putFromWrapperTo{p, "x"})
	p[0] = m
	return m, st
}
開發者ID:andradeandrey,項目名稱:doozer,代碼行數:9,代碼來源:manager_test.go

示例12: TestManagerProposalQueue

func TestManagerProposalQueue(t *testing.T) {
	props := make(chan *Prop)

	st := store.New()
	out := make(chan Packet, 100)
	m := newManager("", 0, nil, nil, nil, props, nil, 0, st, out)
	props <- &Prop{Seqn: 1, Mut: []byte("foo")}

	assert.Equal(t, 1, (<-m).WaitPackets)
}
開發者ID:kr,項目名稱:doozerd,代碼行數:10,代碼來源:manager_test.go

示例13: TestManagerFill

func TestManagerFill(t *testing.T) {
	st := store.New()
	p := make(ChanPutCloserTo)
	st.Ops <- store.Op{1, mustEncodeSet(membersDir+"a", "x")}
	st.Ops <- store.Op{2, mustEncodeSet(slotDir+"0", "a")}
	mg := NewManager("a", 1, st, p)

	mg.fillUntil <- 4
	assert.Equal(t, uint64(3), (<-p).Msg.Seqn())
}
開發者ID:andradeandrey,項目名稱:doozer,代碼行數:10,代碼來源:manager_test.go

示例14: TestRegistrarSlotInitFirst

func TestRegistrarSlotInitFirst(t *testing.T) {
	st := store.New()
	(st.Ops <- store.Op{1, mustEncodeSet(slotDir+"0", "a")})
	st.Sync(1)
	rg := NewRegistrar(st, 1, 0)

	members, active := rg.setsForVersion(1)
	assert.Equal(t, 0, len(members))
	assert.Equal(t, []string{"a"}, active)
}
開發者ID:andradeandrey,項目名稱:doozer,代碼行數:10,代碼來源:registrar_test.go

示例15: TestRegistrarInitFirst

func TestRegistrarInitFirst(t *testing.T) {
	st := store.New()
	(st.Ops <- store.Op{1, mustEncodeSet(membersKey+"/a", "1")})
	st.Sync(1)
	rg := NewRegistrar(st, 1, 0)

	members, active := rg.setsForVersion(1)
	assert.Equal(t, 1, len(members))
	assert.Equal(t, 0, len(active))
}
開發者ID:andradeandrey,項目名稱:doozer,代碼行數:10,代碼來源:registrar_test.go


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