Skip to content

Add version update for ProcessManager instances#893

Merged
dmitrykuzmin merged 20 commits intomasterfrom
update-procman-version
Dec 7, 2018
Merged

Add version update for ProcessManager instances#893
dmitrykuzmin merged 20 commits intomasterfrom
update-procman-version

Conversation

@dmitrykuzmin
Copy link
Contributor

@dmitrykuzmin dmitrykuzmin commented Nov 28, 2018

This PR handles issue #880.

Previously, the entity versioning didn't work for the ProcessManager implementations.

Now, the version of the ProcessManager is incremented by one upon any command or event dispatched to it (as process managers can update their state in command handlers, unlike aggregates).

The other side of the changes is that now ProcessManager state must be consistent with the model requirements upon handling any command.

For instance, if the QuizProcman receives a command PmStartQuiz, and the id field of procman is required, the handler method should set the ID from the command right away and not wait until PmQuizStarted event.

This is done because the version update requires the entity state to be valid.

@dmitrykuzmin dmitrykuzmin self-assigned this Nov 28, 2018
@codecov
Copy link

codecov bot commented Nov 28, 2018

Codecov Report

Merging #893 into master will increase coverage by 0.16%.
The diff coverage is 99.1%.

@@             Coverage Diff              @@
##             master     #893      +/-   ##
============================================
+ Coverage     93.22%   93.39%   +0.16%     
- Complexity     3823     3859      +36     
============================================
  Files           522      529       +7     
  Lines         12591    12637      +46     
  Branches        710      708       -2     
============================================
+ Hits          11738    11802      +64     
+ Misses          625      605      -20     
- Partials        228      230       +2

@dmitrykuzmin dmitrykuzmin requested a review from armiol November 28, 2018 14:42
@dmitrykuzmin
Copy link
Contributor Author

@armiol PTAL.

Copy link
Contributor

@armiol armiol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitrykuzmin please see my comments.

}

/**
* Advances the transaction version.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be more precise here, as transactions do not have versions themselves.

import org.checkerframework.checker.nullness.qual.Nullable;

/**
* The context which {@link EntityVersioning} uses for version increment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we turn this value object into something that acts? E.g. can this be a VersionIncrement, which is responsible for setting a new version to an entity in a transaction?

@dmitrykuzmin
Copy link
Contributor Author

@armiol PTAL.

Copy link
Contributor

@armiol armiol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitrykuzmin as discussed vocally, let's change how things work:

  • Have a Phase in a lifecycle of each entity, defining it as an atomic entity state change, that advances entity version.
  • Most likely, Phase will need to have an entity-specific VersionIncrement as a mandatory ctor param.
  • Looks like we are going to have at least types of Phases: CommandDispatchingPhase and EventDispatchingPhase. Not 100% sure, as process managers have different scenarios dispatching commands (@Assign, @Command) and events (@React, @Command), so maybe there will be operation-specific phases.
  • Have three types of Transactions — one for each entity type.
  • Get rid of ambiguous incrementVersion() and advanceVersion(EventEnvelope) methods in Transaction.
  • Resolve the todo item in PmTransaction for dispatch(..) method, which is in fact never called.

@Nullable EventEnvelope event() {
return event;
}
abstract Version nextVersion();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why this method isn't protected.

@Override
protected void advanceVersion() {
super.advanceVersion();
protected void incrementVersion() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And let's discuss why this method got renamed.

@SpineEventEngine SpineEventEngine deleted a comment Dec 1, 2018
@dmitrykuzmin
Copy link
Contributor Author

@armiol PTAL.

Copy link
Contributor

@armiol armiol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitrykuzmin looks good. However, @Command cases in PM are not covered, as it looks to me.

A process manager should update its version upon commanding (either command -> one or several commands, or event -> one or several commands).

/**
* A transaction that supports event {@linkplain EventPlayer playing}.
*
* <p>Event playing is a process of applying the events to the certain entity with no expected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this sentence. It's clear from the referenced EventPlayer.

* the type of entity ID
*/
@Internal
public class CommandDispatchingPhase<I> extends Phase<I, List<Event>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem here would be @Command-er methods in Process Manager, which return commands (split into several or transform the given one into another).

The same issue is in EventDispatchingPhase. As Process Managers may @Command upon events, turning events into commands.

@armiol
Copy link
Contributor

armiol commented Dec 6, 2018

@dmitrykuzmin let's create some tests for @Command-ing scenarios and then see, what needs updates in the code.

@dmitrykuzmin
Copy link
Contributor Author

@armiol PTAL. The implementation does handle Commanding methods but it is indeed misleading.

Refactoring it will require even more changes to how we perform DispatchCommand so I thought to do it in a separate PR.

@dmitrykuzmin dmitrykuzmin merged commit 6aac6e4 into master Dec 7, 2018
@dmitrykuzmin dmitrykuzmin deleted the update-procman-version branch December 7, 2018 16:33
@armiol armiol mentioned this pull request Dec 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants