|
|
@@ -11,8 +11,8 @@ import (
|
|
|
// Ensure that the store can retrieve an existing value.
|
|
|
func TestStoreGetValue(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- e, err := s.Get("/foo", false, false, 2, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ e, err := s.Get("/foo", false, false)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "get", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -23,14 +23,14 @@ func TestStoreGetValue(t *testing.T) {
|
|
|
// Note that hidden files should not be returned.
|
|
|
func TestStoreGetDirectory(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- s.Create("/foo/bar", "X", false, Permanent, 3, 1)
|
|
|
- s.Create("/foo/_hidden", "*", false, Permanent, 4, 1)
|
|
|
- s.Create("/foo/baz", "", false, Permanent, 5, 1)
|
|
|
- s.Create("/foo/baz/bat", "Y", false, Permanent, 6, 1)
|
|
|
- s.Create("/foo/baz/_hidden", "*", false, Permanent, 7, 1)
|
|
|
- s.Create("/foo/baz/ttl", "Y", false, time.Now().Add(time.Second*3), 8, 1)
|
|
|
- e, err := s.Get("/foo", true, false, 8, 1)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ s.Create("/foo/bar", "X", false, Permanent)
|
|
|
+ s.Create("/foo/_hidden", "*", false, Permanent)
|
|
|
+ s.Create("/foo/baz", "", false, Permanent)
|
|
|
+ s.Create("/foo/baz/bat", "Y", false, Permanent)
|
|
|
+ s.Create("/foo/baz/_hidden", "*", false, Permanent)
|
|
|
+ s.Create("/foo/baz/ttl", "Y", false, time.Now().Add(time.Second*3))
|
|
|
+ e, err := s.Get("/foo", true, false)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "get", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -53,13 +53,13 @@ func TestStoreGetDirectory(t *testing.T) {
|
|
|
// Ensure that the store can retrieve a directory in sorted order.
|
|
|
func TestStoreGetSorted(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- s.Create("/foo/x", "0", false, Permanent, 3, 1)
|
|
|
- s.Create("/foo/z", "0", false, Permanent, 4, 1)
|
|
|
- s.Create("/foo/y", "", false, Permanent, 5, 1)
|
|
|
- s.Create("/foo/y/a", "0", false, Permanent, 6, 1)
|
|
|
- s.Create("/foo/y/b", "0", false, Permanent, 7, 1)
|
|
|
- e, err := s.Get("/foo", true, true, 8, 1)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ s.Create("/foo/x", "0", false, Permanent)
|
|
|
+ s.Create("/foo/z", "0", false, Permanent)
|
|
|
+ s.Create("/foo/y", "", false, Permanent)
|
|
|
+ s.Create("/foo/y/a", "0", false, Permanent)
|
|
|
+ s.Create("/foo/y/b", "0", false, Permanent)
|
|
|
+ e, err := s.Get("/foo", true, true)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.KVPairs[0].Key, "/foo/x", "")
|
|
|
assert.Equal(t, e.KVPairs[1].Key, "/foo/y", "")
|
|
|
@@ -71,7 +71,7 @@ func TestStoreGetSorted(t *testing.T) {
|
|
|
// Ensure that the store can create a new key if it doesn't already exist.
|
|
|
func TestStoreCreateValue(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- e, err := s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
+ e, err := s.Create("/foo", "bar", false, Permanent)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "create", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -81,14 +81,13 @@ func TestStoreCreateValue(t *testing.T) {
|
|
|
assert.Nil(t, e.KVPairs, "")
|
|
|
assert.Nil(t, e.Expiration, "")
|
|
|
assert.Equal(t, e.TTL, 0, "")
|
|
|
- assert.Equal(t, e.Index, uint64(2), "")
|
|
|
- assert.Equal(t, e.Term, uint64(1), "")
|
|
|
+ assert.Equal(t, e.Index, uint64(1), "")
|
|
|
}
|
|
|
|
|
|
// Ensure that the store can create a new directory if it doesn't already exist.
|
|
|
func TestStoreCreateDirectory(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- e, err := s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
+ e, err := s.Create("/foo", "", false, Permanent)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "create", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -98,22 +97,21 @@ func TestStoreCreateDirectory(t *testing.T) {
|
|
|
// Ensure that the store fails to create a key if it already exists.
|
|
|
func TestStoreCreateFailsIfExists(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- e, _err := s.Create("/foo", "", false, Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ e, _err := s.Create("/foo", "", false, Permanent)
|
|
|
err := _err.(*etcdErr.Error)
|
|
|
assert.Equal(t, err.ErrorCode, etcdErr.EcodeNodeExist, "")
|
|
|
assert.Equal(t, err.Message, "Already exists", "")
|
|
|
assert.Equal(t, err.Cause, "/foo", "")
|
|
|
- assert.Equal(t, err.Index, uint64(3), "")
|
|
|
- assert.Equal(t, err.Term, uint64(1), "")
|
|
|
+ assert.Equal(t, err.Index, uint64(1), "")
|
|
|
assert.Nil(t, e, 0, "")
|
|
|
}
|
|
|
|
|
|
// Ensure that the store can update a key if it already exists.
|
|
|
func TestStoreUpdateValue(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- e, err := s.Update("/foo", "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ e, err := s.Update("/foo", "baz", Permanent)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "update", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -121,17 +119,16 @@ func TestStoreUpdateValue(t *testing.T) {
|
|
|
assert.Equal(t, e.PrevValue, "bar", "")
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
assert.Equal(t, e.TTL, 0, "")
|
|
|
- assert.Equal(t, e.Index, uint64(3), "")
|
|
|
- assert.Equal(t, e.Term, uint64(1), "")
|
|
|
- e, _ = s.Get("/foo", false, false, 3, 1)
|
|
|
+ assert.Equal(t, e.Index, uint64(2), "")
|
|
|
+ e, _ = s.Get("/foo", false, false)
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
}
|
|
|
|
|
|
// Ensure that the store cannot update a directory.
|
|
|
func TestStoreUpdateFailsIfDirectory(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- e, _err := s.Update("/foo", "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ e, _err := s.Update("/foo", "baz", Permanent)
|
|
|
err := _err.(*etcdErr.Error)
|
|
|
assert.Equal(t, err.ErrorCode, etcdErr.EcodeNotFile, "")
|
|
|
assert.Equal(t, err.Message, "Not A File", "")
|
|
|
@@ -142,14 +139,14 @@ func TestStoreUpdateFailsIfDirectory(t *testing.T) {
|
|
|
// Ensure that the store can update the TTL on a value.
|
|
|
func TestStoreUpdateValueTTL(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- go mockSyncService(s.deleteExpiredKeys)
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- _, err := s.Update("/foo", "baz", time.Now().Add(500*time.Millisecond), 3, 1)
|
|
|
- e, _ := s.Get("/foo", false, false, 3, 1)
|
|
|
+ go mockSyncService(s.DeleteExpiredKeys)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ _, err := s.Update("/foo", "baz", time.Now().Add(500*time.Millisecond))
|
|
|
+ e, _ := s.Get("/foo", false, false)
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
|
|
|
time.Sleep(600 * time.Millisecond)
|
|
|
- e, err = s.Get("/foo", false, false, 3, 1)
|
|
|
+ e, err = s.Get("/foo", false, false)
|
|
|
assert.Nil(t, e, "")
|
|
|
assert.Equal(t, err.(*etcdErr.Error).ErrorCode, etcdErr.EcodeKeyNotFound, "")
|
|
|
}
|
|
|
@@ -157,15 +154,15 @@ func TestStoreUpdateValueTTL(t *testing.T) {
|
|
|
// Ensure that the store can update the TTL on a directory.
|
|
|
func TestStoreUpdateDirTTL(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- go mockSyncService(s.deleteExpiredKeys)
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- s.Create("/foo/bar", "baz", false, Permanent, 3, 1)
|
|
|
- _, err := s.Update("/foo", "", time.Now().Add(500*time.Millisecond), 3, 1)
|
|
|
- e, _ := s.Get("/foo/bar", false, false, 3, 1)
|
|
|
+ go mockSyncService(s.DeleteExpiredKeys)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ s.Create("/foo/bar", "baz", false, Permanent)
|
|
|
+ _, err := s.Update("/foo", "", time.Now().Add(500*time.Millisecond))
|
|
|
+ e, _ := s.Get("/foo/bar", false, false)
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
|
|
|
time.Sleep(600 * time.Millisecond)
|
|
|
- e, err = s.Get("/foo/bar", false, false, 3, 1)
|
|
|
+ e, err = s.Get("/foo/bar", false, false)
|
|
|
assert.Nil(t, e, "")
|
|
|
assert.Equal(t, err.(*etcdErr.Error).ErrorCode, etcdErr.EcodeKeyNotFound, "")
|
|
|
}
|
|
|
@@ -173,8 +170,8 @@ func TestStoreUpdateDirTTL(t *testing.T) {
|
|
|
// Ensure that the store can delete a value.
|
|
|
func TestStoreDeleteValue(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- e, err := s.Delete("/foo", false, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ e, err := s.Delete("/foo", false)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "delete", "")
|
|
|
}
|
|
|
@@ -182,8 +179,8 @@ func TestStoreDeleteValue(t *testing.T) {
|
|
|
// Ensure that the store can delete a directory if recursive is specified.
|
|
|
func TestStoreDeleteDiretory(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- e, err := s.Delete("/foo", true, 3, 1)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ e, err := s.Delete("/foo", true)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "delete", "")
|
|
|
}
|
|
|
@@ -191,8 +188,8 @@ func TestStoreDeleteDiretory(t *testing.T) {
|
|
|
// Ensure that the store cannot delete a directory if recursive is not specified.
|
|
|
func TestStoreDeleteDiretoryFailsIfNonRecursive(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- e, _err := s.Delete("/foo", false, 3, 1)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ e, _err := s.Delete("/foo", false)
|
|
|
err := _err.(*etcdErr.Error)
|
|
|
assert.Equal(t, err.ErrorCode, etcdErr.EcodeNotFile, "")
|
|
|
assert.Equal(t, err.Message, "Not A File", "")
|
|
|
@@ -202,60 +199,60 @@ func TestStoreDeleteDiretoryFailsIfNonRecursive(t *testing.T) {
|
|
|
// Ensure that the store can conditionally update a key if it has a previous value.
|
|
|
func TestStoreCompareAndSwapPrevValue(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- e, err := s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ e, err := s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "compareAndSwap", "")
|
|
|
assert.Equal(t, e.PrevValue, "bar", "")
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
- e, _ = s.Get("/foo", false, false, 3, 1)
|
|
|
+ e, _ = s.Get("/foo", false, false)
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
}
|
|
|
|
|
|
// Ensure that the store cannot conditionally update a key if it has the wrong previous value.
|
|
|
func TestStoreCompareAndSwapPrevValueFailsIfNotMatch(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- e, _err := s.CompareAndSwap("/foo", "wrong_value", 0, "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ e, _err := s.CompareAndSwap("/foo", "wrong_value", 0, "baz", Permanent)
|
|
|
err := _err.(*etcdErr.Error)
|
|
|
assert.Equal(t, err.ErrorCode, etcdErr.EcodeTestFailed, "")
|
|
|
assert.Equal(t, err.Message, "Test Failed", "")
|
|
|
assert.Nil(t, e, "")
|
|
|
- e, _ = s.Get("/foo", false, false, 3, 1)
|
|
|
+ e, _ = s.Get("/foo", false, false)
|
|
|
assert.Equal(t, e.Value, "bar", "")
|
|
|
}
|
|
|
|
|
|
// Ensure that the store can conditionally update a key if it has a previous index.
|
|
|
func TestStoreCompareAndSwapPrevIndex(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- e, err := s.CompareAndSwap("/foo", "", 2, "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ e, err := s.CompareAndSwap("/foo", "", 1, "baz", Permanent)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Action, "compareAndSwap", "")
|
|
|
assert.Equal(t, e.PrevValue, "bar", "")
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
- e, _ = s.Get("/foo", false, false, 3, 1)
|
|
|
+ e, _ = s.Get("/foo", false, false)
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
}
|
|
|
|
|
|
// Ensure that the store cannot conditionally update a key if it has the wrong previous index.
|
|
|
func TestStoreCompareAndSwapPrevIndexFailsIfNotMatch(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- e, _err := s.CompareAndSwap("/foo", "", 100, "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ e, _err := s.CompareAndSwap("/foo", "", 100, "baz", Permanent)
|
|
|
err := _err.(*etcdErr.Error)
|
|
|
assert.Equal(t, err.ErrorCode, etcdErr.EcodeTestFailed, "")
|
|
|
assert.Equal(t, err.Message, "Test Failed", "")
|
|
|
assert.Nil(t, e, "")
|
|
|
- e, _ = s.Get("/foo", false, false, 3, 1)
|
|
|
+ e, _ = s.Get("/foo", false, false)
|
|
|
assert.Equal(t, e.Value, "bar", "")
|
|
|
}
|
|
|
|
|
|
// Ensure that the store can watch for key creation.
|
|
|
func TestStoreWatchCreate(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- c, _ := s.Watch("/foo", false, 0, 0, 1)
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
+ c, _ := s.Watch("/foo", false, 0)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
e := nbselect(c)
|
|
|
assert.Equal(t, e.Action, "create", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -266,8 +263,8 @@ func TestStoreWatchCreate(t *testing.T) {
|
|
|
// Ensure that the store can watch for recursive key creation.
|
|
|
func TestStoreWatchRecursiveCreate(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- c, _ := s.Watch("/foo", true, 0, 0, 1)
|
|
|
- s.Create("/foo/bar", "baz", false, Permanent, 2, 1)
|
|
|
+ c, _ := s.Watch("/foo", true, 0)
|
|
|
+ s.Create("/foo/bar", "baz", false, Permanent)
|
|
|
e := nbselect(c)
|
|
|
assert.Equal(t, e.Action, "create", "")
|
|
|
assert.Equal(t, e.Key, "/foo/bar", "")
|
|
|
@@ -276,9 +273,9 @@ func TestStoreWatchRecursiveCreate(t *testing.T) {
|
|
|
// Ensure that the store can watch for key updates.
|
|
|
func TestStoreWatchUpdate(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- c, _ := s.Watch("/foo", false, 0, 0, 1)
|
|
|
- s.Update("/foo", "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ c, _ := s.Watch("/foo", false, 0)
|
|
|
+ s.Update("/foo", "baz", Permanent)
|
|
|
e := nbselect(c)
|
|
|
assert.Equal(t, e.Action, "update", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -287,9 +284,9 @@ func TestStoreWatchUpdate(t *testing.T) {
|
|
|
// Ensure that the store can watch for recursive key updates.
|
|
|
func TestStoreWatchRecursiveUpdate(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo/bar", "baz", false, Permanent, 2, 1)
|
|
|
- c, _ := s.Watch("/foo", true, 0, 0, 1)
|
|
|
- s.Update("/foo/bar", "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo/bar", "baz", false, Permanent)
|
|
|
+ c, _ := s.Watch("/foo", true, 0)
|
|
|
+ s.Update("/foo/bar", "baz", Permanent)
|
|
|
e := nbselect(c)
|
|
|
assert.Equal(t, e.Action, "update", "")
|
|
|
assert.Equal(t, e.Key, "/foo/bar", "")
|
|
|
@@ -298,9 +295,9 @@ func TestStoreWatchRecursiveUpdate(t *testing.T) {
|
|
|
// Ensure that the store can watch for key deletions.
|
|
|
func TestStoreWatchDelete(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- c, _ := s.Watch("/foo", false, 0, 0, 1)
|
|
|
- s.Delete("/foo", false, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ c, _ := s.Watch("/foo", false, 0)
|
|
|
+ s.Delete("/foo", false)
|
|
|
e := nbselect(c)
|
|
|
assert.Equal(t, e.Action, "delete", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -309,9 +306,9 @@ func TestStoreWatchDelete(t *testing.T) {
|
|
|
// Ensure that the store can watch for recursive key deletions.
|
|
|
func TestStoreWatchRecursiveDelete(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo/bar", "baz", false, Permanent, 2, 1)
|
|
|
- c, _ := s.Watch("/foo", true, 0, 0, 1)
|
|
|
- s.Delete("/foo/bar", false, 3, 1)
|
|
|
+ s.Create("/foo/bar", "baz", false, Permanent)
|
|
|
+ c, _ := s.Watch("/foo", true, 0)
|
|
|
+ s.Delete("/foo/bar", false)
|
|
|
e := nbselect(c)
|
|
|
assert.Equal(t, e.Action, "delete", "")
|
|
|
assert.Equal(t, e.Key, "/foo/bar", "")
|
|
|
@@ -320,9 +317,9 @@ func TestStoreWatchRecursiveDelete(t *testing.T) {
|
|
|
// Ensure that the store can watch for CAS updates.
|
|
|
func TestStoreWatchCompareAndSwap(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "bar", false, Permanent, 2, 1)
|
|
|
- c, _ := s.Watch("/foo", false, 0, 0, 1)
|
|
|
- s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent, 3, 1)
|
|
|
+ s.Create("/foo", "bar", false, Permanent)
|
|
|
+ c, _ := s.Watch("/foo", false, 0)
|
|
|
+ s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
|
|
|
e := nbselect(c)
|
|
|
assert.Equal(t, e.Action, "compareAndSwap", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
@@ -331,9 +328,9 @@ func TestStoreWatchCompareAndSwap(t *testing.T) {
|
|
|
// Ensure that the store can watch for recursive CAS updates.
|
|
|
func TestStoreWatchRecursiveCompareAndSwap(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo/bar", "baz", false, Permanent, 2, 1)
|
|
|
- c, _ := s.Watch("/foo", true, 0, 0, 1)
|
|
|
- s.CompareAndSwap("/foo/bar", "baz", 0, "bat", Permanent, 3, 1)
|
|
|
+ s.Create("/foo/bar", "baz", false, Permanent)
|
|
|
+ c, _ := s.Watch("/foo", true, 0)
|
|
|
+ s.CompareAndSwap("/foo/bar", "baz", 0, "bat", Permanent)
|
|
|
e := nbselect(c)
|
|
|
assert.Equal(t, e.Action, "compareAndSwap", "")
|
|
|
assert.Equal(t, e.Key, "/foo/bar", "")
|
|
|
@@ -342,17 +339,18 @@ func TestStoreWatchRecursiveCompareAndSwap(t *testing.T) {
|
|
|
// Ensure that the store can watch for key expiration.
|
|
|
func TestStoreWatchExpire(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- go mockSyncService(s.deleteExpiredKeys)
|
|
|
- s.Create("/foo", "bar", false, time.Now().Add(500*time.Millisecond), 2, 1)
|
|
|
- s.Create("/foofoo", "barbarbar", false, time.Now().Add(500*time.Millisecond), 2, 1)
|
|
|
+ go mockSyncService(s.DeleteExpiredKeys)
|
|
|
+ s.Create("/foo", "bar", false, time.Now().Add(500*time.Millisecond))
|
|
|
+ s.Create("/foofoo", "barbarbar", false, time.Now().Add(500*time.Millisecond))
|
|
|
|
|
|
- c, _ := s.Watch("/", true, 0, 0, 1)
|
|
|
+ c, _ := s.Watch("/", true, 0)
|
|
|
e := nbselect(c)
|
|
|
assert.Nil(t, e, "")
|
|
|
time.Sleep(600 * time.Millisecond)
|
|
|
e = nbselect(c)
|
|
|
assert.Equal(t, e.Action, "expire", "")
|
|
|
assert.Equal(t, e.Key, "/foo", "")
|
|
|
+ c, _ = s.Watch("/", true, 4)
|
|
|
e = nbselect(c)
|
|
|
assert.Equal(t, e.Action, "expire", "")
|
|
|
assert.Equal(t, e.Key, "/foofoo", "")
|
|
|
@@ -361,19 +359,19 @@ func TestStoreWatchExpire(t *testing.T) {
|
|
|
// Ensure that the store can recover from a previously saved state.
|
|
|
func TestStoreRecover(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- s.Create("/foo/x", "bar", false, Permanent, 3, 1)
|
|
|
- s.Create("/foo/y", "baz", false, Permanent, 4, 1)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ s.Create("/foo/x", "bar", false, Permanent)
|
|
|
+ s.Create("/foo/y", "baz", false, Permanent)
|
|
|
b, err := s.Save()
|
|
|
|
|
|
s2 := newStore()
|
|
|
s2.Recovery(b)
|
|
|
|
|
|
- e, err := s.Get("/foo/x", false, false, 4, 1)
|
|
|
+ e, err := s.Get("/foo/x", false, false)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Value, "bar", "")
|
|
|
|
|
|
- e, err = s.Get("/foo/y", false, false, 4, 1)
|
|
|
+ e, err = s.Get("/foo/y", false, false)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Value, "baz", "")
|
|
|
}
|
|
|
@@ -381,25 +379,25 @@ func TestStoreRecover(t *testing.T) {
|
|
|
// Ensure that the store can recover from a previously saved state that includes an expiring key.
|
|
|
func TestStoreRecoverWithExpiration(t *testing.T) {
|
|
|
s := newStore()
|
|
|
- go mockSyncService(s.deleteExpiredKeys)
|
|
|
- s.Create("/foo", "", false, Permanent, 2, 1)
|
|
|
- s.Create("/foo/x", "bar", false, Permanent, 3, 1)
|
|
|
- s.Create("/foo/y", "baz", false, time.Now().Add(5*time.Millisecond), 4, 1)
|
|
|
+ go mockSyncService(s.DeleteExpiredKeys)
|
|
|
+ s.Create("/foo", "", false, Permanent)
|
|
|
+ s.Create("/foo/x", "bar", false, Permanent)
|
|
|
+ s.Create("/foo/y", "baz", false, time.Now().Add(5*time.Millisecond))
|
|
|
b, err := s.Save()
|
|
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
|
s2 := newStore()
|
|
|
- go mockSyncService(s2.deleteExpiredKeys)
|
|
|
+ go mockSyncService(s2.DeleteExpiredKeys)
|
|
|
s2.Recovery(b)
|
|
|
|
|
|
time.Sleep(600 * time.Millisecond)
|
|
|
|
|
|
- e, err := s.Get("/foo/x", false, false, 4, 1)
|
|
|
+ e, err := s.Get("/foo/x", false, false)
|
|
|
assert.Nil(t, err, "")
|
|
|
assert.Equal(t, e.Value, "bar", "")
|
|
|
|
|
|
- e, err = s.Get("/foo/y", false, false, 4, 1)
|
|
|
+ e, err = s.Get("/foo/y", false, false)
|
|
|
assert.NotNil(t, err, "")
|
|
|
assert.Nil(t, e, "")
|
|
|
}
|
|
|
@@ -414,9 +412,9 @@ func nbselect(c <-chan *Event) *Event {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func mockSyncService(f func(now time.Time, index uint64, term uint64)) {
|
|
|
+func mockSyncService(f func(now time.Time)) {
|
|
|
ticker := time.Tick(time.Millisecond * 500)
|
|
|
for now := range ticker {
|
|
|
- f(now, 2, 1)
|
|
|
+ f(now)
|
|
|
}
|
|
|
}
|