Documentation ¶
Overview ¶
Package tests implements a very simple and unoptimized version of the dag.
It also contains mocks of various other structures that are useful for tests. Additionally, there is a mechanism for saving and loading dags from files.
Index ¶
- func AddUnit(dag gomel.Dag, pu gomel.Preunit) (gomel.Unit, error)
- func CollectUnits(dag gomel.Dag) map[gomel.Unit]bool
- func CreateDagFromTestFile(filename string, df DagFactory) (gomel.Dag, gomel.Adder, error)
- func CreateRandomNonForking(nProcesses, nUnits int) gomel.Dag
- func FromPreunit(pu gomel.Preunit, parents []gomel.Unit, dag gomel.Dag) gomel.Unit
- func NewAdder(dag gomel.Dag) gomel.Adder
- func NewOrderer() gomel.Orderer
- func NewPreunit(creator uint16, crown *gomel.Crown, data core.Data, rsData []byte, ...) gomel.Preunit
- func NewPreunitFromEpoch(epoch gomel.EpochID, creator uint16, crown *gomel.Crown, data core.Data, ...) gomel.Preunit
- func NewTestRandomSource() gomel.RandomSource
- func ReadDag(reader io.Reader, df DagFactory) (gomel.Dag, gomel.Adder, error)
- func WriteDag(writer io.Writer, dag gomel.Dag) error
- type Dag
- func (dag *Dag) AddCheck(check gomel.UnitChecker)
- func (dag *Dag) AfterInsert(hook gomel.InsertHook)
- func (dag *Dag) BeforeInsert(hook gomel.InsertHook)
- func (dag *Dag) BuildUnit(pu gomel.Preunit, parents []gomel.Unit) gomel.Unit
- func (dag *Dag) Check(u gomel.Unit) error
- func (dag *Dag) DecodeParents(pu gomel.Preunit) ([]gomel.Unit, error)
- func (dag *Dag) EpochID() gomel.EpochID
- func (dag *Dag) GetByID(id uint64) []gomel.Unit
- func (dag *Dag) GetUnit(hash *gomel.Hash) gomel.Unit
- func (dag *Dag) GetUnits(hashes []*gomel.Hash) []gomel.Unit
- func (dag *Dag) Insert(u gomel.Unit)
- func (dag *Dag) IsQuorum(number uint16) bool
- func (dag *Dag) MaximalUnitsPerProcess() gomel.SlottedUnits
- func (dag *Dag) NProc() uint16
- func (dag *Dag) UnitsAbove(heights []int) []gomel.Unit
- func (dag *Dag) UnitsOnLevel(level int) gomel.SlottedUnits
- type DagFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectUnits ¶
CollectUnits retrieves all units in depth-first order from a given dag.
func CreateDagFromTestFile ¶
CreateDagFromTestFile reads a dag description from the given test file and uses the factory to build the dag.
func CreateRandomNonForking ¶
CreateRandomNonForking creates a random test dag when given
nProcesses - number of processes nUnits - number of units to include in the dag
func FromPreunit ¶
FromPreunit makes a new test unit based on the given preunit and parents.
func NewOrderer ¶
NewOrderer returns an instance of the gomel.Orderer interface that is not performing any action when invoked. It is mainly used as a placeholder for the gomel.Orderer interface. In order to provide some non-trivial functionality, one should "override" some of its methods.
func NewPreunit ¶
func NewPreunit(creator uint16, crown *gomel.Crown, data core.Data, rsData []byte, priv gomel.PrivateKey) gomel.Preunit
NewPreunit creates a preunit.
func NewPreunitFromEpoch ¶
func NewPreunitFromEpoch(epoch gomel.EpochID, creator uint16, crown *gomel.Crown, data core.Data, rsData []byte, priv gomel.PrivateKey) gomel.Preunit
NewPreunitFromEpoch creates a preunit.
func NewTestRandomSource ¶
func NewTestRandomSource() gomel.RandomSource
NewTestRandomSource returns a simple RandomSource for testing.
func ReadDag ¶
ReadDag reads a dag description from the given reader and builds the dag using the given dag factory.
func WriteDag ¶
WriteDag writes a description of the given dag in the following format:
The 1st line contains an integer N - the number of processes. Then there is one line per unit in the following format:
C-H-V [Parents]
Where
(1) C is the Creator of a unit, (2) H is the Height of a unit, (3) V is the Version of a unit (0 for non-forked units, forks created by the same process on the same height are enumerated with consecutive integers) (4) Parents is the list of units separated by a single space encoded in the same C-H-V format
Types ¶
type Dag ¶
Dag is a basic implementation of dag for testing.
func (*Dag) AfterInsert ¶
func (dag *Dag) AfterInsert(hook gomel.InsertHook)
AfterInsert implementation
func (*Dag) BeforeInsert ¶
func (dag *Dag) BeforeInsert(hook gomel.InsertHook)
BeforeInsert implementation
func (*Dag) DecodeParents ¶
DecodeParents of the given preunit.
func (*Dag) GetUnit ¶
GetUnit returns the units with the given hashes or nil, when it doesn't find them.
func (*Dag) GetUnits ¶
GetUnits returns the units with the given hashes or nil, when it doesn't find them.
func (*Dag) IsQuorum ¶
IsQuorum checks whether the provided number of processes constitutes a quorum.
func (*Dag) MaximalUnitsPerProcess ¶
func (dag *Dag) MaximalUnitsPerProcess() gomel.SlottedUnits
MaximalUnitsPerProcess returns the maximal units for all processes.
func (*Dag) UnitsAbove ¶
UnitsAbove returns all units above given heights.
func (*Dag) UnitsOnLevel ¶
func (dag *Dag) UnitsOnLevel(level int) gomel.SlottedUnits
UnitsOnLevel returns all units at the given level.
type DagFactory ¶
type DagFactory interface { // CreateDag creates empty dag with a given configuration. CreateDag(nProc uint16) (gomel.Dag, gomel.Adder) }
DagFactory is an interface to create dags.
func NewTestDagFactory ¶
func NewTestDagFactory() DagFactory
NewTestDagFactory returns a factory for creating test dags.
func NewTestDagFactoryWithChecks ¶
func NewTestDagFactoryWithChecks() DagFactory
NewTestDagFactoryWithChecks returns a factory for creating test dags with basic compliance checks.
func NewTestDagFactoryWithEpochID ¶
func NewTestDagFactoryWithEpochID(id gomel.EpochID) DagFactory
NewTestDagFactoryWithEpochID returns a factory for creating test dags.