fixtures

package
v0.0.0-...-eadad3b Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package fixtures is a set of test fixtures and mocks of the various types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEnvelope

func NewEnvelope(
	id string,
	m dogma.Message,
	times ...time.Time,
) *envelopespec.Envelope

NewEnvelope returns a new envelope containing the given message.

If id is empty, a new UUID is generated.

times can contain up to two elements, the first is the created time, the second is the scheduled-for time.

func NewPacker

func NewPacker(roles message.TypeRoles) *parcel.Packer

NewPacker returns a parcel packer that uses a deterministic ID sequence and clock.

MessageID is a monotonically increasing integer, starting at 0. CreatedAt starts at 2000-01-01 00:00:00 UTC and increases by 1 second for each message.

The given roles are valid both as produced and consumed roles.

func NewParcel

func NewParcel(
	id string,
	m dogma.Message,
	times ...time.Time,
) parcel.Parcel

NewParcel returns a new parcel containing the given message.

If id is empty, a new UUID is generated.

times can contain up to two elements, the first is the created time, the second is the scheduled-for time.

Types

type AcknowledgerStub

type AcknowledgerStub struct {
	handler.Acknowledger

	AckFunc  func(context.Context, persistence.Batch) (persistence.Result, error)
	NackFunc func(context.Context, error) error
}

AcknowledgerStub is a test implementation of the handler.Acknowledger interface.

func (*AcknowledgerStub) Ack

Ack acknowledges the message, ensuring it is not handled again.

b is the batch from the unit-of-work.

func (*AcknowledgerStub) Nack

func (a *AcknowledgerStub) Nack(ctx context.Context, cause error) error

Nack negatively-acknowledges the message, causing it to be retried.

type DataStoreStub

type DataStoreStub struct {
	persistence.DataStore

	LoadAggregateMetaDataFunc func(context.Context, string, string) (persistence.AggregateMetaData, error)
	LoadEventsByTypeFunc      func(context.Context, map[string]struct{}, uint64) (persistence.EventResult, error)
	LoadEventsBySourceFunc    func(context.Context, string, string, string) (persistence.EventResult, error)
	LoadOffsetFunc            func(context.Context, string) (uint64, error)
	LoadProcessInstanceFunc   func(context.Context, string, string) (persistence.ProcessInstance, error)
	LoadQueueMessagesFunc     func(context.Context, int) ([]persistence.QueueMessage, error)
	PersistFunc               func(context.Context, persistence.Batch) (persistence.Result, error)
	CloseFunc                 func() error
}

DataStoreStub is a test implementation of the persistence.DataStore interface.

func NewDataStoreStub

func NewDataStoreStub() *DataStoreStub

NewDataStoreStub returns a new data-store stub that uses an in-memory persistence provider.

func (*DataStoreStub) Close

func (ds *DataStoreStub) Close() error

Close closes the data store.

func (*DataStoreStub) LoadAggregateMetaData

func (ds *DataStoreStub) LoadAggregateMetaData(
	ctx context.Context,
	hk, id string,
) (persistence.AggregateMetaData, error)

LoadAggregateMetaData loads the meta-data for an aggregate instance.

func (*DataStoreStub) LoadEventsBySource

func (ds *DataStoreStub) LoadEventsBySource(
	ctx context.Context,
	hk, id, d string,
) (persistence.EventResult, error)

LoadEventsBySource loads the events produced by a specific handler.

func (*DataStoreStub) LoadEventsByType

func (ds *DataStoreStub) LoadEventsByType(
	ctx context.Context,
	f map[string]struct{},
	o uint64,
) (persistence.EventResult, error)

LoadEventsByType loads events that match a specific set of message types.

func (*DataStoreStub) LoadOffset

func (ds *DataStoreStub) LoadOffset(
	ctx context.Context,
	ak string,
) (uint64, error)

LoadOffset loads the offset associated with a specific application.

func (*DataStoreStub) LoadProcessInstance

func (ds *DataStoreStub) LoadProcessInstance(
	ctx context.Context,
	hk, id string,
) (persistence.ProcessInstance, error)

LoadProcessInstance loads a process instance.

func (*DataStoreStub) LoadQueueMessages

func (ds *DataStoreStub) LoadQueueMessages(
	ctx context.Context,
	n int,
) ([]persistence.QueueMessage, error)

LoadQueueMessages loads the next n messages from the queue.

