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

Clean up deprecated requester/client/filter API #1960

Merged
merged 1 commit into from
Nov 19, 2021

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

#1956 removed requester/client methods that take
HttpExecutionStrategy. All deprecated API can be removed now.

Modifications:

  • Remove deprecated request method from a requester;
  • Remove deprecated reserveConnection method from a client;
  • Remove NewToDeprecated utility;
  • Migrate all existing filters and tests to the new filter API;
  • Pass an HttpExecutionStrategy through request context;

Result:

No deprecated API on requester/client/filter API.

@idelpivnitskiy idelpivnitskiy self-assigned this Nov 18, 2021
@idelpivnitskiy idelpivnitskiy added the breaking-change PR with breaking changes, removed APIs or other binary incompatibilities. label Nov 18, 2021
@idelpivnitskiy
Copy link
Member Author

idelpivnitskiy commented Nov 18, 2021

Depends on #1956, review only the last commit: 59dac1c

return blockingInvocation(requester.request(strategy, request.toStreamingRequest())
.flatMap(StreamingHttpResponse::toResponse));
return blockingInvocation(requester.request(request.toStreamingRequest())
.flatMap(response -> response.toResponse().subscribeShareContext()));
Copy link
Member

Choose a reason for hiding this comment

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

can you clarify why we need .subscribeShareContext here? typically this is used as the last operator in a defer(() -> ... subscribeShareContext())

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding was that subscribeShareContext() is required for any async operator in order to share it. It looks like without subscribeShareContext(), users of aggregated API have a copy of the context when their filter processes a payload body instead of sharing a single context.

Copy link
Member

Choose a reason for hiding this comment

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

yes subscribeShareContext will make it so when subscribe is done, the context map is not copied (same instance is used). Good catch, seems like this would impact operators transforming the response publisher (see below). Can you add some quick tests for this? IIRC @tkountis extracted out AbstractHttpServiceAsyncContextTest can we just use this from the blocking Client API to verify?

diff --git a/servicetalk-examples/http/helloworld/src/main/java/io/servicetalk/examples/http/helloworld/blocking/BlockingHelloWorldClient.java b/servicetalk-examples/http/helloworld/src/main/java/io/servicetalk/examples/http/helloworld/blocking/BlockingHelloWorldClient.java
index 1913a24a3..cb1eb0b59 100644
--- a/servicetalk-examples/http/helloworld/src/main/java/io/servicetalk/examples/http/helloworld/blocking/BlockingHelloWorldClient.java
+++ b/servicetalk-examples/http/helloworld/src/main/java/io/servicetalk/examples/http/helloworld/blocking/BlockingHelloWorldClient.java
@@ -15,8 +15,16 @@
  */
 package io.servicetalk.examples.http.helloworld.blocking;
 
+import io.servicetalk.concurrent.api.AsyncContext;
+import io.servicetalk.concurrent.api.Single;
 import io.servicetalk.http.api.BlockingHttpClient;
+import io.servicetalk.http.api.FilterableStreamingHttpClient;
 import io.servicetalk.http.api.HttpResponse;
+import io.servicetalk.http.api.StreamingHttpClientFilter;
+import io.servicetalk.http.api.StreamingHttpClientFilterFactory;
+import io.servicetalk.http.api.StreamingHttpRequest;
+import io.servicetalk.http.api.StreamingHttpRequester;
+import io.servicetalk.http.api.StreamingHttpResponse;
 import io.servicetalk.http.netty.HttpClients;
 
 import static io.servicetalk.http.api.HttpSerializers.textSerializerUtf8;
@@ -24,7 +32,26 @@ import static io.servicetalk.http.api.HttpSerializers.textSerializerUtf8;
 public final class BlockingHelloWorldClient {
 
     public static void main(String[] args) throws Exception {
-        try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).buildBlocking()) {
+        try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080)
+                .appendClientFilter(client1 -> new StreamingHttpClientFilter(client1) {
+                    @Override
+                    protected Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate,
+                                                                    final StreamingHttpRequest request) {
+                        System.err.println("1: " + AsyncContext.context());
+                        return delegate.request(request)
+                                .flatMap(response -> {
+                                    System.err.println("2: " + AsyncContext.context());
+                                    return Single.succeeded(response.transformPayloadBody(body -> {
+                                        System.err.println("3: " + AsyncContext.context());
+                                        return body.map(buf -> {
+                                            System.err.println("4: " + AsyncContext.context());
+                                            return buf;
+                                        });
+                                    }));
+                                });
+                    }
+                })
+                .buildBlocking()) {
             HttpResponse response = client.request(client.get("/sayHello"));
             System.out.println(response.toString((name, value) -> value));
             System.out.println(response.payloadBody(textSerializerUtf8()));

with subscribeShareContext:

1: CopyOnWriteContextMap@56e8b606:{}
2: CopyOnWriteContextMap@56e8b606:{}
3: CopyOnWriteContextMap@56e8b606:{}
4: CopyOnWriteContextMap@56e8b606:{}

without subscribeShareContext (note different instance in 4):

1: CopyOnWriteContextMap@56e8b606:{}
2: CopyOnWriteContextMap@56e8b606:{}
3: CopyOnWriteContextMap@56e8b606:{}
4: CopyOnWriteContextMap@1223cd05:{}

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tried to adopt AbstractHttpServiceAsyncContextTest for BlockingHttpService, but it doesn't cover a use-case of a context change between aggregating a request payload body and further processing. I've opened #1967 to track it.

Motivation:

`HttpExecutionStrategy`. All deprecated API can be removed now.

Modifications:

- Remove deprecated `request` method from a requester;
- Remove deprecated `reserveConnection` method from a client;
- Remove `NewToDeprecated` utility;
- Migrate all existing filters and tests to the new filter API;
- Pass an `HttpExecutionStrategy` through request context;

Result:

No deprecated API on requester/client/filter API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change PR with breaking changes, removed APIs or other binary incompatibilities.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants