tests

package
v3.0.0-...-c8eabd8 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package tests contains various helper functions and modules used in tests.

This package is internally used by Dragonboat, applications are not expected to import this package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// TestMonkeyEnabled indicates whether we are in monkey test mode
	TestMonkeyEnabled = false
)

Functions

func DirExist

func DirExist(name string, fs config.IFS) (bool, error)

func Mkdir

func Mkdir(dir string, fs config.IFS) error

func MkdirAll

func MkdirAll(dir string, fs config.IFS) error

func NewConcurrentKVTest

func NewConcurrentKVTest(clusterID uint64, nodeID uint64) sm.IConcurrentStateMachine

NewConcurrentKVTest creates and return a new KVTest object.

func NewDiskKVTest

func NewDiskKVTest(clusterID uint64, nodeID uint64) sm.IOnDiskStateMachine

NewDiskKVTest creates a new disk kv test state machine.

func NewKVTest

func NewKVTest(clusterID uint64, nodeID uint64) sm.IStateMachine

NewKVTest creates and return a new KVTest object.

func NewPebbleFS

func NewPebbleFS(fs config.IFS) pvfs.FS

NewPebbleFS creates a new pebble/vfs.FS instance.

func ReadyToReturnTestKnob

func ReadyToReturnTestKnob(stopC <-chan struct{}, delay bool, pos string) bool

ReadyToReturnTestKnob is a test knob that returns a boolean value indicating whether the system is being shutdown. In production, this function always return false without check the stopC chan.

Types

type ConcurrentKVTest

type ConcurrentKVTest struct {
	ClusterID uint64
	NodeID    uint64
	// contains filtered or unexported fields
}

ConcurrentKVTest is a in memory key-value store struct used for testing purposes. Note that both key/value are suppose to be valid utf-8 strings.

func (*ConcurrentKVTest) Close

func (s *ConcurrentKVTest) Close() error

Close closes the IStateMachine instance

func (*ConcurrentKVTest) GetHash

func (s *ConcurrentKVTest) GetHash() (uint64, error)

GetHash returns a uint64 representing the current object state.

func (*ConcurrentKVTest) Lookup

func (s *ConcurrentKVTest) Lookup(key interface{}) (interface{}, error)

Lookup performances local looks up for the sepcified data.

func (*ConcurrentKVTest) PrepareSnapshot

func (s *ConcurrentKVTest) PrepareSnapshot() (interface{}, error)

PrepareSnapshot makes preparations for taking concurrent snapshot.

func (*ConcurrentKVTest) RecoverFromSnapshot

func (s *ConcurrentKVTest) RecoverFromSnapshot(r io.Reader,
	files []sm.SnapshotFile,
	done <-chan struct{}) error

RecoverFromSnapshot recovers the state using the provided snapshot.

func (*ConcurrentKVTest) SaveSnapshot

func (s *ConcurrentKVTest) SaveSnapshot(ctx interface{},
	w io.Writer,
	fileCollection sm.ISnapshotFileCollection,
	done <-chan struct{}) error

SaveSnapshot saves the current object state into a snapshot using the specified io.Writer object.

func (*ConcurrentKVTest) Update

func (s *ConcurrentKVTest) Update(ents []sm.Entry) ([]sm.Entry, error)

Update updates the object using the specified committed raft entry.

type ConcurrentSnapshot

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

ConcurrentSnapshot is a IConcurrentStateMachine used for testing purposes.

func (*ConcurrentSnapshot) Close

func (c *ConcurrentSnapshot) Close() error

Close closes the state machine.

func (*ConcurrentSnapshot) GetHash

func (c *ConcurrentSnapshot) GetHash() (uint64, error)

GetHash returns the uint64 hash value representing the state of a state machine.

func (*ConcurrentSnapshot) Lookup

func (c *ConcurrentSnapshot) Lookup(query interface{}) (interface{}, error)

Lookup queries the state machine.

func (*ConcurrentSnapshot) PrepareSnapshot

func (c *ConcurrentSnapshot) PrepareSnapshot() (interface{}, error)

PrepareSnapshot makes preparations for taking concurrent snapshot.

func (*ConcurrentSnapshot) RecoverFromSnapshot

