zio.blocks.projection.testing

Members list

Type members

Classlikes

A zio.blocks.projection.ProjectionStore kept in memory, for tests. TestEngine creates one for each projection.

A zio.blocks.projection.ProjectionStore kept in memory, for tests. TestEngine creates one for each projection.

The rows are kept in a map from entity ID to row, and the watermark and the schema hash in two Refs. Nothing is written to disk, so everything is lost when the program ends.

insert fails if the ID is already taken. updateFields changes the row as a DynamicValue. When there is no row yet, it starts from a default one, in which the ID field holds entityId and the other fields hold empty values, such as None, 0, "" or false. It accepts a field either by its column name, in snake_case, or by its Scala name. recreateTable only removes the rows, and addColumn does nothing, because a map has no columns.

The constructor is private: create a store with InMemoryProjectionStore.make.

Type parameters

A

the type of a row, with an zio.blocks.projection.EntityPath that names its ID field

Attributes

Companion
object
Source
InMemoryProjectionStore.scala
Supertypes
trait ProjectionStore[A]
class Object
trait Matchable
class Any

Attributes

Companion
class
Source
InMemoryProjectionStore.scala
Supertypes
class Object
trait Matchable
class Any
Self type
object TestContext

Attributes

Source
TestContext.scala
Supertypes
class Object
trait Matchable
class Any
Self type
object TestEngine

Attributes

Companion
class
Source
TestEngine.scala
Supertypes
class Object
trait Matchable
class Any
Self type
TestEngine.type
final class TestEngine

A running ProjectionEngine wired entirely in memory, for tests and examples.

A running ProjectionEngine wired entirely in memory, for tests and examples.

For every projection it creates an InMemoryProjectionStore, and for every distinct source name used by the projections it creates an in-memory event store backed by a Hub. If no projection declares a source, a single "_default" source is created. The engine is started when the TestEngine is built and stopped when the enclosing Scope closes, so no database or files are involved. This replaces the verbose ProjectionEngine.makeWithStores wiring.

Use append to feed events in and query to read the projected rows back. Appending only publishes the event; the engine processes it asynchronously, so a query issued straight after an append may not see the result yet.

Events are stored with the event class's simple name as their tag, and they are kept in memory only.

val projection = Projection[UserProfile]("userProfiles")
 .from("users").routeToSelf
 .on[UserCreated].insert((e, ctx) => UserProfile(ctx.entityId, e.name, e.email))

val program = ZIO.scoped {
 for {
   engine <- TestEngine.make(projection)
   _      <- engine.append("user-1", UserCreated("Alice", "a@b.com"))
   u1     <- engine.query(projection, "user-1")
 } yield u1
}

Value parameters

engine

the underlying engine that processes the events

projections

the projections this engine runs, in the order they were given

stores

the in-memory store of each projection, keyed by projection name

Attributes

Companion
object
Source
TestEngine.scala
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
class
Source
TestProjectionEngine.scala
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Companion
object
Source
TestProjectionEngine.scala
Supertypes
class Object
trait Matchable
class Any