zentol commented on a change in pull request #7263: [FLINK-11081] Support
binding port range for REST server
URL: https://github.com/apache/flink/pull/7263#discussion_r255057367
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointConfigurationTest.java
##########
@@ -49,17 +74,228 @@ public void testBasicMapping() throws
ConfigurationException {
Configuration originalConfig = new Configuration();
originalConfig.setString(RestOptions.ADDRESS, ADDRESS);
originalConfig.setString(RestOptions.BIND_ADDRESS,
BIND_ADDRESS);
- originalConfig.setInteger(RestOptions.PORT, PORT);
+ originalConfig.setString(RestOptions.BIND_PORT, BIND_PORT);
originalConfig.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH,
CONTENT_LENGTH);
originalConfig.setString(WebOptions.TMP_DIR,
temporaryFolder.getRoot().getAbsolutePath());
final RestServerEndpointConfiguration result =
RestServerEndpointConfiguration.fromConfiguration(originalConfig);
Assert.assertEquals(ADDRESS, result.getRestAddress());
Assert.assertEquals(BIND_ADDRESS, result.getRestBindAddress());
- Assert.assertEquals(PORT, result.getRestBindPort());
+ Assert.assertEquals(BIND_PORT, result.getRestBindPort());
Assert.assertEquals(CONTENT_LENGTH,
result.getMaxContentLength());
Assert.assertThat(
result.getUploadDir().toAbsolutePath().toString(),
containsString(temporaryFolder.getRoot().getAbsolutePath()));
}
+
+ @Test
+ public void testDefaultRestServerBindPort() throws Exception {
+ testRestServerBindPort(null, "8081");
+ }
+
+ @Test
+ public void testRestServerSpecificBindPort() throws Exception {
+ testRestServerBindPort("12345", "12345");
+ }
+
+ @Test
+ public void testRestServerSpecificBindPortRange() throws Exception {
+ testRestServerBindPort("12345,12346", "12345");
+ }
+
+ @Test
+ public void testRestServerBindPortRange() throws Exception {
+ testRestServerBindPort("12345-12350", "12345");
+ }
+
+ @Test
+ public void testRestServerBindPortAndConnectionPortSuccess() throws
Exception {
+ testRestServerBindPortAndConnectionPort("12345,12346", 12345);
+ }
+
+ @Test
+ public void testRestServerBindPortAndConnectionPortFailed() throws
Exception {
+ try {
+ testRestServerBindPortAndConnectionPort("12345-12346",
12347);
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("Connection refused")
+ && e.getMessage().contains("12347"));
+ }
+ }
+
+ @Test
+ public void testRestServerBindPortConflict() throws Exception {
+ RestServerEndpoint serverEndpoint1 = null;
+ RestServerEndpoint serverEndpoint2 = null;
+ RestClient restClient = null;
+
+ try {
+ final Configuration config = new Configuration();
+ config.setString(RestOptions.ADDRESS, "localhost");
+ config.setString(RestOptions.BIND_PORT, "12345,12346");
+
+ RestServerEndpointITCase.TestHandler testHandler;
+
+ RestServerEndpointConfiguration serverConfig =
RestServerEndpointConfiguration.fromConfiguration(config);
+ RestClientConfiguration clientConfig =
RestClientConfiguration.fromConfiguration(config);
+
+ final String restAddress = "http://localhost:1234";
+ RestfulGateway mockRestfulGateway =
TestingRestfulGateway.newBuilder()
+ .setAddress("http://localhost:1234")
+ .build();
+
+ final GatewayRetriever<RestfulGateway>
mockGatewayRetriever = () ->
+
CompletableFuture.completedFuture(mockRestfulGateway);
+
+ testHandler = new RestServerEndpointITCase.TestHandler(
+ CompletableFuture.completedFuture(restAddress),
+ mockGatewayRetriever,
+ RpcUtils.INF_TIMEOUT);
+
+ RestServerEndpointITCase.TestVersionHandler
testVersionHandler = new RestServerEndpointITCase.TestVersionHandler(
+ mockGatewayRetriever,
+ RpcUtils.INF_TIMEOUT);
+
+ final List<Tuple2<RestHandlerSpecification,
ChannelInboundHandler>> handlers = Arrays.asList(
+ Tuple2.of(new
RestServerEndpointITCase.TestHeaders(), testHandler),
+
Tuple2.of(testVersionHandler.getMessageHeaders(), testVersionHandler));
+
+ serverEndpoint1 = new
RestServerEndpointITCase.TestRestServerEndpoint(serverConfig, handlers);
Review comment:
everything before this line can be moved out of the try block
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services