InteractionEnv facilitates testing of complex interactions between the members of a raft group.
type InteractionEnv struct { Options *InteractionOpts Nodes []Node Messages []pb.Message // in-flight messages Output *RedirectLogger }
func NewInteractionEnv(opts *InteractionOpts) *InteractionEnv
NewInteractionEnv initializes an InteractionEnv. opts may be nil.
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 (env *InteractionEnv) Campaign(t *testing.T, idx int) error
Campaign the node at the given index.
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 (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 (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 (env *InteractionEnv) LogLevel(name string) error
func (env *InteractionEnv) ProcessReady(idx int) error
ProcessReady runs Ready handling on the node with the given index.
func (env *InteractionEnv) Propose(idx int, data []byte) error
Propose a regular entry.
func (env *InteractionEnv) ProposeConfChange(idx int, c raftpb.ConfChangeI) error
ProposeConfChange proposes a configuration change on the node with the given index.
func (env *InteractionEnv) RaftLog(idx int) error
RaftLog pretty prints the raft log to the output buffer.
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 (env *InteractionEnv) Status(idx int) error
Status pretty-prints the raft status for the node at the given index to the output buffer.
func (env *InteractionEnv) Tick(idx int, num int) error
Tick the node at the given index the given number of times.
InteractionOpts groups the options for an InteractionEnv.
type InteractionOpts struct { OnConfig func(*raft.Config) }
Node is a member of a raft group tested via an InteractionEnv.
type Node struct { *raft.RawNode Storage Config *raft.Config History []pb.Snapshot }
type Recipient struct { ID uint64 Drop bool }
type RedirectLogger struct { *strings.Builder Lvl int // 0 = DEBUG, 1 = INFO, 2 = WARNING, 3 = ERROR, 4 = FATAL, 5 = NONE }
func (l *RedirectLogger) Debug(v ...interface{})
func (l *RedirectLogger) Debugf(format string, v ...interface{})
func (l *RedirectLogger) Error(v ...interface{})
func (l *RedirectLogger) Errorf(format string, v ...interface{})
func (l *RedirectLogger) Fatal(v ...interface{})
func (l *RedirectLogger) Fatalf(format string, v ...interface{})
func (l *RedirectLogger) Info(v ...interface{})
func (l *RedirectLogger) Infof(format string, v ...interface{})
func (l *RedirectLogger) Panic(v ...interface{})
func (l *RedirectLogger) Panicf(format string, v ...interface{})
func (l *RedirectLogger) Warning(v ...interface{})
func (l *RedirectLogger) Warningf(format string, v ...interface{})
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.
type Storage interface { raft.Storage SetHardState(state pb.HardState) error ApplySnapshot(pb.Snapshot) error Compact(newFirstIndex uint64) error Append([]pb.Entry) error }