Skip to content
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

Merged
merged 40 commits into from
Apr 24, 2017
Merged

Validation of Stand input #437

merged 40 commits into from
Apr 24, 2017

Conversation

armiol
Copy link
Contributor

@armiol armiol commented Apr 19, 2017

This PR brings the automatic validation of actor requests sent to Stand instances.

Each request Message is validated in two steps.

  • It has to conform the constraints set in its Message definition.
  • It has to be supported by the Stand instance. In particular:
    • the TypeUrl of Query.getTarget() must be exposed for reading;
    • the TypeUrl of Topic.getTarget() must be exposed for reading;
    • the 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 via StreamObservers 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.

@armiol armiol self-assigned this Apr 19, 2017
…rvers.noopObserver()` utility method to suite the `StandShould` needs better.
@codecov
Copy link

codecov bot commented Apr 19, 2017

Codecov Report

Merging #437 into master will increase coverage by 0.14%.
The diff coverage is 99.54%.

@@             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

@armiol
Copy link
Contributor Author

armiol commented Apr 19, 2017

@alexander-yevsyukov PTAL.

Copy link
Contributor

@alexander-yevsyukov alexander-yevsyukov left a 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() {
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 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);
Copy link
Contributor

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;
Copy link
Contributor

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");
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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,
Copy link
Contributor

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,
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 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>(
Copy link
Contributor

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.

@armiol armiol merged commit e6a4646 into master Apr 24, 2017
@armiol armiol deleted the stand-input-validation branch April 24, 2017 21:14
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