#!/usr/bin/env bash
################################################################################
# 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.
################################################################################

source "$(dirname "$0")"/common.sh

TABLE_DATA_DIR="${TEST_DATA_DIR}/table"

start_cluster

# Set address for sql gateway.
set_config_key "sql-gateway.endpoint.rest.address" "localhost"
export FLINK_CONF_DIR="${FLINK_DIR}/conf"
start_sql_gateway

TEST_JDBC_DRIVER_JAR=${END_TO_END_DIR}/flink-end-to-end-tests-jdbc-driver/target/JdbcDriverExample.jar
TEST_JDBC_DRIVER_CLASS="org.apache.flink.table.jdbc.driver.tests.FlinkDriverExample"

java -cp ${TEST_JDBC_DRIVER_JAR} ${TEST_JDBC_DRIVER_CLASS} ${TABLE_DATA_DIR}

# check result:
#1,11,111
#2,22,222
#3,33,333
#4,44,444
check_result_hash "SqlJdbcDriver" "${TABLE_DATA_DIR}/output.dat" "a5843c415e87aa01202001e3f06b9298"

stop_sql_gateway
stop_cluster
