|
@@ -10,10 +10,10 @@ import (
|
|
|
func TestCreateAndGet(t *testing.T) {
|
|
func TestCreateAndGet(t *testing.T) {
|
|
|
s := New()
|
|
s := New()
|
|
|
|
|
|
|
|
- s.Create("/foobar", "bar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foobar", "bar", false, Permanent, 1, 1)
|
|
|
|
|
|
|
|
// already exist, create should fail
|
|
// already exist, create should fail
|
|
|
- _, err := s.Create("/foobar", "bar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ _, err := s.Create("/foobar", "bar", false, Permanent, 1, 1)
|
|
|
|
|
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
t.Fatal("Create should fail")
|
|
t.Fatal("Create should fail")
|
|
@@ -27,14 +27,14 @@ func TestCreateAndGet(t *testing.T) {
|
|
|
createAndGet(s, "/foo/foo/bar", t)
|
|
createAndGet(s, "/foo/foo/bar", t)
|
|
|
|
|
|
|
|
// meet file, create should fail
|
|
// meet file, create should fail
|
|
|
- _, err = s.Create("/foo/bar/bar", "bar", Permanent, 2, 1)
|
|
|
|
|
|
|
+ _, err = s.Create("/foo/bar/bar", "bar", false, Permanent, 2, 1)
|
|
|
|
|
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
t.Fatal("Create should fail")
|
|
t.Fatal("Create should fail")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// create a directory
|
|
// create a directory
|
|
|
- _, err = s.Create("/fooDir", "", Permanent, 3, 1)
|
|
|
|
|
|
|
+ _, err = s.Create("/fooDir", "", false, Permanent, 3, 1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal("Cannot create /fooDir")
|
|
t.Fatal("Cannot create /fooDir")
|
|
@@ -47,7 +47,7 @@ func TestCreateAndGet(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// create a file under directory
|
|
// create a file under directory
|
|
|
- _, err = s.Create("/fooDir/bar", "bar", Permanent, 4, 1)
|
|
|
|
|
|
|
+ _, err = s.Create("/fooDir/bar", "bar", false, Permanent, 4, 1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal("Cannot create /fooDir/bar = bar")
|
|
t.Fatal("Cannot create /fooDir/bar = bar")
|
|
@@ -57,7 +57,7 @@ func TestCreateAndGet(t *testing.T) {
|
|
|
func TestUpdateFile(t *testing.T) {
|
|
func TestUpdateFile(t *testing.T) {
|
|
|
s := New()
|
|
s := New()
|
|
|
|
|
|
|
|
- _, err := s.Create("/foo/bar", "bar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ _, err := s.Create("/foo/bar", "bar", false, Permanent, 1, 1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("cannot create %s=bar [%s]", "/foo/bar", err.Error())
|
|
t.Fatalf("cannot create %s=bar [%s]", "/foo/bar", err.Error())
|
|
@@ -80,24 +80,24 @@ func TestUpdateFile(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// create a directory, update its ttl, to see if it will be deleted
|
|
// create a directory, update its ttl, to see if it will be deleted
|
|
|
- _, err = s.Create("/foo/foo", "", Permanent, 3, 1)
|
|
|
|
|
|
|
+ _, err = s.Create("/foo/foo", "", false, Permanent, 3, 1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("cannot create dir [%s] [%s]", "/foo/foo", err.Error())
|
|
t.Fatalf("cannot create dir [%s] [%s]", "/foo/foo", err.Error())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _, err = s.Create("/foo/foo/foo1", "bar1", Permanent, 4, 1)
|
|
|
|
|
|
|
+ _, err = s.Create("/foo/foo/foo1", "bar1", false, Permanent, 4, 1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal("cannot create [%s]", err.Error())
|
|
t.Fatal("cannot create [%s]", err.Error())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _, err = s.Create("/foo/foo/foo2", "", Permanent, 5, 1)
|
|
|
|
|
|
|
+ _, err = s.Create("/foo/foo/foo2", "", false, Permanent, 5, 1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal("cannot create [%s]", err.Error())
|
|
t.Fatal("cannot create [%s]", err.Error())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _, err = s.Create("/foo/foo/foo2/boo", "boo1", Permanent, 6, 1)
|
|
|
|
|
|
|
+ _, err = s.Create("/foo/foo/foo2/boo", "boo1", false, Permanent, 6, 1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal("cannot create [%s]", err.Error())
|
|
t.Fatal("cannot create [%s]", err.Error())
|
|
|
}
|
|
}
|
|
@@ -158,11 +158,11 @@ func TestListDirectory(t *testing.T) {
|
|
|
|
|
|
|
|
// create dir /foo
|
|
// create dir /foo
|
|
|
// set key-value /foo/foo=bar
|
|
// set key-value /foo/foo=bar
|
|
|
- s.Create("/foo/foo", "bar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/foo", "bar", false, Permanent, 1, 1)
|
|
|
|
|
|
|
|
// create dir /foo/fooDir
|
|
// create dir /foo/fooDir
|
|
|
// set key-value /foo/fooDir/foo=bar
|
|
// set key-value /foo/fooDir/foo=bar
|
|
|
- s.Create("/foo/fooDir/foo", "bar", Permanent, 2, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/fooDir/foo", "bar", false, Permanent, 2, 1)
|
|
|
|
|
|
|
|
e, err := s.Get("/foo", true, false, 2, 1)
|
|
e, err := s.Get("/foo", true, false, 2, 1)
|
|
|
|
|
|
|
@@ -189,7 +189,7 @@ func TestListDirectory(t *testing.T) {
|
|
|
|
|
|
|
|
// create dir /foo/_hidden
|
|
// create dir /foo/_hidden
|
|
|
// set key-value /foo/_hidden/foo -> bar
|
|
// set key-value /foo/_hidden/foo -> bar
|
|
|
- s.Create("/foo/_hidden/foo", "bar", Permanent, 3, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/_hidden/foo", "bar", false, Permanent, 3, 1)
|
|
|
|
|
|
|
|
e, _ = s.Get("/foo", false, false, 2, 1)
|
|
e, _ = s.Get("/foo", false, false, 2, 1)
|
|
|
|
|
|
|
@@ -201,7 +201,7 @@ func TestListDirectory(t *testing.T) {
|
|
|
func TestRemove(t *testing.T) {
|
|
func TestRemove(t *testing.T) {
|
|
|
s := New()
|
|
s := New()
|
|
|
|
|
|
|
|
- s.Create("/foo", "bar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo", "bar", false, Permanent, 1, 1)
|
|
|
_, err := s.Delete("/foo", false, 1, 1)
|
|
_, err := s.Delete("/foo", false, 1, 1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -214,9 +214,9 @@ func TestRemove(t *testing.T) {
|
|
|
t.Fatalf("can get the node after deletion")
|
|
t.Fatalf("can get the node after deletion")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- s.Create("/foo/bar", "bar", Permanent, 1, 1)
|
|
|
|
|
- s.Create("/foo/car", "car", Permanent, 1, 1)
|
|
|
|
|
- s.Create("/foo/dar/dar", "dar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/bar", "bar", false, Permanent, 1, 1)
|
|
|
|
|
+ s.Create("/foo/car", "car", false, Permanent, 1, 1)
|
|
|
|
|
+ s.Create("/foo/dar/dar", "dar", false, Permanent, 1, 1)
|
|
|
|
|
|
|
|
_, err = s.Delete("/foo", false, 1, 1)
|
|
_, err = s.Delete("/foo", false, 1, 1)
|
|
|
|
|
|
|
@@ -242,7 +242,7 @@ func TestExpire(t *testing.T) {
|
|
|
|
|
|
|
|
expire := time.Now().Add(time.Second)
|
|
expire := time.Now().Add(time.Second)
|
|
|
|
|
|
|
|
- s.Create("/foo", "bar", expire, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo", "bar", false, expire, 1, 1)
|
|
|
|
|
|
|
|
_, err := s.Get("/foo", false, false, 1, 1)
|
|
_, err := s.Get("/foo", false, false, 1, 1)
|
|
|
|
|
|
|
@@ -260,7 +260,7 @@ func TestExpire(t *testing.T) {
|
|
|
|
|
|
|
|
// test if we can reach the node before expiration
|
|
// test if we can reach the node before expiration
|
|
|
expire = time.Now().Add(time.Second)
|
|
expire = time.Now().Add(time.Second)
|
|
|
- s.Create("/foo", "bar", expire, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo", "bar", false, expire, 1, 1)
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 50)
|
|
time.Sleep(time.Millisecond * 50)
|
|
|
_, err = s.Get("/foo", false, false, 1, 1)
|
|
_, err = s.Get("/foo", false, false, 1, 1)
|
|
@@ -271,7 +271,7 @@ func TestExpire(t *testing.T) {
|
|
|
|
|
|
|
|
expire = time.Now().Add(time.Second)
|
|
expire = time.Now().Add(time.Second)
|
|
|
|
|
|
|
|
- s.Create("/foo", "bar", expire, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo", "bar", false, expire, 1, 1)
|
|
|
_, err = s.Delete("/foo", false, 1, 1)
|
|
_, err = s.Delete("/foo", false, 1, 1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -281,7 +281,7 @@ func TestExpire(t *testing.T) {
|
|
|
|
|
|
|
|
func TestTestAndSet(t *testing.T) { // TODO prevValue == nil ?
|
|
func TestTestAndSet(t *testing.T) { // TODO prevValue == nil ?
|
|
|
s := New()
|
|
s := New()
|
|
|
- s.Create("/foo", "bar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo", "bar", false, Permanent, 1, 1)
|
|
|
|
|
|
|
|
// test on wrong previous value
|
|
// test on wrong previous value
|
|
|
_, err := s.TestAndSet("/foo", "barbar", 0, "car", Permanent, 2, 1)
|
|
_, err := s.TestAndSet("/foo", "barbar", 0, "car", Permanent, 2, 1)
|
|
@@ -316,7 +316,7 @@ func TestWatch(t *testing.T) {
|
|
|
s := New()
|
|
s := New()
|
|
|
// watch at a deeper path
|
|
// watch at a deeper path
|
|
|
c, _ := s.Watch("/foo/foo/foo", false, 0, 0, 1)
|
|
c, _ := s.Watch("/foo/foo/foo", false, 0, 0, 1)
|
|
|
- s.Create("/foo/foo/foo", "bar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/foo/foo", "bar", false, Permanent, 1, 1)
|
|
|
|
|
|
|
|
e := nonblockingRetrive(c)
|
|
e := nonblockingRetrive(c)
|
|
|
if e.Key != "/foo/foo/foo" || e.Action != Create {
|
|
if e.Key != "/foo/foo/foo" || e.Action != Create {
|
|
@@ -346,7 +346,7 @@ func TestWatch(t *testing.T) {
|
|
|
|
|
|
|
|
// watch at a prefix
|
|
// watch at a prefix
|
|
|
c, _ = s.Watch("/foo", true, 0, 4, 1)
|
|
c, _ = s.Watch("/foo", true, 0, 4, 1)
|
|
|
- s.Create("/foo/foo/boo", "bar", Permanent, 5, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/foo/boo", "bar", false, Permanent, 5, 1)
|
|
|
e = nonblockingRetrive(c)
|
|
e = nonblockingRetrive(c)
|
|
|
if e.Key != "/foo/foo/boo" || e.Action != Create {
|
|
if e.Key != "/foo/foo/boo" || e.Action != Create {
|
|
|
t.Fatal("watch for Create subdirectory fails")
|
|
t.Fatal("watch for Create subdirectory fails")
|
|
@@ -374,7 +374,7 @@ func TestWatch(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// watch expire
|
|
// watch expire
|
|
|
- s.Create("/foo/foo/boo", "foo", time.Now().Add(time.Second*1), 9, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/foo/boo", "foo", false, time.Now().Add(time.Second*1), 9, 1)
|
|
|
c, _ = s.Watch("/foo", true, 0, 9, 1)
|
|
c, _ = s.Watch("/foo", true, 0, 9, 1)
|
|
|
time.Sleep(time.Second * 2)
|
|
time.Sleep(time.Second * 2)
|
|
|
e = nonblockingRetrive(c)
|
|
e = nonblockingRetrive(c)
|
|
@@ -382,7 +382,7 @@ func TestWatch(t *testing.T) {
|
|
|
t.Fatal("watch for Expiration of Create() subdirectory fails ", e)
|
|
t.Fatal("watch for Expiration of Create() subdirectory fails ", e)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- s.Create("/foo/foo/boo", "foo", Permanent, 10, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/foo/boo", "foo", false, Permanent, 10, 1)
|
|
|
s.Update("/foo/foo/boo", "bar", time.Now().Add(time.Second*1), 11, 1)
|
|
s.Update("/foo/foo/boo", "bar", time.Now().Add(time.Second*1), 11, 1)
|
|
|
c, _ = s.Watch("/foo", true, 0, 11, 1)
|
|
c, _ = s.Watch("/foo", true, 0, 11, 1)
|
|
|
time.Sleep(time.Second * 2)
|
|
time.Sleep(time.Second * 2)
|
|
@@ -391,7 +391,7 @@ func TestWatch(t *testing.T) {
|
|
|
t.Fatal("watch for Expiration of Update() subdirectory fails ", e)
|
|
t.Fatal("watch for Expiration of Update() subdirectory fails ", e)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- s.Create("/foo/foo/boo", "foo", Permanent, 12, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/foo/boo", "foo", false, Permanent, 12, 1)
|
|
|
s.TestAndSet("/foo/foo/boo", "foo", 0, "bar", time.Now().Add(time.Second*1), 13, 1)
|
|
s.TestAndSet("/foo/foo/boo", "foo", 0, "bar", time.Now().Add(time.Second*1), 13, 1)
|
|
|
c, _ = s.Watch("/foo", true, 0, 13, 1)
|
|
c, _ = s.Watch("/foo", true, 0, 13, 1)
|
|
|
time.Sleep(time.Second * 2)
|
|
time.Sleep(time.Second * 2)
|
|
@@ -409,7 +409,7 @@ func TestSort(t *testing.T) {
|
|
|
|
|
|
|
|
i := uint64(1)
|
|
i := uint64(1)
|
|
|
for _, k := range keys {
|
|
for _, k := range keys {
|
|
|
- _, err := s.Create(k, "bar", Permanent, i, 1)
|
|
|
|
|
|
|
+ _, err := s.Create(k, "bar", false, Permanent, i, 1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
panic(err)
|
|
panic(err)
|
|
|
} else {
|
|
} else {
|
|
@@ -447,7 +447,7 @@ func TestSaveAndRecover(t *testing.T) {
|
|
|
|
|
|
|
|
i := uint64(1)
|
|
i := uint64(1)
|
|
|
for _, k := range keys {
|
|
for _, k := range keys {
|
|
|
- _, err := s.Create(k, "bar", Permanent, i, 1)
|
|
|
|
|
|
|
+ _, err := s.Create(k, "bar", false, Permanent, i, 1)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
panic(err)
|
|
panic(err)
|
|
|
} else {
|
|
} else {
|
|
@@ -459,7 +459,7 @@ func TestSaveAndRecover(t *testing.T) {
|
|
|
// test if we can reach the node before expiration
|
|
// test if we can reach the node before expiration
|
|
|
|
|
|
|
|
expire := time.Now().Add(time.Second)
|
|
expire := time.Now().Add(time.Second)
|
|
|
- s.Create("/foo/foo", "bar", expire, 1, 1)
|
|
|
|
|
|
|
+ s.Create("/foo/foo", "bar", false, expire, 1, 1)
|
|
|
b, err := s.Save()
|
|
b, err := s.Save()
|
|
|
|
|
|
|
|
cloneFs := New()
|
|
cloneFs := New()
|
|
@@ -514,7 +514,7 @@ func GenKeys(num int, depth int) []string {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func createAndGet(s *Store, path string, t *testing.T) {
|
|
func createAndGet(s *Store, path string, t *testing.T) {
|
|
|
- _, err := s.Create(path, "bar", Permanent, 1, 1)
|
|
|
|
|
|
|
+ _, err := s.Create(path, "bar", false, Permanent, 1, 1)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatalf("cannot create %s=bar [%s]", path, err.Error())
|
|
t.Fatalf("cannot create %s=bar [%s]", path, err.Error())
|