2019-04-07 00:31:20 +00:00
|
|
|
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
instance = cluster.add_instance('instance',
|
|
|
|
config_dir="configs")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
2019-10-31 08:45:14 +00:00
|
|
|
def test_system_settings(started_cluster):
|
|
|
|
assert instance.query("SELECT name, value, min, max, readonly from system.settings WHERE name = 'force_index_by_date'") ==\
|
|
|
|
"force_index_by_date\t0\t\\N\t\\N\t1\n"
|
|
|
|
|
|
|
|
assert instance.query("SELECT name, value, min, max, readonly from system.settings WHERE name = 'max_memory_usage'") ==\
|
2019-10-30 21:37:28 +00:00
|
|
|
"max_memory_usage\t10000000000\t5000000000\t20000000000\t0\n"
|
|
|
|
|
2019-10-31 08:45:14 +00:00
|
|
|
assert instance.query("SELECT name, value, min, max, readonly from system.settings WHERE name = 'readonly'") ==\
|
|
|
|
"readonly\t0\t\\N\t\\N\t0\n"
|
|
|
|
|
2019-10-30 21:37:28 +00:00
|
|
|
|
2019-04-24 15:03:15 +00:00
|
|
|
def test_read_only_constraint(started_cluster):
|
|
|
|
# Change a setting for session with SET.
|
|
|
|
assert instance.query("SELECT value FROM system.settings WHERE name='force_index_by_date'") ==\
|
|
|
|
"0\n"
|
|
|
|
|
|
|
|
expected_error = "Setting force_index_by_date should not be changed"
|
|
|
|
assert expected_error in instance.query_and_get_error("SET force_index_by_date=1")
|
|
|
|
|
|
|
|
# Change a setting for query with SETTINGS.
|
|
|
|
assert instance.query("SELECT value FROM system.settings WHERE name='force_index_by_date'") ==\
|
|
|
|
"0\n"
|
|
|
|
|
|
|
|
assert expected_error in instance.query_and_get_error(
|
|
|
|
"SELECT value FROM system.settings WHERE name='force_index_by_date' "
|
|
|
|
"SETTINGS force_index_by_date=1")
|
|
|
|
|
|
|
|
|
|
|
|
def test_min_constraint(started_cluster):
|
|
|
|
# Change a setting for session with SET.
|
|
|
|
assert instance.query("SELECT value FROM system.settings WHERE name='max_memory_usage'") ==\
|
|
|
|
"10000000000\n"
|
|
|
|
|
|
|
|
assert instance.query("SET max_memory_usage=5000000000;\n"
|
|
|
|
"SELECT value FROM system.settings WHERE name='max_memory_usage'") ==\
|
|
|
|
"5000000000\n"
|
|
|
|
|
|
|
|
expected_error = "Setting max_memory_usage shouldn't be less than 5000000000"
|
|
|
|
assert expected_error in instance.query_and_get_error("SET max_memory_usage=4999999999")
|
|
|
|
|
|
|
|
# Change a setting for query with SETTINGS.
|
|
|
|
assert instance.query("SELECT value FROM system.settings WHERE name='max_memory_usage'") ==\
|
|
|
|
"10000000000\n"
|
|
|
|
|
|
|
|
assert instance.query("SET max_memory_usage=5000000001;\n"
|
|
|
|
"SELECT value FROM system.settings WHERE name='max_memory_usage'") ==\
|
|
|
|
"5000000001\n"
|
|
|
|
|
|
|
|
assert expected_error in instance.query_and_get_error(
|
|
|
|
"SELECT value FROM system.settings WHERE name='max_memory_usage' "
|
|
|
|
"SETTINGS max_memory_usage=4999999999")
|
|
|
|
|
|
|
|
|
2019-04-07 00:31:20 +00:00
|
|
|
def test_max_constraint(started_cluster):
|
|
|
|
# Change a setting for session with SET.
|
|
|
|
assert instance.query("SELECT value FROM system.settings WHERE name='max_memory_usage'") ==\
|
|
|
|
"10000000000\n"
|
|
|
|
|
|
|
|
assert instance.query("SET max_memory_usage=20000000000;\n"
|
|
|
|
"SELECT value FROM system.settings WHERE name='max_memory_usage'") ==\
|
|
|
|
"20000000000\n"
|
|
|
|
|
|
|
|
expected_error = "Setting max_memory_usage shouldn't be greater than 20000000000"
|
|
|
|
assert expected_error in instance.query_and_get_error("SET max_memory_usage=20000000001")
|
|
|
|
|
2019-04-24 15:03:15 +00:00
|
|
|
# Change a setting for query with SETTINGS.
|
2019-04-07 00:31:20 +00:00
|
|
|
assert instance.query("SELECT value FROM system.settings WHERE name='max_memory_usage'") ==\
|
|
|
|
"10000000000\n"
|
|
|
|
|
|
|
|
assert instance.query("SELECT value FROM system.settings WHERE name='max_memory_usage' "
|
2019-04-24 15:03:15 +00:00
|
|
|
"SETTINGS max_memory_usage=19999999999") == "19999999999\n"
|
2019-04-07 00:31:20 +00:00
|
|
|
|
|
|
|
assert expected_error in instance.query_and_get_error(
|
|
|
|
"SELECT value FROM system.settings WHERE name='max_memory_usage' "
|
|
|
|
"SETTINGS max_memory_usage=20000000001")
|
2019-04-24 15:03:15 +00:00
|
|
|
|