func (c *ConcurrentSnapshot) RecoverFromSnapshot(r io.Reader,
	files []sm.SnapshotFile, stopc <-chan struct{}) error

RecoverFromSnapshot recovers the state machine from a snapshot.

func (*ConcurrentSnapshot) SaveSnapshot

func (c *ConcurrentSnapshot) SaveSnapshot(ctx interface{},
	w io.Writer,
	fc sm.ISnapshotFileCollection, stopc <-chan struct{}) error

SaveSnapshot saves the snapshot.

func (*ConcurrentSnapshot) Update

func (c *ConcurrentSnapshot) Update(entries []sm.Entry) ([]sm.Entry, error)

Update updates the state machine.

type ConcurrentUpdate

type ConcurrentUpdate struct {
	UpdateCount int
	// contains filtered or unexported fields
}

ConcurrentUpdate is a IConcurrentStateMachine used for testing purposes.

func (*ConcurrentUpdate) Close

func (c *ConcurrentUpdate) Close() error

Close closes the state machine.

func (*ConcurrentUpdate) GetHash

func (c *ConcurrentUpdate) GetHash() (uint64, error)

GetHash returns the uint64 hash value representing the state of a state machine.

func (*ConcurrentUpdate) Lookup

func (c *ConcurrentUpdate) Lookup(query interface{}) (interface{}, error)

Lookup queries the state machine.

func (*ConcurrentUpdate) PrepareSnapshot

func (c *ConcurrentUpdate) PrepareSnapshot() (interface{}, error)

PrepareSnapshot makes preparations for taking concurrent snapshot.

func (*ConcurrentUpdate) RecoverFromSnapshot

func (c *ConcurrentUpdate) RecoverFromSnapshot(r io.Reader,
	files []sm.SnapshotFile, stopc <-chan struct{}) error

RecoverFromSnapshot recovers the state machine from a snapshot.

func (*ConcurrentUpdate) SaveSnapshot

func (c *ConcurrentUpdate) SaveSnapshot(ctx interface{},
	w io.Writer,
	fc sm.ISnapshotFileCollection, stopc <-chan struct{}) error

SaveSnapshot saves the snapshot.

func (*ConcurrentUpdate) Update

func (c *ConcurrentUpdate) Update(entries []sm.Entry) ([]sm.Entry, error)

Update updates the state machine.

type DiskKVTest

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

DiskKVTest is a state machine used for testing on disk kv.

func (*DiskKVTest) Close

func (d *DiskKVTest) Close() error

Close closes the state machine.

func (*DiskKVTest) GetHash

func (d *DiskKVTest) GetHash() (uint64, error)

GetHash returns a hash value representing the state of the state machine.

func (*DiskKVTest) Lookup

func (d *DiskKVTest) Lookup(key interface{}) (interface{}, error)

Lookup queries the state machine.

func (*DiskKVTest) Open

func (d *DiskKVTest) Open(stopc <-chan struct{}) (uint64, error)

Open opens the state machine.

func (*DiskKVTest) PrepareSnapshot

func (d *DiskKVTest) PrepareSnapshot() (interface{}, error)

PrepareSnapshot prepares snapshotting.

func (*DiskKVTest) RecoverFromSnapshot

func (d *DiskKVTest) RecoverFromSnapshot(r io.Reader,
	done <-chan struct{}) error

RecoverFromSnapshot recovers the state machine state from snapshot.

func (*DiskKVTest) SaveSnapshot

func (d *DiskKVTest) SaveSnapshot(ctx interface{},
	w io.Writer, done <-chan struct{}) error

SaveSnapshot saves the state machine state.

func (*DiskKVTest) SetTestFS

func (d *DiskKVTest) SetTestFS(fs config.IFS)

SetTestFS sets the fs of the test SM.

func (*DiskKVTest) Sync

func (d *DiskKVTest) Sync() error

Sync synchronizes state machine's in-core state with that on disk.

func (*DiskKVTest) Update

func (d *DiskKVTest) Update(ents []sm.Entry) ([]sm.Entry, error)

Update updates the state machine.

type KVJson

type KVJson struct {
	KVStore map[string]string `json:"KVStore"`
	Count   uint64            `json:"Count"`
	Junk    []byte            `json:"Junk"`
}

