-
Notifications
You must be signed in to change notification settings - Fork 184
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
Conversation
8effca0
to
59dac1c
Compare
servicetalk-grpc-api/src/main/java/io/servicetalk/grpc/api/DefaultGrpcClientCallFactory.java
Show resolved
Hide resolved
return blockingInvocation(requester.request(strategy, request.toStreamingRequest()) | ||
.flatMap(StreamingHttpResponse::toResponse)); | ||
return blockingInvocation(requester.request(request.toStreamingRequest()) | ||
.flatMap(response -> response.toResponse().subscribeShareContext())); |
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.
can you clarify why we need .subscribeShareContext
here? typically this is used as the last operator in a defer(() -> ... subscribeShareContext())
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.
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.
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.
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:{}
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'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.
servicetalk-http-api/src/main/java/io/servicetalk/http/api/StreamingHttpClientToHttpClient.java
Outdated
Show resolved
Hide resolved
...-http-api/src/main/java/io/servicetalk/http/api/StreamingHttpConnectionToHttpConnection.java
Show resolved
Hide resolved
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.
769854d
to
58a06fe
Compare
Motivation:
#1956 removed requester/client methods that take
HttpExecutionStrategy
. All deprecated API can be removed now.Modifications:
request
method from a requester;reserveConnection
method from a client;NewToDeprecated
utility;HttpExecutionStrategy
through request context;Result:
No deprecated API on requester/client/filter API.