This commit is contained in:
Yatsishin Ilya 2023-01-03 21:28:54 +00:00
parent 14274d650b
commit bbc02c0762
2 changed files with 82 additions and 33 deletions

View File

@ -206,6 +206,7 @@ def check_kafka_is_available(kafka_id, kafka_port):
p.communicate()
return p.returncode == 0
def check_postgresql_java_client_is_available(postgresql_java_client_id):
p = subprocess.Popen(
("docker", "exec", "-i", postgresql_java_client_id, "java", "-version"),
@ -214,6 +215,7 @@ def check_postgresql_java_client_is_available(postgresql_java_client_id):
p.communicate()
return p.returncode == 0
def check_rabbitmq_is_available(rabbitmq_id):
p = subprocess.Popen(
("docker", "exec", "-i", rabbitmq_id, "rabbitmqctl", "await_startup"),
@ -526,7 +528,9 @@ class ClickHouseCluster:
# available when with_postgresql_java_client = True
self.postgresql_java_client_host = "java"
self.postgresql_java_client_docker_id = self.get_instance_docker_id(self.postgresql_java_client_host)
self.postgresql_java_client_docker_id = self.get_instance_docker_id(
self.postgresql_java_client_host
)
# available when with_mysql_client == True
self.mysql_client_host = "mysql_client"
@ -981,7 +985,9 @@ class ClickHouseCluster:
self.base_cmd.extend(
[
"--file",
p.join(docker_compose_yml_dir, "docker_compose_postgresql_java_client.yml"),
p.join(
docker_compose_yml_dir, "docker_compose_postgresql_java_client.yml"
),
]
)
self.base_postgresql_java_client_cmd = [
@ -1366,7 +1372,7 @@ class ClickHouseCluster:
with_odbc_drivers=False,
with_postgres=False,
with_postgres_cluster=False,
with_postgresql_java_client = False,
with_postgresql_java_client=False,
with_hdfs=False,
with_kerberized_hdfs=False,
with_mongo=False,
@ -2058,7 +2064,9 @@ class ClickHouseCluster:
start = time.time()
while time.time() - start < timeout:
try:
if check_postgresql_java_client_is_available(self.postgresql_java_client_docker_id):
if check_postgresql_java_client_is_available(
self.postgresql_java_client_docker_id
):
logging.debug("PostgreSQL Java Client is available")
return True
time.sleep(0.5)
@ -2369,7 +2377,9 @@ class ClickHouseCluster:
if not os.path.exists(self.instances_dir):
os.mkdir(self.instances_dir)
else:
logging.warning("Instance directory already exists. Did you call cluster.start() for second time?")
logging.warning(
"Instance directory already exists. Did you call cluster.start() for second time?"
)
logging.debug(f"Cluster start called. is_up={self.is_up}")
self.print_all_docker_pieces()
@ -2515,9 +2525,14 @@ class ClickHouseCluster:
self.up_called = True
self.wait_postgres_cluster_to_start()
if self.with_postgresql_java_client and self.base_postgresql_java_client_cmd:
if (
self.with_postgresql_java_client
and self.base_postgresql_java_client_cmd
):
logging.debug("Setup Postgres Java Client")
subprocess_check_call(self.base_postgresql_java_client_cmd + common_opts)
subprocess_check_call(
self.base_postgresql_java_client_cmd + common_opts
)
self.up_called = True
self.wait_postgresql_java_client()

View File

@ -35,6 +35,7 @@ cluster.add_instance(
server_port = 5433
@pytest.fixture(scope="module")
def started_cluster():
try:
@ -47,43 +48,65 @@ def started_cluster():
finally:
cluster.shutdown()
def test_psql_client(started_cluster):
node = cluster.instances["node"]
for query_file in ['query1.sql', 'query2.sql', 'query3.sql', 'query4.sql']:
started_cluster.copy_file_to_container(started_cluster.postgres_id, os.path.join(SCRIPT_DIR, 'queries', query_file), f'/{query_file}')
cmd_prefix = ['/usr/bin/psql', f"sslmode=require host={node.hostname} port={server_port} user=default dbname=default password=123"]
for query_file in ["query1.sql", "query2.sql", "query3.sql", "query4.sql"]:
started_cluster.copy_file_to_container(
started_cluster.postgres_id,
os.path.join(SCRIPT_DIR, "queries", query_file),
f"/{query_file}",
)
cmd_prefix = [
"/usr/bin/psql",
f"sslmode=require host={node.hostname} port={server_port} user=default dbname=default password=123",
]
cmd_prefix += ["--no-align", "--field-separator=' '"]
res = started_cluster.exec_in_container(started_cluster.postgres_id,
cmd_prefix + ['-f', '/query1.sql'],
shell=True
res = started_cluster.exec_in_container(
started_cluster.postgres_id, cmd_prefix + ["-f", "/query1.sql"], shell=True
)
logging.debug(res)
assert res == "\n".join(["a", "1", "(1 row)", ""])
res = started_cluster.exec_in_container(started_cluster.postgres_id,
cmd_prefix + ['-f', '/query2.sql'],
shell=True
res = started_cluster.exec_in_container(
started_cluster.postgres_id, cmd_prefix + ["-f", "/query2.sql"], shell=True
)
logging.debug(res)
assert res == "\n".join(["a", "колонка", "(1 row)", ""])
res = started_cluster.exec_in_container(started_cluster.postgres_id,
cmd_prefix + ['-f', '/query3.sql'],
shell=True
res = started_cluster.exec_in_container(
started_cluster.postgres_id, cmd_prefix + ["-f", "/query3.sql"], shell=True
)
logging.debug(res)
assert res == "\n".join(
["SELECT 0","SELECT 0","SELECT 0","INSERT 0 0", "INSERT 0 0", "column", "0", "0", "1", "1", "5", "5", "(6 rows)", "SELECT 0\n"]
[
"SELECT 0",
"SELECT 0",
"SELECT 0",
"INSERT 0 0",
"INSERT 0 0",
"column",
"0",
"0",
"1",
"1",
"5",
"5",
"(6 rows)",
"SELECT 0\n",
]
)
res = started_cluster.exec_in_container(started_cluster.postgres_id,
cmd_prefix + ['-f', '/query4.sql'],
shell=True
res = started_cluster.exec_in_container(
started_cluster.postgres_id, cmd_prefix + ["-f", "/query4.sql"], shell=True
)
logging.debug(res)
assert res == "\n".join(["SELECT 0","INSERT 0 0","tmp_column", "0", "1", "(2 rows)", "SELECT 0\n"])
assert res == "\n".join(
["SELECT 0", "INSERT 0 0", "tmp_column", "0", "1", "(2 rows)", "SELECT 0\n"]
)
def test_python_client(started_cluster):
node = cluster.instances["node"]
@ -134,9 +157,7 @@ def test_python_client(started_cluster):
decimal.Decimal("0.3333330000"),
uuid.UUID("61f0c404-5cb3-11e7-907b-a6006ad3dba0"),
)
cur.execute(
"DROP DATABASE x"
)
cur.execute("DROP DATABASE x")
def test_java_client(started_cluster):
@ -147,13 +168,26 @@ def test_java_client(started_cluster):
# database not exists exception.
with pytest.raises(Exception) as exc:
res = started_cluster.exec_in_container(started_cluster.postgresql_java_client_docker_id,
["bash", "-c", f"java JavaConnectorTest --host {node.hostname} --port {server_port} --user default --database abc"],
)
assert 'org.postgresql.util.PSQLException: ERROR: Invalid user or password' in str(exc.value)
res = started_cluster.exec_in_container(
started_cluster.postgresql_java_client_docker_id,
[
"bash",
"-c",
f"java JavaConnectorTest --host {node.hostname} --port {server_port} --user default --database abc",
],
)
assert (
"org.postgresql.util.PSQLException: ERROR: Invalid user or password"
in str(exc.value)
)
# non-empty password passed.
res= started_cluster.exec_in_container(started_cluster.postgresql_java_client_docker_id,
["bash", "-c", f"java JavaConnectorTest --host {node.hostname} --port {server_port} --user default --password 123 --database default"]
res = started_cluster.exec_in_container(
started_cluster.postgresql_java_client_docker_id,
[
"bash",
"-c",
f"java JavaConnectorTest --host {node.hostname} --port {server_port} --user default --password 123 --database default",
],
)
assert res == reference