コード例 #1
0
ファイル: timer_test.go プロジェクト: andradeandrey/doozer
func TestDeleteTimer(t *testing.T) {
	st := store.New()
	timer := New(testPattern, OneMillisecond, st)
	defer timer.Close()

	never := "/timer/never/ticks"
	does := "/timer/does/tick"

	// Wait one minute to ensure it doesn't tick before
	// the following delete and assert.
	st.Ops <- store.Op{1, encodeTimer(never, 30*OneMillisecond)}

	st.Ops <- store.Op{2, encodeTimer(does, 60*OneMillisecond)}

	st.Ops <- store.Op{3, store.MustEncodeDel(never, store.Clobber)}

	// If the first timer failed to delete, it would come out first.
	assert.Equal(t, does, (<-timer.C).Path) // From seqn 2
}
コード例 #2
0
ファイル: lock_test.go プロジェクト: andradeandrey/doozer
func TestLockSimple(t *testing.T) {
	st := store.New()
	defer close(st.Ops)
	fp := &test.FakeProposer{Store: st}
	go Clean(fp.Store, fp)

	// start our session
	fp.Propose(store.MustEncodeSet("/session/a", "1.2.3.4:55", store.Clobber))

	// lock something for a
	fp.Propose(store.MustEncodeSet("/lock/x", "a", store.Missing))
	fp.Propose(store.MustEncodeSet("/lock/y", "b", store.Missing))
	fp.Propose(store.MustEncodeSet("/lock/z", "a", store.Missing))

	// watch the locks to be deleted
	ch := fp.Watch("/lock/*")

	// end the session
	fp.Propose(store.MustEncodeDel("/session/a", store.Clobber))

	// now that the session has ended, check all locks it owned are released
	assert.Equal(t, "/lock/x", (<-ch).Path)
	assert.Equal(t, "/lock/z", (<-ch).Path)
}
コード例 #3
0
ファイル: member_test.go プロジェクト: andradeandrey/doozer
func TestMemberSimple(t *testing.T) {
	st := store.New()
	defer close(st.Ops)
	fp := &test.FakeProposer{Store: st}
	go Clean(fp.Store, fp)

	// start our session
	fp.Propose(store.MustEncodeSet("/session/a", "foo", store.Missing))

	keys := map[string]string{
		"/doozer/slot/0":    "a",
		"/doozer/members/a": "addr",
		"/doozer/info/a/x":  "a",
		"/doozer/info/a/y":  "b",
	}

	// join the cluster
	for k, p := range keys {
		fp.Propose(store.MustEncodeSet(k, p, store.Missing))
	}

	// watch the keys to be deleted
	ch := fp.Watch("/doozer/**")

	// end the session
	fp.Propose(store.MustEncodeDel("/session/a", store.Clobber))

	// now that the session has ended, check its membership is cleaned up
	for i := 0; i < len(keys); i++ {
		ev := <-ch
		_, ok := keys[ev.Path]
		keys[ev.Path] = "", false
		assert.T(t, ok)
		assert.Equal(t, "", ev.Body)
	}
}