testing

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge interface {
	// StartVertex is the head of the connection
	SetStartVertex(Vertex)
	GetStartVertex() Vertex
	// EndVertex is the end of the connection
	SetEndVertex(Vertex)
	GetEndVertex() Vertex
	// Condition defines a function to determine if this connection is accessible
	SetCondition(func(...interface{}) bool)
	GetCondition() func(...interface{}) bool
	// Action defines function to perform when the end vertex reached
	SetAction(func())
	GetAction() func()
	DeepCopy() Edge
}

Edge is the connection between two vertices

func NewHistoryEventEdge

func NewHistoryEventEdge(
	start Vertex,
	end Vertex,
) Edge

NewHistoryEventEdge initials a new edge between two HistoryEventVertexes

type EventGenerator

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

EventGenerator is a history event generator The event generator will generate next history event based on the history event transition graph defined in the model

func (*EventGenerator) AddExitVertex

func (g *EventGenerator) AddExitVertex(
	exit ...Vertex,
)

AddExitVertex adds the terminate history event vertex

func (*EventGenerator) AddInitialEntryVertex

func (g *EventGenerator) AddInitialEntryVertex(
	entry ...Vertex,
)

AddInitialEntryVertex adds the initial history event vertices Generator will only start from one of the entry vertex

func (*EventGenerator) AddModel

func (g *EventGenerator) AddModel(
	model Model,
)

AddModel adds a history event model

func (*EventGenerator) AddRandomEntryVertex

func (g *EventGenerator) AddRandomEntryVertex(
	exit ...Vertex,
)

AddRandomEntryVertex adds the random history event vertex

func (*EventGenerator) DeepCopy

func (g *EventGenerator) DeepCopy() Generator

DeepCopy copy a new instance of generator

func (*EventGenerator) GetNextVertices

func (g *EventGenerator) GetNextVertices() []Vertex

GetNextVertices generates a batch of history events happened in the same transaction

func (*EventGenerator) GetVersion

func (g *EventGenerator) GetVersion() int64

GetVersion returns event version

func (*EventGenerator) HasNextVertex

func (g *EventGenerator) HasNextVertex() bool

HasNextVertex checks if there is accessible history event vertex

func (EventGenerator) ListGeneratedVertices

func (g EventGenerator) ListGeneratedVertices() []Vertex

ListGeneratedVertices returns all the generated history events

func (*EventGenerator) Reset

func (g *EventGenerator) Reset()

Reset reset the generator to the initial state

func (*EventGenerator) SetBatchGenerationRule

func (g *EventGenerator) SetBatchGenerationRule(
	canDoBatchFunc func([]Vertex, []Vertex) bool,
)

SetBatchGenerationRule sets a function to determine next generated batch of history events

func (*EventGenerator) SetVersion

func (g *EventGenerator) SetVersion(version int64)

SetVersion sets the event version

type Generator

type Generator interface {
	// InitialEntryVertex is the beginning vertices of the graph
	// Only one vertex will be picked as the entry
	AddInitialEntryVertex(...Vertex)
	// ExitVertex is the terminate vertices of the graph
	AddExitVertex(...Vertex)
	// RandomEntryVertex is a random entry point which can be access at any state of the generator
	AddRandomEntryVertex(...Vertex)
	// AddModel loads model into the generator
	// AddModel can load multiple models and models will be joint if there is common vertices
	AddModel(Model)
	// HasNextVertex determines if there is more vertex to generate
	HasNextVertex() bool
	// GetNextVertices generates next vertex batch
	GetNextVertices() []Vertex
	// ListGeneratedVertices lists the pasted generated vertices
	ListGeneratedVertices() []Vertex
	// Reset cleans up all the internal states and reset to a brand new generator
	Reset()
	// DeepCopy copy a new instance of generator
	DeepCopy() Generator
	// SetBatchGenerationRule sets a function that used in GetNextVertex to return batch result
	SetBatchGenerationRule(func([]Vertex, []Vertex) bool)
	// SetVersion sets the event version
	SetVersion(int64)
	// GetVersion gets the event version
	GetVersion() int64
}

Generator generates a sequence of vertices based on the defined models It must define InitialEntryVertex and ExitVertex To use a generator:

for generator.HasNextVertex {
    generator.GetNextVertices
}

func InitializeHistoryEventGenerator

func InitializeHistoryEventGenerator(
	domain string,
	defaultVersion int64,
) Generator

InitializeHistoryEventGenerator initializes the history event generator

func NewEventGenerator

func NewEventGenerator(
	seed int64,
) Generator

NewEventGenerator initials the event generator

type HistoryEventEdge

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

HistoryEventEdge is the directional edge of two history events

func (*HistoryEventEdge) DeepCopy

func (c *HistoryEventEdge) DeepCopy() Edge

DeepCopy copies a new edge

func (HistoryEventEdge) GetAction

func (c HistoryEventEdge) GetAction() func()

