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
- Graph
-
- Supertypes