test

package
v0.0.0-...-2ce89f0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCluster

func WithCluster(t *testing.T, addrs []net.Addr) *cluster

Start new cluster and auto-cleanup at the end of the test

Types

type ClusterState

type ClusterState struct {
	Leader     net.Addr
	Term       int
	Followers  []net.Addr
	Candidates []net.Addr
}

Return addr of the single leader of the cluster and its term.

type MockRaftNode

type MockRaftNode struct {
}

Mock local Raft node to test basic function without starting a real network server

func (*MockRaftNode) Id

func (node *MockRaftNode) Id() string

func (*MockRaftNode) Peers

func (node *MockRaftNode) Peers() []raft.RaftPeer

type RaftNode

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

Local Raft node implementation

Expects node to be already up and running. Does not handle startup or shutdown

func (*RaftNode) Id

func (node *RaftNode) Id() string

func (*RaftNode) Peers

func (node *RaftNode) Peers() []raft.RaftPeer

type RaftPeer

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

Remote Raft node implementation. Can be used as RPC proxy

Uses port number as id. Expects node to be already connected to the addr and running

func (*RaftPeer) AppendEntries

func (peer *RaftPeer) AppendEntries(args raft.AppendEntriesArgs, reply *raft.AppendEntriesReply) error

func (*RaftPeer) Id

func (peer *RaftPeer) Id() string

func (*RaftPeer) RequestVote

func (peer *RaftPeer) RequestVote(args raft.RequestVoteArgs, reply *raft.RequestVoteReply) error

type RaftSettings

type RaftSettings struct {
	MinElectionTimeout  time.Duration
	MaxElectionTimeout  time.Duration
	MinHeartbeatTimeout time.Duration
	MaxHeartbeatTimeout time.Duration
}

Implementation of raft.RaftSettings

Default timeouts are the ones suggested in the original paper

func NewRaftSettings

func NewRaftSettings() RaftSettings

func (RaftSettings) ElectionTimeout

func (settings RaftSettings) ElectionTimeout() time.Duration

func (RaftSettings) HeartbeatTimeout

func (settings RaftSettings) HeartbeatTimeout() time.Duration

func (RaftSettings) Majority

func (settings RaftSettings) Majority(peers int) int

Jump to

Keyboard shortcuts

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