sagaSpec
Specifies a saga's behaviour: given a commit of a stream, its own context's or one it reads from another context (a StateEvent, built with stateEvent), or the rejection or the commit of a command it derived, the commands it derives and the commands it schedules. handlers are the handlers of the saga under test, from the function the compiler generated for it (<processor>Handlers, orderSagaHandlers for OrderSaga), which constructs that saga only, with its own services:
sagaSpec(orderSagaHandlers()) {
whenEvent(stateEvent(order, OrderState("order-1"), orderCreated)) {
expectCommands(ReserveStock("order-1", 2))
expectDeterministic()
whenRejected(commands.single(), code = "inventory.stock.insufficient") {
expectCommand(CancelOrder("..."), to = order)
}
whenCommitted(commands.single(), version = 3) {
expectCommand(ConfirmStock("product-1"), to = order)
}
}
}Each call of a handler gets a fresh ExecutionSagaContext, as the runtime gives each handling of a commit, so the ids the saga derives are the same on every call for the same commit. Its ids are SequentialIds, counted anew for each call: id-1… and <aggregate>-1….
The synchronous calls a saga makes (me.ahoo.wow.api.subscribe.SagaContext.call) are answered by answerCalls, committed at version 1 by default (committedResult); ProcessorExpectations.calls lists them.