Chronicle.Testing.InMemoryKernel (cratis_chronicle v3.16.1)

Copy Markdown View Source

An in-memory fake Chronicle kernel: a GenServer holding an event log plus a %GRPC.Channel{} interceptor answering the subset of the Chronicle wire protocol the client needs to append, read, and register artifacts.

This is the seam Chronicle.Testing.start_supervised_client/1 uses to run a real Chronicle.Client against no real kernel: the client's own append, constraint, and unit-of-work code runs completely unchanged, talking to this process instead of a socket.

Supported RPCs: the compatibility check, Append/AppendManyForEventSources, reads (ForEventSourceIdAndEventTypes/FromSequenceNumber), TailSequenceNumber, HasEventsForEventSourceId, and the registration calls for event types, event sources, constraints, read models and projections (acknowledged, not modeled — constraint definitions are supplied directly at start_link/1, not parsed off the wire; see the moduledoc on Chronicle.Testing). Every other RPC returns {:error, {:not_supported_in_memory, rpc}} — most prominently closes_stream constraints and the actual ReadModels/Projections query surface, which is why Chronicle.Testing.read_model/3 reads reducer state kept by Chronicle.Testing.Dispatcher instead of querying a kernel sink that does not exist.

Concurrency scopes are honored along every dimension (:event_source_id, :event_stream_type, :event_stream_id, :event_source_type, :event_types, including ExpectsNoMatchingEvent). Constraints support :unique (ignoring casing, scoped, respecting removal) and :unique_event_type.

Summary

Functions

Returns every committed wire event, across every event source and sequence, in append order. Used by Chronicle.Testing.Assertions.

Returns a %GRPC.Channel{} whose interceptor answers RPCs against this kernel.

Returns a specification to start this module under a supervisor.

Starts an in-memory kernel.

Subscribes pid to every committed append batch: {:chronicle_testing_appended, event_store, namespace, event_sequence_id, [wire_event, ...]}.

Returns every committed wire event for event_source_id, across every event sequence, in append order.

Functions

all_wire_events(kernel)

@spec all_wire_events(GenServer.server()) :: [map()]

Returns every committed wire event, across every event source and sequence, in append order. Used by Chronicle.Testing.Assertions.

channel(kernel)

@spec channel(GenServer.server()) :: GRPC.Channel.t()

Returns a %GRPC.Channel{} whose interceptor answers RPCs against this kernel.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts an in-memory kernel.

Options

subscribe(kernel, pid)

@spec subscribe(GenServer.server(), pid()) :: :ok

Subscribes pid to every committed append batch: {:chronicle_testing_appended, event_store, namespace, event_sequence_id, [wire_event, ...]}.

wire_events_for(kernel, event_source_id)

@spec wire_events_for(GenServer.server(), String.t()) :: [map()]

Returns every committed wire event for event_source_id, across every event sequence, in append order.