deploytest

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BaseListenPort defines the starting port number on which test replicas will be listening
	// in case the test is being run with the "grpc" or "libp2p" setting for networking.
	// A node with numeric ID id will listen on port (BaseListenPort + id)
	BaseListenPort = 10000

	// RequestListenPort is the port number on which nodes' RequestReceivers listen for incoming requests.
	RequestListenPort = 20000
)

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(parentLogger logging.Logger) logging.Logger

NewLogger returns a new logger suitable for tests. If parentLogger is not nil, it returns a thread-safe wrapper around parentLogger. Otherwise, it returns a thread-safe wrapper around logging.ConsoleDebugLogger.

func NewNodeIDs

func NewNodeIDs(nNodes int) []t.NodeID

NewNodeIDs returns a slice of node ids of the given size suitable for testing.

func NewSimTimerModule

func NewSimTimerModule(node *SimNode) modules.ActiveModule

NewSimTimerModule returns a Timer modules to be used in simulation.

Types

type Deployment

type Deployment struct {
	TestConfig *TestConfig

	// The test simulation is only used if the deployment is configured to use "sim" transport.
	Simulation *Simulation

	// The replicas of the deployment.
	TestReplicas []*TestReplica

	// Dummy clients to submit requests to replicas over the (local loopback) network.
	Clients []*dummyclient.DummyClient
}

The Deployment represents a list of replicas interconnected by a simulated network transport.

func NewDeployment

func NewDeployment(conf *TestConfig) (*Deployment, error)

NewDeployment returns a Deployment initialized according to the passed configuration.

func (*Deployment) EventLogFiles added in v0.1.1

func (d *Deployment) EventLogFiles() map[t.NodeID]string

func (*Deployment) Run

func (d *Deployment) Run(ctx context.Context) (nodeErrors []error, heapObjects int64, heapAlloc int64)

Run launches the test deployment. It starts all test replicas, the dummy client, and the fake message transport subsystem, waits until the replicas stop, and returns the final statuses of all the replicas.

type EventDelayFn

type EventDelayFn func(e *eventpb.Event) time.Duration

EventDelayFn defines a function to provide event processing delay.

type FakeApp

type FakeApp struct {
	ProtocolModule t.ModuleID

	Membership map[t.NodeID]t.NodeAddress

	// The state of the FakeApp only consists of a counter of processed requests.
	RequestsProcessed uint64
}

FakeApp represents a dummy stub application used for testing only.

func NewFakeApp

func NewFakeApp() *FakeApp

func (*FakeApp) ApplyTXs added in v0.2.0

func (fa *FakeApp) ApplyTXs(txs []*requestpb.Request) error

func (*FakeApp) Checkpoint added in v0.2.0

func (fa *FakeApp) Checkpoint(_ *checkpoint.StableCheckpoint) error

func (*FakeApp) RestoreState

func (fa *FakeApp) RestoreState(checkpoint *checkpoint.StableCheckpoint) error

func (*FakeApp) Snapshot

func (fa *FakeApp) Snapshot() ([]byte, error)
type FakeLink struct {
	FakeTransport *FakeTransport
	Source        t.NodeID
	DoneC         chan struct{}
	// contains filtered or unexported fields
}

func (*FakeLink) ApplyEvents

func (fl *FakeLink) ApplyEvents(
	ctx context.Context,
	eventList *events.EventList,
) error

func (*FakeLink) CloseOldConnections

func (fl *FakeLink) CloseOldConnections(_ map[t.NodeID]t.NodeAddress)

func (*FakeLink) Connect

func (fl *FakeLink) Connect(_ map[t.NodeID]t.NodeAddress)

func (*FakeLink) EventsOut

func (fl *FakeLink) EventsOut() <-chan *events.EventList

func (*FakeLink) ImplementsModule

func (fl *FakeLink) ImplementsModule()

The ImplementsModule method only serves the purpose of indicating that this is a Module and must not be called.

func (*FakeLink) Send

func (fl *FakeLink) Send(dest t.NodeID, msg *messagepb.Message) error

