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

Split ClientBase to enabled synchronous calls #147

Merged
merged 6 commits into from Jun 24, 2017
Merged

Split ClientBase to enabled synchronous calls #147

merged 6 commits into from Jun 24, 2017

Conversation

gabrielittner
Copy link
Contributor

This is my first go at splitting ClientBase for #145

The second commit contains the actual changes, the other two are just make the diff of the second nicer.

Exception error = null;
try {
result = AsyncClientBase.this.invokeRequest(call);
//TODO a nicer way would be a struct exception base class and only catch that
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See todo. Do we want something like a StructException as base class for the explicitly declared exceptions which are passed to fail()?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right, in that it would make this bit of code cleaner; I think it might possibly end up complicating other codebases that assume Struct is the base type of Thrifty codegen.

I don't remember exactly what the problem was, but I believe I tried this and couldn't make it work out. I think because I wanted Struct as the absolute base, and that can't work - either it must extend Exception, or we have two parallel hierarchies.

Don't quite recall why the latter didn't work - probably I just didn't want the hassle of having multiple base types.

ThriftException e = ThriftException.read(protocol);
protocol.readMessageEnd();
handleExceptionMessage(call, e);
//TODO there was no throw/return here before but the sync impl of handleExceptionMessage throws
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this one. It used to call fail, but not return. Does this mean we can get a proper result or a second fail call afterwards?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, if it didn't bail out in the old version, that's definitely a bug. A ThriftException usually means that the client and server will never be able to talk successfully to one another!

Throwing in the sync client is the right thing to do; async should finish reading the message and return. Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed this to throw a custom exception after handleExceptionMessage(). For sync that will never be reached because the ThriftException is thrown before. The async client will catch the custom exception and just swallow it because it's handleExceptionMessage() already called fail(). (Kotlin's Nothing as return type for handleExceptionMessage() would be really nice here)

We should probably add a test that the async client doesn't call fail() twice after receiving a TMessageType.EXCEPTION. I'm not very familiar with server thrift code, is there an easy way to make it send one?

*/
protected void enqueue(MethodCall<?> methodCall) {
protected final Object execute(MethodCall<?> methodCall) throws Exception {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want this here or a second ClientBase subclass like SyncClientBase (in that case handleExceptionMessage() could be abstract in here).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mmm, I could go either way, but this seems simpler for now. It would be an easy refactor later, if we find that we need the separation.

@codecov-io
Copy link

codecov-io commented Jun 19, 2017

Codecov Report

Merging #147 into master will decrease coverage by 0.09%.
The diff coverage is 60.5%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master     #147     +/-   ##
===========================================
- Coverage     65.57%   65.47%   -0.1%     
- Complexity      926      933      +7     
===========================================
  Files            87       88      +1     
  Lines          4782     4803     +21     
  Branches        561      562      +1     
===========================================
+ Hits           3136     3145      +9     
- Misses         1409     1422     +13     
+ Partials        237      236      -1
Impacted Files Coverage Δ Complexity Δ
...main/java/com/microsoft/thrifty/gen/TypeNames.java 93.65% <100%> (ø) 2 <0> (ø) ⬇️
...java/com/microsoft/thrifty/service/ClientBase.java 51.21% <51.61%> (-12.94%) 4 <2> (-3)
...com/microsoft/thrifty/service/AsyncClientBase.java 62.79% <62.79%> (ø) 8 <8> (?)
...in/java/com/microsoft/thrifty/schema/Location.java 78.04% <0%> (+4.87%) 16% <0%> (+2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 553882c...a98f7cc. Read the comment docs.

@benjamin-bader
Copy link
Collaborator

Thanks for the contribution - this looks pretty good! I'd like to take a little bit to review, but have some other work I have to handle first. I'm excited to get this in, so thanks for your patience in the meantime!

Copy link
Collaborator

@benjamin-bader benjamin-bader left a comment

Choose a reason for hiding this comment

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

Nice work, and thanks for your patience.

I don't have much feedback at this point; we'll definitely want conformance tests with synchronous clients, but that will have to wait for codegen support.

Once the todos are addressed/removed, this will be good to go.

Exception error = null;
try {
result = AsyncClientBase.this.invokeRequest(call);
//TODO a nicer way would be a struct exception base class and only catch that
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right, in that it would make this bit of code cleaner; I think it might possibly end up complicating other codebases that assume Struct is the base type of Thrifty codegen.

I don't remember exactly what the problem was, but I believe I tried this and couldn't make it work out. I think because I wanted Struct as the absolute base, and that can't work - either it must extend Exception, or we have two parallel hierarchies.

Don't quite recall why the latter didn't work - probably I just didn't want the hassle of having multiple base types.

ThriftException e = ThriftException.read(protocol);
protocol.readMessageEnd();
handleExceptionMessage(call, e);
//TODO there was no throw/return here before but the sync impl of handleExceptionMessage throws
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, if it didn't bail out in the old version, that's definitely a bug. A ThriftException usually means that the client and server will never be able to talk successfully to one another!

Throwing in the sync client is the right thing to do; async should finish reading the message and return. Good catch!

*/
protected void enqueue(MethodCall<?> methodCall) {
protected final Object execute(MethodCall<?> methodCall) throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mmm, I could go either way, but this seems simpler for now. It would be an easy refactor later, if we find that we need the separation.

@benjamin-bader benjamin-bader merged commit dac6432 into microsoft:master Jun 24, 2017
@benjamin-bader
Copy link
Collaborator

Awesome, thank you!

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.

None yet

4 participants