Documentation
¶
Index ¶
- Constants
- func NewLogger(parentLogger logging.Logger) logging.Logger
- func NewNodeIDsDefaultWeights(nNodes int) map[t.NodeID]types.VoteWeight
- func NewNodeIDsWeights(nNodes int, weightFunction func(t.NodeID) types.VoteWeight) map[t.NodeID]types.VoteWeight
- 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(_ *trantorpbtypes.Membership)
- func (fl *FakeLink) Connect(_ *trantorpbtypes.Membership)
- 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) error
- type FakeTransport
- func (ft *FakeTransport) Close()
- func (ft *FakeTransport) Link(source t.NodeID) (net.Transport, error)
- func (ft *FakeTransport) Membership() *trantorpbtypes.Membership
- 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
- 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 // TXListenPort is the port number on which nodes' TransactionReceivers listen for incoming transactions. TXListenPort = 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 NewNodeIDsDefaultWeights ¶ added in v0.4.0
func NewNodeIDsDefaultWeights(nNodes int) map[t.NodeID]types.VoteWeight
func NewNodeIDsWeights ¶ added in v0.4.0
func NewNodeIDsWeights(nNodes int, weightFunction func(t.NodeID) types.VoteWeight) map[t.NodeID]types.VoteWeight
NewNodeIDsWeights returns a map of node ids of the given size suitable for testing with the nodeID as key and their weight as value. The weight is calculated with a function parameter that is iteratively called in order from the first nodeID 0 to the last nodeID nNodes-1
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 transactions 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 // The state of the FakeApp only consists of a counter of processed transactions. TransactionsProcessed 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 []*trantorpbtypes.Transaction) 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
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(_ *trantorpbtypes.Membership)
func (*FakeLink) Connect ¶
func (fl *FakeLink) Connect(_ *trantorpbtypes.Membership)
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.
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(nodeIDsWeight map[t.NodeID]types.VoteWeight) *FakeTransport
func (*FakeTransport) Close ¶
func (ft *FakeTransport) Close()
func (*FakeTransport) Membership ¶ added in v0.4.0
func (ft *FakeTransport) Membership() *trantorpbtypes.Membership
type LocalCryptoSystem ¶
type LocalCryptoSystem interface { Crypto(id t.NodeID) (mirCrypto.Crypto, error) Module(id t.NodeID) (modules.Module, error) }
func NewLocalCryptoSystem ¶
func NewLocalCryptoSystem(_ string, nodeIDs []t.NodeID, _ logging.Logger) (LocalCryptoSystem, error)
NewLocalCryptoSystem creates an instance of LocalCryptoSystem suitable for tests. In the current implementation, cryptoType can only be "pseudo". TODO: Think about merging all the code in this file with the pseudo crypto implementation.
type LocalGrpcTransport ¶
type LocalGrpcTransport struct {
// contains filtered or unexported fields
}
func NewLocalGrpcTransport ¶
func NewLocalGrpcTransport(nodeIDsWeight map[t.NodeID]types.VoteWeight, logger logging.Logger) (*LocalGrpcTransport, error)
func (*LocalGrpcTransport) Close ¶
func (t *LocalGrpcTransport) Close()
func (*LocalGrpcTransport) Membership ¶ added in v0.4.0
func (t *LocalGrpcTransport) Membership() *trantorpbtypes.Membership
type LocalLibp2pTransport ¶
type LocalLibp2pTransport struct {
// contains filtered or unexported fields
}
func NewLocalLibp2pTransport ¶
func NewLocalLibp2pTransport(nodeIDsWeight map[t.NodeID]types.VoteWeight, logger logging.Logger) *LocalLibp2pTransport
func (*LocalLibp2pTransport) Close ¶
func (t *LocalLibp2pTransport) Close()
func (*LocalLibp2pTransport) Membership ¶ added in v0.4.0
func (t *LocalLibp2pTransport) Membership() *trantorpbtypes.Membership
type LocalTransportLayer ¶
type LocalTransportLayer interface { Link(source t.NodeID) (net.Transport, error) Membership() *trantorpbtypes.Membership Close() }
func NewLocalTransportLayer ¶
func NewLocalTransportLayer(sim *Simulation, transportType string, nodeIDsWeight map[t.NodeID]types.VoteWeight, logger logging.Logger) (LocalTransportLayer, error)
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, nodeIDsWeight map[t.NodeID]types.VoteWeight, delayFn MessageDelayFn) *SimTransport
func (*SimTransport) Close ¶
func (st *SimTransport) Close()
func (*SimTransport) Membership ¶ added in v0.4.0
func (st *SimTransport) Membership() *trantorpbtypes.Membership
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. Membership *trantorpbtypes.Membership // 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 transactions each client submits during the execution of the deployment. NumFakeTXs int // The number of transactions sent over the network (by a single DummyClient) NumNetTXs int // The target module for the clients' transactions. FakeTXDestModule 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. Membership *trantorpbtypes.Membership // Node's representation within the simulation runtime Sim *SimNode // Node's process within the simulation runtime Proc *testsim.Process // Number of simulated transactions inserted in the test replica by a hypothetical client. NumFakeTXs int // ID of the module to which fake transactions should be sent. FakeTXDestModule 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.