func (*FakeLink) Start

func (fl *FakeLink) Start() error

func (*FakeLink) Stop

func (fl *FakeLink) Stop()

func (*FakeLink) WaitFor

func (fl *FakeLink) WaitFor(_ int)

WaitFor returns immediately. It does not need to wait for anything, since the Connect() function already waits for all the connections. TODO: Technically this does not properly implement the semantics, as calling WaitFor without having called Connect should block. Fix this.

type FakeTransport

type FakeTransport struct {
	// Buffers is source x dest
	Buffers   map[t.NodeID]map[t.NodeID]chan *events.EventList
	NodeSinks map[t.NodeID]chan *events.EventList
	// contains filtered or unexported fields
}

func NewFakeTransport

func NewFakeTransport(nodeIDs []t.NodeID) *FakeTransport

func (*FakeTransport) Close

func (ft *FakeTransport) Close()
func (ft *FakeTransport) Link(source t.NodeID) (net.Transport, error)

func (*FakeTransport) Nodes

func (ft *FakeTransport) Nodes() map[t.NodeID]t.NodeAddress

func (*FakeTransport) RecvC

func (ft *FakeTransport) RecvC(dest t.NodeID) <-chan *events.EventList

func (*FakeTransport) Send

func (ft *FakeTransport) Send(source, dest t.NodeID, msg *messagepb.Message)

type LocalCryptoSystem

type LocalCryptoSystem interface {
	Crypto(id t.NodeID) mirCrypto.Crypto
	Module(id t.NodeID) modules.Module
}

func NewLocalCryptoSystem

func NewLocalCryptoSystem(_ string, nodeIDs []t.NodeID, _ logging.Logger) LocalCryptoSystem

NewLocalCryptoSystem creates an instance of LocalCryptoSystem suitable for tests. In the current implementation, cryptoType can only be "pseudo".

type LocalGrpcTransport

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

func NewLocalGrpcTransport

func NewLocalGrpcTransport(nodeIDs []t.NodeID, logger logging.Logger) *LocalGrpcTransport

func (*LocalGrpcTransport) Close

func (t *LocalGrpcTransport) Close()
func (t *LocalGrpcTransport) Link(sourceID t.NodeID) (net.Transport, error)

func (*LocalGrpcTransport) Nodes

func (t *LocalGrpcTransport) Nodes() map[t.NodeID]t.NodeAddress

type LocalLibp2pTransport

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

func NewLocalLibp2pTransport

func NewLocalLibp2pTransport(nodeIDs []t.NodeID, logger logging.Logger) *LocalLibp2pTransport

func (*LocalLibp2pTransport) Close

func (t *LocalLibp2pTransport) Close()
func (t *LocalLibp2pTransport) Link(sourceID t.NodeID) (net.Transport, error)

func (*LocalLibp2pTransport) Nodes

func (t *LocalLibp2pTransport) Nodes() map[t.NodeID]t.NodeAddress

type LocalTransportLayer

type LocalTransportLayer interface {
	Link(source t.NodeID) (net.Transport, error)
	Nodes() map[t.NodeID]t.NodeAddress
	Close()
}

func NewLocalTransportLayer

func NewLocalTransportLayer(sim *Simulation, transportType string, nodeIDs []t.NodeID, logger logging.Logger) LocalTransportLayer

NewLocalTransportLayer creates an instance of LocalTransportLayer suitable for tests. transportType is one of: "sim", "fake", "grpc", or "libp2p".

type MessageDelayFn

type MessageDelayFn func(from, to t.NodeID) time.Duration

type SimNode

type SimNode struct {
	*Simulation
	// contains filtered or unexported fields
}

SimNode represents a Mir node deployed in the simulation runtime.

func (*SimNode) SendEvents

func (n *SimNode) SendEvents(proc *testsim.Process, eventList *events.EventList)

SendEvents notifies simulation about the list of emitted events on behalf of the given process.

func (*SimNode) Start

func (n *SimNode) Start(proc *testsim.Process, walEvents *events.EventList)

