tests

package
v0.0.0-...-dfb9311 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 18 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUnit

func AddUnit(dag gomel.Dag, pu gomel.Preunit) (gomel.Unit, error)

AddUnit adds a preunit to the given dag.

func CollectUnits

func CollectUnits(dag gomel.Dag) map[gomel.Unit]bool

CollectUnits retrieves all units in depth-first order from a given dag.

func CreateDagFromTestFile

func CreateDagFromTestFile(filename string, df DagFactory) (gomel.Dag, gomel.Adder, error)

CreateDagFromTestFile reads a dag description from the given test file and uses the factory to build the dag.

func CreateRandomNonForking

func CreateRandomNonForking(nProcesses, nUnits int) gomel.Dag

CreateRandomNonForking creates a random test dag when given

nProcesses - number of processes
nUnits     - number of units to include in the dag

func FromPreunit

func FromPreunit(pu gomel.Preunit, parents []gomel.Unit, dag gomel.Dag) gomel.Unit

FromPreunit makes a new test unit based on the given preunit and parents.

func NewAdder

func NewAdder(dag gomel.Dag) gomel.Adder

NewAdder creates a very simple adder for testing purposes.

func NewOrderer

func NewOrderer() gomel.Orderer

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

func ReadDag(reader io.Reader, df DagFactory) (gomel.Dag, gomel.Adder, error)

ReadDag reads a dag description from the given reader and builds the dag using the given dag factory.

func WriteDag

func WriteDag(writer io.Writer, dag gomel.Dag) error

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

type Dag struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Dag is a basic implementation of dag for testing.

func (*Dag) AddCheck

func (dag *Dag) AddCheck(check gomel.UnitChecker)

AddCheck implementation

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) BuildUnit

func (dag *Dag) BuildUnit(pu gomel.Preunit, parents []gomel.Unit) gomel.Unit

BuildUnit makes a new test unit based on the given preunit and parents.

func (*Dag) Check

func (dag *Dag) Check(u gomel.Unit) error

Check checks.

func (*Dag) DecodeParents

func (dag *Dag) DecodeParents(pu gomel.Preunit) ([]gomel.Unit, error)

DecodeParents of the given preunit.

func (*Dag) EpochID

func (dag *Dag) EpochID() gomel.EpochID

EpochID implementation

func (*Dag) GetByID

func (dag *Dag) GetByID(id uint64) []gomel.Unit

GetByID returns all the units associated with the given ID.

func (*Dag) GetUnit

func (dag *Dag) GetUnit(hash *gomel.Hash) gomel.Unit

GetUnit returns the units with the given hashes or nil, when it doesn't find them.

func (*Dag) GetUnits

func (dag *Dag) GetUnits(hashes []*gomel.Hash) []gomel.Unit

GetUnits returns the units with the given hashes or nil, when it doesn't find them.

func (*Dag) Insert

func (dag *Dag) Insert(u gomel.Unit)

Insert the unit into the dag.

func (*Dag) IsQuorum

func (dag *Dag) IsQuorum(number uint16) bool

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) NProc

func (dag *Dag) NProc() uint16

NProc returns the number of processes in this dag.

func (*Dag) UnitsAbove

func (dag *Dag) UnitsAbove(heights []int) []gomel.Unit

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.

Jump to

Keyboard shortcuts

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