KVJson is an util struct for serializing and deserializing data.

type KVTest

type KVTest struct {
	ClusterID uint64            `json:"-"`
	NodeID    uint64            `json:"-"`
	KVStore   map[string]string `json:"KVStore"`
	Count     uint64            `json:"Count"`
	Junk      []byte            `json:"Junk"`
	// contains filtered or unexported fields
}

KVTest is a in memory key-value store struct used for testing purposes. Note that both key/value are suppose to be valid utf-8 strings.

func (*KVTest) Close

func (s *KVTest) Close() error

Close closes the IStateMachine instance

func (*KVTest) DisableLargeDelay

func (s *KVTest) DisableLargeDelay()

DisableLargeDelay disables random large delays.

func (*KVTest) GetHash

func (s *KVTest) GetHash() (uint64, error)

GetHash returns a uint64 representing the current object state.

func (*KVTest) Lookup

func (s *KVTest) Lookup(key interface{}) (interface{}, error)

Lookup performances local looks up for the sepcified data.

func (*KVTest) RecoverFromSnapshot

func (s *KVTest) RecoverFromSnapshot(r io.Reader,
	files []sm.SnapshotFile,
	done <-chan struct{}) error

RecoverFromSnapshot recovers the state using the provided snapshot.

func (*KVTest) SaveSnapshot

func (s *KVTest) SaveSnapshot(w io.Writer,
	fileCollection sm.ISnapshotFileCollection,
	done <-chan struct{}) error

SaveSnapshot saves the current object state into a snapshot using the specified io.Writer object.

func (*KVTest) Update

func (s *KVTest) Update(entry sm.Entry) (sm.Result, error)

Update updates the object using the specified committed raft entry.

type NoOP

type NoOP struct {
	MillisecondToSleep uint64
	NoAlloc            bool
}

NoOP is a IStateMachine struct used for testing purpose.

func (*NoOP) Close

func (n *NoOP) Close() error

Close closes the NoOP IStateMachine.

func (*NoOP) GetHash

func (n *NoOP) GetHash() (uint64, error)

GetHash returns a uint64 value representing the current state of the object.

func (*NoOP) Lookup

func (n *NoOP) Lookup(key interface{}) (interface{}, error)

Lookup locally looks up the data.

func (*NoOP) NALookup

func (n *NoOP) NALookup(key []byte) ([]byte, error)

NALookup locally looks up the data.

func (*NoOP) RecoverFromSnapshot

func (n *NoOP) RecoverFromSnapshot(r io.Reader,
	files []sm.SnapshotFile,
	done <-chan struct{}) error

RecoverFromSnapshot recovers the object from the snapshot specified by the io.Reader object.

func (*NoOP) SaveSnapshot

func (n *NoOP) SaveSnapshot(w io.Writer,
	fileCollection sm.ISnapshotFileCollection,
	done <-chan struct{}) error

SaveSnapshot saves the state of the object to the provided io.Writer object.

func (*NoOP) Update

func (n *NoOP) Update(data []byte) (sm.Result, error)

Update updates the object.

type PebbleFS

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

PebbleFS is a wrapper struct that implements the pebble/vfs.FS interface.

func (*PebbleFS) Create

func (p *PebbleFS) Create(name string) (pvfs.File, error)

Create ...

func (*PebbleFS) GetDiskUsage

func (p *PebbleFS) GetDiskUsage(path string) (pvfs.DiskUsage, error)
func (p *PebbleFS) Link(oldname, newname string) error

Link ...

func (*PebbleFS) List

func (p *PebbleFS) List(dir string) ([]string, error)

List ...

func (*PebbleFS) Lock

func (p *PebbleFS) Lock(name string) (io.Closer, error)

Lock ...

func (*PebbleFS) MkdirAll

func (p *PebbleFS) MkdirAll(dir string, perm os.FileMode) error

MkdirAll ...

func (*PebbleFS) Open

func (p *PebbleFS) Open(name string, opts ...pvfs.OpenOption) (pvfs.File, error)

Open ...

func (*PebbleFS) OpenDir

func (p *PebbleFS) OpenDir(name string) (pvfs.File, error)

OpenDir ...

func (*PebbleFS) PathBase

func (p *PebbleFS) PathBase(path string) string

PathBase ...

