deadwind4 commented on code in PR #20174:
URL: https://github.com/apache/flink/pull/20174#discussion_r936167354
##########
flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/flink/LocalStandaloneFlinkResource.java:
##########
@@ -183,12 +185,49 @@ public ClusterController startCluster(int
numTaskManagers) throws IOException {
throw new RuntimeException("Cluster did not start in expected
time-frame.");
}
+ @Override
+ public GatewayController startSqlGateway() throws IOException {
Review Comment:
```suggestion
public GatewayController startSqlGatewayAndFlinkCluster() throws
IOException {
```
##########
flink-end-to-end-tests/flink-sql-gateway-test/src/test/java/org/apache/flink/table/gateway/SqlGatewayE2ECase.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.endpoint.hive.HiveServer2Endpoint;
+import org.apache.flink.table.gateway.containers.HiveContainer;
+import org.apache.flink.test.util.SQLJobSubmission;
+import org.apache.flink.tests.util.TestUtils;
+import org.apache.flink.tests.util.flink.FlinkResource;
+import org.apache.flink.tests.util.flink.FlinkResourceSetup;
+import org.apache.flink.tests.util.flink.GatewayController;
+import org.apache.flink.tests.util.flink.JarLocation;
+import org.apache.flink.tests.util.flink.LocalStandaloneFlinkResourceFactory;
+import org.apache.flink.util.FileUtils;
+import org.apache.flink.util.NetUtils;
+import org.apache.flink.util.TestLogger;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static
org.apache.flink.table.catalog.hive.HiveCatalog.isEmbeddedMetastore;
+import static
org.apache.flink.table.endpoint.hive.HiveServer2EndpointConfigOptions.CATALOG_HIVE_CONF_DIR;
+import static
org.apache.flink.table.endpoint.hive.HiveServer2EndpointConfigOptions.THRIFT_PORT;
+import static org.apache.flink.tests.util.TestUtils.readCsvResultFiles;
+import static org.junit.Assert.assertEquals;
+
+/** E2E Tests for {@code SqlGateway} with {@link HiveServer2Endpoint}. */
+public class SqlGatewayE2ECase extends TestLogger {
+
+ private static final Path HIVE_SQL_CONNECTOR_JAR =
+
TestUtils.getResource(".*dependencies/flink-sql-connector-hive-.*.jar");
+ private static final Path HADOOP_CLASS_PATH =
TestUtils.getResource(".*hadoop.classpath");
+ private static final String GATEWAY_E2E_SQL = "gateway_e2e.sql";
+ private static final Configuration ENDPOINT_CONFIG = new Configuration();
+ private static final String RESULT_KEY = "$RESULT";
+
+ @ClassRule public static final TemporaryFolder FOLDER = new
TemporaryFolder();
+ @ClassRule public static final HiveContainer HIVE_CONTAINER = new
HiveContainer();
+ @Rule public final FlinkResource flinkResource = buildFlinkResource();
+
+ private static NetUtils.Port port;
+
+ @BeforeClass
+ public static void beforeClass() {
+ ENDPOINT_CONFIG.setString(
+ getPrefixedConfigOptionName(CATALOG_HIVE_CONF_DIR),
createHiveConf().getParent());
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ port.close();
+ }
+
+ @Test
+ public void testExecuteStatement() throws Exception {
+ URL url =
SqlGatewayE2ECase.class.getClassLoader().getResource(GATEWAY_E2E_SQL);
+ if (url == null) {
+ throw new FileNotFoundException(GATEWAY_E2E_SQL);
+ }
+ File result = FOLDER.newFolder("csv");
+ String sql =
+ Files.readAllLines(new File(url.getFile()).toPath()).stream()
+ .filter(line -> !line.trim().startsWith("--"))
+ .collect(Collectors.joining());
+ List<String> lines =
+ Arrays.stream(sql.split(";"))
+ .map(line -> line.replace(RESULT_KEY,
result.getAbsolutePath()))
+ .collect(Collectors.toList());
+
+ try (GatewayController controller = flinkResource.startSqlGateway()) {
Review Comment:
```suggestion
try (GatewayController controller =
flinkResource.startSqlGatewayAndFlinkCluster()) {
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]