You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ma...@apache.org on 2023/07/31 07:12:00 UTC
[flink] 03/03: [hotfix][rest] Expose fields with getters for testing
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 1f73784078dcdef08355d437b00e349d9579943d
Author: Patrick Lucas <me...@patricklucas.com>
AuthorDate: Thu Jul 27 10:03:32 2023 +0200
[hotfix][rest] Expose fields with getters for testing
Previously, these fields were package-private, non-final, and annotated
with `@VisibleForTesting`. This change makes them private final and adds
`@VisibleForTesting`-annotated getters for consistency with other
fields.
---
.../org/apache/flink/runtime/rest/RestClient.java | 7 ++++++-
.../flink/runtime/rest/RestServerEndpoint.java | 7 ++++++-
.../runtime/rest/RestExternalHandlersITCase.java | 21 ++++++++++++---------
3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
index 949c0badb60..f92fbbfdc62 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
@@ -140,7 +140,7 @@ public class RestClient implements AutoCloseableAsync {
private final Collection<CompletableFuture<Channel>> responseChannelFutures =
ConcurrentHashMap.newKeySet();
- @VisibleForTesting List<OutboundChannelHandlerFactory> outboundChannelHandlerFactories;
+ private final List<OutboundChannelHandlerFactory> outboundChannelHandlerFactories;
/**
* Creates a new RestClient for the provided root URL. If the protocol of the URL is "https",
@@ -289,6 +289,11 @@ public class RestClient implements AutoCloseableAsync {
return responseChannelFutures;
}
+ @VisibleForTesting
+ List<OutboundChannelHandlerFactory> getOutboundChannelHandlerFactories() {
+ return outboundChannelHandlerFactories;
+ }
+
@Override
public CompletableFuture<Void> closeAsync() {
return shutdownInternally(Time.seconds(10L));
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java
index ca72337307a..004cb8106ec 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java
@@ -109,7 +109,7 @@ public abstract class RestServerEndpoint implements RestService {
private State state = State.CREATED;
- @VisibleForTesting List<InboundChannelHandlerFactory> inboundChannelHandlerFactories;
+ private final List<InboundChannelHandlerFactory> inboundChannelHandlerFactories;
public RestServerEndpoint(Configuration configuration)
throws IOException, ConfigurationException {
@@ -152,6 +152,11 @@ public abstract class RestServerEndpoint implements RestService {
Comparator.comparingInt(InboundChannelHandlerFactory::priority).reversed());
}
+ @VisibleForTesting
+ List<InboundChannelHandlerFactory> getInboundChannelHandlerFactories() {
+ return inboundChannelHandlerFactories;
+ }
+
/**
* This method is called at the beginning of {@link #start()} to setup all handlers that the
* REST server endpoint implementation requires.
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 def6c628c2d..0509a15088f 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
@@ -47,6 +47,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledExecutorService;
@@ -124,21 +125,23 @@ class RestExternalHandlersITCase {
}
@Test
- void testHandlersMustBeLoaded() throws Exception {
- assertEquals(serverEndpoint.inboundChannelHandlerFactories.size(), 2);
+ void testHandlersMustBeLoaded() {
+ final List<InboundChannelHandlerFactory> inboundChannelHandlerFactories =
+ serverEndpoint.getInboundChannelHandlerFactories();
+ assertEquals(inboundChannelHandlerFactories.size(), 2);
assertTrue(
- serverEndpoint.inboundChannelHandlerFactories.get(0)
- instanceof Prio1InboundChannelHandlerFactory);
+ inboundChannelHandlerFactories.get(0) instanceof Prio1InboundChannelHandlerFactory);
assertTrue(
- serverEndpoint.inboundChannelHandlerFactories.get(1)
- instanceof Prio0InboundChannelHandlerFactory);
+ inboundChannelHandlerFactories.get(1) instanceof Prio0InboundChannelHandlerFactory);
- assertEquals(restClient.outboundChannelHandlerFactories.size(), 2);
+ final List<OutboundChannelHandlerFactory> outboundChannelHandlerFactories =
+ restClient.getOutboundChannelHandlerFactories();
+ assertEquals(outboundChannelHandlerFactories.size(), 2);
assertTrue(
- restClient.outboundChannelHandlerFactories.get(0)
+ outboundChannelHandlerFactories.get(0)
instanceof Prio1OutboundChannelHandlerFactory);
assertTrue(
- restClient.outboundChannelHandlerFactories.get(1)
+ outboundChannelHandlerFactories.get(1)
instanceof Prio0OutboundChannelHandlerFactory);
try {