[FLINK-24193][rest][tests] Migrate tests to ClassLoaderExtension
diff --git a/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/utils/WebFrontendBootstrapTest.java b/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/utils/WebFrontendBootstrapTest.java
index f58093f..42c2491 100644
--- a/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/utils/WebFrontendBootstrapTest.java
+++ b/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/utils/WebFrontendBootstrapTest.java
@@ -20,31 +20,43 @@
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.io.network.netty.InboundChannelHandlerFactory;
import org.apache.flink.runtime.io.network.netty.Prio0InboundChannelHandlerFactory;
import org.apache.flink.runtime.io.network.netty.Prio1InboundChannelHandlerFactory;
import org.apache.flink.runtime.rest.handler.router.Router;
import org.apache.flink.runtime.webmonitor.history.HistoryServerStaticFileServerHandler;
import org.apache.flink.runtime.webmonitor.history.HistoryServerTest;
+import org.apache.flink.testutils.junit.extensions.ContextClassLoaderExtension;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.Extension;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
import org.slf4j.LoggerFactory;
-import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/** Tests for the WebFrontendBootstrap. */
public class WebFrontendBootstrapTest {
- @Rule public TemporaryFolder tmp = new TemporaryFolder();
+ @RegisterExtension
+ static final Extension CONTEXT_CLASS_LOADER_EXTENSION =
+ ContextClassLoaderExtension.builder()
+ .withServiceEntry(
+ InboundChannelHandlerFactory.class,
+ Prio0InboundChannelHandlerFactory.class.getCanonicalName(),
+ Prio1InboundChannelHandlerFactory.class.getCanonicalName())
+ .build();
+
+ @TempDir Path tmp;
@Test
- public void testHandlersMustBeLoaded() throws Exception {
- File webDir = tmp.newFolder("webDir");
+ void testHandlersMustBeLoaded() throws Exception {
+ Path webDir = Files.createDirectories(tmp.resolve("webDir"));
Configuration configuration = new Configuration();
configuration.setString(
Prio0InboundChannelHandlerFactory.REDIRECT_FROM_URL, "/nonExisting");
@@ -55,7 +67,7 @@
new WebFrontendBootstrap(
router,
LoggerFactory.getLogger(WebFrontendBootstrapTest.class),
- tmp.newFolder("uploadDir"),
+ Files.createDirectories(webDir.resolve("uploadDir")).toFile(),
null,
"localhost",
0,
@@ -73,13 +85,13 @@
try {
Tuple2<Integer, String> index =
HistoryServerTest.getFromHTTP("http://localhost:" + port + "/index.html");
- Assert.assertEquals(index.f0.intValue(), 200);
- Assert.assertTrue(index.f1.contains("Apache Flink Web Dashboard"));
+ assertEquals(index.f0.intValue(), 200);
+ assertTrue(index.f1.contains("Apache Flink Web Dashboard"));
Tuple2<Integer, String> index2 =
HistoryServerTest.getFromHTTP("http://localhost:" + port + "/nonExisting");
- Assert.assertEquals(index2.f0.intValue(), 200);
- Assert.assertEquals(index, index2);
+ assertEquals(index2.f0.intValue(), 200);
+ assertEquals(index, index2);
} finally {
webUI.shutdown();
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java
index bc8dd31..9fd6dcc 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java
@@ -21,6 +21,8 @@
import org.apache.flink.api.common.time.Time;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.runtime.io.network.netty.InboundChannelHandlerFactory;
+import org.apache.flink.runtime.io.network.netty.OutboundChannelHandlerFactory;
import org.apache.flink.runtime.io.network.netty.Prio0InboundChannelHandlerFactory;
import org.apache.flink.runtime.io.network.netty.Prio1InboundChannelHandlerFactory;
import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
@@ -29,23 +31,26 @@
import org.apache.flink.runtime.rest.messages.ResponseBody;
import org.apache.flink.runtime.rest.util.TestRestServerEndpoint;
import org.apache.flink.runtime.testutils.TestingUtils;
+import org.apache.flink.testutils.junit.extensions.ContextClassLoaderExtension;
import org.apache.flink.util.ConfigurationException;
import org.apache.flink.util.TestLogger;
import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.Extension;
+import org.junit.jupiter.api.extension.RegisterExtension;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/** IT cases for {@link RestClient} and {@link RestServerEndpoint}. */
public class RestExternalHandlersITCase extends TestLogger {
@@ -59,6 +64,19 @@
private RestClient restClient;
private InetSocketAddress serverAddress;
+ @RegisterExtension
+ static final Extension CONTEXT_CLASS_LOADER_EXTENSION =
+ ContextClassLoaderExtension.builder()
+ .withServiceEntry(
+ InboundChannelHandlerFactory.class,
+ Prio0InboundChannelHandlerFactory.class.getCanonicalName(),
+ Prio1InboundChannelHandlerFactory.class.getCanonicalName())
+ .withServiceEntry(
+ OutboundChannelHandlerFactory.class,
+ Prio0OutboundChannelHandlerFactory.class.getCanonicalName(),
+ Prio1OutboundChannelHandlerFactory.class.getCanonicalName())
+ .build();
+
private final Configuration config;
public RestExternalHandlersITCase() {
@@ -78,15 +96,15 @@
return config;
}
- @Before
- public void setup() throws Exception {
+ @BeforeEach
+ private void setup() throws Exception {
serverEndpoint = TestRestServerEndpoint.builder(config).buildAndStart();
restClient = new TestRestClient(config);
serverAddress = serverEndpoint.getServerAddress();
}
- @After
- public void teardown() throws Exception {
+ @AfterEach
+ private void teardown() throws Exception {
if (restClient != null) {
restClient.shutdown(timeout);
restClient = null;
@@ -99,7 +117,7 @@
}
@Test
- public void testHandlersMustBeLoaded() throws Exception {
+ void testHandlersMustBeLoaded() throws Exception {
assertEquals(serverEndpoint.inboundChannelHandlerFactories.size(), 2);
assertTrue(
serverEndpoint.inboundChannelHandlerFactories.get(0)
diff --git a/flink-runtime/src/test/resources/META-INF/services/org.apache.flink.runtime.io.network.netty.InboundChannelHandlerFactory b/flink-runtime/src/test/resources/META-INF/services/org.apache.flink.runtime.io.network.netty.InboundChannelHandlerFactory
deleted file mode 100644
index 09b801c..0000000
--- a/flink-runtime/src/test/resources/META-INF/services/org.apache.flink.runtime.io.network.netty.InboundChannelHandlerFactory
+++ /dev/null
@@ -1,17 +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.
-
-org.apache.flink.runtime.io.network.netty.Prio0InboundChannelHandlerFactory
-org.apache.flink.runtime.io.network.netty.Prio1InboundChannelHandlerFactory
diff --git a/flink-runtime/src/test/resources/META-INF/services/org.apache.flink.runtime.io.network.netty.OutboundChannelHandlerFactory b/flink-runtime/src/test/resources/META-INF/services/org.apache.flink.runtime.io.network.netty.OutboundChannelHandlerFactory
deleted file mode 100644
index ea7be93..0000000
--- a/flink-runtime/src/test/resources/META-INF/services/org.apache.flink.runtime.io.network.netty.OutboundChannelHandlerFactory
+++ /dev/null
@@ -1,17 +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.
-
-org.apache.flink.runtime.rest.Prio0OutboundChannelHandlerFactory
-org.apache.flink.runtime.rest.Prio1OutboundChannelHandlerFactory