提交 7c37450c 编写于 作者: A alesapin

Better code and tests

上级 5b4b8754
......@@ -441,6 +441,7 @@ namespace ErrorCodes
extern const int CANNOT_PARSE_ELF = 464;
extern const int CANNOT_PARSE_DWARF = 465;
extern const int INSECURE_PATH = 466;
extern const int CANNOT_PARSE_BOOL = 467;
extern const int KEEPER_EXCEPTION = 999;
extern const int POCO_EXCEPTION = 1000;
......
......@@ -4,6 +4,7 @@
#include <Common/getNumberOfPhysicalCPUCores.h>
#include <Common/FieldVisitors.h>
#include <IO/ReadHelpers.h>
#include <IO/ReadBufferFromString.h>
#include <IO/WriteHelpers.h>
......@@ -26,6 +27,7 @@ namespace ErrorCodes
extern const int SIZE_OF_FIXED_STRING_DOESNT_MATCH;
extern const int BAD_ARGUMENTS;
extern const int UNKNOWN_SETTING;
extern const int CANNOT_PARSE_BOOL;
}
......@@ -66,12 +68,25 @@ void SettingNumber<Type>::set(const String & x)
template <>
void SettingNumber<bool>::set(const String & x)
{
if (x == "false")
set(false);
else if (x == "true")
set(true);
if (x.size() == 1)
{
if (x[0] == '0')
set(false);
else if (x[0] == '1')
set(true);
else
throw Exception("Cannot parse bool from string '" + x + "'", ErrorCodes::CANNOT_PARSE_BOOL);
}
else
set(parse<bool>(x));
{
ReadBufferFromString buf(x);
if (checkStringCaseInsensitive("true", buf))
set(true);
else if (checkStringCaseInsensitive("false", buf))
set(false);
else
throw Exception("Cannot parse bool from string '" + x + "'", ErrorCodes::CANNOT_PARSE_BOOL);
}
}
template <typename Type>
......
<yandex>
<merge_tree>
<replicated_can_become_leader>false</replicated_can_become_leader>
<replicated_can_become_leader>0</replicated_can_become_leader>
</merge_tree>
</yandex>
<yandex>
<merge_tree>
<replicated_can_become_leader>FAlse</replicated_can_become_leader>
</merge_tree>
</yandex>
import pytest
from helpers.cluster import ClickHouseCluster
from helpers.client import QueryRuntimeException
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance('node1', main_configs=['configs/notleader.xml'], with_zookeeper=True)
node2 = cluster.add_instance('node2', with_zookeeper=True)
node2 = cluster.add_instance('node2', main_configs=['configs/notleaderignorecase.xml'], with_zookeeper=True)
node3 = cluster.add_instance('node3', with_zookeeper=True)
@pytest.fixture(scope="module")
......@@ -12,7 +13,7 @@ def start_cluster():
try:
cluster.start()
for i, node in enumerate((node1, node2, node3)):
for i, node in enumerate((node1, node2)):
node.query(
'''
CREATE TABLE test_table(date Date, id UInt32, dummy UInt32)
......@@ -21,6 +22,15 @@ def start_cluster():
'''.format(i)
)
with pytest.raises(QueryRuntimeException):
node3.query(
'''
CREATE TABLE test_table(date Date, id UInt32, dummy UInt32)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_table', '{}')
PARTITION BY date ORDER BY id SETTINGS replicated_can_become_leader=0sad
'''.format(3)
)
yield cluster
finally:
......@@ -29,5 +39,4 @@ def start_cluster():
def test_can_become_leader(start_cluster):
assert node1.query("select can_become_leader from system.replicas where table = 'test_table'") == '0\n'
assert node2.query("select can_become_leader from system.replicas where table = 'test_table'") == '1\n'
assert node3.query("select can_become_leader from system.replicas where table = 'test_table'") == '1\n'
assert node2.query("select can_become_leader from system.replicas where table = 'test_table'") == '0\n'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册