Skip to content

Commit

Permalink
createTTL's ttl use time.Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
einxie authored and pmazzini committed Jun 11, 2020
1 parent 14d65b8 commit 252464f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,7 @@ func (c *Conn) CreateContainer(path string, data []byte, flags int32, acl []ACL)
return res.Path, err
}

// ttl: ms
func (c *Conn) CreateTTL(path string, data []byte, flags int32, acl []ACL, ttl int64) (string, error) {
func (c *Conn) CreateTTL(path string, data []byte, flags int32, acl []ACL, ttl time.Duration) (string, error) {
if err := validatePath(path, flags&FlagSequence == FlagSequence); err != nil {
return "", err
}
Expand All @@ -1078,7 +1077,7 @@ func (c *Conn) CreateTTL(path string, data []byte, flags int32, acl []ACL, ttl i
}

res := &createResponse{}
_, err := c.request(opCreateTTL, &CreateTTLRequest{path, data, acl, flags, ttl}, res, nil)
_, err := c.request(opCreateTTL, &CreateTTLRequest{path, data, acl, flags, ttl.Nanoseconds() / 1e6}, res, nil)
return res.Path, err
}

Expand Down
8 changes: 4 additions & 4 deletions zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ func TestCreateTTL(t *testing.T) {
if err := zk.Delete(path, -1); err != nil && err != ErrNoNode {
t.Fatalf("Delete returned error: %+v", err)
}
if _, err := zk.CreateTTL("", []byte{1, 2, 3, 4}, FlagTTL|FlagEphemeral, WorldACL(PermAll), 60*1000); err != ErrInvalidPath {
if _, err := zk.CreateTTL("", []byte{1, 2, 3, 4}, FlagTTL|FlagEphemeral, WorldACL(PermAll), 60*time.Second); err != ErrInvalidPath {
t.Fatalf("Create path check failed")
}
if _, err := zk.CreateTTL(path, []byte{1, 2, 3, 4}, 0, WorldACL(PermAll), 60*1000); err != ErrInvalidFlags {
if _, err := zk.CreateTTL(path, []byte{1, 2, 3, 4}, 0, WorldACL(PermAll), 60*time.Second); err != ErrInvalidFlags {
t.Fatalf("Create flags check failed")
}
if p, err := zk.CreateTTL(path, []byte{1, 2, 3, 4}, FlagTTL|FlagEphemeral, WorldACL(PermAll), 60*1000); err != nil {
if p, err := zk.CreateTTL(path, []byte{1, 2, 3, 4}, FlagTTL|FlagEphemeral, WorldACL(PermAll), 60*time.Second); err != nil {
t.Fatalf("Create returned error: %+v", err)
} else if p != path {
t.Fatalf("Create returned different path '%s' != '%s'", p, path)
Expand All @@ -136,7 +136,7 @@ func TestCreateTTL(t *testing.T) {
if err := zk.Delete(path, -1); err != nil && err != ErrNoNode {
t.Fatalf("Delete returned error: %+v", err)
}
if p, err := zk.CreateTTL(path, []byte{1, 2, 3, 4}, FlagTTL|FlagSequence, WorldACL(PermAll), 60*1000); err != nil {
if p, err := zk.CreateTTL(path, []byte{1, 2, 3, 4}, FlagTTL|FlagSequence, WorldACL(PermAll), 60*time.Second); err != nil {
t.Fatalf("Create returned error: %+v", err)
} else if !strings.HasPrefix(p, path) {
t.Fatalf("Create returned invalid path '%s' are not '%s' with sequence", p, path)
Expand Down

0 comments on commit 252464f

Please sign in to comment.