etcd: github.com/coreos/etcd/raft/rafttest Index | Files

package rafttest

import "github.com/coreos/etcd/raft/rafttest"

Package rafttest provides functional tests for etcd's raft implementation.

Index

Package Files

doc.go interaction_env.go interaction_env_handler.go interaction_env_handler_add_nodes.go interaction_env_handler_campaign.go interaction_env_handler_compact.go interaction_env_handler_deliver_msgs.go interaction_env_handler_log_level.go interaction_env_handler_process_ready.go interaction_env_handler_propose.go interaction_env_handler_propose_conf_change.go interaction_env_handler_raft_log.go interaction_env_handler_stabilize.go interaction_env_handler_status.go interaction_env_handler_tick_heartbeat.go interaction_env_logger.go network.go node.go

type InteractionEnv Uses

type InteractionEnv struct {
    Options  *InteractionOpts
    Nodes    []Node
    Messages []pb.Message // in-flight messages

    Output *RedirectLogger
}

InteractionEnv facilitates testing of complex interactions between the members of a raft group.

func NewInteractionEnv Uses

func NewInteractionEnv(opts *InteractionOpts) *InteractionEnv

NewInteractionEnv initializes an InteractionEnv. opts may be nil.

func (*InteractionEnv) AddNodes Uses

func (env *InteractionEnv) AddNodes(n int, snap pb.Snapshot) error

AddNodes adds n new nodes initializes from the given snapshot (which may be empty). They will be assigned consecutive IDs.

func (*InteractionEnv) Campaign Uses

func (env *InteractionEnv) Campaign(t *testing.T, idx int) error

Campaign the node at the given index.

func (*InteractionEnv) Compact Uses

func (env *InteractionEnv) Compact(idx int, newFirstIndex uint64) error

Compact truncates the log on the node at index idx so that the supplied new first index results.

func (*InteractionEnv) DeliverMsgs Uses

func (env *InteractionEnv) DeliverMsgs(rs ...Recipient) int

DeliverMsgs goes through env.Messages and, depending on the Drop flag, delivers or drops messages to the specified Recipients. Returns the number of messages handled (i.e. delivered or dropped). A handled message is removed from env.Messages.

func (*InteractionEnv) Handle Uses

func (env *InteractionEnv) Handle(t *testing.T, d datadriven.TestData) string

Handle is the entrypoint for data-driven interaction testing. Commands and parameters are parsed from the supplied TestData. Errors during data parsing are reported via the supplied *testing.T; errors from the raft nodes and the storage engine are reported to the output buffer.

func (*InteractionEnv) LogLevel Uses

func (env *InteractionEnv) LogLevel(name string) error

func (*InteractionEnv) ProcessReady Uses

func (env *InteractionEnv) ProcessReady(idx int) error

ProcessReady runs Ready handling on the node with the given index.

func (*InteractionEnv) Propose Uses

func (env *InteractionEnv) Propose(idx int, data []byte) error

Propose a regular entry.

func (*InteractionEnv) ProposeConfChange Uses

func (env *InteractionEnv) ProposeConfChange(idx int, c raftpb.ConfChangeI) error

ProposeConfChange proposes a configuration change on the node with the given index.

func (*InteractionEnv) RaftLog Uses

func (env *InteractionEnv) RaftLog(idx int) error

RaftLog pretty prints the raft log to the output buffer.

func (*InteractionEnv) Stabilize Uses

func (env *InteractionEnv) Stabilize(idxs ...int) error

Stabilize repeatedly runs Ready handling on and message delivery to the set of nodes specified via the idxs slice until reaching a fixed point.

func (*InteractionEnv) Status Uses

func (env *InteractionEnv) Status(idx int) error

Status pretty-prints the raft status for the node at the given index to the output buffer.

func (*InteractionEnv) Tick Uses

func (env *InteractionEnv) Tick(idx int, num int) error

Tick the node at the given index the given number of times.

type InteractionOpts Uses

type InteractionOpts struct {
    OnConfig func(*raft.Config)
}

InteractionOpts groups the options for an InteractionEnv.

type Node Uses

type Node struct {
    *raft.RawNode
    Storage

    Config  *raft.Config
    History []pb.Snapshot
}

A Node is a member of a raft group tested via an InteractionEnv.

type Recipient Uses

type Recipient struct {
    ID   uint64
    Drop bool
}

type RedirectLogger Uses

type RedirectLogger struct {
    *strings.Builder
    Lvl int // 0 = DEBUG, 1 = INFO, 2 = WARNING, 3 = ERROR, 4 = FATAL, 5 = NONE
}

func (*RedirectLogger) Debug Uses

func (l *RedirectLogger) Debug(v ...interface{})

func (*RedirectLogger) Debugf Uses

func (l *RedirectLogger) Debugf(format string, v ...interface{})

func (*RedirectLogger) Error Uses

func (l *RedirectLogger) Error(v ...interface{})

func (*RedirectLogger) Errorf Uses

func (l *RedirectLogger) Errorf(format string, v ...interface{})

func (*RedirectLogger) Fatal Uses

func (l *RedirectLogger) Fatal(v ...interface{})

func (*RedirectLogger) Fatalf Uses

func (l *RedirectLogger) Fatalf(format string, v ...interface{})

func (*RedirectLogger) Info Uses

func (l *RedirectLogger) Info(v ...interface{})

func (*RedirectLogger) Infof Uses

func (l *RedirectLogger) Infof(format string, v ...interface{})

func (*RedirectLogger) Panic Uses

func (l *RedirectLogger) Panic(v ...interface{})

func (*RedirectLogger) Panicf Uses

func (l *RedirectLogger) Panicf(format string, v ...interface{})

func (*RedirectLogger) Warning Uses

func (l *RedirectLogger) Warning(v ...interface{})

func (*RedirectLogger) Warningf Uses

func (l *RedirectLogger) Warningf(format string, v ...interface{})

type Storage Uses

type Storage interface {
    raft.Storage
    SetHardState(state pb.HardState) error
    ApplySnapshot(pb.Snapshot) error
    Compact(newFirstIndex uint64) error
    Append([]pb.Entry) error
}

Storage is the interface used by InteractionEnv. It is comprised of raft's Storage interface plus access to operations that maintain the log and drive the Ready handling loop.

Package rafttest imports 17 packages (graph). Updated 2019-10-09. Refresh now. Tools for package owners.