-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: event-sourced entity testkit support for initial events/state #127
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good
akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/EventSourcedTestKit.java
Show resolved
Hide resolved
akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/EventSourcedTestKit.java
Outdated
Show resolved
Hide resolved
Update permissions table to reflect that users that have Developer role assigned to them can delete services. Closes: lightbend/kalix#12442
018ca01
to
e8a8db9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
docs/src/modules/operations/pages/projects/manage-project-access.adoc
Outdated
Show resolved
Hide resolved
akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/EventSourcedTestKit.java
Outdated
Show resolved
Hide resolved
akka-javasdk-testkit/src/main/java/akka/javasdk/testkit/EventSourcedTestKit.java
Outdated
Show resolved
Hide resolved
…ourcedTestKit.java Co-authored-by: Renato Cavalcanti <[email protected]>
…ourcedTestKit.java Co-authored-by: Renato Cavalcanti <[email protected]>
Similar can probably be done for KV entities, but that's not as personally relevant for me :) |
Yeah, it will be good to align the testkits and have the means to provide a initial state to a KVE as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this one for now and add the same on KVE on follow-up.
When testing an entity, it's generally required to put the entity into a given state (essentially the "given" in a "given-when-then" or the "arrange" in an "arrange-act-assert").
Presently the testkit supports doing this only by executing calls against the entity. In many situations, this is sufficient and captures the real-world encapsulation of the entity.
One limitation of this is that it can only test states which are reachable by the present set of calls and the events persistable from those calls.
This limitation becomes apparent if previously deployed code had a bug resulting in persistence of some sequence of events which could only be persisted before the bug was fixed. Since the persisted events are "part of the permanent record", part of the fix must necessarily be adjusting the entity's logic to behave as well as possible if that sequence of events was persisted (e.g. changing the state those events resulted in, or changing how future calls are handled in such a state). However, changing the entity's logic such that such a sequence of events is not persisted would mean that there could be no regression testing for the actual fix. There is a workaround: leave some logic in the entity which would persist the otherwise impossible sequence of events (the general form of this would be a method in the entity to unconditionally persist given events, which could be an "attractive nuisance" (especially in a larger team)).
Since the logic in the entity is only present for the purpose of tests, we can preserve the encapsulation (at least outside of tests) by instead allowing the testkit to be initialized into provided states, which is what this change implements.
With this change, the initial state for the testkit can be defined in terms of events (which will be treated as if they were read from persistence before any calls are made against the entity, viz. the initial state will be the left-fold over those events) or in terms of an initial state.