You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/12/18 16:38:25 UTC
[GitHub] [flink] yuzelin opened a new pull request, #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
yuzelin opened a new pull request, #21525:
URL: https://github.com/apache/flink/pull/21525
<!--
*Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
Add configureSession REST API in the SQL Gateway.
## Brief change log
- Add `ConfigureSessionHandler`, `ConfigureSessionHeaders`, `ConfigureSessionRequestBody`.
- Add test in `SessionCaseITTest`.
- Bump version to V2 and update `sql_gateway_rest_api_v2.snapshot`.
## Verifying this change
This change added tests and can be verified as follows:
*(example:)*
- `testConfigureSession` in `SessionCaseITTest`.
- Existed `SqlGatewayRestAPIStabilityTest`.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? yes
- If yes, how is the feature documented? JavaDocs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] fsk119 commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
fsk119 commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1053229800
##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/util/SqlGatewayRestAPIVersion.java:
##########
@@ -35,7 +35,8 @@
// The bigger the ordinal(its position in enum declaration), the higher the level of the
// version.
V0(false, false),
- V1(true, true);
+ V1(true, true),
+ V2(false, true);
Review Comment:
Please do as Hive does and add some description about the change.
```
enum TProtocolVersion {
HIVE_CLI_SERVICE_PROTOCOL_V1,
// V2 adds support for asynchronous execution
HIVE_CLI_SERVICE_PROTOCOL_V2
// V3 add varchar type, primitive type qualifiers
HIVE_CLI_SERVICE_PROTOCOL_V3
// V4 add decimal precision/scale, char type
HIVE_CLI_SERVICE_PROTOCOL_V4
// V5 adds error details when GetOperationStatus returns in error state
HIVE_CLI_SERVICE_PROTOCOL_V5
// V6 uses binary type for binary payload (was string) and uses columnar result set
HIVE_CLI_SERVICE_PROTOCOL_V6
// V7 adds support for delegation token based connection
HIVE_CLI_SERVICE_PROTOCOL_V7
// V8 adds support for interval types
HIVE_CLI_SERVICE_PROTOCOL_V8
// V9 adds support for serializing ResultSets in SerDe
HIVE_CLI_SERVICE_PROTOCOL_V9
// V10 adds support for in place updates via GetOperationStatus
HIVE_CLI_SERVICE_PROTOCOL_V10
// V11 adds timestamp with local time zone type
HIVE_CLI_SERVICE_PROTOCOL_V11
}
```
// V2 supports to configureSession and allow to serialize the RowData with PLAIN_TEXT or JSON.
##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/header/session/ConfigureSessionHeaders.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.table.gateway.rest.header.session;
+
+import org.apache.flink.runtime.rest.HttpMethodWrapper;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.runtime.rest.versioning.RestAPIVersion;
+import org.apache.flink.table.gateway.rest.header.SqlGatewayMessageHeaders;
+import org.apache.flink.table.gateway.rest.message.session.ConfigureSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionHandleIdPathParameter;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+import org.apache.flink.table.gateway.rest.util.SqlGatewayRestAPIVersion;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/** Message headers for configuring a session. */
+public class ConfigureSessionHeaders
+ implements SqlGatewayMessageHeaders<
+ ConfigureSessionRequestBody, EmptyResponseBody, SessionMessageParameters> {
+
+ private static final ConfigureSessionHeaders INSTANCE = new ConfigureSessionHeaders();
+
+ private static final String URL =
+ "/sessions/:" + SessionHandleIdPathParameter.KEY + "/configure_session";
Review Comment:
I think "/configure_session" is not very suitable. Because Flink currently uses '-' to concat the words in the URL, e.g.
```
/taskmanagers/:taskmanagerid/thread-dump
```
Many documents also recommend us to use - rather than _ in the url.
[1] https://stackoverflow.com/questions/5362954/why-use-instead-off-in-url
[2] https://studiohawk.com.au/blog/dash-or-underscore-in-url-heres-how-its-affecting-your-seo/
##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/handler/session/ConfigureSessionHandler.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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.table.gateway.rest.handler.session;
+
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.handler.RestHandlerException;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.runtime.rest.messages.MessageHeaders;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.gateway.rest.handler.AbstractSqlGatewayRestHandler;
+import org.apache.flink.table.gateway.rest.message.session.ConfigureSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionHandleIdPathParameter;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+import org.apache.flink.table.gateway.rest.util.SqlGatewayRestAPIVersion;
+
+import javax.annotation.Nonnull;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+/** Handler to execute a statement. */
Review Comment:
Handler to configure a session with statement?
##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/util/SqlGatewayRestAPIVersion.java:
##########
@@ -35,7 +35,8 @@
// The bigger the ordinal(its position in enum declaration), the higher the level of the
// version.
V0(false, false),
- V1(true, true);
+ V1(true, true),
Review Comment:
I think V2 is the default version now.
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SessionRelatedITCase.java:
##########
@@ -85,11 +115,11 @@ void testCreateAndCloseSessions() throws Exception {
CompletableFuture<OpenSessionResponseBody> response =
sendRequest(openSessionHeaders, emptyParameters, openSessionRequestBody);
String sessionHandleId = response.get().getSessionHandle();
- assertThat(sessionHandleId).isNotNull();
+ assertNotNull(sessionHandleId);
Review Comment:
Why modify this? I think `org.assertj.core.api.Assertions.assertThat` is suggested test API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057486097
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -58,154 +58,139 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getBaseConfig;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getFlinkConfig;
+import static org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient.getTestRestClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** IT cases for {@link SqlGatewayRestEndpoint}. */
class SqlGatewayRestEndpointITCase {
- private static final SqlGatewayService service = null;
-
- private static RestServerEndpoint serverEndpoint;
- private static RestClient restClient;
+ private static SqlGatewayRestEndpoint serverEndpoint;
+ private static TestRestClient restClient;
private static InetSocketAddress serverAddress;
- private static TestBadCaseHandler testHandler;
- private static TestVersionSelectionHeaders1 header1;
- private static TestVersionSelectionHeaders2 header2;
private static TestBadCaseHeaders badCaseHeader;
- private static TestVersionHandler testVersionHandler1;
- private static TestVersionHandler testVersionHandler2;
+ private static TestBadCaseHandler testHandler;
+
+ private static TestVersionSelectionHeaders0 header0;
+ private static TestVersionSelectionHeaders12 header12;
+
+ private static TestVersionHandler testVersionHandler0;
+ private static TestVersionHandler testVersionHandler12;
private static Configuration config;
private static final Time timeout = Time.seconds(10L);
@BeforeEach
void setup() throws Exception {
// Test version cases
- header1 = new TestVersionSelectionHeaders1();
- header2 = new TestVersionSelectionHeaders2();
- testVersionHandler1 = new TestVersionHandler(service, header1);
- testVersionHandler2 = new TestVersionHandler(service, header2);
+ header0 = new TestVersionSelectionHeaders0();
+ header12 = new TestVersionSelectionHeaders12();
+ testVersionHandler0 = new TestVersionHandler(header0);
+ testVersionHandler12 = new TestVersionHandler(header12);
// Test exception cases
badCaseHeader = new TestBadCaseHeaders();
- testHandler = new TestBadCaseHandler(service);
+ testHandler = new TestBadCaseHandler();
// Init
final String address = InetAddress.getLoopbackAddress().getHostAddress();
config = getBaseConfig(getFlinkConfig(address, address, "0"));
serverEndpoint =
- TestingSqlGatewayRestEndpoint.builder(config, service)
+ TestSqlGatewayRestEndpoint.builder(config)
.withHandler(badCaseHeader, testHandler)
- .withHandler(header1, testVersionHandler1)
- .withHandler(header2, testVersionHandler2)
+ .withHandler(header0, testVersionHandler0)
+ .withHandler(header12, testVersionHandler12)
.buildAndStart();
- restClient =
- new RestClient(
- config,
- Executors.newFixedThreadPool(
- 1, new ExecutorThreadFactory("rest-client-thread-pool")));
+ restClient = getTestRestClient();
serverAddress = serverEndpoint.getServerAddress();
}
@AfterEach
void stop() throws Exception {
-
if (restClient != null) {
- restClient.shutdown(timeout);
+ restClient.shutdown();
restClient = null;
}
if (serverEndpoint != null) {
- serverEndpoint.closeAsync().get(timeout.getSize(), timeout.getUnit());
+ serverEndpoint.stop();
serverEndpoint = null;
}
}
/** Test that {@link SqlGatewayMessageHeaders} can identify the version correctly. */
@Test
void testSqlGatewayMessageHeaders() throws Exception {
- // The header only support V1, but send request by V0
+ // The header can't support V0, but sends request by V0
assertThatThrownBy(
() ->
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
SqlGatewayRestAPIVersion.V0))
- .isInstanceOf(IllegalArgumentException.class);
-
- // The header only support V1, send request by V1
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ IllegalArgumentException.class,
+ String.format(
+ "The requested version V0 is not supported by the request (method=%s URL=%s). Supported versions are: %s.",
+ header12.getHttpMethod(),
+ header12.getTargetRestEndpointURL(),
+ header12.getSupportedAPIVersions().stream()
+ .map(RestAPIVersion::getURLVersionPrefix)
+ .collect(Collectors.joining(",")))));
+
+ // The header only supports V0, sends request by V0
CompletableFuture<TestResponse> specifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header0,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
+ SqlGatewayRestAPIVersion.V0);
- TestResponse testResponse1 = specifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse1.getStatus()).isEqualTo("V1");
+ TestResponse testResponse1 =
+ specifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse1.getStatus()).isEqualTo("V0");
- // The header only support V1, send request by latest version V1
+ // The header supports V1 and V2, lets the client get the latest version as default
CompletableFuture<TestResponse> unspecifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList());
- TestResponse testResponse2 = unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ TestResponse testResponse2 =
+ unspecifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse2.getStatus()).isEqualTo("V2");
Review Comment:
> This part is same to `testDefaultVersionRouting`? If so, I think we can remove here.
No, it is to test getting the latest version of all the supported versions. In `RestClient` line 315.
Default version routing is needed when the message doesn't provide version. The message header here will provide the version.
> nit: BTW, it's better to introduce a case that API is only available in the high version, which is the actual case. With the default version routing, the request works.
Not needed because the RestClient can get the supported version, so we can use the V0 case instead of introducing a new header.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot commented on pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #21525:
URL: https://github.com/apache/flink/pull/21525#issuecomment-1356834105
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "1c3a82cf18e77cf18e4c10d5046d29e375591112",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "1c3a82cf18e77cf18e4c10d5046d29e375591112",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 1c3a82cf18e77cf18e4c10d5046d29e375591112 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] fsk119 merged pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
fsk119 merged PR #21525:
URL: https://github.com/apache/flink/pull/21525
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] fsk119 commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
fsk119 commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057036923
##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/util/SqlGatewayRestAPIVersion.java:
##########
@@ -34,8 +39,14 @@
implements RestAPIVersion<SqlGatewayRestAPIVersion>, EndpointVersion {
// The bigger the ordinal(its position in enum declaration), the higher the level of the
// version.
+
+ // V0 is just for test
V0(false, false),
+
Review Comment:
// V1 introduces basic API for rest endpoint
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -58,154 +58,139 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getBaseConfig;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getFlinkConfig;
+import static org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient.getTestRestClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** IT cases for {@link SqlGatewayRestEndpoint}. */
class SqlGatewayRestEndpointITCase {
- private static final SqlGatewayService service = null;
-
- private static RestServerEndpoint serverEndpoint;
- private static RestClient restClient;
+ private static SqlGatewayRestEndpoint serverEndpoint;
+ private static TestRestClient restClient;
private static InetSocketAddress serverAddress;
- private static TestBadCaseHandler testHandler;
- private static TestVersionSelectionHeaders1 header1;
- private static TestVersionSelectionHeaders2 header2;
private static TestBadCaseHeaders badCaseHeader;
- private static TestVersionHandler testVersionHandler1;
- private static TestVersionHandler testVersionHandler2;
+ private static TestBadCaseHandler testHandler;
+
+ private static TestVersionSelectionHeaders0 header0;
+ private static TestVersionSelectionHeaders12 header12;
+
+ private static TestVersionHandler testVersionHandler0;
+ private static TestVersionHandler testVersionHandler12;
private static Configuration config;
private static final Time timeout = Time.seconds(10L);
@BeforeEach
void setup() throws Exception {
// Test version cases
- header1 = new TestVersionSelectionHeaders1();
- header2 = new TestVersionSelectionHeaders2();
- testVersionHandler1 = new TestVersionHandler(service, header1);
- testVersionHandler2 = new TestVersionHandler(service, header2);
+ header0 = new TestVersionSelectionHeaders0();
+ header12 = new TestVersionSelectionHeaders12();
+ testVersionHandler0 = new TestVersionHandler(header0);
+ testVersionHandler12 = new TestVersionHandler(header12);
// Test exception cases
badCaseHeader = new TestBadCaseHeaders();
- testHandler = new TestBadCaseHandler(service);
+ testHandler = new TestBadCaseHandler();
// Init
final String address = InetAddress.getLoopbackAddress().getHostAddress();
config = getBaseConfig(getFlinkConfig(address, address, "0"));
serverEndpoint =
- TestingSqlGatewayRestEndpoint.builder(config, service)
+ TestSqlGatewayRestEndpoint.builder(config)
.withHandler(badCaseHeader, testHandler)
- .withHandler(header1, testVersionHandler1)
- .withHandler(header2, testVersionHandler2)
+ .withHandler(header0, testVersionHandler0)
+ .withHandler(header12, testVersionHandler12)
.buildAndStart();
- restClient =
- new RestClient(
- config,
- Executors.newFixedThreadPool(
- 1, new ExecutorThreadFactory("rest-client-thread-pool")));
+ restClient = getTestRestClient();
serverAddress = serverEndpoint.getServerAddress();
}
@AfterEach
void stop() throws Exception {
-
if (restClient != null) {
- restClient.shutdown(timeout);
+ restClient.shutdown();
restClient = null;
}
if (serverEndpoint != null) {
- serverEndpoint.closeAsync().get(timeout.getSize(), timeout.getUnit());
+ serverEndpoint.stop();
serverEndpoint = null;
}
}
/** Test that {@link SqlGatewayMessageHeaders} can identify the version correctly. */
@Test
void testSqlGatewayMessageHeaders() throws Exception {
- // The header only support V1, but send request by V0
+ // The header can't support V0, but sends request by V0
assertThatThrownBy(
() ->
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
SqlGatewayRestAPIVersion.V0))
- .isInstanceOf(IllegalArgumentException.class);
-
- // The header only support V1, send request by V1
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ IllegalArgumentException.class,
+ String.format(
+ "The requested version V0 is not supported by the request (method=%s URL=%s). Supported versions are: %s.",
+ header12.getHttpMethod(),
+ header12.getTargetRestEndpointURL(),
+ header12.getSupportedAPIVersions().stream()
+ .map(RestAPIVersion::getURLVersionPrefix)
+ .collect(Collectors.joining(",")))));
+
+ // The header only supports V0, sends request by V0
CompletableFuture<TestResponse> specifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header0,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
+ SqlGatewayRestAPIVersion.V0);
- TestResponse testResponse1 = specifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse1.getStatus()).isEqualTo("V1");
+ TestResponse testResponse1 =
+ specifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse1.getStatus()).isEqualTo("V0");
- // The header only support V1, send request by latest version V1
+ // The header supports V1 and V2, lets the client get the latest version as default
CompletableFuture<TestResponse> unspecifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList());
- TestResponse testResponse2 = unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ TestResponse testResponse2 =
+ unspecifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse2.getStatus()).isEqualTo("V2");
Review Comment:
This part is same to `testDefaultVersionRouting`? If so, I think we can remove here.
nit: BTW, it's better to introduce a case that API is only available in the high version, which is the actual case. With the default version routing, the request works.
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/RestAPIITCaseBase.java:
##########
@@ -20,15 +20,13 @@
import org.apache.flink.api.common.time.Time;
import org.apache.flink.configuration.Configuration;
-import org.apache.flink.runtime.rest.RestClient;
import org.apache.flink.runtime.rest.messages.MessageHeaders;
import org.apache.flink.runtime.rest.messages.MessageParameters;
import org.apache.flink.runtime.rest.messages.RequestBody;
import org.apache.flink.runtime.rest.messages.ResponseBody;
+import org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient;
import org.apache.flink.table.gateway.service.utils.SqlGatewayServiceExtension;
import org.apache.flink.test.junit5.MiniClusterExtension;
-import org.apache.flink.util.ExecutorUtils;
-import org.apache.flink.util.concurrent.ExecutorThreadFactory;
import org.jetbrains.annotations.Nullable;
Review Comment:
Align code style with others. Use `import javax.annotation.Nullable;` instead. Please also help to fix the same problems in the `SqlGatewayRestEndpointITCase`.
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -58,154 +58,139 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getBaseConfig;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getFlinkConfig;
+import static org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient.getTestRestClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** IT cases for {@link SqlGatewayRestEndpoint}. */
class SqlGatewayRestEndpointITCase {
- private static final SqlGatewayService service = null;
-
- private static RestServerEndpoint serverEndpoint;
- private static RestClient restClient;
+ private static SqlGatewayRestEndpoint serverEndpoint;
+ private static TestRestClient restClient;
private static InetSocketAddress serverAddress;
- private static TestBadCaseHandler testHandler;
- private static TestVersionSelectionHeaders1 header1;
- private static TestVersionSelectionHeaders2 header2;
private static TestBadCaseHeaders badCaseHeader;
- private static TestVersionHandler testVersionHandler1;
- private static TestVersionHandler testVersionHandler2;
+ private static TestBadCaseHandler testHandler;
+
+ private static TestVersionSelectionHeaders0 header0;
+ private static TestVersionSelectionHeaders12 header12;
+
+ private static TestVersionHandler testVersionHandler0;
+ private static TestVersionHandler testVersionHandler12;
private static Configuration config;
private static final Time timeout = Time.seconds(10L);
@BeforeEach
void setup() throws Exception {
// Test version cases
- header1 = new TestVersionSelectionHeaders1();
- header2 = new TestVersionSelectionHeaders2();
- testVersionHandler1 = new TestVersionHandler(service, header1);
- testVersionHandler2 = new TestVersionHandler(service, header2);
+ header0 = new TestVersionSelectionHeaders0();
+ header12 = new TestVersionSelectionHeaders12();
+ testVersionHandler0 = new TestVersionHandler(header0);
+ testVersionHandler12 = new TestVersionHandler(header12);
// Test exception cases
badCaseHeader = new TestBadCaseHeaders();
- testHandler = new TestBadCaseHandler(service);
+ testHandler = new TestBadCaseHandler();
// Init
final String address = InetAddress.getLoopbackAddress().getHostAddress();
config = getBaseConfig(getFlinkConfig(address, address, "0"));
serverEndpoint =
- TestingSqlGatewayRestEndpoint.builder(config, service)
+ TestSqlGatewayRestEndpoint.builder(config)
.withHandler(badCaseHeader, testHandler)
- .withHandler(header1, testVersionHandler1)
- .withHandler(header2, testVersionHandler2)
+ .withHandler(header0, testVersionHandler0)
+ .withHandler(header12, testVersionHandler12)
.buildAndStart();
- restClient =
- new RestClient(
- config,
- Executors.newFixedThreadPool(
- 1, new ExecutorThreadFactory("rest-client-thread-pool")));
+ restClient = getTestRestClient();
serverAddress = serverEndpoint.getServerAddress();
}
@AfterEach
void stop() throws Exception {
-
if (restClient != null) {
- restClient.shutdown(timeout);
+ restClient.shutdown();
restClient = null;
}
if (serverEndpoint != null) {
- serverEndpoint.closeAsync().get(timeout.getSize(), timeout.getUnit());
+ serverEndpoint.stop();
serverEndpoint = null;
}
}
/** Test that {@link SqlGatewayMessageHeaders} can identify the version correctly. */
@Test
void testSqlGatewayMessageHeaders() throws Exception {
- // The header only support V1, but send request by V0
+ // The header can't support V0, but sends request by V0
assertThatThrownBy(
() ->
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
SqlGatewayRestAPIVersion.V0))
- .isInstanceOf(IllegalArgumentException.class);
-
- // The header only support V1, send request by V1
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ IllegalArgumentException.class,
+ String.format(
+ "The requested version V0 is not supported by the request (method=%s URL=%s). Supported versions are: %s.",
+ header12.getHttpMethod(),
+ header12.getTargetRestEndpointURL(),
+ header12.getSupportedAPIVersions().stream()
+ .map(RestAPIVersion::getURLVersionPrefix)
+ .collect(Collectors.joining(",")))));
+
+ // The header only supports V0, sends request by V0
CompletableFuture<TestResponse> specifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header0,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
+ SqlGatewayRestAPIVersion.V0);
- TestResponse testResponse1 = specifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse1.getStatus()).isEqualTo("V1");
+ TestResponse testResponse1 =
+ specifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse1.getStatus()).isEqualTo("V0");
- // The header only support V1, send request by latest version V1
+ // The header supports V1 and V2, lets the client get the latest version as default
CompletableFuture<TestResponse> unspecifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList());
- TestResponse testResponse2 = unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ TestResponse testResponse2 =
+ unspecifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse2.getStatus()).isEqualTo("V2");
}
/** Test that requests of different version are routed to correct handlers. */
@Test
void testVersionSelection() throws Exception {
- CompletableFuture<TestResponse> version1Response =
- restClient.sendRequest(
- serverAddress.getHostName(),
- serverAddress.getPort(),
- header1,
- EmptyMessageParameters.getInstance(),
- EmptyRequestBody.getInstance(),
- Collections.emptyList(),
- SqlGatewayRestAPIVersion.V0);
-
- TestResponse testResponse = version1Response.get(5, TimeUnit.SECONDS);
- assertThat(testResponse.getStatus()).isEqualTo("V0");
-
- CompletableFuture<TestResponse> version2Response =
- restClient.sendRequest(
- serverAddress.getHostName(),
- serverAddress.getPort(),
- header2,
- EmptyMessageParameters.getInstance(),
- EmptyRequestBody.getInstance(),
- Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
- TestResponse testResponse2 = version2Response.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ validateVersionSelection(header0, SqlGatewayRestAPIVersion.V0);
+ validateVersionSelection(header12, SqlGatewayRestAPIVersion.V1);
+ validateVersionSelection(header12, SqlGatewayRestAPIVersion.V2);
Review Comment:
Use for-loop? In the future, we add a new version, we don't need to write another `validateVersionSelection`
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -563,4 +502,51 @@ protected CompletableFuture<TestResponse> handleRequest(
return CompletableFuture.completedFuture(new TestResponse(version.name()));
}
}
+
+ private static class TestBadCaseHandler
+ extends AbstractSqlGatewayRestHandler<
+ TestRequest, TestResponse, EmptyMessageParameters> {
+
+ private final OneShotLatch closeLatch = new OneShotLatch();
+
+ private CompletableFuture<Void> closeFuture = CompletableFuture.completedFuture(null);
+
+ private Function<Integer, CompletableFuture<TestResponse>> handlerBody;
+
+ TestBadCaseHandler() {
+ super(null, Collections.emptyMap(), badCaseHeader);
+ }
Review Comment:
I prefer to use the origin constructor.
```
TestBadCaseHandler(SqlGatewayService sqlGatewayService) { Collections.emptyList(),
super(sqlGatewayService, Collections.emptyMap(), badCaseHeader); version);
}
```
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/util/SqlGatewayRestClientAndEndpointUtils.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.table.gateway.rest.util;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.rest.RestClient;
+import org.apache.flink.runtime.rest.handler.RestHandlerSpecification;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+import org.apache.flink.table.gateway.rest.SqlGatewayRestEndpoint;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.ExecutorUtils;
+import org.apache.flink.util.concurrent.ExecutorThreadFactory;
+
+import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/** The test REST client and endpoint utils for sql gateway rest api testing. */
+public class SqlGatewayRestClientAndEndpointUtils {
+
+ // --------------------------------------------------------------------------------------------
+ // Rest Endpoint
+ // --------------------------------------------------------------------------------------------
+
+ /**
+ * Utility for setting up a rest server based on {@link SqlGatewayRestEndpoint} with a given set
+ * of handlers.
+ */
+ public static class TestSqlGatewayRestEndpoint extends SqlGatewayRestEndpoint {
Review Comment:
Why merge the TestSqlGatewayRestEndpoint and TestClient into a util class? It's fine to introduce a two separated class. BTW, the class name `SqlGatewayRestClientAndEndpointUtils` is a little strange for others....
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -532,27 +468,30 @@ public EmptyMessageParameters getUnresolvedMessageParameters() {
}
}
- private static class TestVersionSelectionHeaders1 extends TestVersionSelectionHeadersBase {
+ private static class TestVersionSelectionHeaders0 extends TestVersionSelectionHeadersBase {
@Override
public Collection<SqlGatewayRestAPIVersion> getSupportedAPIVersions() {
return Collections.singleton(SqlGatewayRestAPIVersion.V0);
}
}
- private static class TestVersionSelectionHeaders2 extends TestVersionSelectionHeadersBase {
+ private static class TestVersionSelectionHeaders12 extends TestVersionSelectionHeadersBase {
@Override
public Collection<SqlGatewayRestAPIVersion> getSupportedAPIVersions() {
- return Collections.singleton(SqlGatewayRestAPIVersion.V1);
+ return Arrays.asList(SqlGatewayRestAPIVersion.V1, SqlGatewayRestAPIVersion.V2);
Review Comment:
```
List<SqlGatewayRestAPIVersion> versions =
Arrays.asList(SqlGatewayRestAPIVersion.values());
versions.remove(SqlGatewayRestAPIVersion.V0);
return versions;
```
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -532,27 +468,30 @@ public EmptyMessageParameters getUnresolvedMessageParameters() {
}
}
- private static class TestVersionSelectionHeaders1 extends TestVersionSelectionHeadersBase {
+ private static class TestVersionSelectionHeaders0 extends TestVersionSelectionHeadersBase {
@Override
public Collection<SqlGatewayRestAPIVersion> getSupportedAPIVersions() {
return Collections.singleton(SqlGatewayRestAPIVersion.V0);
}
}
- private static class TestVersionSelectionHeaders2 extends TestVersionSelectionHeadersBase {
+ private static class TestVersionSelectionHeaders12 extends TestVersionSelectionHeadersBase {
Review Comment:
How about renaming to TestVersionSelectionHeadersNot0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on PR #21525:
URL: https://github.com/apache/flink/pull/21525#issuecomment-1366075740
@flinkbot run azure
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057502548
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -58,154 +58,139 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getBaseConfig;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getFlinkConfig;
+import static org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient.getTestRestClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** IT cases for {@link SqlGatewayRestEndpoint}. */
class SqlGatewayRestEndpointITCase {
- private static final SqlGatewayService service = null;
-
- private static RestServerEndpoint serverEndpoint;
- private static RestClient restClient;
+ private static SqlGatewayRestEndpoint serverEndpoint;
+ private static TestRestClient restClient;
private static InetSocketAddress serverAddress;
- private static TestBadCaseHandler testHandler;
- private static TestVersionSelectionHeaders1 header1;
- private static TestVersionSelectionHeaders2 header2;
private static TestBadCaseHeaders badCaseHeader;
- private static TestVersionHandler testVersionHandler1;
- private static TestVersionHandler testVersionHandler2;
+ private static TestBadCaseHandler testHandler;
+
+ private static TestVersionSelectionHeaders0 header0;
+ private static TestVersionSelectionHeaders12 header12;
+
+ private static TestVersionHandler testVersionHandler0;
+ private static TestVersionHandler testVersionHandler12;
private static Configuration config;
private static final Time timeout = Time.seconds(10L);
@BeforeEach
void setup() throws Exception {
// Test version cases
- header1 = new TestVersionSelectionHeaders1();
- header2 = new TestVersionSelectionHeaders2();
- testVersionHandler1 = new TestVersionHandler(service, header1);
- testVersionHandler2 = new TestVersionHandler(service, header2);
+ header0 = new TestVersionSelectionHeaders0();
+ header12 = new TestVersionSelectionHeaders12();
+ testVersionHandler0 = new TestVersionHandler(header0);
+ testVersionHandler12 = new TestVersionHandler(header12);
// Test exception cases
badCaseHeader = new TestBadCaseHeaders();
- testHandler = new TestBadCaseHandler(service);
+ testHandler = new TestBadCaseHandler();
// Init
final String address = InetAddress.getLoopbackAddress().getHostAddress();
config = getBaseConfig(getFlinkConfig(address, address, "0"));
serverEndpoint =
- TestingSqlGatewayRestEndpoint.builder(config, service)
+ TestSqlGatewayRestEndpoint.builder(config)
.withHandler(badCaseHeader, testHandler)
- .withHandler(header1, testVersionHandler1)
- .withHandler(header2, testVersionHandler2)
+ .withHandler(header0, testVersionHandler0)
+ .withHandler(header12, testVersionHandler12)
.buildAndStart();
- restClient =
- new RestClient(
- config,
- Executors.newFixedThreadPool(
- 1, new ExecutorThreadFactory("rest-client-thread-pool")));
+ restClient = getTestRestClient();
serverAddress = serverEndpoint.getServerAddress();
}
@AfterEach
void stop() throws Exception {
-
if (restClient != null) {
- restClient.shutdown(timeout);
+ restClient.shutdown();
restClient = null;
}
if (serverEndpoint != null) {
- serverEndpoint.closeAsync().get(timeout.getSize(), timeout.getUnit());
+ serverEndpoint.stop();
serverEndpoint = null;
}
}
/** Test that {@link SqlGatewayMessageHeaders} can identify the version correctly. */
@Test
void testSqlGatewayMessageHeaders() throws Exception {
- // The header only support V1, but send request by V0
+ // The header can't support V0, but sends request by V0
assertThatThrownBy(
() ->
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
SqlGatewayRestAPIVersion.V0))
- .isInstanceOf(IllegalArgumentException.class);
-
- // The header only support V1, send request by V1
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ IllegalArgumentException.class,
+ String.format(
+ "The requested version V0 is not supported by the request (method=%s URL=%s). Supported versions are: %s.",
+ header12.getHttpMethod(),
+ header12.getTargetRestEndpointURL(),
+ header12.getSupportedAPIVersions().stream()
+ .map(RestAPIVersion::getURLVersionPrefix)
+ .collect(Collectors.joining(",")))));
+
+ // The header only supports V0, sends request by V0
CompletableFuture<TestResponse> specifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header0,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
+ SqlGatewayRestAPIVersion.V0);
- TestResponse testResponse1 = specifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse1.getStatus()).isEqualTo("V1");
+ TestResponse testResponse1 =
+ specifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse1.getStatus()).isEqualTo("V0");
- // The header only support V1, send request by latest version V1
+ // The header supports V1 and V2, lets the client get the latest version as default
CompletableFuture<TestResponse> unspecifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList());
- TestResponse testResponse2 = unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ TestResponse testResponse2 =
+ unspecifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse2.getStatus()).isEqualTo("V2");
}
/** Test that requests of different version are routed to correct handlers. */
@Test
void testVersionSelection() throws Exception {
- CompletableFuture<TestResponse> version1Response =
- restClient.sendRequest(
- serverAddress.getHostName(),
- serverAddress.getPort(),
- header1,
- EmptyMessageParameters.getInstance(),
- EmptyRequestBody.getInstance(),
- Collections.emptyList(),
- SqlGatewayRestAPIVersion.V0);
-
- TestResponse testResponse = version1Response.get(5, TimeUnit.SECONDS);
- assertThat(testResponse.getStatus()).isEqualTo("V0");
-
- CompletableFuture<TestResponse> version2Response =
- restClient.sendRequest(
- serverAddress.getHostName(),
- serverAddress.getPort(),
- header2,
- EmptyMessageParameters.getInstance(),
- EmptyRequestBody.getInstance(),
- Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
- TestResponse testResponse2 = version2Response.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ validateVersionSelection(header0, SqlGatewayRestAPIVersion.V0);
+ validateVersionSelection(header12, SqlGatewayRestAPIVersion.V1);
+ validateVersionSelection(header12, SqlGatewayRestAPIVersion.V2);
Review Comment:
Now I think this test is very similar to the test 'testSqlGatewayMessageHeaders', because both test the message is routed correctly. So I think we can delete this test, and add a test case (specify version as V1 to send headerNot0) in `testSqlGatewayMessageHeaders`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057499949
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -532,27 +468,30 @@ public EmptyMessageParameters getUnresolvedMessageParameters() {
}
}
- private static class TestVersionSelectionHeaders1 extends TestVersionSelectionHeadersBase {
+ private static class TestVersionSelectionHeaders0 extends TestVersionSelectionHeadersBase {
@Override
public Collection<SqlGatewayRestAPIVersion> getSupportedAPIVersions() {
return Collections.singleton(SqlGatewayRestAPIVersion.V0);
}
}
- private static class TestVersionSelectionHeaders2 extends TestVersionSelectionHeadersBase {
+ private static class TestVersionSelectionHeaders12 extends TestVersionSelectionHeadersBase {
@Override
public Collection<SqlGatewayRestAPIVersion> getSupportedAPIVersions() {
- return Collections.singleton(SqlGatewayRestAPIVersion.V1);
+ return Arrays.asList(SqlGatewayRestAPIVersion.V1, SqlGatewayRestAPIVersion.V2);
Review Comment:
Can't remove or add value to the list returned by `Arrays.asList.` I used `new ArrayList(Arrays.asList(xx))`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057476274
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/util/SqlGatewayRestClientAndEndpointUtils.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.table.gateway.rest.util;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.rest.RestClient;
+import org.apache.flink.runtime.rest.handler.RestHandlerSpecification;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+import org.apache.flink.table.gateway.rest.SqlGatewayRestEndpoint;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.ExecutorUtils;
+import org.apache.flink.util.concurrent.ExecutorThreadFactory;
+
+import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/** The test REST client and endpoint utils for sql gateway rest api testing. */
+public class SqlGatewayRestClientAndEndpointUtils {
+
+ // --------------------------------------------------------------------------------------------
+ // Rest Endpoint
+ // --------------------------------------------------------------------------------------------
+
+ /**
+ * Utility for setting up a rest server based on {@link SqlGatewayRestEndpoint} with a given set
+ * of handlers.
+ */
+ public static class TestSqlGatewayRestEndpoint extends SqlGatewayRestEndpoint {
Review Comment:
Split.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057502548
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -58,154 +58,139 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getBaseConfig;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getFlinkConfig;
+import static org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient.getTestRestClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** IT cases for {@link SqlGatewayRestEndpoint}. */
class SqlGatewayRestEndpointITCase {
- private static final SqlGatewayService service = null;
-
- private static RestServerEndpoint serverEndpoint;
- private static RestClient restClient;
+ private static SqlGatewayRestEndpoint serverEndpoint;
+ private static TestRestClient restClient;
private static InetSocketAddress serverAddress;
- private static TestBadCaseHandler testHandler;
- private static TestVersionSelectionHeaders1 header1;
- private static TestVersionSelectionHeaders2 header2;
private static TestBadCaseHeaders badCaseHeader;
- private static TestVersionHandler testVersionHandler1;
- private static TestVersionHandler testVersionHandler2;
+ private static TestBadCaseHandler testHandler;
+
+ private static TestVersionSelectionHeaders0 header0;
+ private static TestVersionSelectionHeaders12 header12;
+
+ private static TestVersionHandler testVersionHandler0;
+ private static TestVersionHandler testVersionHandler12;
private static Configuration config;
private static final Time timeout = Time.seconds(10L);
@BeforeEach
void setup() throws Exception {
// Test version cases
- header1 = new TestVersionSelectionHeaders1();
- header2 = new TestVersionSelectionHeaders2();
- testVersionHandler1 = new TestVersionHandler(service, header1);
- testVersionHandler2 = new TestVersionHandler(service, header2);
+ header0 = new TestVersionSelectionHeaders0();
+ header12 = new TestVersionSelectionHeaders12();
+ testVersionHandler0 = new TestVersionHandler(header0);
+ testVersionHandler12 = new TestVersionHandler(header12);
// Test exception cases
badCaseHeader = new TestBadCaseHeaders();
- testHandler = new TestBadCaseHandler(service);
+ testHandler = new TestBadCaseHandler();
// Init
final String address = InetAddress.getLoopbackAddress().getHostAddress();
config = getBaseConfig(getFlinkConfig(address, address, "0"));
serverEndpoint =
- TestingSqlGatewayRestEndpoint.builder(config, service)
+ TestSqlGatewayRestEndpoint.builder(config)
.withHandler(badCaseHeader, testHandler)
- .withHandler(header1, testVersionHandler1)
- .withHandler(header2, testVersionHandler2)
+ .withHandler(header0, testVersionHandler0)
+ .withHandler(header12, testVersionHandler12)
.buildAndStart();
- restClient =
- new RestClient(
- config,
- Executors.newFixedThreadPool(
- 1, new ExecutorThreadFactory("rest-client-thread-pool")));
+ restClient = getTestRestClient();
serverAddress = serverEndpoint.getServerAddress();
}
@AfterEach
void stop() throws Exception {
-
if (restClient != null) {
- restClient.shutdown(timeout);
+ restClient.shutdown();
restClient = null;
}
if (serverEndpoint != null) {
- serverEndpoint.closeAsync().get(timeout.getSize(), timeout.getUnit());
+ serverEndpoint.stop();
serverEndpoint = null;
}
}
/** Test that {@link SqlGatewayMessageHeaders} can identify the version correctly. */
@Test
void testSqlGatewayMessageHeaders() throws Exception {
- // The header only support V1, but send request by V0
+ // The header can't support V0, but sends request by V0
assertThatThrownBy(
() ->
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
SqlGatewayRestAPIVersion.V0))
- .isInstanceOf(IllegalArgumentException.class);
-
- // The header only support V1, send request by V1
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ IllegalArgumentException.class,
+ String.format(
+ "The requested version V0 is not supported by the request (method=%s URL=%s). Supported versions are: %s.",
+ header12.getHttpMethod(),
+ header12.getTargetRestEndpointURL(),
+ header12.getSupportedAPIVersions().stream()
+ .map(RestAPIVersion::getURLVersionPrefix)
+ .collect(Collectors.joining(",")))));
+
+ // The header only supports V0, sends request by V0
CompletableFuture<TestResponse> specifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header0,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
+ SqlGatewayRestAPIVersion.V0);
- TestResponse testResponse1 = specifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse1.getStatus()).isEqualTo("V1");
+ TestResponse testResponse1 =
+ specifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse1.getStatus()).isEqualTo("V0");
- // The header only support V1, send request by latest version V1
+ // The header supports V1 and V2, lets the client get the latest version as default
CompletableFuture<TestResponse> unspecifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList());
- TestResponse testResponse2 = unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ TestResponse testResponse2 =
+ unspecifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse2.getStatus()).isEqualTo("V2");
}
/** Test that requests of different version are routed to correct handlers. */
@Test
void testVersionSelection() throws Exception {
- CompletableFuture<TestResponse> version1Response =
- restClient.sendRequest(
- serverAddress.getHostName(),
- serverAddress.getPort(),
- header1,
- EmptyMessageParameters.getInstance(),
- EmptyRequestBody.getInstance(),
- Collections.emptyList(),
- SqlGatewayRestAPIVersion.V0);
-
- TestResponse testResponse = version1Response.get(5, TimeUnit.SECONDS);
- assertThat(testResponse.getStatus()).isEqualTo("V0");
-
- CompletableFuture<TestResponse> version2Response =
- restClient.sendRequest(
- serverAddress.getHostName(),
- serverAddress.getPort(),
- header2,
- EmptyMessageParameters.getInstance(),
- EmptyRequestBody.getInstance(),
- Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
- TestResponse testResponse2 = version2Response.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ validateVersionSelection(header0, SqlGatewayRestAPIVersion.V0);
+ validateVersionSelection(header12, SqlGatewayRestAPIVersion.V1);
+ validateVersionSelection(header12, SqlGatewayRestAPIVersion.V2);
Review Comment:
Good Idea. And I think test for header0 is not necessary so I remove it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057486097
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -58,154 +58,139 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getBaseConfig;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getFlinkConfig;
+import static org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient.getTestRestClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** IT cases for {@link SqlGatewayRestEndpoint}. */
class SqlGatewayRestEndpointITCase {
- private static final SqlGatewayService service = null;
-
- private static RestServerEndpoint serverEndpoint;
- private static RestClient restClient;
+ private static SqlGatewayRestEndpoint serverEndpoint;
+ private static TestRestClient restClient;
private static InetSocketAddress serverAddress;
- private static TestBadCaseHandler testHandler;
- private static TestVersionSelectionHeaders1 header1;
- private static TestVersionSelectionHeaders2 header2;
private static TestBadCaseHeaders badCaseHeader;
- private static TestVersionHandler testVersionHandler1;
- private static TestVersionHandler testVersionHandler2;
+ private static TestBadCaseHandler testHandler;
+
+ private static TestVersionSelectionHeaders0 header0;
+ private static TestVersionSelectionHeaders12 header12;
+
+ private static TestVersionHandler testVersionHandler0;
+ private static TestVersionHandler testVersionHandler12;
private static Configuration config;
private static final Time timeout = Time.seconds(10L);
@BeforeEach
void setup() throws Exception {
// Test version cases
- header1 = new TestVersionSelectionHeaders1();
- header2 = new TestVersionSelectionHeaders2();
- testVersionHandler1 = new TestVersionHandler(service, header1);
- testVersionHandler2 = new TestVersionHandler(service, header2);
+ header0 = new TestVersionSelectionHeaders0();
+ header12 = new TestVersionSelectionHeaders12();
+ testVersionHandler0 = new TestVersionHandler(header0);
+ testVersionHandler12 = new TestVersionHandler(header12);
// Test exception cases
badCaseHeader = new TestBadCaseHeaders();
- testHandler = new TestBadCaseHandler(service);
+ testHandler = new TestBadCaseHandler();
// Init
final String address = InetAddress.getLoopbackAddress().getHostAddress();
config = getBaseConfig(getFlinkConfig(address, address, "0"));
serverEndpoint =
- TestingSqlGatewayRestEndpoint.builder(config, service)
+ TestSqlGatewayRestEndpoint.builder(config)
.withHandler(badCaseHeader, testHandler)
- .withHandler(header1, testVersionHandler1)
- .withHandler(header2, testVersionHandler2)
+ .withHandler(header0, testVersionHandler0)
+ .withHandler(header12, testVersionHandler12)
.buildAndStart();
- restClient =
- new RestClient(
- config,
- Executors.newFixedThreadPool(
- 1, new ExecutorThreadFactory("rest-client-thread-pool")));
+ restClient = getTestRestClient();
serverAddress = serverEndpoint.getServerAddress();
}
@AfterEach
void stop() throws Exception {
-
if (restClient != null) {
- restClient.shutdown(timeout);
+ restClient.shutdown();
restClient = null;
}
if (serverEndpoint != null) {
- serverEndpoint.closeAsync().get(timeout.getSize(), timeout.getUnit());
+ serverEndpoint.stop();
serverEndpoint = null;
}
}
/** Test that {@link SqlGatewayMessageHeaders} can identify the version correctly. */
@Test
void testSqlGatewayMessageHeaders() throws Exception {
- // The header only support V1, but send request by V0
+ // The header can't support V0, but sends request by V0
assertThatThrownBy(
() ->
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
SqlGatewayRestAPIVersion.V0))
- .isInstanceOf(IllegalArgumentException.class);
-
- // The header only support V1, send request by V1
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ IllegalArgumentException.class,
+ String.format(
+ "The requested version V0 is not supported by the request (method=%s URL=%s). Supported versions are: %s.",
+ header12.getHttpMethod(),
+ header12.getTargetRestEndpointURL(),
+ header12.getSupportedAPIVersions().stream()
+ .map(RestAPIVersion::getURLVersionPrefix)
+ .collect(Collectors.joining(",")))));
+
+ // The header only supports V0, sends request by V0
CompletableFuture<TestResponse> specifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header0,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
+ SqlGatewayRestAPIVersion.V0);
- TestResponse testResponse1 = specifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse1.getStatus()).isEqualTo("V1");
+ TestResponse testResponse1 =
+ specifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse1.getStatus()).isEqualTo("V0");
- // The header only support V1, send request by latest version V1
+ // The header supports V1 and V2, lets the client get the latest version as default
CompletableFuture<TestResponse> unspecifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList());
- TestResponse testResponse2 = unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ TestResponse testResponse2 =
+ unspecifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse2.getStatus()).isEqualTo("V2");
Review Comment:
> This part is same to `testDefaultVersionRouting`? If so, I think we can remove here.
No, it is to test getting the latest version of all the supported versions. In `RestClient` line 315.
> nit: BTW, it's better to introduce a case that API is only available in the high version, which is the actual case. With the default version routing, the request works.
Added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057486097
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -58,154 +58,139 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getBaseConfig;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getFlinkConfig;
+import static org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient.getTestRestClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** IT cases for {@link SqlGatewayRestEndpoint}. */
class SqlGatewayRestEndpointITCase {
- private static final SqlGatewayService service = null;
-
- private static RestServerEndpoint serverEndpoint;
- private static RestClient restClient;
+ private static SqlGatewayRestEndpoint serverEndpoint;
+ private static TestRestClient restClient;
private static InetSocketAddress serverAddress;
- private static TestBadCaseHandler testHandler;
- private static TestVersionSelectionHeaders1 header1;
- private static TestVersionSelectionHeaders2 header2;
private static TestBadCaseHeaders badCaseHeader;
- private static TestVersionHandler testVersionHandler1;
- private static TestVersionHandler testVersionHandler2;
+ private static TestBadCaseHandler testHandler;
+
+ private static TestVersionSelectionHeaders0 header0;
+ private static TestVersionSelectionHeaders12 header12;
+
+ private static TestVersionHandler testVersionHandler0;
+ private static TestVersionHandler testVersionHandler12;
private static Configuration config;
private static final Time timeout = Time.seconds(10L);
@BeforeEach
void setup() throws Exception {
// Test version cases
- header1 = new TestVersionSelectionHeaders1();
- header2 = new TestVersionSelectionHeaders2();
- testVersionHandler1 = new TestVersionHandler(service, header1);
- testVersionHandler2 = new TestVersionHandler(service, header2);
+ header0 = new TestVersionSelectionHeaders0();
+ header12 = new TestVersionSelectionHeaders12();
+ testVersionHandler0 = new TestVersionHandler(header0);
+ testVersionHandler12 = new TestVersionHandler(header12);
// Test exception cases
badCaseHeader = new TestBadCaseHeaders();
- testHandler = new TestBadCaseHandler(service);
+ testHandler = new TestBadCaseHandler();
// Init
final String address = InetAddress.getLoopbackAddress().getHostAddress();
config = getBaseConfig(getFlinkConfig(address, address, "0"));
serverEndpoint =
- TestingSqlGatewayRestEndpoint.builder(config, service)
+ TestSqlGatewayRestEndpoint.builder(config)
.withHandler(badCaseHeader, testHandler)
- .withHandler(header1, testVersionHandler1)
- .withHandler(header2, testVersionHandler2)
+ .withHandler(header0, testVersionHandler0)
+ .withHandler(header12, testVersionHandler12)
.buildAndStart();
- restClient =
- new RestClient(
- config,
- Executors.newFixedThreadPool(
- 1, new ExecutorThreadFactory("rest-client-thread-pool")));
+ restClient = getTestRestClient();
serverAddress = serverEndpoint.getServerAddress();
}
@AfterEach
void stop() throws Exception {
-
if (restClient != null) {
- restClient.shutdown(timeout);
+ restClient.shutdown();
restClient = null;
}
if (serverEndpoint != null) {
- serverEndpoint.closeAsync().get(timeout.getSize(), timeout.getUnit());
+ serverEndpoint.stop();
serverEndpoint = null;
}
}
/** Test that {@link SqlGatewayMessageHeaders} can identify the version correctly. */
@Test
void testSqlGatewayMessageHeaders() throws Exception {
- // The header only support V1, but send request by V0
+ // The header can't support V0, but sends request by V0
assertThatThrownBy(
() ->
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
SqlGatewayRestAPIVersion.V0))
- .isInstanceOf(IllegalArgumentException.class);
-
- // The header only support V1, send request by V1
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ IllegalArgumentException.class,
+ String.format(
+ "The requested version V0 is not supported by the request (method=%s URL=%s). Supported versions are: %s.",
+ header12.getHttpMethod(),
+ header12.getTargetRestEndpointURL(),
+ header12.getSupportedAPIVersions().stream()
+ .map(RestAPIVersion::getURLVersionPrefix)
+ .collect(Collectors.joining(",")))));
+
+ // The header only supports V0, sends request by V0
CompletableFuture<TestResponse> specifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header0,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
+ SqlGatewayRestAPIVersion.V0);
- TestResponse testResponse1 = specifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse1.getStatus()).isEqualTo("V1");
+ TestResponse testResponse1 =
+ specifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse1.getStatus()).isEqualTo("V0");
- // The header only support V1, send request by latest version V1
+ // The header supports V1 and V2, lets the client get the latest version as default
CompletableFuture<TestResponse> unspecifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList());
- TestResponse testResponse2 = unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ TestResponse testResponse2 =
+ unspecifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse2.getStatus()).isEqualTo("V2");
Review Comment:
> This part is same to `testDefaultVersionRouting`? If so, I think we can remove here.
No, it is to test getting the latest version of all the supported versions. In `RestClient` line 315.
> nit: BTW, it's better to introduce a case that API is only available in the high version, which is the actual case. With the default version routing, the request works.
Added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] yuzelin commented on a diff in pull request #21525: [FLINK-30416][sql-gateway] Add configureSession REST API in the SQL Gateway
Posted by GitBox <gi...@apache.org>.
yuzelin commented on code in PR #21525:
URL: https://github.com/apache/flink/pull/21525#discussion_r1057502548
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpointITCase.java:
##########
@@ -58,154 +58,139 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import java.util.stream.Collectors;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getBaseConfig;
import static org.apache.flink.table.gateway.rest.util.RestConfigUtils.getFlinkConfig;
+import static org.apache.flink.table.gateway.rest.util.SqlGatewayRestClientAndEndpointUtils.TestRestClient.getTestRestClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** IT cases for {@link SqlGatewayRestEndpoint}. */
class SqlGatewayRestEndpointITCase {
- private static final SqlGatewayService service = null;
-
- private static RestServerEndpoint serverEndpoint;
- private static RestClient restClient;
+ private static SqlGatewayRestEndpoint serverEndpoint;
+ private static TestRestClient restClient;
private static InetSocketAddress serverAddress;
- private static TestBadCaseHandler testHandler;
- private static TestVersionSelectionHeaders1 header1;
- private static TestVersionSelectionHeaders2 header2;
private static TestBadCaseHeaders badCaseHeader;
- private static TestVersionHandler testVersionHandler1;
- private static TestVersionHandler testVersionHandler2;
+ private static TestBadCaseHandler testHandler;
+
+ private static TestVersionSelectionHeaders0 header0;
+ private static TestVersionSelectionHeaders12 header12;
+
+ private static TestVersionHandler testVersionHandler0;
+ private static TestVersionHandler testVersionHandler12;
private static Configuration config;
private static final Time timeout = Time.seconds(10L);
@BeforeEach
void setup() throws Exception {
// Test version cases
- header1 = new TestVersionSelectionHeaders1();
- header2 = new TestVersionSelectionHeaders2();
- testVersionHandler1 = new TestVersionHandler(service, header1);
- testVersionHandler2 = new TestVersionHandler(service, header2);
+ header0 = new TestVersionSelectionHeaders0();
+ header12 = new TestVersionSelectionHeaders12();
+ testVersionHandler0 = new TestVersionHandler(header0);
+ testVersionHandler12 = new TestVersionHandler(header12);
// Test exception cases
badCaseHeader = new TestBadCaseHeaders();
- testHandler = new TestBadCaseHandler(service);
+ testHandler = new TestBadCaseHandler();
// Init
final String address = InetAddress.getLoopbackAddress().getHostAddress();
config = getBaseConfig(getFlinkConfig(address, address, "0"));
serverEndpoint =
- TestingSqlGatewayRestEndpoint.builder(config, service)
+ TestSqlGatewayRestEndpoint.builder(config)
.withHandler(badCaseHeader, testHandler)
- .withHandler(header1, testVersionHandler1)
- .withHandler(header2, testVersionHandler2)
+ .withHandler(header0, testVersionHandler0)
+ .withHandler(header12, testVersionHandler12)
.buildAndStart();
- restClient =
- new RestClient(
- config,
- Executors.newFixedThreadPool(
- 1, new ExecutorThreadFactory("rest-client-thread-pool")));
+ restClient = getTestRestClient();
serverAddress = serverEndpoint.getServerAddress();
}
@AfterEach
void stop() throws Exception {
-
if (restClient != null) {
- restClient.shutdown(timeout);
+ restClient.shutdown();
restClient = null;
}
if (serverEndpoint != null) {
- serverEndpoint.closeAsync().get(timeout.getSize(), timeout.getUnit());
+ serverEndpoint.stop();
serverEndpoint = null;
}
}
/** Test that {@link SqlGatewayMessageHeaders} can identify the version correctly. */
@Test
void testSqlGatewayMessageHeaders() throws Exception {
- // The header only support V1, but send request by V0
+ // The header can't support V0, but sends request by V0
assertThatThrownBy(
() ->
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
SqlGatewayRestAPIVersion.V0))
- .isInstanceOf(IllegalArgumentException.class);
-
- // The header only support V1, send request by V1
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ IllegalArgumentException.class,
+ String.format(
+ "The requested version V0 is not supported by the request (method=%s URL=%s). Supported versions are: %s.",
+ header12.getHttpMethod(),
+ header12.getTargetRestEndpointURL(),
+ header12.getSupportedAPIVersions().stream()
+ .map(RestAPIVersion::getURLVersionPrefix)
+ .collect(Collectors.joining(",")))));
+
+ // The header only supports V0, sends request by V0
CompletableFuture<TestResponse> specifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header0,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
+ SqlGatewayRestAPIVersion.V0);
- TestResponse testResponse1 = specifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse1.getStatus()).isEqualTo("V1");
+ TestResponse testResponse1 =
+ specifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse1.getStatus()).isEqualTo("V0");
- // The header only support V1, send request by latest version V1
+ // The header supports V1 and V2, lets the client get the latest version as default
CompletableFuture<TestResponse> unspecifiedVersionResponse =
restClient.sendRequest(
serverAddress.getHostName(),
serverAddress.getPort(),
- header2,
+ header12,
EmptyMessageParameters.getInstance(),
EmptyRequestBody.getInstance(),
Collections.emptyList());
- TestResponse testResponse2 = unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ TestResponse testResponse2 =
+ unspecifiedVersionResponse.get(timeout.getSize(), timeout.getUnit());
+ assertThat(testResponse2.getStatus()).isEqualTo("V2");
}
/** Test that requests of different version are routed to correct handlers. */
@Test
void testVersionSelection() throws Exception {
- CompletableFuture<TestResponse> version1Response =
- restClient.sendRequest(
- serverAddress.getHostName(),
- serverAddress.getPort(),
- header1,
- EmptyMessageParameters.getInstance(),
- EmptyRequestBody.getInstance(),
- Collections.emptyList(),
- SqlGatewayRestAPIVersion.V0);
-
- TestResponse testResponse = version1Response.get(5, TimeUnit.SECONDS);
- assertThat(testResponse.getStatus()).isEqualTo("V0");
-
- CompletableFuture<TestResponse> version2Response =
- restClient.sendRequest(
- serverAddress.getHostName(),
- serverAddress.getPort(),
- header2,
- EmptyMessageParameters.getInstance(),
- EmptyRequestBody.getInstance(),
- Collections.emptyList(),
- SqlGatewayRestAPIVersion.V1);
- TestResponse testResponse2 = version2Response.get(5, TimeUnit.SECONDS);
- assertThat(testResponse2.getStatus()).isEqualTo("V1");
+ validateVersionSelection(header0, SqlGatewayRestAPIVersion.V0);
+ validateVersionSelection(header12, SqlGatewayRestAPIVersion.V1);
+ validateVersionSelection(header12, SqlGatewayRestAPIVersion.V2);
Review Comment:
Now I think this test is very similar to the test 'testSqlGatewayMessageHeaders', because both test the message is routed correctly. So I think we can delete this test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org