zktest

package
v3.3.43 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = log.Logger(log.DefaultLogger.CreateChild())

DefaultLogger is used by zktest if no logger is set

View Source
var ErrDeleteFailed = errors.New("delete eventually failed")

ErrDeleteFailed is retured when EnsureDelete() is unable to ensure the delete

View Source
var ErrDeleteOnRoot = errors.New("cannot delete on root path")

ErrDeleteOnRoot is returned when EnsureDelete is called with a root path

Functions

func EnsureDelete

func EnsureDelete(z ZkConnSupported, path string) error

EnsureDelete will ensure that path is deleted from zk, trying up to three times before eventually failing with an error

Types

type MemoryZkServer

type MemoryZkServer struct {
	sfxtest.ErrChecker

	GlobalChan chan zk.Event
	Logger     log.Logger

	ChanTimeout time.Duration
	// contains filtered or unexported fields
}

MemoryZkServer can be used in the place of a zk.Conn() to unit test zk connections

func New

func New() *MemoryZkServer

New returns a new testing zk connection

func (*MemoryZkServer) Conn

func (z *MemoryZkServer) Conn() (ZkConnSupported, <-chan zk.Event, error)

Conn satisfies the ZkConnector interface for zkplus so we can easily pass the memory zk server into a builder

func (*MemoryZkServer) Connect

func (z *MemoryZkServer) Connect() (*ZkConn, <-chan zk.Event, error)

Connect to this server

func (*MemoryZkServer) Pretty

func (z *MemoryZkServer) Pretty() string

Pretty returns a pretty print of the zk structure

type ZkConn

type ZkConn struct {
	Logger log.Logger

	sfxtest.ErrChecker
	// contains filtered or unexported fields
}

ZkConn is the connection type returned from a MemoryZkConn that simulates a zk connection

func (*ZkConn) Children

func (z *ZkConn) Children(path string) ([]string, *zk.Stat, error)

Children gets children of a path

func (*ZkConn) ChildrenW

func (z *ZkConn) ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error)

ChildrenW is like children but also sets a watch

func (*ZkConn) Close

func (z *ZkConn) Close()

Close sends disconnected to all waiting events and deregisteres this conn with the parent server

func (*ZkConn) Create

func (z *ZkConn) Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error)

Create a Zk node

func (*ZkConn) Delete

func (z *ZkConn) Delete(path string, version int32) error

Delete a Zk node

func (*ZkConn) Exists

func (z *ZkConn) Exists(path string) (bool, *zk.Stat, error)

Exists returns true if the path exists

func (*ZkConn) ExistsW

func (z *ZkConn) ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error)

ExistsW is like Exists but also sets a watch.

func (*ZkConn) Get

func (z *ZkConn) Get(path string) ([]byte, *zk.Stat, error)

Get the bytes of a zk path

func (*ZkConn) GetW

func (z *ZkConn) GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error)

GetW is like Get, but also sets a watch

func (*ZkConn) Set

func (z *ZkConn) Set(path string, data []byte, version int32) (*zk.Stat, error)

Set the data of a zk node

type ZkConnSupported

type ZkConnSupported interface {
	// Exists returns true if the path exists
	Exists(path string) (bool, *zk.Stat, error)
	ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error)
	Get(path string) ([]byte, *zk.Stat, error)
	GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error)
	Children(path string) ([]string, *zk.Stat, error)
	ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error)
	Delete(path string, version int32) error
	Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error)
	Set(path string, data []byte, version int32) (*zk.Stat, error)
	Close()
}

ZkConnSupported is the interface of zk.Conn we currently support

Jump to

Keyboard shortcuts

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