jmalloc / ax

A message-driven application toolkit for Go. [EXPERIMENTAL]
MIT License
9 stars 3 forks source link

Fix faulty "new saga instance" behaviour as a result of the mapping refactor. #80

Closed jmalloc closed 6 years ago

jmalloc commented 6 years ago

The previous change had a design flaw insofar as the onus was put on the mapper to decide whether a message would be applied to a new saga instance or an existing instance.

This was possible for keyset based mapper, because it had database entries if and only the saga instance already exited, but is not possible for the direct mapper because it is stateless.

This change modifies the interfaces of saga.Mapper and saga.Persister such that the mapper is only responsible for deciding whether the message is mapped to an instance at all, and the persister is responsible for determining whether the instance already exists or not.

The saga handler calls the not-found handler if the persister returns an instance at revision zero but the message is not a trigger.

It so happens that this PR fixes #49 and makes a similar change to the persistence.MessageStore interface.

jmalloc commented 6 years ago

/cc @koden-km This is a fix to the fault that I mentioned on Slack. It was kind of insidious and only became apparent when I introduced the direct mapping. I would have caught it with tests!

codecov-io commented 6 years ago

Codecov Report

Merging #80 into master will increase coverage by 0.37%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #80      +/-   ##
==========================================
+ Coverage   33.77%   34.14%   +0.37%     
==========================================
  Files          56       56              
  Lines        1904     1883      -21     
==========================================
  Hits          643      643              
+ Misses       1251     1230      -21     
  Partials       10       10
Impacted Files Coverage Δ
src/ax/saga/mapping/keyset/mapper.go 0% <0%> (ø) :arrow_up:
src/ax/saga/persistence/crud/persister.go 0% <0%> (ø) :arrow_up:
src/ax/saga/mapping/direct/mapper.go 0% <0%> (ø) :arrow_up:
src/axmysql/sagarepository.go 0% <0%> (ø) :arrow_up:
src/axmysql/messagestore.go 0% <0%> (ø) :arrow_up:
src/ax/saga/persistence/eventsourcing/persister.go 0% <0%> (ø) :arrow_up:
.../ax/saga/persistence/eventsourcing/messagestore.go 0% <0%> (ø) :arrow_up:
src/ax/saga/handler.go 0% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 306272d...fb63020. Read the comment docs.