GetAction returns the action

func (HistoryEventEdge) GetCondition

func (c HistoryEventEdge) GetCondition() func(...interface{}) bool

GetCondition returns the condition

func (HistoryEventEdge) GetEndVertex

func (c HistoryEventEdge) GetEndVertex() Vertex

GetEndVertex returns the end vertex

func (HistoryEventEdge) GetStartVertex

func (c HistoryEventEdge) GetStartVertex() Vertex

GetStartVertex returns the start vertex

func (*HistoryEventEdge) SetAction

func (c *HistoryEventEdge) SetAction(action func())

SetAction sets an action to perform when the end vertex hits

func (*HistoryEventEdge) SetCondition

func (c *HistoryEventEdge) SetCondition(
	condition func(...interface{}) bool,
)

SetCondition sets the condition to access this edge

func (*HistoryEventEdge) SetEndVertex

func (c *HistoryEventEdge) SetEndVertex(end Vertex)

SetEndVertex sets the end vertex

func (*HistoryEventEdge) SetStartVertex

func (c *HistoryEventEdge) SetStartVertex(
	start Vertex,
)

SetStartVertex sets the start vertex

type HistoryEventModel

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

HistoryEventModel is a graph represents relationships among history event types

func (*HistoryEventModel) AddEdge

func (m *HistoryEventModel) AddEdge(
	edge ...Edge,
)

AddEdge adds an edge to the model

func (HistoryEventModel) ListEdges

func (m HistoryEventModel) ListEdges() []Edge

ListEdges returns all added edges

type HistoryEventVertex

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

HistoryEventVertex represents one type of history event

func (HistoryEventVertex) DeepCopy

func (he HistoryEventVertex) DeepCopy() Vertex

DeepCopy returns the a deep copy of vertex

func (*HistoryEventVertex) GenerateData

func (he *HistoryEventVertex) GenerateData(
	input ...interface{},
) interface{}

GenerateData generates the data and return

func (HistoryEventVertex) GetData

func (he HistoryEventVertex) GetData() interface{}

GetData returns the vertex data

func (HistoryEventVertex) GetDataFunc

func (he HistoryEventVertex) GetDataFunc() func(...interface{}) interface{}

GetDataFunc returns the data generation function

func (HistoryEventVertex) GetMaxNextVertex

func (he HistoryEventVertex) GetMaxNextVertex() int

GetMaxNextVertex returns the max concurrent path

func (HistoryEventVertex) GetName

func (he HistoryEventVertex) GetName() string

GetName returns the name

func (HistoryEventVertex) IsStrictOnNextVertex

func (he HistoryEventVertex) IsStrictOnNextVertex() bool

IsStrictOnNextVertex returns the isStrict flag

func (*HistoryEventVertex) SetDataFunc

func (he *HistoryEventVertex) SetDataFunc(
	dataFunc func(...interface{}) interface{},
)

SetDataFunc sets the data generation function

func (*HistoryEventVertex) SetIsStrictOnNextVertex

func (he *HistoryEventVertex) SetIsStrictOnNextVertex(
	isStrict bool,
)

SetIsStrictOnNextVertex sets if a vertex can be added between the current vertex and its child Vertices

func (*HistoryEventVertex) SetMaxNextVertex

func (he *HistoryEventVertex) SetMaxNextVertex(
	maxNextGeneration int,
)

SetMaxNextVertex sets the max concurrent path can be generated from this vertex

func (*HistoryEventVertex) SetName

func (he *HistoryEventVertex) SetName(
	name string,
)

SetName sets the name

type Model

type Model interface {
	AddEdge(...Edge)
	ListEdges() []Edge
}

Model represents a state transition graph that contains all the relationships of Vertex

func NewHistoryEventModel

func NewHistoryEventModel() Model

NewHistoryEventModel initials new history event model

type Vertex

type Vertex interface {
	// The name of the vertex. Usually, this will be the Cadence event type
	SetName(string)
	GetName() string
	//Equals(Vertex) bool
	// IsStrictOnNextVertex means if the vertex must be followed by its children
	// When IsStrictOnNextVertex set to true, it means this event can only follow by its neighbors
	SetIsStrictOnNextVertex(bool)
	IsStrictOnNextVertex() bool
	// MaxNextVertex means the max neighbors can branch out from this vertex
	SetMaxNextVertex(int)
	GetMaxNextVertex() int

	// SetVertexDataFunc sets a function to generate end vertex data
	SetDataFunc(func(...interface{}) interface{})
	GetDataFunc() func(...interface{}) interface{}
	GenerateData(...interface{}) interface{}
	GetData() interface{}
	DeepCopy() Vertex
}

Vertex represents a state in the model. A state represents a type of an Cadence event

func NewHistoryEventVertex

func NewHistoryEventVertex(
	name string,
) Vertex

NewHistoryEventVertex initials a history event vertex

Jump to

Keyboard shortcuts

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