This is an automated email from the ASF dual-hosted git repository. chesnay pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit b1a1874f6638eccda86d27069f10cdde55826955 Author: Chesnay Schepler <[email protected]> AuthorDate: Sun Apr 3 20:27:43 2022 +0200 [FLINK-26995][tests] Mark several tests as unit tests --- .../rest/handler/AbstractHandlerITCase.java | 123 --------------------- .../runtime/rest/handler/AbstractHandlerTest.java | 85 ++++++++++++++ ... ZooKeeperUtilsWriteLeaderInformationTest.java} | 2 +- ...ssignerITCases.java => BucketAssignerTest.java} | 2 +- 4 files changed, 87 insertions(+), 125 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/AbstractHandlerITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/AbstractHandlerITCase.java deleted file mode 100644 index 60676591a74..00000000000 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/AbstractHandlerITCase.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.flink.runtime.rest.handler; - -import org.apache.flink.configuration.Configuration; -import org.apache.flink.configuration.RestOptions; -import org.apache.flink.runtime.rest.RestClient; -import org.apache.flink.runtime.rest.messages.EmptyMessageParameters; -import org.apache.flink.runtime.rest.messages.EmptyRequestBody; -import org.apache.flink.runtime.rest.messages.EmptyResponseBody; -import org.apache.flink.runtime.rest.util.TestMessageHeaders; -import org.apache.flink.runtime.rest.util.TestRestHandler; -import org.apache.flink.runtime.rest.util.TestRestServerEndpoint; -import org.apache.flink.runtime.webmonitor.RestfulGateway; -import org.apache.flink.runtime.webmonitor.TestingDispatcherGateway; -import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever; -import org.apache.flink.util.ConfigurationException; -import org.apache.flink.util.TestLogger; -import org.apache.flink.util.concurrent.Executors; -import org.apache.flink.util.concurrent.FutureUtils; - -import org.hamcrest.core.StringContains; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import java.net.InetAddress; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -/** Tests to cover functionality provided by {@link AbstractHandler}. */ -public class AbstractHandlerITCase extends TestLogger { - - private static final RestfulGateway mockRestfulGateway = - TestingDispatcherGateway.newBuilder().build(); - - private static final GatewayRetriever<RestfulGateway> mockGatewayRetriever = - () -> CompletableFuture.completedFuture(mockRestfulGateway); - - private static final Configuration REST_BASE_CONFIG; - - static { - final String loopbackAddress = InetAddress.getLoopbackAddress().getHostAddress(); - - final Configuration config = new Configuration(); - config.setString(RestOptions.BIND_PORT, "0"); - config.setString(RestOptions.BIND_ADDRESS, loopbackAddress); - config.setString(RestOptions.ADDRESS, loopbackAddress); - - REST_BASE_CONFIG = config; - } - - @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); - - private RestClient createRestClient(int serverPort) throws ConfigurationException { - Configuration config = new Configuration(REST_BASE_CONFIG); - config.setInteger(RestOptions.PORT, serverPort); - - return new RestClient(config, Executors.directExecutor()); - } - - @Test - public void testOOMErrorMessageEnrichment() throws Exception { - final TestMessageHeaders<EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> - messageHeaders = - TestMessageHeaders.emptyBuilder() - .setTargetRestEndpointURL("/test-handler") - .build(); - - final TestRestHandler< - RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> - testRestHandler = - new TestRestHandler<>( - mockGatewayRetriever, - messageHeaders, - FutureUtils.completedExceptionally( - new OutOfMemoryError("Metaspace"))); - - try (final TestRestServerEndpoint server = - TestRestServerEndpoint.builder(REST_BASE_CONFIG) - .withHandler(messageHeaders, testRestHandler) - .buildAndStart(); - final RestClient restClient = - createRestClient(server.getServerAddress().getPort())) { - CompletableFuture<EmptyResponseBody> response = - restClient.sendRequest( - server.getServerAddress().getHostName(), - server.getServerAddress().getPort(), - messageHeaders, - EmptyMessageParameters.getInstance(), - EmptyRequestBody.getInstance()); - try { - response.get(); - fail( - "An ExecutionException was expected here being caused by the OutOfMemoryError."); - } catch (ExecutionException e) { - assertThat( - e.getMessage(), - StringContains.containsString( - "Metaspace. The metaspace out-of-memory error has occurred. ")); - } - } - } -} diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/AbstractHandlerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/AbstractHandlerTest.java index 974cab706b9..522480846f8 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/AbstractHandlerTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/AbstractHandlerTest.java @@ -18,17 +18,28 @@ package org.apache.flink.runtime.rest.handler; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.RestOptions; import org.apache.flink.runtime.rest.HttpMethodWrapper; +import org.apache.flink.runtime.rest.RestClient; import org.apache.flink.runtime.rest.handler.router.RouteResult; import org.apache.flink.runtime.rest.handler.router.RoutedRequest; import org.apache.flink.runtime.rest.messages.EmptyMessageParameters; import org.apache.flink.runtime.rest.messages.EmptyRequestBody; +import org.apache.flink.runtime.rest.messages.EmptyResponseBody; import org.apache.flink.runtime.rest.messages.UntypedResponseMessageHeaders; +import org.apache.flink.runtime.rest.util.TestMessageHeaders; +import org.apache.flink.runtime.rest.util.TestRestHandler; +import org.apache.flink.runtime.rest.util.TestRestServerEndpoint; import org.apache.flink.runtime.rpc.RpcUtils; import org.apache.flink.runtime.webmonitor.RestfulGateway; +import org.apache.flink.runtime.webmonitor.TestingDispatcherGateway; import org.apache.flink.runtime.webmonitor.TestingRestfulGateway; import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever; +import org.apache.flink.util.ConfigurationException; import org.apache.flink.util.TestLogger; +import org.apache.flink.util.concurrent.Executors; +import org.apache.flink.util.concurrent.FutureUtils; import org.apache.flink.shaded.netty4.io.netty.buffer.Unpooled; import org.apache.flink.shaded.netty4.io.netty.channel.Channel; @@ -40,6 +51,7 @@ import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpVersion; import org.apache.flink.shaded.netty4.io.netty.util.Attribute; import org.apache.flink.shaded.netty4.io.netty.util.AttributeKey; +import org.hamcrest.core.StringContains; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -47,12 +59,16 @@ import org.junit.rules.TemporaryFolder; import javax.annotation.Nonnull; +import java.net.InetAddress; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicReference; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -62,6 +78,75 @@ public class AbstractHandlerTest extends TestLogger { @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + private static final RestfulGateway mockRestfulGateway = + TestingDispatcherGateway.newBuilder().build(); + + private static final GatewayRetriever<RestfulGateway> mockGatewayRetriever = + () -> CompletableFuture.completedFuture(mockRestfulGateway); + + private static final Configuration REST_BASE_CONFIG; + + static { + final String loopbackAddress = InetAddress.getLoopbackAddress().getHostAddress(); + + final Configuration config = new Configuration(); + config.setString(RestOptions.BIND_PORT, "0"); + config.setString(RestOptions.BIND_ADDRESS, loopbackAddress); + config.setString(RestOptions.ADDRESS, loopbackAddress); + + REST_BASE_CONFIG = config; + } + + private RestClient createRestClient(int serverPort) throws ConfigurationException { + Configuration config = new Configuration(REST_BASE_CONFIG); + config.setInteger(RestOptions.PORT, serverPort); + + return new RestClient(config, Executors.directExecutor()); + } + + @Test + public void testOOMErrorMessageEnrichment() throws Exception { + final TestMessageHeaders<EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> + messageHeaders = + TestMessageHeaders.emptyBuilder() + .setTargetRestEndpointURL("/test-handler") + .build(); + + final TestRestHandler< + RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> + testRestHandler = + new TestRestHandler<>( + mockGatewayRetriever, + messageHeaders, + FutureUtils.completedExceptionally( + new OutOfMemoryError("Metaspace"))); + + try (final TestRestServerEndpoint server = + TestRestServerEndpoint.builder(REST_BASE_CONFIG) + .withHandler(messageHeaders, testRestHandler) + .buildAndStart(); + final RestClient restClient = + createRestClient(server.getServerAddress().getPort())) { + CompletableFuture<EmptyResponseBody> response = + restClient.sendRequest( + server.getServerAddress().getHostName(), + server.getServerAddress().getPort(), + messageHeaders, + EmptyMessageParameters.getInstance(), + EmptyRequestBody.getInstance()); + try { + response.get(); + fail( + "An ExecutionException was expected here being caused by the OutOfMemoryError."); + } catch (ExecutionException e) { + assertThat( + e.getMessage(), + StringContains.containsString( + "Metaspace. The metaspace out-of-memory error has occurred. ")); + } + } + } + @Test public void testFileCleanup() throws Exception { final Path dir = temporaryFolder.newFolder().toPath(); diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsWriteLeaderInformationTest.java similarity index 98% rename from flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsITCase.java rename to flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsWriteLeaderInformationTest.java index b4b6818f814..5c85c2df336 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsITCase.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsWriteLeaderInformationTest.java @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** Integration tests for the {@link ZooKeeperUtils}. */ @ExtendWith(TestLoggerExtension.class) -class ZooKeeperUtilsITCase { +class ZooKeeperUtilsWriteLeaderInformationTest { private final ZooKeeperExtension zooKeeperExtension = new ZooKeeperExtension(); @RegisterExtension diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketAssignerITCases.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketAssignerTest.java similarity index 98% rename from flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketAssignerITCases.java rename to flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketAssignerTest.java index e12638a4474..31ddb8cdabe 100644 --- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketAssignerITCases.java +++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/filesystem/BucketAssignerTest.java @@ -33,7 +33,7 @@ import org.junit.rules.TemporaryFolder; import java.io.File; /** Integration tests for {@link BucketAssigner bucket assigners}. */ -public class BucketAssignerITCases { +public class BucketAssignerTest { @ClassRule public static final TemporaryFolder TEMP_FOLDER = new TemporaryFolder();
