inmemory

package
v0.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package inmemory provides an in-memory implementation of an Event Store, and some other utilities that use an in-memory backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventStore

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

EventStore is an in-memory eventstore.Store implementation.

func NewEventStore

func NewEventStore() *EventStore

NewEventStore creates a new empty EventStore instance.

func (*EventStore) Append

func (s *EventStore) Append(
	ctx context.Context,
	id stream.ID,
	expected eventstore.VersionCheck,
	events ...eventually.Event,
) (int64, error)

Append inserts the specified Domain Events into the Event Stream specified by the current instance, returning the new version of the Event Stream.

A version can be specified to enable an Optimistic Concurrency check on append, by using the expected version of the Event Stream prior to appending the new Events.

Alternatively, -1 can be used if no Optimistic Concurrency check should be carried out.

An instance of ConflictError will be returned if the optimistic locking version check fails against the current version of the Event Stream.

func (*EventStore) LatestSequenceNumber

func (s *EventStore) LatestSequenceNumber(ctx context.Context) (int64, error)

LatestSequenceNumber returns the size of the internal Event Log. This method never fails.

func (*EventStore) Stream

func (s *EventStore) Stream(
	ctx context.Context,
	es eventstore.EventStream,
	target stream.Target,
	selectt eventstore.Select,
) error

Stream streams committed events in the Event Store onto the provided EventStream, from the specified Global Sequence Number in `from`, based on the provided stream.Target.

Note: this call is synchronous, and will return when all the Events have been successfully written to the provided EventStream, or when the context has been canceled.

This method fails only when the context is canceled.

type TrackingEventStore

type TrackingEventStore struct {
	eventstore.Appender
	// contains filtered or unexported fields
}

TrackingEventStore is an Event Store wrapper to track the Events committed to the inner Event Store.

Useful for tests assertion.

func NewTrackingEventStore

func NewTrackingEventStore(appender eventstore.Appender) *TrackingEventStore

NewTrackingEventStore wraps an Event Store to capture events that get appended to it.

func (*TrackingEventStore) Append

func (es *TrackingEventStore) Append(
	ctx context.Context,
	id stream.ID,
	expected eventstore.VersionCheck,
	events ...eventually.Event,
) (int64, error)

Append forwards the call to the wrapped Event Store instance and, if the operation concludes successfully, records these events internally.

The recorded events can be accessed by calling Recorded().

func (*TrackingEventStore) Recorded

func (es *TrackingEventStore) Recorded() []eventstore.Event

Recorded returns the list of Events that have been appended to the Event Store.

Please note: these events do not record the Sequence Number assigned by the Event Store. Usually you should not need it in test assertions, since the order of Events in the returned slice always follows the global order of the Event Stream (or the Event Store).

Jump to

Keyboard shortcuts

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