|
|
@@ -489,7 +489,7 @@ func TestStoreCompareAndSwapPrevIndexFailsIfNotMatch(t *testing.T) {
|
|
|
// Ensure that the store can watch for key creation.
|
|
|
func TestStoreWatchCreate(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- w, _ := s.Watch("/foo", false, 0)
|
|
|
+ w, _ := s.Watch("/foo", false, false, 0)
|
|
|
c := w.EventChan
|
|
|
s.Create("/foo", false, "bar", false, Permanent)
|
|
|
e := nbselect(c)
|
|
|
@@ -502,7 +502,7 @@ func TestStoreWatchCreate(t *testing.T) {
|
|
|
// Ensure that the store can watch for recursive key creation.
|
|
|
func TestStoreWatchRecursiveCreate(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- w, _ := s.Watch("/foo", true, 0)
|
|
|
+ w, _ := s.Watch("/foo", true, false, 0)
|
|
|
s.Create("/foo/bar", false, "baz", false, Permanent)
|
|
|
e := nbselect(w.EventChan)
|
|
|
assert.Equal(t, e.Action, "create", "")
|
|
|
@@ -513,7 +513,7 @@ func TestStoreWatchRecursiveCreate(t *testing.T) {
|
|
|
func TestStoreWatchUpdate(t *testing.T) {
|
|
|
s := newStore()
|
|
|
s.Create("/foo", false, "bar", false, Permanent)
|
|
|
- w, _ := s.Watch("/foo", false, 0)
|
|
|
+ w, _ := s.Watch("/foo", false, false, 0)
|
|
|
s.Update("/foo", "baz", Permanent)
|
|
|
e := nbselect(w.EventChan)
|
|
|
assert.Equal(t, e.Action, "update", "")
|
|
|
@@ -524,7 +524,7 @@ func TestStoreWatchUpdate(t *testing.T) {
|
|
|
func TestStoreWatchRecursiveUpdate(t *testing.T) {
|
|
|
s := newStore()
|
|
|
s.Create("/foo/bar", false, "baz", false, Permanent)
|
|
|
- w, _ := s.Watch("/foo", true, 0)
|
|
|
+ w, _ := s.Watch("/foo", true, false, 0)
|
|
|
s.Update("/foo/bar", "baz", Permanent)
|
|
|
e := nbselect(w.EventChan)
|
|
|
assert.Equal(t, e.Action, "update", "")
|
|
|
@@ -535,7 +535,7 @@ func TestStoreWatchRecursiveUpdate(t *testing.T) {
|
|
|
func TestStoreWatchDelete(t *testing.T) {
|
|
|
s := newStore()
|
|
|
s.Create("/foo", false, "bar", false, Permanent)
|
|
|
- w, _ := s.Watch("/foo", false, 0)
|
|
|
+ w, _ := s.Watch("/foo", false, false, 0)
|
|
|
s.Delete("/foo", false, false)
|
|
|
e := nbselect(w.EventChan)
|
|
|
assert.Equal(t, e.Action, "delete", "")
|
|
|
@@ -546,7 +546,7 @@ func TestStoreWatchDelete(t *testing.T) {
|
|
|
func TestStoreWatchRecursiveDelete(t *testing.T) {
|
|
|
s := newStore()
|
|
|
s.Create("/foo/bar", false, "baz", false, Permanent)
|
|
|
- w, _ := s.Watch("/foo", true, 0)
|
|
|
+ w, _ := s.Watch("/foo", true, false, 0)
|
|
|
s.Delete("/foo/bar", false, false)
|
|
|
e := nbselect(w.EventChan)
|
|
|
assert.Equal(t, e.Action, "delete", "")
|
|
|
@@ -557,7 +557,7 @@ func TestStoreWatchRecursiveDelete(t *testing.T) {
|
|
|
func TestStoreWatchCompareAndSwap(t *testing.T) {
|
|
|
s := newStore()
|
|
|
s.Create("/foo", false, "bar", false, Permanent)
|
|
|
- w, _ := s.Watch("/foo", false, 0)
|
|
|
+ w, _ := s.Watch("/foo", false, false, 0)
|
|
|
s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
|
|
|
e := nbselect(w.EventChan)
|
|
|
assert.Equal(t, e.Action, "compareAndSwap", "")
|
|
|
@@ -568,7 +568,7 @@ func TestStoreWatchCompareAndSwap(t *testing.T) {
|
|
|
func TestStoreWatchRecursiveCompareAndSwap(t *testing.T) {
|
|
|
s := newStore()
|
|
|
s.Create("/foo/bar", false, "baz", false, Permanent)
|
|
|
- w, _ := s.Watch("/foo", true, 0)
|
|
|
+ w, _ := s.Watch("/foo", true, false, 0)
|
|
|
s.CompareAndSwap("/foo/bar", "baz", 0, "bat", Permanent)
|
|
|
e := nbselect(w.EventChan)
|
|
|
assert.Equal(t, e.Action, "compareAndSwap", "")
|
|
|
@@ -588,7 +588,7 @@ func TestStoreWatchExpire(t *testing.T) {
|
|
|
s.Create("/foo", false, "bar", false, time.Now().Add(500*time.Millisecond))
|
|
|
s.Create("/foofoo", false, "barbarbar", false, time.Now().Add(500*time.Millisecond))
|
|
|
|
|
|
- w, _ := s.Watch("/", true, 0)
|
|
|
+ w, _ := s.Watch("/", true, false, 0)
|
|
|
c := w.EventChan
|
|
|
e := nbselect(c)
|
|
|
assert.Nil(t, e, "")
|
|
|
@@ -596,12 +596,34 @@ func TestStoreWatchExpire(t *testing.T) {
|
|
|
e = nbselect(c)
|
|
|
assert.Equal(t, e.Action, "expire", "")
|
|
|
assert.Equal(t, e.Node.Key, "/foo", "")
|
|
|
- w, _ = s.Watch("/", true, 4)
|
|
|
+ w, _ = s.Watch("/", true, false, 4)
|
|
|
e = nbselect(w.EventChan)
|
|
|
assert.Equal(t, e.Action, "expire", "")
|
|
|
assert.Equal(t, e.Node.Key, "/foofoo", "")
|
|
|
}
|
|
|
|
|
|
+// Ensure that the store can watch in streaming mode.
|
|
|
+func TestStoreWatchStream(t *testing.T) {
|
|
|
+ s := newStore()
|
|
|
+ w, _ := s.Watch("/foo", false, true, 0)
|
|
|
+ // first modification
|
|
|
+ s.Create("/foo", false, "bar", false, Permanent)
|
|
|
+ e := nbselect(w.EventChan)
|
|
|
+ assert.Equal(t, e.Action, "create", "")
|
|
|
+ assert.Equal(t, e.Node.Key, "/foo", "")
|
|
|
+ assert.Equal(t, e.Node.Value, "bar", "")
|
|
|
+ e = nbselect(w.EventChan)
|
|
|
+ assert.Nil(t, e, "")
|
|
|
+ // second modification
|
|
|
+ s.Update("/foo", "baz", Permanent)
|
|
|
+ e = nbselect(w.EventChan)
|
|
|
+ assert.Equal(t, e.Action, "update", "")
|
|
|
+ assert.Equal(t, e.Node.Key, "/foo", "")
|
|
|
+ assert.Equal(t, e.Node.Value, "baz", "")
|
|
|
+ e = nbselect(w.EventChan)
|
|
|
+ assert.Nil(t, e, "")
|
|
|
+}
|
|
|
+
|
|
|
// Ensure that the store can recover from a previously saved state.
|
|
|
func TestStoreRecover(t *testing.T) {
|
|
|
s := newStore()
|