This is an automated email from the ASF dual-hosted git repository. chesnay pushed a commit to branch release-1.17 in repository https://gitbox.apache.org/repos/asf/flink.git
commit 75c4a7c67fcebb03d073cc4eedbf495e1355b01e Author: Chesnay Schepler <ches...@apache.org> AuthorDate: Wed Apr 5 14:47:43 2023 +0200 [FLINK-31733][tests] Simplify DocumentingRestEndpoint setup --- .../flink/docs/rest/OpenApiSpecGeneratorTest.java | 64 +++++----------------- .../flink/docs/rest/RestAPIDocGeneratorTest.java | 47 ++++------------ .../runtime/rest/util/DocumentingRestEndpoint.java | 8 +++ 3 files changed, 35 insertions(+), 84 deletions(-) diff --git a/flink-docs/src/test/java/org/apache/flink/docs/rest/OpenApiSpecGeneratorTest.java b/flink-docs/src/test/java/org/apache/flink/docs/rest/OpenApiSpecGeneratorTest.java index 6aa2b15f72d..3e0493c6095 100644 --- a/flink-docs/src/test/java/org/apache/flink/docs/rest/OpenApiSpecGeneratorTest.java +++ b/flink-docs/src/test/java/org/apache/flink/docs/rest/OpenApiSpecGeneratorTest.java @@ -18,22 +18,15 @@ package org.apache.flink.docs.rest; -import org.apache.flink.api.java.tuple.Tuple2; import org.apache.flink.docs.rest.data.TestEmptyMessageHeaders; import org.apache.flink.docs.rest.data.TestExcludeMessageHeaders; -import org.apache.flink.runtime.rest.handler.RestHandlerSpecification; import org.apache.flink.runtime.rest.util.DocumentingRestEndpoint; import org.apache.flink.runtime.rest.versioning.RuntimeRestAPIVersion; import org.apache.flink.util.FileUtils; -import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler; - import org.junit.jupiter.api.Test; import java.io.File; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; @@ -48,7 +41,8 @@ class OpenApiSpecGeneratorTest { File file = File.createTempFile("rest_v0_", ".html"); OpenApiSpecGenerator.createDocumentationFile( title, - new TestExcludeDocumentingRestEndpoint(), + DocumentingRestEndpoint.forRestHandlerSpecifications( + new TestEmptyMessageHeaders("/test/empty1", "This is a testing REST API.")), RuntimeRestAPIVersion.V0, file.toPath()); String actual = FileUtils.readFile(file, "UTF-8"); @@ -61,7 +55,16 @@ class OpenApiSpecGeneratorTest { File file = File.createTempFile("rest_v0_", ".html"); OpenApiSpecGenerator.createDocumentationFile( "title", - new TestExcludeDocumentingRestEndpoint(), + DocumentingRestEndpoint.forRestHandlerSpecifications( + new TestEmptyMessageHeaders("/test/empty1", "This is a testing REST API."), + new TestEmptyMessageHeaders( + "/test/empty2", "This is another testing REST API."), + new TestExcludeMessageHeaders( + "/test/exclude1", + "This REST API should not appear in the generated documentation."), + new TestExcludeMessageHeaders( + "/test/exclude2", + "This REST API should also not appear in the generated documentation.")), RuntimeRestAPIVersion.V0, file.toPath()); String actual = FileUtils.readFile(file, "UTF-8"); @@ -79,33 +82,6 @@ class OpenApiSpecGeneratorTest { "This REST API should also not appear in the generated documentation."); } - private static class TestExcludeDocumentingRestEndpoint implements DocumentingRestEndpoint { - - @Override - public List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers( - CompletableFuture<String> localAddressFuture) { - return Arrays.asList( - Tuple2.of( - new TestEmptyMessageHeaders( - "/test/empty1", "This is a testing REST API."), - null), - Tuple2.of( - new TestEmptyMessageHeaders( - "/test/empty2", "This is another testing REST API."), - null), - Tuple2.of( - new TestExcludeMessageHeaders( - "/test/exclude1", - "This REST API should not appear in the generated documentation."), - null), - Tuple2.of( - new TestExcludeMessageHeaders( - "/test/exclude2", - "This REST API should also not appear in the generated documentation."), - null)); - } - } - @Test void testDuplicateOperationIdsAreRejected() throws Exception { File file = File.createTempFile("rest_v0_", ".html"); @@ -113,22 +89,12 @@ class OpenApiSpecGeneratorTest { () -> OpenApiSpecGenerator.createDocumentationFile( "title", - new TestDuplicateOperationIdDocumentingRestEndpoint(), + DocumentingRestEndpoint.forRestHandlerSpecifications( + new TestEmptyMessageHeaders("operation1"), + new TestEmptyMessageHeaders("operation1")), RuntimeRestAPIVersion.V0, file.toPath())) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Duplicate OperationId"); } - - private static class TestDuplicateOperationIdDocumentingRestEndpoint - implements DocumentingRestEndpoint { - - @Override - public List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers( - CompletableFuture<String> localAddressFuture) { - return Arrays.asList( - Tuple2.of(new TestEmptyMessageHeaders("operation1"), null), - Tuple2.of(new TestEmptyMessageHeaders("operation1"), null)); - } - } } diff --git a/flink-docs/src/test/java/org/apache/flink/docs/rest/RestAPIDocGeneratorTest.java b/flink-docs/src/test/java/org/apache/flink/docs/rest/RestAPIDocGeneratorTest.java index d3fc475d23c..298d9e1b5df 100644 --- a/flink-docs/src/test/java/org/apache/flink/docs/rest/RestAPIDocGeneratorTest.java +++ b/flink-docs/src/test/java/org/apache/flink/docs/rest/RestAPIDocGeneratorTest.java @@ -18,22 +18,15 @@ package org.apache.flink.docs.rest; -import org.apache.flink.api.java.tuple.Tuple2; import org.apache.flink.docs.rest.data.TestEmptyMessageHeaders; import org.apache.flink.docs.rest.data.TestExcludeMessageHeaders; -import org.apache.flink.runtime.rest.handler.RestHandlerSpecification; import org.apache.flink.runtime.rest.util.DocumentingRestEndpoint; import org.apache.flink.runtime.rest.versioning.RuntimeRestAPIVersion; import org.apache.flink.util.FileUtils; -import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler; - import org.junit.jupiter.api.Test; import java.io.File; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; import static org.assertj.core.api.Assertions.assertThat; @@ -44,7 +37,18 @@ class RestAPIDocGeneratorTest { void testExcludeFromDocumentation() throws Exception { File file = File.createTempFile("rest_v0_", ".html"); RestAPIDocGenerator.createHtmlFile( - new TestExcludeDocumentingRestEndpoint(), RuntimeRestAPIVersion.V0, file.toPath()); + DocumentingRestEndpoint.forRestHandlerSpecifications( + new TestEmptyMessageHeaders("/test/empty1", "This is a testing REST API."), + new TestEmptyMessageHeaders( + "/test/empty2", "This is another testing REST API."), + new TestExcludeMessageHeaders( + "/test/exclude1", + "This REST API should not appear in the generated documentation."), + new TestExcludeMessageHeaders( + "/test/exclude2", + "This REST API should also not appear in the generated documentation.")), + RuntimeRestAPIVersion.V0, + file.toPath()); String actual = FileUtils.readFile(file, "UTF-8"); assertThat(actual).containsSequence("/test/empty1"); @@ -59,31 +63,4 @@ class RestAPIDocGeneratorTest { .doesNotContain( "This REST API should also not appear in the generated documentation."); } - - private static class TestExcludeDocumentingRestEndpoint implements DocumentingRestEndpoint { - - @Override - public List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers( - CompletableFuture<String> localAddressFuture) { - return Arrays.asList( - Tuple2.of( - new TestEmptyMessageHeaders( - "/test/empty1", "This is a testing REST API."), - null), - Tuple2.of( - new TestEmptyMessageHeaders( - "/test/empty2", "This is another testing REST API."), - null), - Tuple2.of( - new TestExcludeMessageHeaders( - "/test/exclude1", - "This REST API should not appear in the generated documentation."), - null), - Tuple2.of( - new TestExcludeMessageHeaders( - "/test/exclude2", - "This REST API should also not appear in the generated documentation."), - null)); - } - } } diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/util/DocumentingRestEndpoint.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/util/DocumentingRestEndpoint.java index 971ea3410b5..fb27515242b 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/util/DocumentingRestEndpoint.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/util/DocumentingRestEndpoint.java @@ -25,6 +25,7 @@ import org.apache.flink.runtime.rest.messages.MessageHeaders; import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler; +import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -50,4 +51,11 @@ public interface DocumentingRestEndpoint { spec2.getTargetRestEndpointURL())) .collect(Collectors.toList()); } + + static DocumentingRestEndpoint forRestHandlerSpecifications(RestHandlerSpecification... specs) { + return localAddressFuture -> + Arrays.stream(specs) + .map(spec -> Tuple2.of(spec, (ChannelInboundHandler) null)) + .collect(Collectors.toList()); + } }