InMemoryEventLog

class InMemoryEventLog(val partitions: Int = DEFAULT_PARTITIONS, val context: String? = null) : EventLog, AccessWalks

An EventLog in memory, for tests and samples. Appends are serialized by one lock, so the sequence within a partition is trivially the order commits became visible. As the durable backends, it keeps the request key per aggregate type. Each partition keeps its PartitionLineage, PartitionLineage.ROOT as created. It keeps each stream's stamp, stamps the access attributes over a history and records each type's walk (AccessWalks) as the durable logs do; its aggregates are ordered by id, then tenant: an aggregate is one once its first stream committed.

It refuses what the durable logs refuse, before it writes anything, with an IllegalArgumentException: given its context, a stream of another bounded context; and in appendAll, a group of more than one context, or whose streams of one aggregate skip a version (requireChains). Without a context it takes streams of any context, one append at a time, as a test that keeps several contexts in one log does.

Constructors

Link copied to clipboard
constructor(partitions: Int = DEFAULT_PARTITIONS, context: String? = null)

Properties

Link copied to clipboard
open override val appendsAcrossPartitions: Boolean

Its appendAll appends one stream at a time under the one lock, whichever partitions.

Link copied to clipboard

The bounded context whose streams it holds alone, as a node's log; null for streams of any context.

Link copied to clipboard
open override val partitions: Int

Functions

Link copied to clipboard
open suspend override fun advance(type: AggregateType, schema: String, cursor: String?, walked: Long, completed: Boolean): Boolean
Link copied to clipboard
open suspend override fun aggregates(type: AggregateType, after: String?, limit: Int): AggregatePage
Link copied to clipboard
open suspend override fun append(stream: EventStreamRecord, transport: ByteArray?): AppendOutcome
Link copied to clipboard
open suspend override fun appendAll(streams: List<Append>): List<AppendOutcome>

The streams appended one at a time, as EventLog.appendAll does, once the group is one context's (the log's, when it has one) and each aggregate's streams in it come in consecutive versions.

Link copied to clipboard
open suspend override fun claim(type: AggregateType, walk: AccessWalk, expected: String?): Boolean
Link copied to clipboard
open suspend override fun claimCreation(type: AggregateType, tenantId: String, requestId: String, claim: CreationClaim): CreationClaim

No claim: a request is keyed per (tenant, request) and type, so a second attempt under another id meets it.

Link copied to clipboard
open suspend override fun findByRequestId(type: AggregateType, tenantId: String, requestId: String): EventStreamRecord?
Link copied to clipboard
open suspend override fun head(partition: Int): Long?
Link copied to clipboard
open suspend override fun holds(type: AggregateType): Boolean

Whether a stream of type was appended: the store of a type's history is its streams.

Link copied to clipboard
open suspend override fun lineage(partition: Int): PartitionLineage
Link copied to clipboard
open suspend override fun positionOf(ref: AggregateRef, version: Int): LogPosition?
Link copied to clipboard
open override fun read(ref: AggregateRef, fromVersion: Int, toVersion: Int): Flow<EventStreamRecord>
Link copied to clipboard
open override fun readEntries(ref: AggregateRef, fromVersion: Int, toVersion: Int): Flow<LogEntry>
Link copied to clipboard
open suspend override fun readTail(ref: AggregateRef, fromVersion: Int, earlier: Int): AggregateTail

One read under the lock: the tail and the earlier request keys of the same moment.

Link copied to clipboard
open override fun serve(schemas: Map<AggregateType, String>)
Link copied to clipboard
open suspend override fun stamp(ref: AggregateRef, access: Map<String, Any?>, asOf: Int, from: Int, until: Int): Int

Replaces each stream it stamps wherever the log keeps it: by aggregate, by request and in its partition.

Link copied to clipboard
open override fun tail(partition: Int, after: Long?): Flow<LogEntry>
Link copied to clipboard
open suspend override fun walk(type: AggregateType): AccessWalk?