Documentation ¶
Index ¶
- Constants
- Variables
- func EnsureZookeeperUp(scriptRelativeDirPath string) error
- func StopZookeeper(scriptRelativeDirPath string) error
- type BaseZkTestSuite
- type Client
- func (c *Client) AddWatcher(w Watcher)
- func (c *Client) Children(path string) ([]string, error)
- func (c *Client) ChildrenW(path string) ([]string, <-chan zk.Event, error)
- func (c *Client) ClearWatchers()
- func (c *Client) Connect() error
- func (c *Client) Create(path string, data []byte, flags int32, acl []zk.ACL) error
- func (c *Client) CreateDataWithPath(p string, data []byte) error
- func (c *Client) CreateEmptyNode(path string) error
- func (c *Client) Delete(path string) error
- func (c *Client) DeleteTree(path string) error
- func (c *Client) Disconnect()
- func (c *Client) Exists(path string) (bool, *zk.Stat, error)
- func (c *Client) ExistsAll(paths ...string) (bool, error)
- func (c *Client) Get(path string) ([]byte, *zk.Stat, error)
- func (c *Client) GetRecordFromPath(path string) (*model.ZNRecord, error)
- func (c *Client) GetSessionID() string
- func (c *Client) GetSimpleFieldBool(path string, key string) (bool, error)
- func (c *Client) GetSimpleFieldValueByKey(path string, key string) (string, error)
- func (c *Client) GetW(path string) ([]byte, <-chan zk.Event, error)
- func (c *Client) IsConnected() bool
- func (c *Client) RemoveMapFieldKey(path string, key string) error
- func (c *Client) Set(path string, data []byte, version int32) error
- func (c *Client) SetDataForPath(path string, data []byte, version int32) error
- func (c *Client) SetRecordForPath(path string, r *model.ZNRecord) error
- func (c *Client) SetWithDefaultVersion(path string, data []byte) error
- func (c *Client) UpdateMapField(path string, key string, property string, value string) error
- func (c *Client) UpdateSimpleField(path string, key string, value string) error
- type ClientOption
- type ConnFactory
- type Connection
- type FakeZk
- type FakeZkConn
- func (c *FakeZkConn) AddAuth(scheme string, auth []byte) error
- func (c *FakeZkConn) Children(path string) ([]string, *zk.Stat, error)
- func (c *FakeZkConn) ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error)
- func (c *FakeZkConn) Close()
- func (c *FakeZkConn) Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error)
- func (c *FakeZkConn) Delete(path string, version int32) error
- func (c *FakeZkConn) Exists(path string) (bool, *zk.Stat, error)
- func (c *FakeZkConn) ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error)
- func (c *FakeZkConn) Get(path string) ([]byte, *zk.Stat, error)
- func (c *FakeZkConn) GetHistory() *MethodCallHistory
- func (c *FakeZkConn) GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error)
- func (c *FakeZkConn) Multi(ops ...interface{}) ([]zk.MultiResponse, error)
- func (c *FakeZkConn) SessionID() int64
- func (c *FakeZkConn) Set(path string, data []byte, version int32) (*zk.Stat, error)
- func (c *FakeZkConn) SetLogger(l zk.Logger)
- func (c *FakeZkConn) State() zk.State
- type FakeZkOption
- type MethodCall
- type MethodCallHistory
- type Watcher
Constants ¶
const ( // DefaultSessionTimeout is the time for ZK server to expire client session // ZK uses 20 times tickTime, which is set to 200 ms // in existing ZK cluster to ensure proper detection // of Helix node failures DefaultSessionTimeout = 4 * time.Second // FlagsZero is the default ZK data node flag FlagsZero = int32(0) // FlagsEphemeral is the ephemeral ZK data node flag FlagsEphemeral = int32(zk.FlagEphemeral) )
const EmbeddedZkServer = "localhost:2181"
EmbeddedZkServer is the connect string for embedded ZK server
Variables ¶
var ( // ACLPermAll is the mode of ZK nodes where all users have permission to access ACLPermAll = zk.WorldACL(zk.PermAll) )
Functions ¶
func EnsureZookeeperUp ¶
EnsureZookeeperUp starts the embedded (test) Zookeeper if not running.
func StopZookeeper ¶
StopZookeeper stops the embedded (test) Zookeeper if running.
Types ¶
type BaseZkTestSuite ¶
BaseZkTestSuite provides utility to test Zookeeper functions without Helix admin
func (*BaseZkTestSuite) CreateAndConnectClient ¶
func (s *BaseZkTestSuite) CreateAndConnectClient() *Client
CreateAndConnectClient creates ZK client and connects to ZK server
func (*BaseZkTestSuite) SetupSuite ¶
func (s *BaseZkTestSuite) SetupSuite()
SetupSuite ensures ZK server is up
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps utils to communicate with ZK
func (*Client) AddWatcher ¶
AddWatcher adds a Watcher to zk session event
func (*Client) ClearWatchers ¶
func (c *Client) ClearWatchers()
ClearWatchers removes all the watchers the client has
func (*Client) CreateDataWithPath ¶
CreateDataWithPath creates a path with a string
func (*Client) CreateEmptyNode ¶
CreateEmptyNode creates an empty node for future use
func (*Client) DeleteTree ¶
DeleteTree removes ZK path and its children
func (*Client) GetRecordFromPath ¶
GetRecordFromPath returns message by ZK path
func (*Client) GetSessionID ¶
GetSessionID returns current ZK session ID
func (*Client) GetSimpleFieldBool ¶
GetSimpleFieldBool checks if value in path is "TRUE"
func (*Client) GetSimpleFieldValueByKey ¶
GetSimpleFieldValueByKey returns value in simple field by key
func (*Client) IsConnected ¶
IsConnected returns if client is connected to Zookeeper
func (*Client) RemoveMapFieldKey ¶
RemoveMapFieldKey removes a map field by key
func (*Client) SetDataForPath ¶
SetDataForPath updates data at given ZK path
func (*Client) SetRecordForPath ¶
SetRecordForPath sets a record in give ZK path
func (*Client) SetWithDefaultVersion ¶
SetWithDefaultVersion sets data with default version, -1
func (*Client) UpdateMapField ¶
UpdateMapField updates a map field for path key is the top-level key in the MapFields mapProperty is the inner key
Example:
mapFields":{
"partition_1":{ "CURRENT_STATE":"OFFLINE", "INFO":"" }
To set the CURRENT_STATE to ONLINE, use UpdateMapField(
"/CLUSTER/INSTANCES/{instance}/CURRENT_STATE/{sessionID}/{db}", "partition_1", "CURRENT_STATE", "ONLINE")
type ClientOption ¶
type ClientOption func(*Client)
ClientOption provides options or ZK client
func WithConnFactory ¶
func WithConnFactory(connFactory ConnFactory) ClientOption
WithConnFactory configures ConnFactory used to make ZK connections
func WithRetryTimeout ¶
func WithRetryTimeout(t time.Duration) ClientOption
WithRetryTimeout configures retryTimeout for ZK operations
func WithSessionTimeout ¶
func WithSessionTimeout(t time.Duration) ClientOption
WithSessionTimeout configures sessionTimeout
func WithZkSvr ¶
func WithZkSvr(zkSvr string) ClientOption
WithZkSvr configures ZK servers for the client
type ConnFactory ¶
type ConnFactory interface {
NewConn() (Connection, <-chan zk.Event, error)
}
ConnFactory provides interface that creates ZK connections
func NewConnFactory ¶
func NewConnFactory(zkServers []string, sessionTimeout time.Duration) ConnFactory
NewConnFactory creates new connFactory
type Connection ¶
type Connection interface { AddAuth(scheme string, auth []byte) error Children(path string) ([]string, *zk.Stat, error) ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error) Get(path string) ([]byte, *zk.Stat, error) GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error) Exists(path string) (bool, *zk.Stat, error) ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error) Set(path string, data []byte, version int32) (*zk.Stat, error) Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error) Delete(path string, version int32) error Multi(ops ...interface{}) ([]zk.MultiResponse, error) SessionID() int64 SetLogger(zk.Logger) State() zk.State Close() }
Connection is the thread safe interface for ZK connection
type FakeZk ¶
type FakeZk struct {
// contains filtered or unexported fields
}
FakeZk provides utility to make fake connections and manipulate connection states
func NewFakeZk ¶
func NewFakeZk(opts ...FakeZkOption) *FakeZk
NewFakeZk creates new FakeZk test utility
func (*FakeZk) GetConnections ¶
func (z *FakeZk) GetConnections() []*FakeZkConn
GetConnections returns all of the connections FakeZk has made
func (*FakeZk) GetState ¶
func (z *FakeZk) GetState(conn Connection) zk.State
GetState returns state by ZK connection
type FakeZkConn ¶
type FakeZkConn struct {
// contains filtered or unexported fields
}
FakeZkConn is a fake ZK connection for testing
func (*FakeZkConn) AddAuth ¶
func (c *FakeZkConn) AddAuth(scheme string, auth []byte) error
AddAuth addds auth info
func (*FakeZkConn) Delete ¶
func (c *FakeZkConn) Delete(path string, version int32) error
Delete deletes ZK node
func (*FakeZkConn) GetHistory ¶
func (c *FakeZkConn) GetHistory() *MethodCallHistory
GetHistory returns history
func (*FakeZkConn) Multi ¶
func (c *FakeZkConn) Multi(ops ...interface{}) ([]zk.MultiResponse, error)
Multi executes multiple ZK operations
func (*FakeZkConn) SetLogger ¶
func (c *FakeZkConn) SetLogger(l zk.Logger)
SetLogger sets loggeer for the client
type FakeZkOption ¶
type FakeZkOption func(*FakeZk)
FakeZkOption is the optional arg to create a FakeZk
func DefaultConnectionState ¶
func DefaultConnectionState(state zk.State) FakeZkOption
DefaultConnectionState sets the default state when a fake connection is made
type MethodCall ¶
type MethodCall struct { MethodName string Params []interface{} }
MethodCall represents a call record
type MethodCallHistory ¶
MethodCallHistory represents the history of the method called on the connection
func (*MethodCallHistory) GetHistory ¶
func (h *MethodCallHistory) GetHistory() []*MethodCall
GetHistory returns all of the histories
func (*MethodCallHistory) GetHistoryForMethod ¶
func (h *MethodCallHistory) GetHistoryForMethod(method string) []*MethodCall
GetHistoryForMethod returns all of the histories of a method