Start initiates simulation with the events from the write-ahead log on behalf of the given process. To be called concurrently with mir.Node.Run().

func (*SimNode) WrapModule

func (n *SimNode) WrapModule(id t.ModuleID, m modules.Module) modules.Module

WrapModule wraps the module to be used in simulation.

func (*SimNode) WrapModules

func (n *SimNode) WrapModules(mods modules.Modules) modules.Modules

WrapModules wraps the modules to be used in simulation. Mir nodes in the simulation deployment should be given the wrapped modules.

type SimTransport

type SimTransport struct {
	*Simulation
	// contains filtered or unexported fields
}

func NewSimTransport

func NewSimTransport(s *Simulation, nodeIDs []t.NodeID, delayFn MessageDelayFn) *SimTransport

func (*SimTransport) Close

func (st *SimTransport) Close()
func (st *SimTransport) Link(source t.NodeID) (net.Transport, error)

func (*SimTransport) Nodes

func (st *SimTransport) Nodes() map[t.NodeID]t.NodeAddress

type Simulation

type Simulation struct {
	*testsim.Runtime
	// contains filtered or unexported fields
}

Simulation represents a test deployment in the simulation runtime.

func NewSimulation

func NewSimulation(rnd *rand.Rand, nodeIDs []t.NodeID, delayFn EventDelayFn) *Simulation

func (*Simulation) Node

func (s *Simulation) Node(id t.NodeID) *SimNode

type TestConfig

type TestConfig struct {
	// Optional information about the test.
	Info string

	// The test simulation is only used if the deployment is configured to use "sim" transport.
	Simulation *Simulation

	// IDs of nodes in this test.
	NodeIDs []t.NodeID

	// List of nodes.
	Nodes map[t.NodeID]t.NodeAddress

	// The modules that will be run by each replica.
	NodeModules map[t.NodeID]modules.Modules

	// Number of clients in the tested deployment.
	NumClients int

	// The number of requests each client submits during the execution of the deployment.
	NumFakeRequests int

	// The number of requests sent over the network (by a single DummyClient)
	NumNetRequests int

	// The target module for the clients' requests.
	FakeRequestsDestModule t.ModuleID

	// Directory where all the test-related files will be stored.
	// If empty, an OS-default temporary directory will be used.
	Directory string

	// Logger to use for producing diagnostic messages.
	Logger logging.Logger

	// TransportLayer to work with network transport.
	TransportLayer LocalTransportLayer

	// Fake applications of all the test replicas. Required for checking results.
	FakeApps map[t.NodeID]*FakeApp
}

TestConfig contains the parameters of the deployment to be tested.

type TestReplica

type TestReplica struct {

	// ID of the replica as seen by the protocol.
	ID t.NodeID

	// The modules that the node will run.
	Modules modules.Modules

	// Name of the directory where the persisted state of this TestReplica will be stored,
	// along with the logs produced by running the replica.
	Dir string

	// Configuration of the node corresponding to this replica.
	Config *mir.NodeConfig

	// List of replica IDs constituting the (static) membership.
	NodeIDs []t.NodeID

	// List of replicas.
	Nodes map[t.NodeID]t.NodeAddress

	// Node's representation within the simulation runtime
	Sim *SimNode

	// Node's process within the simulation runtime
	Proc *testsim.Process

	// Number of simulated requests inserted in the test replica by a hypothetical client.
	NumFakeRequests int

	// ID of the module to which fake requests should be sent.
	FakeRequestsDestModule t.ModuleID
}

TestReplica represents one replica (that uses one instance of the mir.Node) in the test system.

func (*TestReplica) EventLogFile

func (tr *TestReplica) EventLogFile() string

EventLogFile returns the name of the file where the replica's event log is stored.

func (*TestReplica) Run

func (tr *TestReplica) Run(ctx context.Context) error

Run initializes all the required modules and starts the test replica. The function blocks until the replica stops. The replica stops when stopC is closed. Run returns the error returned by the run of the underlying Mir node.

Jump to

Keyboard shortcuts

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