From 0da413a76bcea01d99e9d384676fcf2587069d8f Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Thu, 26 May 2022 17:21:15 -0700 Subject: [PATCH 1/5] Additional test of expected server offloading Motivation: When a `StreamingHttpService` is converted to another API flavor the expected offloading points change. Modifications: Add a test that verifies that converted HTTP services have the expected offloading. Result: Additional test coverage. --- ...ttpServerDefaultExecutionStrategyTest.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java diff --git a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java new file mode 100644 index 0000000000..77f737a32f --- /dev/null +++ b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java @@ -0,0 +1,86 @@ +package io.servicetalk.http.netty; + +import io.servicetalk.concurrent.api.Single; +import io.servicetalk.http.api.BlockingHttpService; +import io.servicetalk.http.api.BlockingStreamingHttpService; +import io.servicetalk.http.api.HttpApiConversions; +import io.servicetalk.http.api.HttpExecutionStrategies; +import io.servicetalk.http.api.HttpExecutionStrategy; +import io.servicetalk.http.api.HttpService; +import io.servicetalk.http.api.HttpServiceContext; +import io.servicetalk.http.api.StreamingHttpRequest; +import io.servicetalk.http.api.StreamingHttpResponse; +import io.servicetalk.http.api.StreamingHttpResponseFactory; +import io.servicetalk.http.api.StreamingHttpService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static io.servicetalk.concurrent.api.Publisher.from; +import static io.servicetalk.concurrent.api.Single.succeeded; +import static io.servicetalk.http.api.HttpExecutionStrategies.offloadAll; +import static io.servicetalk.http.api.HttpExecutionStrategies.offloadNone; +import static io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class HttpServerDefaultExecutionStrategyTest { + + private static Stream services() { + return Stream.of(offloadNone(), + HttpExecutionStrategies.customStrategyBuilder().offloadSend().build(), + offloadAll()) + .map((HttpExecutionStrategy hes) -> new StreamingHttpService() { + @Override + public Single handle(HttpServiceContext ctx, StreamingHttpRequest request, StreamingHttpResponseFactory responseFactory) { + return succeeded(responseFactory.ok() + .payloadBody(from("Hello World!"), appSerializerUtf8FixLen())); + } + + @Override + public HttpExecutionStrategy requiredOffloads() { + return hes; + } + + public String toString() { + return hes.toString(); + } + }) + .map(service -> Arguments.of(service)); + } + + @ParameterizedTest(name = "{displayName} {index}: service: {0}") + @MethodSource("services") + void testHttpService(StreamingHttpService streamingAsyncService) { + HttpService aggregateService = HttpApiConversions.toHttpService(streamingAsyncService); + HttpExecutionStrategy serviceStrategy = aggregateService.requiredOffloads(); + assertTrue(serviceStrategy.isSendOffloaded(), "Unexpected send strategy " + serviceStrategy); + assertFalse(serviceStrategy.isMetadataReceiveOffloaded(), "Unexpected meta strategy " + serviceStrategy); + assertTrue(serviceStrategy.isDataReceiveOffloaded(), "Unexpected read strategy " + serviceStrategy); + } + + @ParameterizedTest(name = "{displayName} {index}: service: {0}") + @MethodSource("services") + void testBlockingHttpService(StreamingHttpService streamingAsyncService) { + BlockingHttpService blockingHttpService = + HttpApiConversions.toBlockingHttpService(streamingAsyncService); + HttpExecutionStrategy serviceStrategy = blockingHttpService.requiredOffloads(); + assertFalse(serviceStrategy.isSendOffloaded(), "Unexpected send strategy " + serviceStrategy); + assertFalse(serviceStrategy.isMetadataReceiveOffloaded(), "Unexpected meta strategy " + serviceStrategy); + assertTrue(serviceStrategy.isDataReceiveOffloaded(), "Unexpected read strategy " + serviceStrategy); + } + + @ParameterizedTest(name = "{displayName} {index}: service: {0}") + @MethodSource("services") + void testBlockingStreamingHttpService(StreamingHttpService streamingAsyncService) { + BlockingStreamingHttpService blockingStreamingHttpService = + HttpApiConversions.toBlockingStreamingHttpService(streamingAsyncService); + HttpExecutionStrategy serviceStrategy = blockingStreamingHttpService.requiredOffloads(); + assertFalse(serviceStrategy.isSendOffloaded(), "Unexpected send strategy " + serviceStrategy); + assertTrue(serviceStrategy.isMetadataReceiveOffloaded(), "Unexpected meta strategy " + serviceStrategy); + assertFalse(serviceStrategy.isDataReceiveOffloaded(), "Unexpected read strategy " + serviceStrategy); + } +} From 5bb0db380d53a94dc518c5e5fdaaa57d1243d81e Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Thu, 26 May 2022 17:49:21 -0700 Subject: [PATCH 2/5] cleanup imports --- .../http/netty/HttpServerDefaultExecutionStrategyTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java index 77f737a32f..b52720e396 100644 --- a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java +++ b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java @@ -12,7 +12,6 @@ import io.servicetalk.http.api.StreamingHttpResponse; import io.servicetalk.http.api.StreamingHttpResponseFactory; import io.servicetalk.http.api.StreamingHttpService; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; From c3f3d896bd8fd64b21af2623864bbf6b83b1dd5e Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Thu, 26 May 2022 18:49:59 -0700 Subject: [PATCH 3/5] more checkstyle nits --- ...ttpServerDefaultExecutionStrategyTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java index b52720e396..e1f1f98697 100644 --- a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java +++ b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java @@ -1,3 +1,18 @@ +/* + * Copyright © 2022 Apple Inc. and the ServiceTalk project authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.servicetalk.http.netty; import io.servicetalk.concurrent.api.Single; @@ -34,7 +49,9 @@ private static Stream services() { offloadAll()) .map((HttpExecutionStrategy hes) -> new StreamingHttpService() { @Override - public Single handle(HttpServiceContext ctx, StreamingHttpRequest request, StreamingHttpResponseFactory responseFactory) { + public Single handle(final HttpServiceContext ctx, + final StreamingHttpRequest request, + final StreamingHttpResponseFactory responseFactory) { return succeeded(responseFactory.ok() .payloadBody(from("Hello World!"), appSerializerUtf8FixLen())); } From cbac46270c6403dc33ddaa0761d67150c88f0c21 Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Thu, 26 May 2022 20:03:25 -0700 Subject: [PATCH 4/5] more checkstyle nits --- .../http/netty/HttpServerDefaultExecutionStrategyTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java index e1f1f98697..5d0253aa29 100644 --- a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java +++ b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java @@ -27,6 +27,7 @@ import io.servicetalk.http.api.StreamingHttpResponse; import io.servicetalk.http.api.StreamingHttpResponseFactory; import io.servicetalk.http.api.StreamingHttpService; + import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; From bad954a54c1a6b567a031e441ac3a8ab4293ff1f Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Thu, 26 May 2022 20:24:13 -0700 Subject: [PATCH 5/5] fix a pmd nit --- .../http/netty/HttpServerDefaultExecutionStrategyTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java index 5d0253aa29..2453867716 100644 --- a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java +++ b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpServerDefaultExecutionStrategyTest.java @@ -42,7 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class HttpServerDefaultExecutionStrategyTest { +class HttpServerDefaultExecutionStrategyTest { private static Stream services() { return Stream.of(offloadNone(),