ClickHouse/tests/integration/test_disabled_mysql_server/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.5 KiB
Python
Raw Normal View History

2020-10-20 18:12:37 +00:00
import contextlib
import os
import subprocess
2024-09-27 10:19:39 +00:00
import time
import pymysql.cursors
import pytest
2020-10-20 18:12:37 +00:00
from helpers.client import QueryRuntimeException
from helpers.cluster import ClickHouseCluster, get_docker_compose_path
from helpers.network import PartitionManager
cluster = ClickHouseCluster(__file__)
clickhouse_node = cluster.add_instance(
"node1", main_configs=["configs/remote_servers.xml"], with_mysql8=True
2020-10-20 18:12:37 +00:00
)
2020-10-20 18:12:37 +00:00
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
class MySQLNodeInstance:
2021-03-16 10:00:49 +00:00
def __init__(self, started_cluster, user="root", password="clickhouse"):
2020-10-20 18:12:37 +00:00
self.user = user
self.port = cluster.mysql8_port
self.hostname = cluster.mysql8_ip
2020-10-20 18:12:37 +00:00
self.password = password
2020-10-28 19:44:37 +00:00
self.mysql_connection = None # lazy init
2020-10-20 18:12:37 +00:00
def alloc_connection(self):
if self.mysql_connection is None:
self.mysql_connection = pymysql.connect(
user=self.user,
password=self.password,
host=self.hostname,
port=self.port,
autocommit=True,
)
return self.mysql_connection
def query(self, execution_query):
with self.alloc_connection().cursor() as cursor:
cursor.execute(execution_query)
def close(self):
if self.mysql_connection is not None:
self.mysql_connection.close()
def test_disabled_mysql_server(started_cluster):
2021-03-16 10:00:49 +00:00
with contextlib.closing(MySQLNodeInstance(started_cluster)) as mysql_node:
2021-02-15 09:35:45 +00:00
mysql_node.query("DROP DATABASE IF EXISTS test_db_disabled;")
mysql_node.query("CREATE DATABASE test_db_disabled;")
mysql_node.query(
"CREATE TABLE test_db_disabled.test_table ( `id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB;"
)
2020-10-20 18:12:37 +00:00
with PartitionManager() as pm:
2021-02-15 09:35:45 +00:00
clickhouse_node.query(
"CREATE DATABASE test_db_disabled ENGINE = MySQL('mysql80:3306', 'test_db_disabled', 'root', 'clickhouse')"
2021-02-15 09:35:45 +00:00
)
2020-10-20 18:12:37 +00:00
pm._add_rule(
{
2020-10-20 18:12:37 +00:00
"source": clickhouse_node.ip_address,
"destination_port": 3306,
"action": "DROP",
}
2020-10-20 18:12:37 +00:00
)
clickhouse_node.query("SELECT * FROM system.parts")
clickhouse_node.query("SELECT * FROM system.mutations")
clickhouse_node.query("SELECT * FROM system.graphite_retentions")
2021-02-15 09:35:45 +00:00
clickhouse_node.query("DROP DATABASE test_db_disabled")