func (*PebbleFS) PathDir

func (p *PebbleFS) PathDir(path string) string

PathDir ...

func (*PebbleFS) PathJoin

func (p *PebbleFS) PathJoin(elem ...string) string

PathJoin ...

func (*PebbleFS) Remove

func (p *PebbleFS) Remove(name string) error

Remove ...

func (*PebbleFS) RemoveAll

func (p *PebbleFS) RemoveAll(name string) error

RemoveAll ...

func (*PebbleFS) Rename

func (p *PebbleFS) Rename(oldname, newname string) error

Rename ...

func (*PebbleFS) ReuseForWrite

func (p *PebbleFS) ReuseForWrite(oldname, newname string) (pvfs.File, error)

ReuseForWrite ...

func (*PebbleFS) Stat

func (p *PebbleFS) Stat(name string) (os.FileInfo, error)

Stat ...

type TestSnapshot

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

TestSnapshot is a IConcurrentStateMachine used for testing purposes.

func (*TestSnapshot) Close

func (c *TestSnapshot) Close() error

Close closes the state machine.

func (*TestSnapshot) GetHash

func (c *TestSnapshot) GetHash() (uint64, error)

GetHash returns the uint64 hash value representing the state of a state machine.

func (*TestSnapshot) Lookup

func (c *TestSnapshot) Lookup(query interface{}) (interface{}, error)

Lookup queries the state machine.

func (*TestSnapshot) RecoverFromSnapshot

func (c *TestSnapshot) RecoverFromSnapshot(r io.Reader,
	files []sm.SnapshotFile, stopc <-chan struct{}) error

RecoverFromSnapshot recovers the state machine from a snapshot.

func (*TestSnapshot) SaveSnapshot

func (c *TestSnapshot) SaveSnapshot(w io.Writer,
	fc sm.ISnapshotFileCollection, stopc <-chan struct{}) error

SaveSnapshot saves the snapshot.

func (*TestSnapshot) Update

func (c *TestSnapshot) Update(data []byte) (sm.Result, error)

Update updates the state machine.

type TestUpdate

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

TestUpdate is a IStateMachine used for testing purposes.

func (*TestUpdate) Close

func (c *TestUpdate) Close() error

Close closes the state machine.

func (*TestUpdate) GetHash

func (c *TestUpdate) GetHash() (uint64, error)

GetHash returns the uint64 hash value representing the state of a state machine.

func (*TestUpdate) Lookup

func (c *TestUpdate) Lookup(query interface{}) (interface{}, error)

Lookup queries the state machine.

func (*TestUpdate) RecoverFromSnapshot

func (c *TestUpdate) RecoverFromSnapshot(r io.Reader,
	files []sm.SnapshotFile, stopc <-chan struct{}) error

RecoverFromSnapshot recovers the state machine from a snapshot.

func (*TestUpdate) SaveSnapshot

func (c *TestUpdate) SaveSnapshot(w io.Writer,
	fc sm.ISnapshotFileCollection, stopc <-chan struct{}) error

SaveSnapshot saves the snapshot.

func (*TestUpdate) Update

func (c *TestUpdate) Update(data []byte) (sm.Result, error)

Update updates the state machine.

type VerboseSnapshotSM

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

VerboseSnapshotSM ...

func (*VerboseSnapshotSM) Close

func (v *VerboseSnapshotSM) Close() error

Close ...

func (*VerboseSnapshotSM) Lookup

func (v *VerboseSnapshotSM) Lookup(q interface{}) (interface{}, error)

Lookup ...

func (*VerboseSnapshotSM) RecoverFromSnapshot

func (v *VerboseSnapshotSM) RecoverFromSnapshot(r io.Reader,
	collection []sm.SnapshotFile, stopc <-chan struct{}) error

RecoverFromSnapshot ...

func (*VerboseSnapshotSM) SaveSnapshot

func (v *VerboseSnapshotSM) SaveSnapshot(w io.Writer,
	collection sm.ISnapshotFileCollection, stopc <-chan struct{}) error

SsaveSnapshot ...

func (*VerboseSnapshotSM) Update

func (v *VerboseSnapshotSM) Update(data []byte) (sm.Result, error)

Update ...

Jump to

Keyboard shortcuts

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