func (*DataStoreStub) Persist

Persist commits a batch of operations atomically.

type EventResultStub

type EventResultStub struct {
	persistence.EventResult

	NextFunc  func(context.Context) (persistence.Event, bool, error)
	CloseFunc func() error
}

EventResultStub is a test implementation of the persistence.EventResult interface.

func (*EventResultStub) Close

func (r *EventResultStub) Close() error

Close closes the cursor.

func (*EventResultStub) Next

Next returns the next event in the result.

type EventStreamHandlerStub

type EventStreamHandlerStub struct {
	eventstream.Handler

	NextOffsetFunc  func(context.Context, configkit.Identity) (uint64, error)
	HandleEventFunc func(context.Context, uint64, eventstream.Event) error
}

EventStreamHandlerStub is a test implementation of the eventstream.Handler interface.

func (*EventStreamHandlerStub) HandleEvent

func (h *EventStreamHandlerStub) HandleEvent(
	ctx context.Context,
	o uint64,
	ev eventstream.Event,
) error

HandleEvent handles an event obtained from the event stream.

func (*EventStreamHandlerStub) NextOffset

func (h *EventStreamHandlerStub) NextOffset(
	ctx context.Context,
	id configkit.Identity,
) (uint64, error)

NextOffset returns the offset of the next event to be consumed from a specific application's event stream.

type EventStreamStub

type EventStreamStub struct {
	eventstream.Stream

	ApplicationFunc func() configkit.Identity
	EventTypesFunc  func(context.Context) (message.TypeCollection, error)
	OpenFunc        func(context.Context, uint64, message.TypeCollection) (eventstream.Cursor, error)
}

EventStreamStub is a test implementation of the eventstream.Stream interface.

func (*EventStreamStub) Application

func (s *EventStreamStub) Application() configkit.Identity

Application returns the identity of the application that owns the stream.

func (*EventStreamStub) EventTypes

EventTypes returns the set of event types that may appear on the stream.

func (*EventStreamStub) Open

Open returns a cursor that reads events from the stream.

type HandlerStub

type HandlerStub struct {
	handler.Handler

	HandleMessageFunc func(context.Context, handler.UnitOfWork, parcel.Parcel) error
}

HandlerStub is a test implementation of the handler.Provider interface.

func (*HandlerStub) HandleMessage

func (h *HandlerStub) HandleMessage(ctx context.Context, w handler.UnitOfWork, p parcel.Parcel) error

HandleMessage handles the message in p.

type ProviderStub

type ProviderStub struct {
	persistence.Provider

	OpenFunc func(context.Context, string) (persistence.DataStore, error)
}

ProviderStub is a test implementation of the persistence.Provider interface.

func (*ProviderStub) Open

Open returns a data-store for a specific application.

type UnitOfWorkStub

type UnitOfWorkStub struct {
	Commands   []parcel.Parcel
	Events     []parcel.Parcel
	Timeouts   []parcel.Parcel
	Operations []persistence.Operation
	Deferred   []handler.DeferFunc
}

UnitOfWorkStub is a test implementation of the handler.UnitOfWork interface.

func (*UnitOfWorkStub) Defer

func (w *UnitOfWorkStub) Defer(fn handler.DeferFunc)

Defer registers fn to be called when the unit-of-work is complete.

func (*UnitOfWorkStub) Do

Do updates the unit-of-work to include op in the persistence batch.

func (*UnitOfWorkStub) ExecuteCommand

func (w *UnitOfWorkStub) ExecuteCommand(p parcel.Parcel)

ExecuteCommand updates the unit-of-work to execute the command in p.

func (*UnitOfWorkStub) Fail

func (w *UnitOfWorkStub) Fail(err error)

Fail invokes the unit-of-work's deferred functions with the given error.

func (*UnitOfWorkStub) RecordEvent

func (w *UnitOfWorkStub) RecordEvent(p parcel.Parcel)

RecordEvent updates the unit-of-work to record the event in p.

func (*UnitOfWorkStub) ScheduleTimeout

func (w *UnitOfWorkStub) ScheduleTimeout(p parcel.Parcel)

ScheduleTimeout updates the unit-of-work to schedule the timeout in p.

func (*UnitOfWorkStub) Succeed

func (w *UnitOfWorkStub) Succeed(res handler.Result)

Succeed invokes the unit-of-work's deferred functions with the given result.

Jump to

Keyboard shortcuts

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