This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package testexecutor
|
||||
|
||||
import (
|
||||
commitcontract "git.cin.su/m/Assistant/contracts/commit"
|
||||
"git.cin.su/m/Assistant/modules/commit/ports"
|
||||
)
|
||||
|
||||
// Executor is a deterministic external-system simulator. ActionIntentID is
|
||||
// the idempotency identity, so replay can never create a second effect.
|
||||
type Executor struct {
|
||||
LoseAcknowledgement bool
|
||||
effects map[commitcontract.ActionIntentID]bool
|
||||
}
|
||||
|
||||
func New(loseAcknowledgement bool) *Executor {
|
||||
return &Executor{LoseAcknowledgement: loseAcknowledgement, effects: make(map[commitcontract.ActionIntentID]bool)}
|
||||
}
|
||||
|
||||
func (e *Executor) Execute(action commitcontract.AuthorizedAction) ports.ExecutionResult {
|
||||
e.effects[action.Proposal.IntentID] = true
|
||||
if e.LoseAcknowledgement {
|
||||
return ports.ExecutionResult{Known: false}
|
||||
}
|
||||
return ports.ExecutionResult{Known: true, Succeeded: true}
|
||||
}
|
||||
|
||||
func (e *Executor) Reconcile(action commitcontract.AuthorizedAction) ports.ExecutionResult {
|
||||
applied, known := e.effects[action.Proposal.IntentID]
|
||||
return ports.ExecutionResult{Known: known, Succeeded: applied}
|
||||
}
|
||||
|
||||
func (e *Executor) EffectCount() int { return len(e.effects) }
|
||||
Reference in New Issue
Block a user