testutils

package
v0.0.0-...-bc8cfc3 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRaftNode

func AddRaftNode(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode, tc *cautils.TestCA, opts ...raft.NodeOptions)

AddRaftNode adds an additional raft test node to an existing cluster

func AdvanceTicks

func AdvanceTicks(clockSource *fakeclock.FakeClock, ticks int)

AdvanceTicks advances the raft state machine fake clock

func CheckNoValue

func CheckNoValue(t *testing.T, clockSource *fakeclock.FakeClock, raftNode *TestNode)

CheckNoValue checks that there is no value replicated on nodes, generally used to test the absence of a leader

func CheckValue

func CheckValue(t *testing.T, clockSource *fakeclock.FakeClock, raftNode *TestNode, createdNode *api.Node)

CheckValue checks that the value has been propagated between raft members

func CheckValuesOnNodes

func CheckValuesOnNodes(t *testing.T, clockSource *fakeclock.FakeClock, checkNodes map[uint64]*TestNode, ids []string, values []*api.Node)

CheckValuesOnNodes checks that all the nodes in the cluster have the same replicated data, generally used to check if a node can catch up with the logs correctly

func CleanupNonRunningNode

func CleanupNonRunningNode(node *TestNode)

CleanupNonRunningNode frees resources associated with a node which is not running.

func GetAllValuesOnNode

func GetAllValuesOnNode(t *testing.T, clockSource *fakeclock.FakeClock, raftNode *TestNode) ([]string, []*api.Node)

GetAllValuesOnNode returns all values on this node

func NewRaftCluster

func NewRaftCluster(t *testing.T, tc *cautils.TestCA, config ...*api.RaftConfig) (map[uint64]*TestNode, *fakeclock.FakeClock)

NewRaftCluster creates a new raft cluster with 3 nodes for testing

func NewSnapshotMessage

func NewSnapshotMessage(from, to uint64, size int) *raftpb.Message

NewSnapshotMessage creates and returns a raftpb.Message of type MsgSnap where the snapshot data is of the given size and the value of each byte is (index of the byte) % 256.

func ProposeValue

func ProposeValue(t *testing.T, raftNode *TestNode, time time.Duration, nodeID ...string) (*api.Node, error)

ProposeValue proposes a value to a raft test cluster

func ShutdownNode

func ShutdownNode(node *TestNode)

ShutdownNode shuts down a raft test node and deletes the content of the state directory

func TeardownCluster

func TeardownCluster(nodes map[uint64]*TestNode)

TeardownCluster destroys a raft cluster used for tests

func VerifySnapshot

func VerifySnapshot(raftMsg *raftpb.Message) bool

VerifySnapshot verifies that the snapshot data where each byte is of the value (index % sizeof(byte)).

func WaitForCluster

func WaitForCluster(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode)

WaitForCluster waits until leader will be one of specified nodes

func WaitForPeerNumber

func WaitForPeerNumber(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode, count int)

WaitForPeerNumber waits until peers in cluster converge to specified number

Types

type SimpleKeyRotator

type SimpleKeyRotator struct {
	raft.EncryptionKeys
	// contains filtered or unexported fields
}

SimpleKeyRotator does some DEK rotation

func NewSimpleKeyRotator

func NewSimpleKeyRotator(keys raft.EncryptionKeys) *SimpleKeyRotator

NewSimpleKeyRotator returns a basic EncryptionKeyRotator

func (*SimpleKeyRotator) GetKeys

func (s *SimpleKeyRotator) GetKeys() raft.EncryptionKeys

GetKeys returns the current set of keys

func (*SimpleKeyRotator) NeedsRotation

func (s *SimpleKeyRotator) NeedsRotation() bool

NeedsRotation returns whether we need to rotate

func (*SimpleKeyRotator) QueuePendingKey

func (s *SimpleKeyRotator) QueuePendingKey(key []byte)

QueuePendingKey lets us rotate the key

func (*SimpleKeyRotator) RotationNotify

func (s *SimpleKeyRotator) RotationNotify() chan struct{}

RotationNotify returns the rotation notification channel

func (*SimpleKeyRotator) SetNeedsRotation

func (s *SimpleKeyRotator) SetNeedsRotation(override *bool)

SetNeedsRotation enables you to inject a value for NeedsRotation

func (*SimpleKeyRotator) SetUpdateFunc

func (s *SimpleKeyRotator) SetUpdateFunc(updateFunc func() error)

SetUpdateFunc enables you to inject an error when updating keys

func (*SimpleKeyRotator) UpdateKeys

func (s *SimpleKeyRotator) UpdateKeys(newKeys raft.EncryptionKeys) error

UpdateKeys updates the current encryption keys

type TestNode

type TestNode struct {
	*raft.Node
	Server         *grpc.Server
	Listener       *WrappedListener
	SecurityConfig *ca.SecurityConfig
	Address        string
	StateDir       string

	KeyRotator *SimpleKeyRotator
	// contains filtered or unexported fields
}

TestNode represents a raft test node

func CopyNode

func CopyNode(t *testing.T, clockSource *fakeclock.FakeClock, oldNode *TestNode, forceNewCluster bool, kr *SimpleKeyRotator) (*TestNode, context.Context)

CopyNode returns a copy of a node

func Leader

func Leader(nodes map[uint64]*TestNode) *TestNode

Leader determines who is the leader amongst a set of raft nodes belonging to the same cluster

func NewInitNode

func NewInitNode(t *testing.T, tc *cautils.TestCA, raftConfig *api.RaftConfig, opts ...raft.NodeOptions) (*TestNode, *fakeclock.FakeClock)

NewInitNode creates a new raft node initiating the cluster for other members to join

func NewJoinNode

func NewJoinNode(t *testing.T, clockSource *fakeclock.FakeClock, join string, tc *cautils.TestCA, opts ...raft.NodeOptions) *TestNode

NewJoinNode creates a new raft node joining an existing cluster

func NewNode

func NewNode(t *testing.T, clockSource *fakeclock.FakeClock, tc *cautils.TestCA, opts ...raft.NodeOptions) *TestNode

NewNode creates a new raft node to use for tests

func RestartNode

func RestartNode(t *testing.T, clockSource *fakeclock.FakeClock, oldNode *TestNode, forceNewCluster bool) *TestNode

RestartNode restarts a raft test node

func (*TestNode) Leader

func (n *TestNode) Leader() uint64

Leader is wrapper around real Leader method to suppress error. TODO: tests should use Leader method directly.

func (*TestNode) ShutdownRaft

func (n *TestNode) ShutdownRaft()

ShutdownRaft shutdowns only raft part of node.

type WrappedListener

type WrappedListener struct {
	net.Listener
	// contains filtered or unexported fields
}

WrappedListener disables the Close method to make it possible to reuse a socket. close must be called to release the socket.

func NewWrappedListener

func NewWrappedListener(l net.Listener) *WrappedListener

NewWrappedListener creates a new wrapped listener to register the raft server

func RecycleWrappedListener

func RecycleWrappedListener(old *WrappedListener) *WrappedListener

RecycleWrappedListener creates a new wrappedListener that uses the same listening socket as the supplied wrappedListener.

func (*WrappedListener) Accept

func (l *WrappedListener) Accept() (net.Conn, error)

Accept accepts new connections on a wrapped listener

func (*WrappedListener) Close

func (l *WrappedListener) Close() error

Close notifies that the listener can't accept any more connections

func (*WrappedListener) CloseListener

func (l *WrappedListener) CloseListener() error

CloseListener closes the underlying listener

Jump to

Keyboard shortcuts

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