Back to godoc.org

Package engine

v0.6.0
Latest Go to latest
Published: Jun 12, 2020 | License: MIT | Module: github.com/dogmatiq/testkit

Overview

Package engine contains an in-memory Dogma engine.

Index

Package Files

Constants

const DefaultTickInterval = 250 * time.Millisecond

DefaultTickInterval is the default interval at which Run() and RunTimeScaled() will perform an engine tick.

func Run

func Run(
	ctx context.Context,
	e *Engine,
	d time.Duration,
	opts ...OperationOption,
) error

Run repeatedly calls e.Tick() until ctx is canceled or an error occurs.

d is the duration between ticks. If it is 0, DefaultTickInterval is used.

func RunTimeScaled

func RunTimeScaled(
	ctx context.Context,
	e *Engine,
	d time.Duration,
	f float64,
	t time.Time,
	opts ...OperationOption,
) error

RunTimeScaled repeatedly calls e.Tick() until ctx is canceled or an error occurs.

d is the duration between ticks. If it is 0, DefaultTickInterval is used.

Each tick is performed using a WithCurrentTime() option that scales time by a factor of f. For example, if f is 2.0, the engine will see time progress by 2 for every 1 second of real time.

t is the "epoch time", used as current time for the first tick. If t.IsZero() is true, the current time is used.

type Engine

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

Engine is an in-memory Dogma engine that is used to execute tests.

func New

func New(app dogma.Application, options ...Option) (_ *Engine, err error)

New returns a new engine that uses the given app configuration.

func (*Engine) Dispatch

func (e *Engine) Dispatch(
	ctx context.Context,
	m dogma.Message,
	options ...OperationOption,
) error

Dispatch processes a message.

It is not an error to process a message that is not routed to any handlers.

func (*Engine) ExecuteCommand

func (e *Engine) ExecuteCommand(ctx context.Context, m dogma.Message) error

ExecuteCommand enqueues a command for execution.

It panics if the command is not routed to any handlers.

func (*Engine) RecordEvent

func (e *Engine) RecordEvent(ctx context.Context, m dogma.Message) error

RecordEvent records the occurrence of an event.

It is not an error to record an event that is not routed to any handlers.

func (*Engine) Reset

func (e *Engine) Reset()

Reset clears the engine's state, such as aggregate and process roots.

func (*Engine) Tick

func (e *Engine) Tick(
	ctx context.Context,
	options ...OperationOption,
) error

Tick performs one "tick" of the engine.

This allows external control of time-based features of the engine. now is the time that the engine should treat as the current time.

type OperationOption

type OperationOption func(*operationOptions)

OperationOption applies optional settings while dispatching a message or performing a tick.

func EnableAggregates

func EnableAggregates(enabled bool) OperationOption

EnableAggregates returns an operation option that enables or disables aggregate message handlers.

All handler types are enabled by default.

func EnableIntegrations

func EnableIntegrations(enabled bool) OperationOption

EnableIntegrations returns an operation option that enables or disables integration message handlers.

All handler types are enabled by default.

func EnableProcesses

func EnableProcesses(enabled bool) OperationOption

EnableProcesses returns an operation option that enables or disables process message handlers.

All handler types are enabled by default.

func EnableProjections

func EnableProjections(enabled bool) OperationOption

EnableProjections returns an operation option that enables or disables projection message handlers.

All handler types are enabled by default.

func WithCurrentTime

func WithCurrentTime(t time.Time) OperationOption

WithCurrentTime returns an operation option that sets the engine's current time.

Note that if this option is used with the test runner, it will take precedence over the testkit.WithStartTime() option, clobbering any adjustments to the test clock made with the Test.AdvanceTimeTo() and AdvanceTimeBy() methods.

func WithObserver

func WithObserver(o fact.Observer) OperationOption

WithObserver returns an option that registers the given observer for the duration of the operation.

Multiple observers can be registered during a single operation.

type Option

type Option func(*engineOptions)

Option applies optional engine-wide settings.

func WithResetter

func WithResetter(fn func()) Option

WithResetter returns an engine option that registers a reset hook with the engine.

fn is a function to be called whenever the engine is reset.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier