Documentation ¶
Index ¶
- Constants
- func NewLogger(parentLogger logging.Logger) logging.Logger
- func NewNodeIDs(nNodes int) []t.NodeID
- func NewSimTimerModule(node *SimNode) modules.ActiveModule
- type Deployment
- type EventDelayFn
- type FakeApp
- type FakeLink
- func (fl *FakeLink) ApplyEvents(ctx context.Context, eventList *events.EventList) error
- func (fl *FakeLink) CloseOldConnections(_ map[t.NodeID]t.NodeAddress)
- func (fl *FakeLink) Connect(_ map[t.NodeID]t.NodeAddress)
- func (fl *FakeLink) EventsOut() <-chan *events.EventList
- func (fl *FakeLink) ImplementsModule()
- func (fl *FakeLink) Send(dest t.NodeID, msg *messagepb.Message) error
- func (fl *FakeLink) Start() error
- func (fl *FakeLink) Stop()
- func (fl *FakeLink) WaitFor(_ int)
- type FakeTransport
- func (ft *FakeTransport) Close()
- func (ft *FakeTransport) Link(source t.NodeID) (net.Transport, error)
- func (ft *FakeTransport) Nodes() map[t.NodeID]t.NodeAddress
- func (ft *FakeTransport) RecvC(dest t.NodeID) <-chan *events.EventList
- func (ft *FakeTransport) Send(source, dest t.NodeID, msg *messagepb.Message)
- type LocalCryptoSystem
- type LocalGrpcTransport
- type LocalLibp2pTransport
- type LocalTransportLayer
- type MessageDelayFn
- type SimNode
- func (n *SimNode) SendEvents(proc *testsim.Process, eventList *events.EventList)
- func (n *SimNode) Start(proc *testsim.Process, walEvents *events.EventList)
- func (n *SimNode) WrapModule(id t.ModuleID, m modules.Module) modules.Module
- func (n *SimNode) WrapModules(mods modules.Modules) modules.Modules
- type SimTransport
- type Simulation
- type TestConfig
- type TestReplica
Constants ¶
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 ¶
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 ¶
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 ¶
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) Checkpoint ¶ added in v0.2.0
func (fa *FakeApp) Checkpoint(_ *checkpoint.StableCheckpoint) error
func (*FakeApp) RestoreState ¶
func (fa *FakeApp) RestoreState(checkpoint *checkpoint.StableCheckpoint) error
type FakeLink ¶
type FakeLink struct { FakeTransport *FakeTransport Source t.NodeID DoneC chan struct{} // contains filtered or unexported fields }
func (*FakeLink) ApplyEvents ¶
func (*FakeLink) CloseOldConnections ¶
func (fl *FakeLink) CloseOldConnections(_ map[t.NodeID]t.NodeAddress)
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) WaitFor ¶
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 (*FakeTransport) Nodes ¶
func (ft *FakeTransport) Nodes() map[t.NodeID]t.NodeAddress
type LocalCryptoSystem ¶
type LocalCryptoSystem interface { Crypto(id t.NodeID) mirCrypto.Crypto Module(id t.NodeID) modules.Module }
func NewLocalCryptoSystem ¶
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 (*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 (*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 SimNode ¶
type SimNode struct { *Simulation // contains filtered or unexported fields }
SimNode represents a Mir node deployed in the simulation runtime.
func (*SimNode) SendEvents ¶
SendEvents notifies simulation about the list of emitted events on behalf of the given process.
func (*SimNode) Start ¶
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 ¶
WrapModule wraps the module to be used in simulation.
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 (*SimTransport) Nodes ¶
func (st *SimTransport) Nodes() map[t.NodeID]t.NodeAddress
type Simulation ¶
Simulation represents a test deployment in the simulation runtime.
func NewSimulation ¶
func NewSimulation(rnd *rand.Rand, nodeIDs []t.NodeID, delayFn EventDelayFn) *Simulation
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.