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

Add ClientRequestContextBuilder and ServiceRequestContextBuilder #1548

Merged
merged 6 commits into from Jan 28, 2019

Conversation

trustin
Copy link
Member

@trustin trustin commented Jan 23, 2019

Motivation:

  • It is often hard to create a mock of a RequestContext.
  • Sometimes a user want to emulate an incoming request and feed it into
    his or her processing pipeline. For example, if a user implemented complex
    logic which pulls some common information like socket addresses and custom
    attributes from RequestContext, the user might want to create a
    ServiceRequestContext for a request which was streamed from other source
    than Armeria, such as a Kafka queue.

Modifications:

  • Added AbstractRequestContextBuilder.
  • Added ClientRequestContextBuilder.
  • Added ServiceRequestContextBuilder.
  • Added more variants of startRequest(), endRequest(),
    startResponse() and endResponse() to RequestLogBuilder so that a
    user can specify exact timestamps for easier matching.
  • Added RequestLog.sslSession()
  • Updated most test cases to use the builder instead of mocks.

Result:

@trustin trustin added this to the 0.80.0 milestone Jan 23, 2019
@trustin trustin requested a review from taicki January 23, 2019 07:05
@codecov
Copy link

codecov bot commented Jan 23, 2019

Codecov Report

Merging #1548 into master will decrease coverage by 0.14%.
The diff coverage is 63.6%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1548      +/-   ##
============================================
- Coverage     72.62%   72.48%   -0.15%     
- Complexity     7249     7313      +64     
============================================
  Files           677      681       +4     
  Lines         29326    29628     +302     
  Branches       3579     3601      +22     
============================================
+ Hits          21299    21475     +176     
- Misses         6177     6276      +99     
- Partials       1850     1877      +27
Impacted Files Coverage Δ Complexity Δ
...om/linecorp/armeria/common/logging/RequestLog.java 25.71% <ø> (ø) 8 <0> (ø) ⬇️
...om/linecorp/armeria/server/DecodedHttpRequest.java 76.19% <ø> (-1.09%) 17 <0> (ø)
...corp/armeria/common/NonWrappingRequestContext.java 86.2% <ø> (+6.84%) 24 <0> (ø) ⬇️
...rp/armeria/client/UnprocessedRequestException.java 75% <ø> (ø) 3 <0> (ø) ⬇️
.../armeria/common/logging/NoopRequestLogBuilder.java 16.66% <0%> (-4.17%) 5 <0> (ø)
...com/linecorp/armeria/server/HttpServerHandler.java 76.65% <0%> (+0.7%) 73 <0> (+1) ⬆️
...p/armeria/server/DefaultServiceRequestContext.java 84.21% <100%> (+0.69%) 61 <2> (+3) ⬆️
...linecorp/armeria/server/ServiceRequestContext.java 40% <100%> (+15%) 2 <1> (+1) ⬆️
.../linecorp/armeria/common/util/EventLoopGroups.java 43.75% <31.25%> (-12.5%) 7 <2> (+2)
...rp/armeria/client/DefaultClientRequestContext.java 69.74% <33.33%> (-0.95%) 35 <1> (+1)
... and 27 more

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 3ee3eac...b447f88. Read the comment docs.

/**
* Returns a new {@link ClientRequestContextBuilder} created from the specified {@link RpcRequest} and URI.
*/
public static ClientRequestContextBuilder of(RpcRequest request, String uri) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does ClientRequestContextBuilder accept RpcRequest but not ServiceRequestContextBuilder? If the use case is for a server that processes messages from Kafka, for example, it seems like a service (the client is whoever published the message).

Copy link
Member Author

Choose a reason for hiding this comment

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

Because a ServiceRequestContext's request has been always an HttpRequest? For instance, ServiceRequestContext.service() always returns Service<HttpRequest, HttpResponse>. We may want to change this if we support more than HTTP but I guess it would be hard to occur at the moment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case what would it look like to model the kafka request with ServiceRequestContext? Would it need a dummy HTTP request? I'm trying to understand how this will solve the use case, at first I expected to create a ServiceRequestContext with RpcRequest.of(KafkaService.class or something

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, a dummy HTTP request will be required. A user may want to set some custom attributes as well.

Motivation:

- It is often hard to create a mock of a `RequestContext`.
- Sometimes a user want to emulate an incoming request and feed it into
  his or her processing pipeline.

Modifications:

- Added `AbstractRequestContextBuilder`.
- Added `ClientRequestContextBuilder`.
- Added `ServiceRequestContextBuilder`.
- Added more variants of `startRequest()`, `endRequest()`,
  `startResponse()` and `endResponse()` to `RequestLogBuilder` so that a
  user can specify exact timestamps for easier matching.
- Updated most test cases to use the builder instead of mocks.

Result:

- Closes line#1464
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Great job!

@trustin
Copy link
Member Author

trustin commented Jan 24, 2019

Added documentation. Preview:
screenshot_2019-01-24 unit-testing client and service armeria 0 80 0-snapshot documentation

Copy link
Contributor

@hyangtack hyangtack left a comment

Choose a reason for hiding this comment

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

Great job!

@trustin trustin removed the request for review from taicki January 28, 2019 02:32
@trustin trustin merged commit aca1bec into line:master Jan 28, 2019
@trustin trustin deleted the ctx_builder branch January 28, 2019 02:33
@trustin
Copy link
Member Author

trustin commented Jan 28, 2019

Thanks for reviewing.

fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
…ine#1548)

Motivation:

- It is often hard to create a mock of a `RequestContext`.
- Sometimes a user want to emulate an incoming request and feed it into
  his or her processing pipeline. For example, if a user implemented complex
  logic which pulls some common information like socket addresses and custom
  attributes from `RequestContext`, the user might want to create a 
  `ServiceRequestContext` for a request which was streamed from other source
  than Armeria, such as a Kafka queue.

Modifications:

- Added `AbstractRequestContextBuilder`.
- Added `ClientRequestContextBuilder`.
- Added `ServiceRequestContextBuilder`.
- Added more variants of `startRequest()`, `endRequest()`,
  `startResponse()` and `endResponse()` to `RequestLogBuilder` so that a
  user can specify exact timestamps for easier matching.
- Added `RequestLog.sslSession()`
- Updated most test cases to use the builder instead of mocks.

Result:

- Closes line#1464
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants