Documentation
¶
Index ¶
- func ExecutePureTask[C chasm.Component, T any](ctx context.Context, e *Engine, component C, ...) (taskDropped bool, err error)
- func ExecuteSideEffectTask[C chasm.Component, T any](ctx context.Context, e *Engine, component C, ...) (taskDropped bool, err error)
- type Engine
- func (e *Engine) DeleteExecution(_ context.Context, ref chasm.ComponentRef, _ chasm.DeleteExecutionRequest) error
- func (e *Engine) FirePureTasks(ref chasm.ComponentRef, referenceTime time.Time) (executed int, err error)
- func (e *Engine) NotifyExecution(key chasm.ExecutionKey)
- func (e *Engine) PollComponent(ctx context.Context, ref chasm.ComponentRef, ...) ([]byte, error)
- func (e *Engine) ReadComponent(ctx context.Context, ref chasm.ComponentRef, ...) error
- func (e *Engine) StartExecution(ctx context.Context, ref chasm.ComponentRef, ...) (chasm.StartExecutionResult, error)
- func (e *Engine) Tasks(ref chasm.ComponentRef) (map[tasks.Category][]tasks.Task, error)
- func (e *Engine) UpdateComponent(ctx context.Context, ref chasm.ComponentRef, ...) ([]byte, error)
- func (e *Engine) UpdateWithStartExecution(ctx context.Context, ref chasm.ComponentRef, ...) (chasm.EngineUpdateWithStartExecutionResult, error)
- type EngineOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecutePureTask ¶
func ExecutePureTask[C chasm.Component, T any]( ctx context.Context, e *Engine, component C, handler chasm.PureTaskHandler[C, T], attrs chasm.TaskAttributes, task T, ) (taskDropped bool, err error)
ExecutePureTask validates and executes a pure task atomically via Engine.UpdateComponent. It returns taskDropped set to true if chasm.PureTaskHandler.Validate returns (false, nil), indicating the task is no longer relevant and was not executed.
The component ref is resolved automatically — no separate Engine.ReadComponent call to obtain a ref is needed. Pass the component pointer directly.
This helper ensures that Validate is always exercised alongside Execute, matching the real engine's behavior. Use chasm.MockMutableContext directly when you need to inspect the typed task payloads added to the context during execution.
func ExecuteSideEffectTask ¶
func ExecuteSideEffectTask[C chasm.Component, T any]( ctx context.Context, e *Engine, component C, handler chasm.SideEffectTaskHandler[C, T], attrs chasm.TaskAttributes, task T, ) (taskDropped bool, err error)
ExecuteSideEffectTask validates and executes a side effect task. Validation runs via Engine.ReadComponent in read only mode, and if valid, chasm.SideEffectTaskHandler.Execute is called with an engine context so that chasm.UpdateComponent and chasm.ReadComponent inside the handler route through the test engine.
It returns taskDropped set to true if chasm.SideEffectTaskHandler.Validate returns (false, nil), indicating the task is no longer relevant and was not executed.
The component ref is resolved automatically — no separate Engine.ReadComponent call to obtain a ref is needed. Pass the component pointer directly.
Use chasm.MockMutableContext directly when you need to inspect typed task payloads added during execution, since the real engine serializes them into history layer tasks.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is a lightweight in memory CHASM engine for unit tests. It implements chasm.Engine and supports the full set of conflict and reuse policies, as well as blocking [PollComponent] with [NotifyExecution], matching the behavior of the production engine as closely as possible without persistence or shard logic.
func (*Engine) DeleteExecution ¶
func (e *Engine) DeleteExecution( _ context.Context, ref chasm.ComponentRef, _ chasm.DeleteExecutionRequest, ) error
func (*Engine) FirePureTasks ¶
func (e *Engine) FirePureTasks(ref chasm.ComponentRef, referenceTime time.Time) (executed int, err error)
FirePureTasks executes persisted pure tasks due by referenceTime and commits.
func (*Engine) NotifyExecution ¶
func (e *Engine) NotifyExecution(key chasm.ExecutionKey)
NotifyExecution wakes up any [PollComponent] callers waiting on the execution.
func (*Engine) PollComponent ¶
func (e *Engine) PollComponent( ctx context.Context, ref chasm.ComponentRef, predicate func(chasm.Context, chasm.Component) (bool, error), _ ...chasm.TransitionOption, ) ([]byte, error)
PollComponent waits until the supplied predicate is satisfied when evaluated against the component identified by ref. If the predicate is true immediately it returns without blocking. Otherwise it subscribes to [NotifyExecution] signals and re evaluates after each one, just like the production engine. Returns (nil, nil) if ctx is cancelled, matching the long poll timeout semantics of the production engine where the caller is expected to re-poll.
func (*Engine) ReadComponent ¶
func (*Engine) StartExecution ¶
func (e *Engine) StartExecution( ctx context.Context, ref chasm.ComponentRef, startFn func(chasm.MutableContext) (chasm.RootComponent, error), opts ...chasm.TransitionOption, ) (chasm.StartExecutionResult, error)
func (*Engine) Tasks ¶
Tasks returns all physical tasks scheduled for the execution identified by ref, grouped by category. Logical tasks accumulate across every Engine.UpdateComponent, Engine.StartExecution, and Engine.UpdateWithStartExecution call on the execution, and convert to physical tasks on CloseTransaction, matching what the real engine would deliver to task processors.
func (*Engine) UpdateComponent ¶
func (e *Engine) UpdateComponent( ctx context.Context, ref chasm.ComponentRef, updateFn func(chasm.MutableContext, chasm.Component) error, _ ...chasm.TransitionOption, ) ([]byte, error)
func (*Engine) UpdateWithStartExecution ¶
func (e *Engine) UpdateWithStartExecution( ctx context.Context, ref chasm.ComponentRef, startFn func(chasm.MutableContext) (chasm.RootComponent, error), updateFn func(chasm.MutableContext, chasm.Component) error, opts ...chasm.TransitionOption, ) (chasm.EngineUpdateWithStartExecutionResult, error)
type EngineOption ¶
type EngineOption func(*Engine)
func WithTimeSource ¶
func WithTimeSource(ts clock.TimeSource) EngineOption
WithTimeSource overrides the engine's default time source. The default is a clock.EventTimeSource initialized to time.Now at engine creation, which gives deterministic, frozen time suitable for most unit tests. Pass a *clock.EventTimeSource when tests need to advance time explicitly; the caller holds the reference and calls ts.Update(...) directly.