-
Notifications
You must be signed in to change notification settings - Fork 12
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
Validation of Stand input #437
Conversation
…scription` requests: declare it in the model definition.
…xt` value against the expected one.
…lidation rules defined in their Protobuf definition.
…system; Update `Stand` external API to include `StreamObserver` as a parameter to allow async responses. Add some utilities to work with `StreamObserver`s.
… a bit to simplify documenting.
…e to reuse it for the `Query` and `Topic` validation.
…rvers.noopObserver()` utility method to suite the `StandShould` needs better.
Codecov Report
@@ Coverage Diff @@
## master #437 +/- ##
===========================================
+ Coverage 91.56% 91.7% +0.14%
- Complexity 2784 2839 +55
===========================================
Files 295 305 +10
Lines 9057 9234 +177
Branches 639 647 +8
===========================================
+ Hits 8293 8468 +175
- Misses 580 583 +3
+ Partials 184 183 -1 |
# Conflicts: # server/src/test/java/org/spine3/server/Given.java
@alexander-yevsyukov PTAL. |
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, but please see my questions on test coverage and layout comments
* | ||
* @return an instance of {@code StreamObserver} which does nothing | ||
*/ | ||
public static <T> StreamObserver<T> noopObserver() { |
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.
Can we have it as noOpObserver()
? It would be consistent with other noOp
things around.
return new StreamObserver<T>() { | ||
@Override | ||
public void onError(Throwable t) { | ||
delegate.onError(t); |
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.
Please check that this is tested. The Codecov Chrome plug-in shows to me that these lines are not covered.
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
// Do nothing. | ||
throwable = t; |
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.
Please check if this is tested.
public T firstResponse() { | ||
final boolean noResponses = responses.isEmpty(); | ||
if (noResponses) { | ||
throw new IllegalStateException("No responses have been received yet"); |
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.
Please test this branch.
* @return all objects received by this {@code StreamObserver} | ||
*/ | ||
public List<T> responses() { | ||
return newArrayList(responses); |
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.
Tested?
* @return {@code true} if the response has been completed, {@code false} otherwise | ||
*/ | ||
public boolean isCompleted() { | ||
return completed; |
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.
Tested?
*/ | ||
@Nullable | ||
public Throwable getError() { | ||
return throwable; |
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.
Tested?
* @param query a related query | ||
* @param error an error occurred | ||
*/ | ||
protected InvalidQueryException(String messageText, |
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.
It looks like we can fit the method signature into one line. Please try.
* @param request a related actor request | ||
* @param error an error occurred | ||
*/ | ||
InvalidRequestException(String messageText, |
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.
Can we fit into one line?
private static RequestNotSupported<Query> missingInRegistry(TypeUrl topicTargetType) { | ||
final String errorMessage = format("The query target type is not supported: %s", | ||
topicTargetType.getTypeName()); | ||
return new RequestNotSupported<Query>( |
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.
Please see if we can fit into one line here and below.
# Conflicts: # server/src/main/java/org/spine3/server/event/EventBus.java
This PR brings the automatic validation of actor requests sent to
Stand
instances.Each request
Message
is validated in two steps.Message
definition.Stand
instance. In particular:TypeUrl
ofQuery.getTarget()
must be exposed for reading;TypeUrl
ofTopic.getTarget()
must be exposed for reading;Subscription
must be present in the subscription registry for it to activate or cancel.In addition, the public API of
Stand
has been modified to send responses viaStreamObserver
s passed as method arguments:Stand.subscribe(Topic, StreamObserver<Subscription>)
;Stand.activate(Subscription, EntityUpdateCallback, StreamObserver<Response>)
;Stand.cancel(Subscription, StreamObserver<Response>)
;The validation errors are passed to the
StreamObserver.onError()
callback in a unified way.