-
Notifications
You must be signed in to change notification settings - Fork 924
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
Add delegating response converter function provider #4336
Add delegating response converter function provider #4336
Conversation
…akes it easier to test its behaviour
…ConverterFunctionProvider
…our from DelegatingResponseConverterFunctionProvider
…Function for clarity
…-converter-function-provider * origin/master: Update the project version to 1.17.1-SNAPSHOT Add the release note for 1.17.0 (line#4330) Send 400 Bad Request when HTTP2 cleartext upgrade contains invalid headers (line#4224) Fix the test failure of `GrpcServiceLogNameTest.logName()` (line#4334) Support `ExchangeType` for the response of annotated service (line#4177) Recover HttpResponse according to a specific exception class (line#4283)
…unrelated tests to fail
Codecov Report
@@ Coverage Diff @@
## master #4336 +/- ##
============================================
+ Coverage 73.81% 73.82% +0.01%
- Complexity 17740 17752 +12
============================================
Files 1510 1512 +2
Lines 66244 66252 +8
Branches 8322 8320 -2
============================================
+ Hits 48896 48911 +15
- Misses 13336 13342 +6
+ Partials 4012 3999 -13
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
Thanks! We are going in the right direction!
Just left a few minor comments. 😉
.../java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionSelector.java
Outdated
Show resolved
Hide resolved
new CompositeResponseConverterFunction(backingConverters))) | ||
.build()); | ||
|
||
for (final DelegatingResponseConverterFunctionProvider provider : delegatingResponseConverterFunctionProviders) { |
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.
Could you fix the lint?
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.
Fixed~
.../java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionSelector.java
Outdated
Show resolved
Hide resolved
.../java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionSelector.java
Outdated
Show resolved
Hide resolved
.../java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionSelector.java
Outdated
Show resolved
Hide resolved
...java/com/linecorp/armeria/server/annotation/DelegatingResponseConverterFunctionProvider.java
Outdated
Show resolved
Hide resolved
...a/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionSelectorTest.java
Outdated
Show resolved
Hide resolved
...ain/java/com/linecorp/armeria/server/protobuf/ProtobufResponseConverterFunctionProvider.java
Outdated
Show resolved
Hide resolved
); | ||
|
||
final HttpResponse response = converterFunction.convertResponse(ctx, null, | ||
new TestClassWithDelegatingResponseConverterProvider(), |
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.
Could you check the lint of test files? 😄
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.
Done 👍 Let me know if there are still issues, checkStyle seems to have passed
...a/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionSelectorTest.java
Outdated
Show resolved
Hide resolved
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.
I wasn't able to review the test files yet, but the changes look good to me 👍
Left some minor comments 🙏
.../java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionSelector.java
Outdated
Show resolved
Hide resolved
...java/com/linecorp/armeria/server/annotation/DelegatingResponseConverterFunctionProvider.java
Show resolved
Hide resolved
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.
Looks great. 😄
Left only minor comments.
...main/java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionUtil.java
Outdated
Show resolved
Hide resolved
...main/java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionUtil.java
Outdated
Show resolved
Hide resolved
...main/java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionUtil.java
Outdated
Show resolved
Hide resolved
...main/java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionUtil.java
Outdated
Show resolved
Hide resolved
...main/java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionUtil.java
Outdated
Show resolved
Hide resolved
import com.linecorp.armeria.server.annotation.ResponseConverterFunctionProvider; | ||
|
||
/** | ||
* For use with ResponseConverterFunctionSelectorTest. |
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.
ditto
} | ||
} | ||
|
||
private Class<?> toClass(Type type) { |
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.
ditto. Let's reduce the cognitive load.
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.
Otherwise, we can just replace this with ClassUtil.typeToClass()
.
@Test | ||
void returnEmptyJsonArrayGivenCustomJsonPrinter() { | ||
final AggregatedHttpResponse response = client.get("/json").aggregate().join(); | ||
assertThat(Objects.requireNonNull(Objects.requireNonNull(response.headers().contentType())) |
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.
Objects.requireNonNull
is used twice for the same value.
Let's use AssertJ API.
final MediaType mediaType = response.headers().contentType();
assertThat(mediaType).isNotNull();
assertThat(mediaType).isSameAs(MediaType.JSON_UTF_8);
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.
We can use MediaType.isJson()
which is a shortcut for that.
@@ -218,8 +218,8 @@ void protobufJsonResponse(String contentType) throws InvalidProtocolBufferExcept | |||
void protobufStreamResponse(String path) { | |||
final AggregatedHttpResponse response = client.get(path).aggregate().join(); | |||
assertThat(response.status()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); | |||
assertThat(cause).isInstanceOf(IllegalArgumentException.class) | |||
.hasMessageContaining("Cannot convert a"); | |||
assertThat(cause).isInstanceOf(IllegalStateException.class) |
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.
Note for reviewers.
The exception is used to be raised by ProtobufResponseConverterFunction
. https://github.com/line/armeria/blob/master/protobuf/src/main/java/com/linecorp/armeria/server/protobuf/ProtobufResponseConverterFunction.java#L243-L244`
The exception is now wrapped by the CompositeResponseConverterFunction
.
https://github.com/line/armeria/blob/master/core/src/main/java/com/linecorp/armeria/internal/server/annotation/CompositeResponseConverterFunction.java#L71-L75
@@ -17,15 +17,15 @@ | |||
package com.linecorp.armeria.server.scalapb | |||
|
|||
import com.linecorp.armeria.common.annotation.{Nullable, UnstableApi} | |||
import com.linecorp.armeria.server.annotation.{ResponseConverterFunction, ResponseConverterFunctionProvider} | |||
import com.linecorp.armeria.server.annotation.{ResponseConverterFunction, DelegatingResponseConverterFunctionProvider} |
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.
We could probably do
import com.linecorp.armeria.server.annotation._
to fix the lint failure. 😉
Co-authored-by: minux <songmw725@gmail.com>
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.
Thanks! I added more minor comments. 😄
...main/java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionUtil.java
Outdated
Show resolved
Hide resolved
...main/java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionUtil.java
Outdated
Show resolved
Hide resolved
...java/com/linecorp/armeria/server/annotation/DelegatingResponseConverterFunctionProvider.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/linecorp/armeria/server/annotation/ResponseConverterFunctionProvider.java
Show resolved
Hide resolved
…tion/ResponseConverterFunctionUtil.java Co-authored-by: minux <songmw725@gmail.com>
…tion/ResponseConverterFunctionUtil.java Co-authored-by: minux <songmw725@gmail.com>
…gatingResponseConverterFunctionProvider.java Co-authored-by: minux <songmw725@gmail.com>
@resquivel-squareup I fixed the code commented by @minwoox and slightly cleaned it up. |
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.
Thanks a lot, @resquivel-squareup 🙇♂️💯
@resquivel-squareup |
Thanks for the added fixes, too! I've been busy recently and so haven't been able to add the fixes 😅 I've signed the CLA @minwoox. Apologies for the delay! |
Please, don't worry about it. Thanks for signing the CLA. 😄 |
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.
Awesome. Thanks! 😄
...main/java/com/linecorp/armeria/internal/server/annotation/ResponseConverterFunctionUtil.java
Outdated
Show resolved
Hide resolved
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.
Looks great! Thanks @resquivel-squareup 🙇 👍 🙇
Congratulations @resquivel-squareup! 🎉 🎉 🎉 |
Potentially resolves issue [4301](line#4301 (comment)) Motivation: Fix bug with Protobuf response converter. The fix now allows us to use a custom converter, while still preserving desired behaviour in other areas. Please see the discussion issue 4301 for more information. Modifications: - Take functionality from `AnnotatedService` into its own `ResponseConverterFunctionSelector` class. This isolates the behaviour of selecting response converters and lets us test its functionality in isolation. - Tests regarding desired order of converter usage - Test to ensure the bug with the Protobuf response converter is fixed - Split existing `ResponseConverterFunctionProvider` functionality into two separate interfaces --- `ResponseConverterFunctionProvider` and `DelegatingResponseConverterFunctionProvider`. These interfaces have different expectations in terms of parameters and usage of passed-in parameters - Several later commits involve resolving merge conflicts which were introduced because there were changes in the master branch to the code which we had pulled out into `ResponseConverterFunctionSelector` in this branch Result: - Closes line#4301. - You will now be able to use a custom JsonFormat.Printer for ProtobufResponseConverterFunction - You will have to update any custom SPI implementations to conform to either `ResponseConverterFunctionProvider` or `DelegatingResponseConverterFunctionProvider`
Potentially resolves issue 4301
Motivation:
Fix bug with Protobuf response converter. The fix now allows us to use a custom converter, while still preserving desired behaviour in other areas.
Please see the discussion issue 4301 for more information.
Modifications:
AnnotatedService
into its ownResponseConverterFunctionSelector
class. This isolates the behaviour of selecting response converters and lets us test its functionality in isolation.ResponseConverterFunctionProvider
functionality into two separate interfaces ---ResponseConverterFunctionProvider
andDelegatingResponseConverterFunctionProvider
. These interfaces have different expectations in terms of parameters and usage of passed-in parametersResponseConverterFunctionSelector
in this branchResult:
ResponseConverterFunctionProvider
orDelegatingResponseConverterFunctionProvider