2019-04-02 22:21:44 +00:00
|
|
|
# coding: utf-8
|
|
|
|
|
2019-12-08 05:40:08 +00:00
|
|
|
import datetime
|
2023-03-13 13:59:00 +00:00
|
|
|
import fnmatch
|
2019-12-08 05:40:08 +00:00
|
|
|
import math
|
2019-12-06 01:26:28 +00:00
|
|
|
import os
|
|
|
|
import time
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2021-03-09 07:32:10 +00:00
|
|
|
import logging
|
2023-10-10 17:51:09 +00:00
|
|
|
from typing import Literal
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
import docker
|
|
|
|
import pymysql.connections
|
|
|
|
import pytest
|
2021-01-22 14:27:23 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster, get_docker_compose_path, run_and_check
|
2019-04-02 22:21:44 +00:00
|
|
|
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
2020-08-12 15:04:36 +00:00
|
|
|
DOCKER_COMPOSE_PATH = get_docker_compose_path()
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2019-04-29 06:05:30 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-03-22 16:39:58 +00:00
|
|
|
node = cluster.add_instance(
|
|
|
|
"node",
|
|
|
|
main_configs=[
|
|
|
|
"configs/ssl_conf.xml",
|
|
|
|
"configs/mysql.xml",
|
|
|
|
"configs/dhparam.pem",
|
|
|
|
"configs/server.crt",
|
|
|
|
"configs/server.key",
|
|
|
|
],
|
|
|
|
user_configs=["configs/users.xml"],
|
|
|
|
env_variables={"UBSAN_OPTIONS": "print_stacktrace=1"},
|
|
|
|
with_mysql_client=True,
|
|
|
|
)
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2021-03-24 13:23:23 +00:00
|
|
|
server_port = 9001
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2019-04-02 22:21:44 +00:00
|
|
|
@pytest.fixture(scope="module")
|
2021-04-13 14:55:31 +00:00
|
|
|
def started_cluster():
|
2019-04-02 22:21:44 +00:00
|
|
|
cluster.start()
|
|
|
|
try:
|
2021-04-13 14:55:31 +00:00
|
|
|
yield cluster
|
2019-04-02 22:21:44 +00:00
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
@pytest.fixture(scope="module")
|
2019-04-07 10:29:30 +00:00
|
|
|
def golang_container():
|
2022-03-22 16:39:58 +00:00
|
|
|
docker_compose = os.path.join(
|
|
|
|
DOCKER_COMPOSE_PATH, "docker_compose_mysql_golang_client.yml"
|
|
|
|
)
|
2021-01-22 14:27:23 +00:00
|
|
|
run_and_check(
|
2022-03-22 16:39:58 +00:00
|
|
|
[
|
|
|
|
"docker-compose",
|
|
|
|
"-p",
|
|
|
|
cluster.project_name,
|
|
|
|
"-f",
|
|
|
|
docker_compose,
|
|
|
|
"up",
|
2022-03-31 13:56:07 +00:00
|
|
|
"--force-recreate",
|
2022-03-22 16:39:58 +00:00
|
|
|
"-d",
|
|
|
|
"--no-build",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
yield docker.DockerClient(
|
|
|
|
base_url="unix:///var/run/docker.sock",
|
|
|
|
version=cluster.docker_api_version,
|
|
|
|
timeout=600,
|
|
|
|
).containers.get(cluster.project_name + "_golang1_1")
|
2019-04-02 22:21:44 +00:00
|
|
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
@pytest.fixture(scope="module")
|
2019-07-21 12:09:41 +00:00
|
|
|
def php_container():
|
2022-03-22 16:39:58 +00:00
|
|
|
docker_compose = os.path.join(
|
|
|
|
DOCKER_COMPOSE_PATH, "docker_compose_mysql_php_client.yml"
|
|
|
|
)
|
2021-01-22 14:27:23 +00:00
|
|
|
run_and_check(
|
2022-03-22 16:39:58 +00:00
|
|
|
[
|
|
|
|
"docker-compose",
|
|
|
|
"--env-file",
|
|
|
|
cluster.instances["node"].env_file,
|
|
|
|
"-p",
|
|
|
|
cluster.project_name,
|
|
|
|
"-f",
|
|
|
|
docker_compose,
|
|
|
|
"up",
|
2022-03-31 13:56:07 +00:00
|
|
|
"--force-recreate",
|
2022-03-22 16:39:58 +00:00
|
|
|
"-d",
|
|
|
|
"--no-build",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
yield docker.DockerClient(
|
|
|
|
base_url="unix:///var/run/docker.sock",
|
|
|
|
version=cluster.docker_api_version,
|
|
|
|
timeout=600,
|
|
|
|
).containers.get(cluster.project_name + "_php1_1")
|
2019-07-21 12:09:41 +00:00
|
|
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
@pytest.fixture(scope="module")
|
2019-07-28 13:12:26 +00:00
|
|
|
def nodejs_container():
|
2022-03-22 16:39:58 +00:00
|
|
|
docker_compose = os.path.join(
|
|
|
|
DOCKER_COMPOSE_PATH, "docker_compose_mysql_js_client.yml"
|
|
|
|
)
|
2021-01-22 14:27:23 +00:00
|
|
|
run_and_check(
|
2022-03-22 16:39:58 +00:00
|
|
|
[
|
|
|
|
"docker-compose",
|
|
|
|
"--env-file",
|
|
|
|
cluster.instances["node"].env_file,
|
|
|
|
"-p",
|
|
|
|
cluster.project_name,
|
|
|
|
"-f",
|
|
|
|
docker_compose,
|
|
|
|
"up",
|
2022-03-31 13:56:07 +00:00
|
|
|
"--force-recreate",
|
2022-03-22 16:39:58 +00:00
|
|
|
"-d",
|
|
|
|
"--no-build",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
yield docker.DockerClient(
|
|
|
|
base_url="unix:///var/run/docker.sock",
|
|
|
|
version=cluster.docker_api_version,
|
|
|
|
timeout=600,
|
|
|
|
).containers.get(cluster.project_name + "_mysqljs1_1")
|
2019-07-28 13:12:26 +00:00
|
|
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
@pytest.fixture(scope="module")
|
Enhanced compatibility with native mysql-connector-java(JDBC) (#10021)
* Skip the `/* comments */ SELECT @@variables ...` from mysql-connector-java setup for MySQL Handler #9336
mysql-connector setup query:
/* mysql-connector-java-5.1.38 ( Revision: ${revinfo.commit} ) */SELECT @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout...
ClickHouse side Error:
{} <Error> executeQuery: Code: 62, e.displayText() = DB::Exception: Syntax error: failed at position 74: @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_conn. Expected one of: CAST, NULL...
Client side Exception:
java.sql.SQLException: Syntax error: failed at position 74: @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_conn. Expected one of: CAST...
* add repalce 'SHOW VARIABLES' for mysql-connector-java-5.1.34 #9336
* Add java client(JDBC) integration test to test_mysql_protocol
* shift out java tests from dbms
* Update MySQLHandler.cpp
* Update MySQLHandler.cpp
* test_mysql_protocol: add Test.java exit code 1 when expection
Co-authored-by: alexey-milovidov <milovidov@yandex-team.ru>
2020-04-08 21:52:19 +00:00
|
|
|
def java_container():
|
2022-03-22 16:39:58 +00:00
|
|
|
docker_compose = os.path.join(
|
|
|
|
DOCKER_COMPOSE_PATH, "docker_compose_mysql_java_client.yml"
|
|
|
|
)
|
2021-01-22 14:27:23 +00:00
|
|
|
run_and_check(
|
2022-03-22 16:39:58 +00:00
|
|
|
[
|
|
|
|
"docker-compose",
|
|
|
|
"--env-file",
|
|
|
|
cluster.instances["node"].env_file,
|
|
|
|
"-p",
|
|
|
|
cluster.project_name,
|
|
|
|
"-f",
|
|
|
|
docker_compose,
|
|
|
|
"up",
|
2022-03-31 13:56:07 +00:00
|
|
|
"--force-recreate",
|
2022-03-22 16:39:58 +00:00
|
|
|
"-d",
|
|
|
|
"--no-build",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
yield docker.DockerClient(
|
|
|
|
base_url="unix:///var/run/docker.sock",
|
|
|
|
version=cluster.docker_api_version,
|
|
|
|
timeout=600,
|
|
|
|
).containers.get(cluster.project_name + "_java1_1")
|
Enhanced compatibility with native mysql-connector-java(JDBC) (#10021)
* Skip the `/* comments */ SELECT @@variables ...` from mysql-connector-java setup for MySQL Handler #9336
mysql-connector setup query:
/* mysql-connector-java-5.1.38 ( Revision: ${revinfo.commit} ) */SELECT @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout...
ClickHouse side Error:
{} <Error> executeQuery: Code: 62, e.displayText() = DB::Exception: Syntax error: failed at position 74: @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_conn. Expected one of: CAST, NULL...
Client side Exception:
java.sql.SQLException: Syntax error: failed at position 74: @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_conn. Expected one of: CAST...
* add repalce 'SHOW VARIABLES' for mysql-connector-java-5.1.34 #9336
* Add java client(JDBC) integration test to test_mysql_protocol
* shift out java tests from dbms
* Update MySQLHandler.cpp
* Update MySQLHandler.cpp
* test_mysql_protocol: add Test.java exit code 1 when expection
Co-authored-by: alexey-milovidov <milovidov@yandex-team.ru>
2020-04-08 21:52:19 +00:00
|
|
|
|
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_mysql_client(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2019-07-28 13:12:26 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u user_with_double_sha1 --password=abacaba
|
|
|
|
-e "SELECT 1;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2021-03-09 07:32:10 +00:00
|
|
|
logging.debug(f"test_mysql_client code:{code} stdout:{stdout}, stderr:{stderr}")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert stdout.decode() == "\n".join(["1", "1", ""])
|
2019-07-28 13:12:26 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2019-04-22 10:57:50 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
2019-05-16 03:34:04 +00:00
|
|
|
-e "SELECT 1 as a;"
|
|
|
|
-e "SELECT 'тест' as b;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert stdout.decode() == "\n".join(["a", "1", "b", "тест", ""])
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2019-04-22 10:57:50 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=abc -e "select 1 as a;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert (
|
2022-11-29 14:33:02 +00:00
|
|
|
"mysql: [Warning] Using a password on the command line interface can be insecure.\n"
|
2022-11-29 14:48:05 +00:00
|
|
|
"ERROR 516 (00000): default: Authentication failed: password is incorrect, or there is no user with such name"
|
|
|
|
in stderr.decode()
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2019-04-22 10:57:50 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
2019-04-02 22:21:44 +00:00
|
|
|
-e "use system;"
|
|
|
|
-e "select count(*) from (select name from tables limit 1);"
|
|
|
|
-e "use system2;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert stdout.decode() == "count()\n1\n"
|
|
|
|
expected_msg = "\n".join(
|
|
|
|
[
|
|
|
|
"mysql: [Warning] Using a password on the command line interface can be insecure.",
|
2023-08-11 10:24:16 +00:00
|
|
|
"ERROR 81 (00000) at line 1: Code: 81. DB::Exception: Database system2 does not exist",
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
assert stderr[: len(expected_msg)].decode() == expected_msg
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2019-05-16 03:34:04 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "CREATE DATABASE x;"
|
|
|
|
-e "USE x;"
|
2019-06-16 15:12:37 +00:00
|
|
|
-e "CREATE TABLE table1 (column UInt32) ENGINE = Memory;"
|
2019-05-16 03:34:04 +00:00
|
|
|
-e "INSERT INTO table1 VALUES (0), (1), (5);"
|
|
|
|
-e "INSERT INTO table1 VALUES (0), (1), (5);"
|
2019-06-16 15:12:37 +00:00
|
|
|
-e "SELECT * FROM table1 ORDER BY column;"
|
2019-06-16 07:55:14 +00:00
|
|
|
-e "DROP DATABASE x;"
|
2019-06-16 15:12:37 +00:00
|
|
|
-e "CREATE TEMPORARY TABLE tmp (tmp_column UInt32);"
|
|
|
|
-e "INSERT INTO tmp VALUES (0), (1);"
|
|
|
|
-e "SELECT * FROM tmp ORDER BY tmp_column;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-05-16 03:34:04 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert stdout.decode() == "\n".join(
|
|
|
|
["column", "0", "0", "1", "1", "5", "5", "tmp_column", "0", "1", ""]
|
|
|
|
)
|
2019-05-16 03:34:04 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_mysql_client_exception(started_cluster):
|
2020-09-16 04:26:10 +00:00
|
|
|
# Poco exception.
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-10 06:20:32 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "CREATE TABLE default.t1_remote_mysql AS mysql('127.0.0.1:10086','default','t1_local','default','');"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-10 06:20:32 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
expected_msg = "\n".join(
|
|
|
|
[
|
|
|
|
"mysql: [Warning] Using a password on the command line interface can be insecure.",
|
2023-08-29 12:35:30 +00:00
|
|
|
"ERROR 279 (00000) at line 1: Code: 279. DB::Exception: Connections to mysql failed: default@127.0.0.1:10086 as user default",
|
2022-03-22 16:39:58 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
assert stderr[: len(expected_msg)].decode() == expected_msg
|
2020-07-10 06:20:32 +00:00
|
|
|
|
2020-07-06 08:26:06 +00:00
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_mysql_affected_rows(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-11-05 16:10:27 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "CREATE TABLE IF NOT EXISTS default.t1 (n UInt64) ENGINE MergeTree() ORDER BY tuple();"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-11-05 16:10:27 +00:00
|
|
|
assert code == 0
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-11-05 16:10:27 +00:00
|
|
|
mysql -vvv --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "INSERT INTO default.t1(n) VALUES(1);"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-11-05 16:10:27 +00:00
|
|
|
|
|
|
|
assert code == 0
|
2020-11-06 10:28:37 +00:00
|
|
|
assert "1 row affected" in stdout.decode()
|
2020-11-05 16:10:27 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-11-05 16:10:27 +00:00
|
|
|
mysql -vvv --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "INSERT INTO default.t1(n) SELECT * FROM numbers(1000)"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-11-05 16:10:27 +00:00
|
|
|
|
|
|
|
assert code == 0
|
2020-11-06 01:54:33 +00:00
|
|
|
assert "1000 rows affected" in stdout.decode()
|
2020-11-05 16:10:27 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-11-05 16:10:27 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "DROP TABLE default.t1;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-11-05 16:10:27 +00:00
|
|
|
assert code == 0
|
|
|
|
|
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_mysql_replacement_query(started_cluster):
|
2020-07-09 03:14:52 +00:00
|
|
|
# SHOW TABLE STATUS LIKE.
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-09 03:14:52 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default
|
|
|
|
--password=123 -e "show table status like 'xx';"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-09 03:14:52 +00:00
|
|
|
assert code == 0
|
|
|
|
|
|
|
|
# SHOW VARIABLES.
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-06 08:26:06 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default
|
|
|
|
--password=123 -e "show variables;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-06 08:26:06 +00:00
|
|
|
assert code == 0
|
|
|
|
|
2020-07-09 03:14:52 +00:00
|
|
|
# KILL QUERY.
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-06 08:26:06 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default
|
|
|
|
--password=123 -e "kill query 0;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-06 08:26:06 +00:00
|
|
|
assert code == 0
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-06 08:26:06 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default
|
|
|
|
--password=123 -e "kill query where query_id='mysql:0';"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-06 08:26:06 +00:00
|
|
|
assert code == 0
|
|
|
|
|
2020-07-09 03:14:52 +00:00
|
|
|
# SELECT DATABASE().
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-09 03:14:52 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default
|
|
|
|
--password=123 -e "select database();"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-09 03:14:52 +00:00
|
|
|
assert code == 0
|
2023-03-13 13:59:00 +00:00
|
|
|
assert stdout.decode().lower() in [
|
|
|
|
"currentdatabase()\ndefault\n",
|
|
|
|
"database()\ndefault\n",
|
|
|
|
]
|
2020-07-09 03:14:52 +00:00
|
|
|
|
2023-08-21 08:03:30 +00:00
|
|
|
# SELECT SCHEMA().
|
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default
|
|
|
|
--password=123 -e "select schema();"
|
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
|
|
|
assert code == 0
|
|
|
|
assert stdout.decode().lower() in [
|
|
|
|
"currentdatabase()\ndefault\n",
|
|
|
|
"schema()\ndefault\n",
|
|
|
|
]
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-09 03:14:52 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default
|
|
|
|
--password=123 -e "select DATABASE();"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-09 03:14:52 +00:00
|
|
|
assert code == 0
|
2023-03-13 13:59:00 +00:00
|
|
|
assert stdout.decode().lower() in [
|
|
|
|
"currentdatabase()\ndefault\n",
|
|
|
|
"database()\ndefault\n",
|
|
|
|
]
|
2020-07-09 03:14:52 +00:00
|
|
|
|
2020-07-06 08:26:06 +00:00
|
|
|
|
2021-06-25 02:20:22 +00:00
|
|
|
def test_mysql_select_user(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2021-06-25 02:20:22 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "select user();"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2021-06-25 02:20:22 +00:00
|
|
|
assert code == 0
|
2023-03-13 13:59:00 +00:00
|
|
|
assert stdout.decode() in ["currentUser()\ndefault\n", "user()\ndefault\n"]
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-06-25 02:20:22 +00:00
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_mysql_explain(started_cluster):
|
2020-07-16 08:29:17 +00:00
|
|
|
# EXPLAIN SELECT 1
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-16 08:29:17 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "EXPLAIN SELECT 1;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-16 08:29:17 +00:00
|
|
|
assert code == 0
|
|
|
|
|
|
|
|
# EXPLAIN AST SELECT 1
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-16 08:29:17 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "EXPLAIN AST SELECT 1;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-16 08:29:17 +00:00
|
|
|
assert code == 0
|
|
|
|
|
|
|
|
# EXPLAIN PLAN SELECT 1
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-16 08:29:17 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "EXPLAIN PLAN SELECT 1;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-16 08:29:17 +00:00
|
|
|
assert code == 0
|
2020-07-30 21:26:04 +00:00
|
|
|
|
2020-07-16 08:29:17 +00:00
|
|
|
# EXPLAIN PIPELINE graph=1 SELECT 1
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-07-16 08:29:17 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
|
|
|
-e "EXPLAIN PIPELINE graph=1 SELECT 1;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-07-16 08:29:17 +00:00
|
|
|
assert code == 0
|
2020-07-30 21:26:04 +00:00
|
|
|
|
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_mysql_federated(started_cluster):
|
2020-06-16 20:52:31 +00:00
|
|
|
# For some reason it occasionally fails without retries.
|
|
|
|
retries = 100
|
|
|
|
for try_num in range(retries):
|
2022-03-22 16:39:58 +00:00
|
|
|
node.query(
|
|
|
|
"""DROP DATABASE IF EXISTS mysql_federated""", settings={"password": "123"}
|
|
|
|
)
|
|
|
|
node.query("""CREATE DATABASE mysql_federated""", settings={"password": "123"})
|
|
|
|
node.query(
|
|
|
|
"""CREATE TABLE mysql_federated.test (col UInt32) ENGINE = Log""",
|
|
|
|
settings={"password": "123"},
|
|
|
|
)
|
|
|
|
node.query(
|
|
|
|
"""INSERT INTO mysql_federated.test VALUES (0), (1), (5)""",
|
|
|
|
settings={"password": "123"},
|
|
|
|
)
|
2020-06-16 20:52:31 +00:00
|
|
|
|
2020-09-08 11:20:35 +00:00
|
|
|
def check_retryable_error_in_stderr(stderr):
|
2020-10-02 16:54:07 +00:00
|
|
|
stderr = stderr.decode()
|
2022-03-22 16:39:58 +00:00
|
|
|
return (
|
|
|
|
"Can't connect to local MySQL server through socket" in stderr
|
|
|
|
or "MySQL server has gone away" in stderr
|
|
|
|
or "Server shutdown in progress" in stderr
|
|
|
|
)
|
|
|
|
|
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-06-16 20:52:31 +00:00
|
|
|
mysql
|
|
|
|
-e "DROP SERVER IF EXISTS clickhouse;"
|
|
|
|
-e "CREATE SERVER clickhouse FOREIGN DATA WRAPPER mysql
|
|
|
|
OPTIONS (USER 'default', PASSWORD '123', HOST '{host}', PORT {port}, DATABASE 'mysql_federated');"
|
|
|
|
-e "DROP DATABASE IF EXISTS mysql_federated;"
|
|
|
|
-e "CREATE DATABASE mysql_federated;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-06-16 20:52:31 +00:00
|
|
|
|
|
|
|
if code != 0:
|
2020-10-02 16:54:07 +00:00
|
|
|
print(("stdout", stdout))
|
|
|
|
print(("stderr", stderr))
|
2020-09-08 11:20:35 +00:00
|
|
|
if try_num + 1 < retries and check_retryable_error_in_stderr(stderr):
|
2020-06-16 20:52:31 +00:00
|
|
|
time.sleep(1)
|
|
|
|
continue
|
|
|
|
assert code == 0
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-06-16 20:52:31 +00:00
|
|
|
mysql
|
|
|
|
-e "CREATE TABLE mysql_federated.test(`col` int UNSIGNED) ENGINE=FEDERATED CONNECTION='clickhouse';"
|
|
|
|
-e "SELECT * FROM mysql_federated.test ORDER BY col;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-06-16 20:52:31 +00:00
|
|
|
|
|
|
|
if code != 0:
|
2020-10-02 16:54:07 +00:00
|
|
|
print(("stdout", stdout))
|
|
|
|
print(("stderr", stderr))
|
2020-09-08 11:20:35 +00:00
|
|
|
if try_num + 1 < retries and check_retryable_error_in_stderr(stderr):
|
2020-06-16 20:52:31 +00:00
|
|
|
time.sleep(1)
|
|
|
|
continue
|
|
|
|
assert code == 0
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert stdout.decode() == "\n".join(["col", "0", "1", "5", ""])
|
2020-06-16 20:52:31 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-06-16 20:52:31 +00:00
|
|
|
mysql
|
|
|
|
-e "INSERT INTO mysql_federated.test VALUES (0), (1), (5);"
|
|
|
|
-e "SELECT * FROM mysql_federated.test ORDER BY col;"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-06-16 20:52:31 +00:00
|
|
|
|
|
|
|
if code != 0:
|
2020-10-02 16:54:07 +00:00
|
|
|
print(("stdout", stdout))
|
|
|
|
print(("stderr", stderr))
|
2020-09-08 11:20:35 +00:00
|
|
|
if try_num + 1 < retries and check_retryable_error_in_stderr(stderr):
|
2020-06-16 20:52:31 +00:00
|
|
|
time.sleep(1)
|
|
|
|
continue
|
|
|
|
assert code == 0
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert stdout.decode() == "\n".join(["col", "0", "0", "1", "1", "5", "5", ""])
|
2019-05-16 03:34:04 +00:00
|
|
|
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_mysql_set_variables(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
2020-09-04 04:51:15 +00:00
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
|
2020-09-08 11:20:35 +00:00
|
|
|
-e
|
2020-09-04 04:51:15 +00:00
|
|
|
"
|
|
|
|
SET NAMES=default;
|
|
|
|
SET character_set_results=default;
|
|
|
|
SET FOREIGN_KEY_CHECKS=false;
|
|
|
|
SET AUTOCOMMIT=1;
|
|
|
|
SET sql_mode='strict';
|
|
|
|
SET @@wait_timeout = 2147483;
|
|
|
|
SET SESSION TRANSACTION ISOLATION LEVEL READ;
|
|
|
|
"
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2020-09-04 04:51:15 +00:00
|
|
|
assert code == 0
|
|
|
|
|
|
|
|
|
2023-10-09 18:30:28 +00:00
|
|
|
def test_mysql_boolean_format(started_cluster):
|
|
|
|
node.query(
|
|
|
|
"""
|
|
|
|
CREATE OR REPLACE TABLE mysql_boolean_format_test
|
|
|
|
(
|
|
|
|
`a` Bool,
|
|
|
|
`b` Nullable(Bool),
|
|
|
|
`c` LowCardinality(Nullable(Bool))
|
|
|
|
) ENGINE MergeTree ORDER BY a;
|
|
|
|
""",
|
|
|
|
settings={"password": "123", "allow_suspicious_low_cardinality_types": 1},
|
|
|
|
)
|
|
|
|
node.query(
|
|
|
|
"INSERT INTO mysql_boolean_format_test VALUES (false, true, false), (true, false, true);",
|
|
|
|
settings={"password": "123"},
|
|
|
|
)
|
|
|
|
code, (stdout, stderr) = started_cluster.mysql_client_container.exec_run(
|
|
|
|
"""
|
|
|
|
mysql --protocol tcp -h {host} -P {port} default -u user_with_double_sha1 --password=abacaba
|
|
|
|
-e "SELECT * FROM mysql_boolean_format_test;"
|
|
|
|
""".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
|
|
|
logging.debug(
|
|
|
|
f"test_mysql_boolean_format code:{code} stdout:{stdout}, stderr:{stderr}"
|
|
|
|
)
|
|
|
|
assert stdout.decode() == "a\tb\tc\n" + "0\t1\t0\n" + "1\t0\t1\n"
|
|
|
|
|
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_python_client(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
client = pymysql.connections.Connection(
|
|
|
|
host=started_cluster.get_instance_ip("node"),
|
|
|
|
user="user_with_double_sha1",
|
|
|
|
password="abacaba",
|
|
|
|
database="default",
|
|
|
|
port=server_port,
|
|
|
|
)
|
2019-12-01 11:21:43 +00:00
|
|
|
|
|
|
|
with pytest.raises(pymysql.InternalError) as exc_info:
|
2022-03-22 16:39:58 +00:00
|
|
|
client.query("select name from tables")
|
2019-12-01 11:21:43 +00:00
|
|
|
|
2023-03-13 13:59:00 +00:00
|
|
|
resp = exc_info.value.args[1]
|
2023-03-15 09:38:40 +00:00
|
|
|
assert fnmatch.fnmatch(resp, "*DB::Exception:*tables*UNKNOWN_TABLE*"), resp
|
2019-12-01 11:21:43 +00:00
|
|
|
|
|
|
|
cursor = client.cursor(pymysql.cursors.DictCursor)
|
|
|
|
cursor.execute("select 1 as a, 'тест' as b")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert cursor.fetchall() == [{"a": 1, "b": "тест"}]
|
2019-12-01 11:21:43 +00:00
|
|
|
|
2019-04-02 22:21:44 +00:00
|
|
|
with pytest.raises(pymysql.InternalError) as exc_info:
|
2022-03-22 16:39:58 +00:00
|
|
|
pymysql.connections.Connection(
|
|
|
|
host=started_cluster.get_instance_ip("node"),
|
|
|
|
user="default",
|
|
|
|
password="abacab",
|
|
|
|
database="default",
|
|
|
|
port=server_port,
|
|
|
|
)
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-11-29 14:33:02 +00:00
|
|
|
assert exc_info.value.args[0] == 516
|
2022-11-29 14:48:05 +00:00
|
|
|
assert (
|
|
|
|
"default: Authentication failed: password is incorrect, or there is no user with such name"
|
|
|
|
in exc_info.value.args[1]
|
|
|
|
)
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
client = pymysql.connections.Connection(
|
|
|
|
host=started_cluster.get_instance_ip("node"),
|
|
|
|
user="default",
|
|
|
|
password="123",
|
|
|
|
database="default",
|
|
|
|
port=server_port,
|
|
|
|
)
|
2019-04-02 22:21:44 +00:00
|
|
|
|
|
|
|
with pytest.raises(pymysql.InternalError) as exc_info:
|
2022-03-22 16:39:58 +00:00
|
|
|
client.query("select name from tables")
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2023-03-13 13:59:00 +00:00
|
|
|
resp = exc_info.value.args[1]
|
2023-03-15 09:38:40 +00:00
|
|
|
assert fnmatch.fnmatch(resp, "*DB::Exception:*tables*UNKNOWN_TABLE*"), resp
|
2019-04-02 22:21:44 +00:00
|
|
|
|
|
|
|
cursor = client.cursor(pymysql.cursors.DictCursor)
|
|
|
|
cursor.execute("select 1 as a, 'тест' as b")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert cursor.fetchall() == [{"a": 1, "b": "тест"}]
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
client.select_db("system")
|
2019-04-02 22:21:44 +00:00
|
|
|
|
|
|
|
with pytest.raises(pymysql.InternalError) as exc_info:
|
2022-03-22 16:39:58 +00:00
|
|
|
client.select_db("system2")
|
2019-04-02 22:21:44 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert exc_info.value.args[1].startswith(
|
2023-08-11 10:24:16 +00:00
|
|
|
"Code: 81. DB::Exception: Database system2 does not exist"
|
2022-03-22 16:39:58 +00:00
|
|
|
), exc_info.value.args[1]
|
2019-04-07 10:29:30 +00:00
|
|
|
|
2019-05-16 03:34:04 +00:00
|
|
|
cursor = client.cursor(pymysql.cursors.DictCursor)
|
2022-03-22 16:39:58 +00:00
|
|
|
cursor.execute("CREATE DATABASE x")
|
|
|
|
client.select_db("x")
|
2019-06-16 07:55:14 +00:00
|
|
|
cursor.execute("CREATE TABLE table1 (a UInt32) ENGINE = Memory")
|
2019-05-16 03:34:04 +00:00
|
|
|
cursor.execute("INSERT INTO table1 VALUES (1), (3)")
|
|
|
|
cursor.execute("INSERT INTO table1 VALUES (1), (4)")
|
|
|
|
cursor.execute("SELECT * FROM table1 ORDER BY a")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert cursor.fetchall() == [{"a": 1}, {"a": 1}, {"a": 3}, {"a": 4}]
|
2019-05-16 03:34:04 +00:00
|
|
|
|
2019-04-07 10:29:30 +00:00
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_golang_client(started_cluster, golang_container):
|
2022-03-22 16:39:58 +00:00
|
|
|
with open(os.path.join(SCRIPT_DIR, "golang.reference"), "rb") as fp:
|
2019-12-01 11:21:43 +00:00
|
|
|
reference = fp.read()
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (stdout, stderr) = golang_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"./main --host {host} --port {port} --user default --password 123 --database "
|
|
|
|
"abc".format(host=started_cluster.get_instance_ip("node"), port=server_port),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-04-07 10:29:30 +00:00
|
|
|
|
|
|
|
assert code == 1
|
2023-08-11 10:24:16 +00:00
|
|
|
assert stderr.decode() == "Error 81: Database abc does not exist\n"
|
2019-04-07 10:29:30 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (stdout, stderr) = golang_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"./main --host {host} --port {port} --user default --password 123 --database "
|
|
|
|
"default".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-04-07 10:29:30 +00:00
|
|
|
|
|
|
|
assert code == 0
|
2019-12-01 11:21:43 +00:00
|
|
|
assert stdout == reference
|
2019-04-07 10:29:30 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (stdout, stderr) = golang_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"./main --host {host} --port {port} --user user_with_double_sha1 --password abacaba --database "
|
|
|
|
"default".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-12-01 11:21:43 +00:00
|
|
|
assert code == 0
|
|
|
|
assert stdout == reference
|
2019-07-21 12:09:41 +00:00
|
|
|
|
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_php_client(started_cluster, php_container):
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (stdout, stderr) = php_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"php -f test.php {host} {port} default 123".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-07-21 12:09:41 +00:00
|
|
|
assert code == 0
|
2023-08-01 13:34:19 +00:00
|
|
|
assert stdout.decode() == "tables\ntables\ntables\n"
|
2019-07-23 07:10:06 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (stdout, stderr) = php_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"php -f test_ssl.php {host} {port} default 123".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-07-23 07:10:06 +00:00
|
|
|
assert code == 0
|
2023-08-01 13:34:19 +00:00
|
|
|
assert stdout.decode() == "tables\ntables\ntables\n"
|
2019-12-01 11:21:43 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (stdout, stderr) = php_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"php -f test.php {host} {port} user_with_double_sha1 abacaba".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-12-01 11:21:43 +00:00
|
|
|
assert code == 0
|
2023-08-01 13:34:19 +00:00
|
|
|
assert stdout.decode() == "tables\ntables\ntables\n"
|
2019-12-01 11:21:43 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (stdout, stderr) = php_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"php -f test_ssl.php {host} {port} user_with_double_sha1 abacaba".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-12-01 11:21:43 +00:00
|
|
|
assert code == 0
|
2023-08-01 13:34:19 +00:00
|
|
|
assert stdout.decode() == "tables\ntables\ntables\n"
|
2019-07-28 13:12:26 +00:00
|
|
|
|
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_mysqljs_client(started_cluster, nodejs_container):
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (_, stderr) = nodejs_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"node test.js {host} {port} user_with_sha256 abacaba".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-07-28 14:17:33 +00:00
|
|
|
assert code == 1
|
2022-03-22 16:39:58 +00:00
|
|
|
assert (
|
|
|
|
"MySQL is requesting the sha256_password authentication method, which is not supported."
|
|
|
|
in stderr.decode()
|
|
|
|
)
|
2019-07-28 13:12:26 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (_, stderr) = nodejs_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
'node test.js {host} {port} user_with_empty_password ""'.format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-12-06 01:30:01 +00:00
|
|
|
assert code == 0
|
2019-07-28 13:12:26 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (_, _) = nodejs_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"node test.js {host} {port} user_with_double_sha1 abacaba".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-07-28 13:12:26 +00:00
|
|
|
assert code == 0
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
code, (_, _) = nodejs_container.exec_run(
|
2022-03-22 16:39:58 +00:00
|
|
|
"node test.js {host} {port} user_with_empty_password 123".format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port
|
|
|
|
),
|
|
|
|
demux=True,
|
|
|
|
)
|
2019-07-28 13:12:26 +00:00
|
|
|
assert code == 1
|
2019-12-08 05:40:08 +00:00
|
|
|
|
|
|
|
|
2023-10-10 17:51:09 +00:00
|
|
|
def test_java_client_text(started_cluster, java_container):
|
|
|
|
command = setup_java_client(started_cluster, "false")
|
|
|
|
code, (stdout, stderr) = java_container.exec_run(
|
|
|
|
command,
|
|
|
|
demux=True,
|
|
|
|
)
|
|
|
|
|
2023-11-15 15:53:38 +00:00
|
|
|
with open(os.path.join(SCRIPT_DIR, "java_client.reference")) as fp:
|
2023-08-30 16:59:39 +00:00
|
|
|
reference = fp.read()
|
|
|
|
|
2023-10-10 17:51:09 +00:00
|
|
|
assert stdout.decode() == reference
|
|
|
|
assert code == 0
|
2023-08-31 11:26:27 +00:00
|
|
|
|
2023-08-30 16:59:39 +00:00
|
|
|
|
2023-10-10 17:51:09 +00:00
|
|
|
def test_java_client_binary(started_cluster, java_container):
|
|
|
|
command = setup_java_client(started_cluster, "true")
|
2023-08-30 16:59:39 +00:00
|
|
|
code, (stdout, stderr) = java_container.exec_run(
|
2023-10-10 17:51:09 +00:00
|
|
|
command,
|
2023-08-30 16:59:39 +00:00
|
|
|
demux=True,
|
|
|
|
)
|
2023-10-10 17:51:09 +00:00
|
|
|
|
2023-11-15 15:53:38 +00:00
|
|
|
with open(os.path.join(SCRIPT_DIR, "java_client.reference")) as fp:
|
2023-10-10 17:51:09 +00:00
|
|
|
reference = fp.read()
|
|
|
|
|
2023-08-30 16:59:39 +00:00
|
|
|
assert stdout.decode() == reference
|
2023-10-10 17:51:09 +00:00
|
|
|
assert code == 0
|
2023-08-30 16:59:39 +00:00
|
|
|
|
|
|
|
|
2021-04-13 14:55:31 +00:00
|
|
|
def test_types(started_cluster):
|
2022-03-22 16:39:58 +00:00
|
|
|
client = pymysql.connections.Connection(
|
|
|
|
host=started_cluster.get_instance_ip("node"),
|
|
|
|
user="default",
|
|
|
|
password="123",
|
|
|
|
database="default",
|
|
|
|
port=server_port,
|
|
|
|
)
|
2019-12-08 05:40:08 +00:00
|
|
|
|
|
|
|
cursor = client.cursor(pymysql.cursors.DictCursor)
|
|
|
|
cursor.execute(
|
|
|
|
"select "
|
|
|
|
"toInt8(-pow(2, 7)) as Int8_column, "
|
|
|
|
"toUInt8(pow(2, 8) - 1) as UInt8_column, "
|
|
|
|
"toInt16(-pow(2, 15)) as Int16_column, "
|
|
|
|
"toUInt16(pow(2, 16) - 1) as UInt16_column, "
|
|
|
|
"toInt32(-pow(2, 31)) as Int32_column, "
|
|
|
|
"toUInt32(pow(2, 32) - 1) as UInt32_column, "
|
|
|
|
"toInt64('-9223372036854775808') as Int64_column, " # -2^63
|
|
|
|
"toUInt64('18446744073709551615') as UInt64_column, " # 2^64 - 1
|
|
|
|
"'тест' as String_column, "
|
|
|
|
"toFixedString('тест', 8) as FixedString_column, "
|
|
|
|
"toFloat32(1.5) as Float32_column, "
|
|
|
|
"toFloat64(1.5) as Float64_column, "
|
|
|
|
"toFloat32(NaN) as Float32_NaN_column, "
|
|
|
|
"-Inf as Float64_Inf_column, "
|
|
|
|
"toDate('2019-12-08') as Date_column, "
|
|
|
|
"toDate('1970-01-01') as Date_min_column, "
|
|
|
|
"toDate('1970-01-02') as Date_after_min_column, "
|
|
|
|
"toDateTime('2019-12-08 08:24:03') as DateTime_column"
|
|
|
|
)
|
|
|
|
|
|
|
|
result = cursor.fetchall()[0]
|
|
|
|
expected = [
|
2023-09-04 20:05:51 +00:00
|
|
|
("Int8_column", -(2**7)),
|
|
|
|
("UInt8_column", 2**8 - 1),
|
|
|
|
("Int16_column", -(2**15)),
|
|
|
|
("UInt16_column", 2**16 - 1),
|
|
|
|
("Int32_column", -(2**31)),
|
|
|
|
("UInt32_column", 2**32 - 1),
|
|
|
|
("Int64_column", -(2**63)),
|
|
|
|
("UInt64_column", 2**64 - 1),
|
2022-03-22 16:39:58 +00:00
|
|
|
("String_column", "тест"),
|
|
|
|
("FixedString_column", "тест"),
|
|
|
|
("Float32_column", 1.5),
|
|
|
|
("Float64_column", 1.5),
|
|
|
|
("Float32_NaN_column", float("nan")),
|
|
|
|
("Float64_Inf_column", float("-inf")),
|
|
|
|
("Date_column", datetime.date(2019, 12, 8)),
|
|
|
|
("Date_min_column", datetime.date(1970, 1, 1)),
|
|
|
|
("Date_after_min_column", datetime.date(1970, 1, 2)),
|
|
|
|
("DateTime_column", datetime.datetime(2019, 12, 8, 8, 24, 3)),
|
2019-12-08 05:40:08 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for key, value in expected:
|
|
|
|
if isinstance(value, float) and math.isnan(value):
|
|
|
|
assert math.isnan(result[key])
|
|
|
|
else:
|
|
|
|
assert result[key] == value
|
2023-10-10 17:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup_java_client(started_cluster, binary: Literal["true", "false"]):
|
|
|
|
with open(os.path.join(SCRIPT_DIR, "java_client_test.sql")) as sql:
|
|
|
|
statements = list(
|
|
|
|
filter(
|
|
|
|
lambda s: s != "",
|
|
|
|
map(lambda s: s.strip().replace("\n", " "), sql.read().split(";")),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
for statement in statements:
|
|
|
|
node.query(
|
|
|
|
statement,
|
|
|
|
settings={"password": "123", "allow_suspicious_low_cardinality_types": 1},
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
"java MySQLJavaClientTest "
|
|
|
|
"--host {host} "
|
|
|
|
"--port {port} "
|
|
|
|
"--user user_with_double_sha1 "
|
|
|
|
"--password abacaba "
|
|
|
|
"--database default "
|
|
|
|
"--binary {binary}"
|
|
|
|
).format(
|
|
|
|
host=started_cluster.get_instance_ip("node"), port=server_port, binary=binary
|
|
|
|
)
|