test

package
v0.0.0-...-a660477 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2017 License: MIT, MIT Imports: 13 Imported by: 0

README

test

Managed ZooKeeper cluster with YAML as a data filling language for testing with ZooKeeper.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachNode

func ForEachNode(fullPath string, node ZNode, do func(fullPath string, n ZNode) error) error

ForEachNode calls do with all children nodes and itself.

func UnmarshalYAML

func UnmarshalYAML(yml []byte) (map[string]ZNode, error)

UnmarshalYAML parses bytes into a map of ZNodes.

Types

type ClientGetter

type ClientGetter interface {
	Client() *enhanced.Client
}

ClientGetter represents a getter of *enhanced.Client.

type ClusterGetter

type ClusterGetter interface {
	Zk() *ZkCluster
}

ClusterGetter represents a getter of *ZkCluster.

type ClusterOperation

type ClusterOperation struct {
	ClusterGetter
	// contains filtered or unexported fields
}

ClusterOperation does CUD operations of ZkCluster with NoError assertion.

func (*ClusterOperation) MustCreate

func (o *ClusterOperation) MustCreate(yml string)

MustCreate calls DoCreate on inner ZkCluster with NoError assertion.

func (*ClusterOperation) MustDelete

func (o *ClusterOperation) MustDelete(yml string)

MustDelete calls DoDelete on inner ZkCluster with NoError assertion.

func (*ClusterOperation) MustUpdate

func (o *ClusterOperation) MustUpdate(yml string)

MustUpdate calls DoUpdate on inner ZkCluster with NoError assertion.

type NodeAction

type NodeAction struct {
	// contains filtered or unexported fields
}

NodeAction contains NodeActionFunc(s) that are used while traversing a tree.

func StartNewNodeAction

func StartNewNodeAction(c *ZkCluster) (*NodeAction, error)

StartNewNodeAction create then starts NodeAction on given ZkCluster.

func (*NodeAction) DoCreate

func (a *NodeAction) DoCreate(fullPath string, node ZNode) error

DoCreate is a NodeActionFunc which creates a ZNode with its parents.

func (*NodeAction) DoDelete

func (a *NodeAction) DoDelete(fullPath string, node ZNode) error

DoDelete is a NodeActionFunc which deletes a ZNode with its children.

func (*NodeAction) DoUpdate

func (a *NodeAction) DoUpdate(fullPath string, node ZNode) error

DoUpdate is DoCreate with ErrNodeExists ignored.

func (*NodeAction) Stop

func (a *NodeAction) Stop()

Stop stops NodeAction.

type NodeActionFunc

type NodeActionFunc func(fullPath string, node ZNode) error

NodeActionFunc represents an action to a ZNode.

type ZNode

type ZNode struct {
	Value    *string          `yaml:"value,omitempty"`
	Children map[string]ZNode `yaml:"children,omitempty"`
}

ZNode represents a ZooKeeper znode in YAML.

func (*ZNode) HasValue

func (n *ZNode) HasValue() bool

HasValue returns true if Value is not empty.

func (*ZNode) IsLeaf

func (n *ZNode) IsLeaf() bool

IsLeaf returns true if it has no children.

type ZNodeAssertion

type ZNodeAssertion struct {
	ClientGetter
	// contains filtered or unexported fields
}

ZNodeAssertion contains helpers of ZNode assertion.

func (*ZNodeAssertion) AssertNoZNode

func (a *ZNodeAssertion) AssertNoZNode(pathes ...string)

AssertNoZNode asserts given ZNodes do not exist.

func (*ZNodeAssertion) AssertZNode

func (a *ZNodeAssertion) AssertZNode(pathes ...string)

AssertZNode asserts given ZNodes exist.

func (*ZNodeAssertion) AssertZNodeWithValue

func (a *ZNodeAssertion) AssertZNodeWithValue(path, value string)

AssertZNodeWithValue asserts a ZNode with given value.

type ZkCluster

type ZkCluster struct {
	*zk.TestCluster
	// contains filtered or unexported fields
}

ZkCluster is a managed ZooKeeper cluster for testing purpose.

func StartZkCluster

func StartZkCluster(size int, stdout, stderr io.Writer) (*ZkCluster, error)

StartZkCluster starts a managed ZooKeeper with given size of nodes.

func (*ZkCluster) Connect

func (c *ZkCluster) Connect(idx int) (*enhanced.Client, error)

Connect starts a client to a single server at given index.

func (*ZkCluster) ConnectAll

func (c *ZkCluster) ConnectAll() (*enhanced.Client, error)

ConnectAll starts a client to all servers.

func (*ZkCluster) ConnectionString

func (c *ZkCluster) ConnectionString() string

ConnectionString returns connection string like: 127.0.0.1:21810,127.0.0.1:21811

func (*ZkCluster) DoCreate

func (c *ZkCluster) DoCreate(yml []byte) error

DoCreate creates znodes specified by given YAML.

func (*ZkCluster) DoDelete

func (c *ZkCluster) DoDelete(yml []byte) error

DoDelete deletes znodes specified by given YAML.

func (*ZkCluster) DoUpdate

func (c *ZkCluster) DoUpdate(yml []byte) error

DoUpdate is DoCreate with ErrNodeExists ignored.

func (*ZkCluster) Stop

func (c *ZkCluster) Stop() error

Stop stops the testing cluster.

type ZkEnv

type ZkEnv struct {
	ZNodeAssertion
	ClusterOperation
	// contains filtered or unexported fields
}

ZkEnv should only be used in TESTING. It starts a managed ZooKeeper cluster before testing and stops it after.

func NewZkEnv

func NewZkEnv(t *testing.T) *ZkEnv

NewZkEnv creates a ZkEnv.

func (*ZkEnv) Client

func (z *ZkEnv) Client() *enhanced.Client

Client returns a client to ZooKeeper cluster. NOTE: Don't close the client, it will be closed by .Stop()

func (*ZkEnv) ConnectionString

func (z *ZkEnv) ConnectionString() string

ConnectionString returns the connection string of ZooKeeper cluster.

func (*ZkEnv) NewClient

func (z *ZkEnv) NewClient() *enhanced.Client

NewClient creates a client to ZooKeeper cluster.

func (*ZkEnv) NewClientTimeout

func (z *ZkEnv) NewClientTimeout(timeout time.Duration) *enhanced.Client

NewClientTimeout creates a client to ZooKeeper cluster and wait until it gets connected within given timeout.

func (*ZkEnv) Start

func (z *ZkEnv) Start() *ZkEnv

Start starts ZooKeeper cluster.

func (*ZkEnv) Stop

func (z *ZkEnv) Stop()

Stop stops ZooKeeper cluster.

func (*ZkEnv) With

func (z *ZkEnv) With(fn func(env *ZkEnv))

With calls fn after ".Start()" and "defer .Stop()"

func (*ZkEnv) Zk

func (z *ZkEnv) Zk() *ZkCluster

Zk returns ZooKeeper cluster.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL