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
[#1481] Update peekEvent accordingly #1484
Conversation
Fix javadoc discrepancy stating that the SequentialPolicy is the default policy, whilst the SequentialPerAggregatePolicy is the defautl
The EventBuffer used by the AxonServerConnector as the TrackingEventStream currently contains a blocking loop, taking up to 500ms to exit. This so happens to correspond to the minimum wait time used by the hasNextAvailable method. This occurs because the peakEvent, validated in a do-while-loop, isn't updated when the lock's Condition is signaled. Subsequently, adjust the test to timeout if it takes longer dan 450ms, as that's a signal the loop occurs again whilst it shouldn't #1481
Add short trace logging showing whether we were signaled or waited 500ms #1481
The current solution introduces a form of side effect _why_ it no longer loops in the do-while-loop. Namely, subsequent invocations of the hasNextAvailable method currently introduce the scenario that the next entry from the Iterator is retrieved. This means, the following entry is removed from the delegate EventStream. Although this make sure an early return occurs, it still does an additional unnecessary loop. Instead, we should consistently use one way to validate an event is present, and omit the side effect inducing operation. As this means we'll no longer perform direct invocations of the EventStream which could lead to an exception, we should validate whether the stream is closed prior to proceeding. #1481
For some, the createEventData method was to slow, hence causing the testDataUpcastAndDeserialized with the timeout to fail. Making the result a static field will resolve this #1481
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.
The code is fine, but the changes made allow for some simplification of this class, which will improve the understandability of the code used. Maybe the waitForData can then also be inlined and some of the checks simplified.
...r-connector/src/main/java/org/axonframework/axonserver/connector/event/axon/EventBuffer.java
Outdated
Show resolved
Hide resolved
...r-connector/src/main/java/org/axonframework/axonserver/connector/event/axon/EventBuffer.java
Outdated
Show resolved
Hide resolved
...r-connector/src/main/java/org/axonframework/axonserver/connector/event/axon/EventBuffer.java
Outdated
Show resolved
Hide resolved
...r-connector/src/main/java/org/axonframework/axonserver/connector/event/axon/EventBuffer.java
Outdated
Show resolved
Hide resolved
...r-connector/src/main/java/org/axonframework/axonserver/connector/event/axon/EventBuffer.java
Outdated
Show resolved
Hide resolved
- Rename the constant - Add private peekNullable method and use instead of peek() / peekEvent == null - Pair two if-breaks - Switch do-while-loop to while-loop - Inline waitForData - Remove unintended debug log line #1481
- Reorder field assignment in constructor - Drop if-continue check, as it's no longer needed through the switch from a do-while-loop to the while-loop - Move waitTime creation and validation to occur just before the await invocation #1481
...r-connector/src/main/java/org/axonframework/axonserver/connector/event/axon/EventBuffer.java
Outdated
Show resolved
Hide resolved
Waiting on events should happen if there is no event AND the wait time is bigger than zero. #1481
Further reordering, for a different kind of OCD #1481
Move the EventStream#isClosed check to the peekNullable method. That way we can ensure we validate this operation everytime we try to retrieve a new event from the delegate stream. #1481
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
This pull request updates the
EventBuffer
, to ensure it no longer loops for the defined 500ms "wait time" in thehasNextAvailable
method. This loop was performed as the while-loop validated whether thepeekEvent == null
, thus the event of the constructedIterator<TrackedEventMessage<?>> eventStream
. However thewaitForData
method calls thedelegate
EventStream#peek
method. The latter returns true, causing the lock to be released, but the while-loop kept on going as it didn't change thepeekEvent
.The javadoc adjustments of the
SequencingPolicy
were added unintentionally, but don't hurt this PR.This PR resolves #1481