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/08/02 12:30:51 UTC

[GitHub] [flink] xintongsong commented on a diff in pull request #20418: [FLINK-28161][sql-gateway]Introduce the session related API for REST endpoint

xintongsong commented on code in PR #20418:
URL: https://github.com/apache/flink/pull/20418#discussion_r935472991


##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/header/session/CloseSessionHeaders.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.EmptyRequestBody;
+import org.apache.flink.table.gateway.rest.header.SqlGatewayMessageHeaders;
+import org.apache.flink.table.gateway.rest.message.session.CloseSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionHandleIdPathParameter;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+/** Message headers for closing a session. */
+public class CloseSessionHeaders
+        implements SqlGatewayMessageHeaders<
+                EmptyRequestBody, CloseSessionResponseBody, SessionMessageParameters> {
+
+    private static final CloseSessionHeaders INSTANCE = new CloseSessionHeaders();
+
+    public static final String URL = "/sessions/:" + SessionHandleIdPathParameter.KEY;

Review Comment:
   ```suggestion
       private static final String URL = "/sessions/:" + SessionHandleIdPathParameter.KEY;
   ```



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/message/session/OpenSessionRequestBody.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.message.session;
+
+import org.apache.flink.runtime.rest.messages.RequestBody;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.Map;
+
+/** {@link RequestBody} for opening a session. */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class OpenSessionRequestBody implements RequestBody {
+
+    private static final String FIELD_NAME_SESSION_NAME = "session_name";
+    private static final String FIELD_NAME_PROPERTIES = "properties";

Review Comment:
   Where are the `libs` and `jars` as documented in the FLIP?



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/header/session/TriggerSessionHeartbeatHeaders.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.table.gateway.rest.header.SqlGatewayMessageHeaders;
+import org.apache.flink.table.gateway.rest.message.session.SessionHandleIdPathParameter;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+/** Message headers for closing a session. */
+public class TriggerSessionHeartbeatHeaders
+        implements SqlGatewayMessageHeaders<
+                EmptyRequestBody, EmptyResponseBody, SessionMessageParameters> {
+
+    private static final TriggerSessionHeartbeatHeaders INSTANCE =
+            new TriggerSessionHeartbeatHeaders();
+
+    public static final String URL =

Review Comment:
   ```suggestion
       private static final String URL =
   ```



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/RestAPIITTestBase.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.gateway.rest.util.RestClientUtils;
+import org.apache.flink.table.gateway.service.utils.SqlGatewayServiceExtension;
+import org.apache.flink.test.junit5.MiniClusterExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getBaseConfig;
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getFlinkConfig;

Review Comment:
   It's weird that one test base needs to import methods of another IT case. These methods should be moved to an util class.



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/RestAPIITTestBase.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.gateway.rest.util.RestClientUtils;
+import org.apache.flink.table.gateway.service.utils.SqlGatewayServiceExtension;
+import org.apache.flink.test.junit5.MiniClusterExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getBaseConfig;
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getFlinkConfig;
+
+/** The base class for Rest API IT test. */
+public class RestAPIITTestBase {
+
+    @RegisterExtension
+    @Order(1)
+    public static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
+
+    @RegisterExtension
+    @Order(2)
+    public static final SqlGatewayServiceExtension SQL_GATEWAY_SERVICE_EXTENSION =
+            new SqlGatewayServiceExtension(MINI_CLUSTER::getClientConfiguration);
+
+    SqlGatewayRestEndpoint sqlGatewayRestEndpoint = null;
+
+    RestClientUtils restClientUtils = null;

Review Comment:
   Mark `@Nullable`.



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/header/session/OpenSessionHeaders.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.EmptyMessageParameters;
+import org.apache.flink.table.gateway.rest.header.SqlGatewayMessageHeaders;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+/** Message headers for opening a session. */
+public class OpenSessionHeaders
+        implements SqlGatewayMessageHeaders<
+                OpenSessionRequestBody, OpenSessionResponseBody, EmptyMessageParameters> {
+
+    public static final String URL = "/sessions";
+    private static final OpenSessionHeaders INSTANCE = new OpenSessionHeaders();
+
+    private OpenSessionHeaders() {}
+
+    @Override
+    public HttpMethodWrapper getHttpMethod() {
+        return HttpMethodWrapper.POST;
+    }
+
+    @Override
+    public String getTargetRestEndpointURL() {
+        return URL;
+    }
+
+    @Override
+    public Class<OpenSessionResponseBody> getResponseClass() {
+        return OpenSessionResponseBody.class;
+    }
+
+    @Override
+    public HttpResponseStatus getResponseStatusCode() {
+        return HttpResponseStatus.OK;
+    }
+
+    @Override
+    public String getDescription() {
+        return "Opens a new session with specific properties. Specific properties can be given for current session which will override the default properties of gateway.";

Review Comment:
   This is a reminder for myself, for revisiting the descriptions of the APIs.



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SessionCaseITTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.gateway.api.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.rest.handler.AbstractSqlGatewayRestHandler;
+import org.apache.flink.table.gateway.rest.header.session.CloseSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.GetSessionConfigHeaders;
+import org.apache.flink.table.gateway.rest.header.session.OpenSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.TriggerSessionHeartbeatHeaders;
+import org.apache.flink.table.gateway.rest.message.session.CloseSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.GetSessionConfigResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+import org.apache.flink.table.gateway.service.session.Session;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.table.gateway.rest.handler.session.CloseSessionHandler.CLOSE_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test basic logic of handlers inherited from {@link AbstractSqlGatewayRestHandler} in session
+ * related cases.
+ */
+class SessionCaseITTest extends RestAPIITTestBase {
+
+    private static final String SESSION_NAME = "test";
+    private static final Map<String, String> properties = new HashMap<>();
+    private static final int SESSION_NUMBER = 10;
+
+    static {
+        properties.put("k1", "v1");
+        properties.put("k2", "v2");
+    }
+
+    OpenSessionHeaders openSessionHeaders = OpenSessionHeaders.getInstance();
+    OpenSessionRequestBody openSessionRequestBody =
+            new OpenSessionRequestBody(SESSION_NAME, properties);
+    EmptyMessageParameters emptyParameters = EmptyMessageParameters.getInstance();
+
+    CloseSessionHeaders closeSessionHeaders = CloseSessionHeaders.getInstance();
+    EmptyRequestBody emptyRequestBody = EmptyRequestBody.getInstance();
+    SessionMessageParameters sessionMessageParameters;

Review Comment:
   Can be a local variable.



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/RestAPIITTestBase.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.gateway.rest.util.RestClientUtils;
+import org.apache.flink.table.gateway.service.utils.SqlGatewayServiceExtension;
+import org.apache.flink.test.junit5.MiniClusterExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getBaseConfig;
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getFlinkConfig;
+
+/** The base class for Rest API IT test. */
+public class RestAPIITTestBase {
+
+    @RegisterExtension
+    @Order(1)
+    public static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
+
+    @RegisterExtension
+    @Order(2)
+    public static final SqlGatewayServiceExtension SQL_GATEWAY_SERVICE_EXTENSION =
+            new SqlGatewayServiceExtension(MINI_CLUSTER::getClientConfiguration);
+
+    SqlGatewayRestEndpoint sqlGatewayRestEndpoint = null;

Review Comment:
   Mark `@Nullable` and can be private.



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SessionCaseITTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.gateway.api.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.rest.handler.AbstractSqlGatewayRestHandler;
+import org.apache.flink.table.gateway.rest.header.session.CloseSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.GetSessionConfigHeaders;
+import org.apache.flink.table.gateway.rest.header.session.OpenSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.TriggerSessionHeartbeatHeaders;
+import org.apache.flink.table.gateway.rest.message.session.CloseSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.GetSessionConfigResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+import org.apache.flink.table.gateway.service.session.Session;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.table.gateway.rest.handler.session.CloseSessionHandler.CLOSE_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test basic logic of handlers inherited from {@link AbstractSqlGatewayRestHandler} in session
+ * related cases.
+ */
+class SessionCaseITTest extends RestAPIITTestBase {
+
+    private static final String SESSION_NAME = "test";
+    private static final Map<String, String> properties = new HashMap<>();
+    private static final int SESSION_NUMBER = 10;
+
+    static {
+        properties.put("k1", "v1");
+        properties.put("k2", "v2");
+    }
+
+    OpenSessionHeaders openSessionHeaders = OpenSessionHeaders.getInstance();
+    OpenSessionRequestBody openSessionRequestBody =
+            new OpenSessionRequestBody(SESSION_NAME, properties);
+    EmptyMessageParameters emptyParameters = EmptyMessageParameters.getInstance();
+
+    CloseSessionHeaders closeSessionHeaders = CloseSessionHeaders.getInstance();
+    EmptyRequestBody emptyRequestBody = EmptyRequestBody.getInstance();
+    SessionMessageParameters sessionMessageParameters;
+
+    @Test
+    void testWhenCreateMultiSessions() throws Exception {
+        Set<String> sessionHandleIds = new HashSet<>();
+        for (int num = 0; num < SESSION_NUMBER; ++num) {
+            CompletableFuture<OpenSessionResponseBody> response =
+                    restClientUtils.sendRequest(
+                            openSessionHeaders, emptyParameters, openSessionRequestBody);
+            String sessionHandleId = response.get().getSessionHandle();
+            sessionHandleIds.add(sessionHandleId);
+            assertThat(sessionHandleId).isNotNull();
+            assertThat(
+                            SQL_GATEWAY_SERVICE_EXTENSION
+                                    .getSessionManager()
+                                    .getSession(
+                                            new SessionHandle(UUID.fromString(sessionHandleId))))
+                    .isNotNull();
+        }
+        assertThat(sessionHandleIds).hasSize(SESSION_NUMBER);
+    }
+
+    @Test
+    void testWhenCreateAndCloseSessions() throws Exception {
+        List<SessionHandle> sessionHandles = new ArrayList<>();
+        for (int num = 0; num < SESSION_NUMBER; ++num) {
+            CompletableFuture<OpenSessionResponseBody> response =
+                    restClientUtils.sendRequest(
+                            openSessionHeaders, emptyParameters, openSessionRequestBody);
+            String sessionHandleId = response.get().getSessionHandle();
+            assertThat(sessionHandleId).isNotNull();
+            SessionHandle sessionHandle = new SessionHandle(UUID.fromString(sessionHandleId));
+            assertThat(SQL_GATEWAY_SERVICE_EXTENSION.getSessionManager().getSession(sessionHandle))
+                    .isNotNull();
+            sessionHandles.add(sessionHandle);
+        }
+
+        for (int num = 0; num < SESSION_NUMBER; ++num) {
+            SessionHandle sessionHandle = sessionHandles.get(num);
+            sessionMessageParameters = new SessionMessageParameters(sessionHandle);
+            CompletableFuture<CloseSessionResponseBody> response =
+                    restClientUtils.sendRequest(
+                            closeSessionHeaders, sessionMessageParameters, emptyRequestBody);
+            String status = response.get().getStatus();
+            assertThat(status).isEqualTo(CLOSE_MESSAGE);
+            assertThatThrownBy(
+                            () ->
+                                    SQL_GATEWAY_SERVICE_EXTENSION
+                                            .getSessionManager()
+                                            .getSession(sessionHandle))
+                    .isInstanceOf(SqlGatewayException.class);
+            // Test closing the closed session
+            CompletableFuture<CloseSessionResponseBody> response2 =
+                    restClientUtils.sendRequest(
+                            closeSessionHeaders, sessionMessageParameters, emptyRequestBody);
+            assertThatThrownBy(() -> response2.get()).isInstanceOf(ExecutionException.class);

Review Comment:
   ```suggestion
               assertThatThrownBy(response2::get).isInstanceOf(ExecutionException.class);
   ```



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/handler/session/OpenSessionHandler.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+/*
+ * 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.
+ */
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.MessageHeaders;
+import org.apache.flink.table.gateway.api.SqlGatewayService;
+import org.apache.flink.table.gateway.api.session.SessionEnvironment;
+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.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+import org.apache.flink.table.gateway.rest.util.SqlGatewayRestAPIVersion;
+
+import javax.annotation.Nonnull;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+/** Handler to open session. */
+public class OpenSessionHandler
+        extends AbstractSqlGatewayRestHandler<
+                OpenSessionRequestBody, OpenSessionResponseBody, EmptyMessageParameters> {
+
+    public OpenSessionHandler(
+            SqlGatewayService service,
+            Time timeout,
+            Map<String, String> responseHeaders,
+            MessageHeaders<OpenSessionRequestBody, OpenSessionResponseBody, EmptyMessageParameters>
+                    messageHeaders) {
+        super(service, timeout, responseHeaders, messageHeaders);
+    }
+
+    @Override
+    protected CompletableFuture<OpenSessionResponseBody> handleRequest(
+            SqlGatewayRestAPIVersion version,
+            @Nonnull HandlerRequest<OpenSessionRequestBody> request) {
+        String sessionName = request.getRequestBody().getSessionName();
+        SessionHandle sessionHandle =
+                service.openSession(
+                        SessionEnvironment.newBuilder()
+                                .setSessionEndpointVersion(version)
+                                .setSessionName(sessionName)
+                                .addSessionConfig(request.getRequestBody().getProperties())

Review Comment:
   Minor: Either storing `request.getRequestBody().getXXX()` to a local variable or not is fine, but we'd better keep them consistent.



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/handler/session/TriggerSessionHeartbeatHandler.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.api.common.time.Time;
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.handler.RestHandlerException;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+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.api.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.rest.handler.AbstractSqlGatewayRestHandler;
+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 javax.annotation.Nonnull;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+/** Handler to touch the session. */
+public class TriggerSessionHeartbeatHandler
+        extends AbstractSqlGatewayRestHandler<
+                EmptyRequestBody, EmptyResponseBody, SessionMessageParameters> {
+
+    public TriggerSessionHeartbeatHandler(
+            SqlGatewayService service,
+            Time timeout,
+            Map<String, String> responseHeaders,
+            MessageHeaders<EmptyRequestBody, EmptyResponseBody, SessionMessageParameters>
+                    messageHeaders) {
+        super(service, timeout, responseHeaders, messageHeaders);
+    }
+
+    @Override
+    protected CompletableFuture<EmptyResponseBody> handleRequest(
+            SqlGatewayRestAPIVersion version, @Nonnull HandlerRequest<EmptyRequestBody> request)
+            throws RestHandlerException {
+        try {
+            SessionHandle sessionHandle =
+                    request.getPathParameter(SessionHandleIdPathParameter.class);
+            this.service.getSessionConfig(sessionHandle);

Review Comment:
   Would be better to add an explanation in comment here.



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpoint.java:
##########
@@ -37,6 +46,7 @@
 public class SqlGatewayRestEndpoint extends RestServerEndpoint implements SqlGatewayEndpoint {
 
     public final SqlGatewayService service;
+    protected Time timeout = Time.seconds(1);

Review Comment:
   This should be configurable.



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/RestAPIITTestBase.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.gateway.rest.util.RestClientUtils;
+import org.apache.flink.table.gateway.service.utils.SqlGatewayServiceExtension;
+import org.apache.flink.test.junit5.MiniClusterExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getBaseConfig;
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getFlinkConfig;
+
+/** The base class for Rest API IT test. */
+public class RestAPIITTestBase {

Review Comment:
   ```suggestion
   public abstract class RestAPIITTestBase {
   ```



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpoint.java:
##########
@@ -47,7 +57,43 @@ public SqlGatewayRestEndpoint(Configuration configuration, SqlGatewayService sql
     @Override
     protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(
             CompletableFuture<String> localAddressFuture) {
-        return new ArrayList<>();
+        List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers =
+                new ArrayList<>(32);

Review Comment:
   Unless there's a good reason, we usually don't set the initial capacity of a collection.



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SessionCaseITTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.gateway.api.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.rest.handler.AbstractSqlGatewayRestHandler;
+import org.apache.flink.table.gateway.rest.header.session.CloseSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.GetSessionConfigHeaders;
+import org.apache.flink.table.gateway.rest.header.session.OpenSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.TriggerSessionHeartbeatHeaders;
+import org.apache.flink.table.gateway.rest.message.session.CloseSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.GetSessionConfigResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+import org.apache.flink.table.gateway.service.session.Session;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.table.gateway.rest.handler.session.CloseSessionHandler.CLOSE_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test basic logic of handlers inherited from {@link AbstractSqlGatewayRestHandler} in session
+ * related cases.
+ */
+class SessionCaseITTest extends RestAPIITTestBase {
+
+    private static final String SESSION_NAME = "test";
+    private static final Map<String, String> properties = new HashMap<>();
+    private static final int SESSION_NUMBER = 10;
+
+    static {
+        properties.put("k1", "v1");
+        properties.put("k2", "v2");
+    }
+
+    OpenSessionHeaders openSessionHeaders = OpenSessionHeaders.getInstance();
+    OpenSessionRequestBody openSessionRequestBody =
+            new OpenSessionRequestBody(SESSION_NAME, properties);
+    EmptyMessageParameters emptyParameters = EmptyMessageParameters.getInstance();
+
+    CloseSessionHeaders closeSessionHeaders = CloseSessionHeaders.getInstance();
+    EmptyRequestBody emptyRequestBody = EmptyRequestBody.getInstance();

Review Comment:
   Can be private, final and static.



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SessionCaseITTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.gateway.api.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.rest.handler.AbstractSqlGatewayRestHandler;
+import org.apache.flink.table.gateway.rest.header.session.CloseSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.GetSessionConfigHeaders;
+import org.apache.flink.table.gateway.rest.header.session.OpenSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.TriggerSessionHeartbeatHeaders;
+import org.apache.flink.table.gateway.rest.message.session.CloseSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.GetSessionConfigResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+import org.apache.flink.table.gateway.service.session.Session;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.table.gateway.rest.handler.session.CloseSessionHandler.CLOSE_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test basic logic of handlers inherited from {@link AbstractSqlGatewayRestHandler} in session
+ * related cases.
+ */
+class SessionCaseITTest extends RestAPIITTestBase {
+
+    private static final String SESSION_NAME = "test";
+    private static final Map<String, String> properties = new HashMap<>();
+    private static final int SESSION_NUMBER = 10;
+
+    static {
+        properties.put("k1", "v1");
+        properties.put("k2", "v2");
+    }
+
+    OpenSessionHeaders openSessionHeaders = OpenSessionHeaders.getInstance();
+    OpenSessionRequestBody openSessionRequestBody =
+            new OpenSessionRequestBody(SESSION_NAME, properties);
+    EmptyMessageParameters emptyParameters = EmptyMessageParameters.getInstance();
+
+    CloseSessionHeaders closeSessionHeaders = CloseSessionHeaders.getInstance();
+    EmptyRequestBody emptyRequestBody = EmptyRequestBody.getInstance();
+    SessionMessageParameters sessionMessageParameters;
+
+    @Test
+    void testWhenCreateMultiSessions() throws Exception {

Review Comment:
   Same for other test cases.



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/header/session/GetSessionConfigHeaders.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.EmptyRequestBody;
+import org.apache.flink.table.gateway.rest.header.SqlGatewayMessageHeaders;
+import org.apache.flink.table.gateway.rest.message.session.GetSessionConfigResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionHandleIdPathParameter;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+/** Message headers for closing a session. */
+public class GetSessionConfigHeaders
+        implements SqlGatewayMessageHeaders<
+                EmptyRequestBody, GetSessionConfigResponseBody, SessionMessageParameters> {
+
+    private static final GetSessionConfigHeaders INSTANCE = new GetSessionConfigHeaders();
+
+    public static final String URL = "/sessions/:" + SessionHandleIdPathParameter.KEY;

Review Comment:
   ```suggestion
       private static final String URL = "/sessions/:" + SessionHandleIdPathParameter.KEY;
   ```



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SessionCaseITTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.gateway.api.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.rest.handler.AbstractSqlGatewayRestHandler;
+import org.apache.flink.table.gateway.rest.header.session.CloseSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.GetSessionConfigHeaders;
+import org.apache.flink.table.gateway.rest.header.session.OpenSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.TriggerSessionHeartbeatHeaders;
+import org.apache.flink.table.gateway.rest.message.session.CloseSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.GetSessionConfigResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+import org.apache.flink.table.gateway.service.session.Session;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.table.gateway.rest.handler.session.CloseSessionHandler.CLOSE_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test basic logic of handlers inherited from {@link AbstractSqlGatewayRestHandler} in session
+ * related cases.
+ */
+class SessionCaseITTest extends RestAPIITTestBase {
+
+    private static final String SESSION_NAME = "test";
+    private static final Map<String, String> properties = new HashMap<>();
+    private static final int SESSION_NUMBER = 10;
+
+    static {
+        properties.put("k1", "v1");
+        properties.put("k2", "v2");
+    }
+
+    OpenSessionHeaders openSessionHeaders = OpenSessionHeaders.getInstance();
+    OpenSessionRequestBody openSessionRequestBody =
+            new OpenSessionRequestBody(SESSION_NAME, properties);
+    EmptyMessageParameters emptyParameters = EmptyMessageParameters.getInstance();
+
+    CloseSessionHeaders closeSessionHeaders = CloseSessionHeaders.getInstance();
+    EmptyRequestBody emptyRequestBody = EmptyRequestBody.getInstance();
+    SessionMessageParameters sessionMessageParameters;
+
+    @Test
+    void testWhenCreateMultiSessions() throws Exception {

Review Comment:
   ```suggestion
       void testCreateMultiSessions() throws Exception {
   ```



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/SessionCaseITTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.table.gateway.api.session.SessionHandle;
+import org.apache.flink.table.gateway.api.utils.SqlGatewayException;
+import org.apache.flink.table.gateway.rest.handler.AbstractSqlGatewayRestHandler;
+import org.apache.flink.table.gateway.rest.header.session.CloseSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.GetSessionConfigHeaders;
+import org.apache.flink.table.gateway.rest.header.session.OpenSessionHeaders;
+import org.apache.flink.table.gateway.rest.header.session.TriggerSessionHeartbeatHeaders;
+import org.apache.flink.table.gateway.rest.message.session.CloseSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.GetSessionConfigResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+import org.apache.flink.table.gateway.rest.message.session.SessionMessageParameters;
+import org.apache.flink.table.gateway.service.session.Session;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.table.gateway.rest.handler.session.CloseSessionHandler.CLOSE_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test basic logic of handlers inherited from {@link AbstractSqlGatewayRestHandler} in session
+ * related cases.
+ */
+class SessionCaseITTest extends RestAPIITTestBase {
+
+    private static final String SESSION_NAME = "test";
+    private static final Map<String, String> properties = new HashMap<>();
+    private static final int SESSION_NUMBER = 10;
+
+    static {
+        properties.put("k1", "v1");
+        properties.put("k2", "v2");
+    }
+
+    OpenSessionHeaders openSessionHeaders = OpenSessionHeaders.getInstance();
+    OpenSessionRequestBody openSessionRequestBody =
+            new OpenSessionRequestBody(SESSION_NAME, properties);
+    EmptyMessageParameters emptyParameters = EmptyMessageParameters.getInstance();
+
+    CloseSessionHeaders closeSessionHeaders = CloseSessionHeaders.getInstance();
+    EmptyRequestBody emptyRequestBody = EmptyRequestBody.getInstance();
+    SessionMessageParameters sessionMessageParameters;
+
+    @Test
+    void testWhenCreateMultiSessions() throws Exception {
+        Set<String> sessionHandleIds = new HashSet<>();
+        for (int num = 0; num < SESSION_NUMBER; ++num) {
+            CompletableFuture<OpenSessionResponseBody> response =
+                    restClientUtils.sendRequest(
+                            openSessionHeaders, emptyParameters, openSessionRequestBody);
+            String sessionHandleId = response.get().getSessionHandle();
+            sessionHandleIds.add(sessionHandleId);
+            assertThat(sessionHandleId).isNotNull();
+            assertThat(
+                            SQL_GATEWAY_SERVICE_EXTENSION
+                                    .getSessionManager()
+                                    .getSession(
+                                            new SessionHandle(UUID.fromString(sessionHandleId))))
+                    .isNotNull();
+        }
+        assertThat(sessionHandleIds).hasSize(SESSION_NUMBER);
+    }
+
+    @Test
+    void testWhenCreateAndCloseSessions() throws Exception {

Review Comment:
   This case completely covers `testWhenCreateMultiSessions`.



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/SqlGatewayRestEndpoint.java:
##########
@@ -37,6 +46,7 @@
 public class SqlGatewayRestEndpoint extends RestServerEndpoint implements SqlGatewayEndpoint {
 
     public final SqlGatewayService service;
+    protected Time timeout = Time.seconds(1);

Review Comment:
   And why is this `protected` and not `final`?



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/RestAPIITTestBase.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.gateway.rest.util.RestClientUtils;
+import org.apache.flink.table.gateway.service.utils.SqlGatewayServiceExtension;
+import org.apache.flink.test.junit5.MiniClusterExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getBaseConfig;
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getFlinkConfig;
+
+/** The base class for Rest API IT test. */
+public class RestAPIITTestBase {
+
+    @RegisterExtension
+    @Order(1)
+    public static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();
+
+    @RegisterExtension
+    @Order(2)
+    public static final SqlGatewayServiceExtension SQL_GATEWAY_SERVICE_EXTENSION =
+            new SqlGatewayServiceExtension(MINI_CLUSTER::getClientConfiguration);
+
+    SqlGatewayRestEndpoint sqlGatewayRestEndpoint = null;
+
+    RestClientUtils restClientUtils = null;
+
+    @BeforeEach
+    void start() throws Exception {
+        final String address = InetAddress.getLoopbackAddress().getHostAddress();
+        Configuration config = getBaseConfig(getFlinkConfig(address, address, "0"));
+        sqlGatewayRestEndpoint =
+                new SqlGatewayRestEndpoint(config, SQL_GATEWAY_SERVICE_EXTENSION.getService());
+        sqlGatewayRestEndpoint.start();
+        InetSocketAddress serverAddress = sqlGatewayRestEndpoint.getServerAddress();

Review Comment:
   checkNotNull



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/RestAPIITTestBase.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.gateway.rest.util.RestClientUtils;
+import org.apache.flink.table.gateway.service.utils.SqlGatewayServiceExtension;
+import org.apache.flink.test.junit5.MiniClusterExtension;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getBaseConfig;
+import static org.apache.flink.table.gateway.rest.SqlGatewayRestEndpointITCase.getFlinkConfig;
+
+/** The base class for Rest API IT test. */
+public class RestAPIITTestBase {
+
+    @RegisterExtension
+    @Order(1)
+    public static final MiniClusterExtension MINI_CLUSTER = new MiniClusterExtension();

Review Comment:
   Why do we need a minicluster?



##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/rest/util/RestClientUtils.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.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.SqlGatewayRestEndpoint;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.ExecutorUtils;
+import org.apache.flink.util.concurrent.ExecutorThreadFactory;
+
+import java.io.IOException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/** The utils contains a rest client to send requests to {@link SqlGatewayRestEndpoint}. */
+public class RestClientUtils {

Review Comment:
   Usually, a util class contains static util methods only.
   
   In this case, I think you can create a `RestClient` in a `@BeforeAll` method, and clean it up in a `@AfterAll` method.



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/header/session/OpenSessionHeaders.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.EmptyMessageParameters;
+import org.apache.flink.table.gateway.rest.header.SqlGatewayMessageHeaders;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionRequestBody;
+import org.apache.flink.table.gateway.rest.message.session.OpenSessionResponseBody;
+
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+
+/** Message headers for opening a session. */
+public class OpenSessionHeaders
+        implements SqlGatewayMessageHeaders<
+                OpenSessionRequestBody, OpenSessionResponseBody, EmptyMessageParameters> {
+
+    public static final String URL = "/sessions";

Review Comment:
   Can be private.



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/rest/handler/session/OpenSessionHandler.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+/*
+ * 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.
+ */

Review Comment:
   Extra license.



-- 
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