From 96df26a4d2367ca58c8044fb1642c6806445939c Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Wed, 24 Jul 2019 14:46:50 +0300 Subject: [PATCH] Add test for reloading a dictionary after fail by timer. --- .../dictionaries/dictionary_preset_file.xml | 17 ++++++++++ .../integration/test_dictionaries/test.py | 31 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/dbms/tests/integration/test_dictionaries/configs/dictionaries/dictionary_preset_file.xml b/dbms/tests/integration/test_dictionaries/configs/dictionaries/dictionary_preset_file.xml index 14b82305b4d..d04d0be3f90 100644 --- a/dbms/tests/integration/test_dictionaries/configs/dictionaries/dictionary_preset_file.xml +++ b/dbms/tests/integration/test_dictionaries/configs/dictionaries/dictionary_preset_file.xml @@ -33,4 +33,21 @@ + + + no_file_2 + + + /etc/clickhouse-server/config.d/dictionary_preset_no_file_2.txt + TabSeparated + + + 1 + + key + aInt32 + 0 + + + diff --git a/dbms/tests/integration/test_dictionaries/test.py b/dbms/tests/integration/test_dictionaries/test.py index dfb27cd2ed7..251fe7f31ee 100644 --- a/dbms/tests/integration/test_dictionaries/test.py +++ b/dbms/tests/integration/test_dictionaries/test.py @@ -294,7 +294,7 @@ def test_reload_after_loading(started_cluster): assert query("SELECT dictGetInt32('cmd', 'a', toUInt64(7))") == "83\n" -def test_reload_after_fail(started_cluster): +def test_reload_after_fail_by_system_reload(started_cluster): query = instance.query # dictionaries_lazy_load == false, so this dictionary is not loaded. @@ -321,3 +321,32 @@ def test_reload_after_fail(started_cluster): query("SYSTEM RELOAD DICTIONARY 'no_file'") query("SELECT dictGetInt32('no_file', 'a', toUInt64(9))") == "10\n" assert get_status("no_file") == "LOADED" + + +def test_reload_after_fail_by_timer(started_cluster): + query = instance.query + + # dictionaries_lazy_load == false, so this dictionary is not loaded. + assert get_status("no_file_2") == "NOT_LOADED" + + # We expect an error because the file source doesn't exist. + expected_error = "No such file" + assert expected_error in instance.query_and_get_error("SELECT dictGetInt32('no_file_2', 'a', toUInt64(9))") + assert get_status("no_file_2") == "FAILED" + + # Passed time should not change anything now, the status is still FAILED. + time.sleep(6); + assert expected_error in instance.query_and_get_error("SELECT dictGetInt32('no_file_2', 'a', toUInt64(9))") + assert get_status("no_file_2") == "FAILED" + + # Creating the file source makes the dictionary able to load. + instance.copy_file_to_container(os.path.join(SCRIPT_DIR, "configs/dictionaries/dictionary_preset_file.txt"), "/etc/clickhouse-server/config.d/dictionary_preset_no_file_2.txt") + time.sleep(6); + query("SELECT dictGetInt32('no_file_2', 'a', toUInt64(9))") == "10\n" + assert get_status("no_file_2") == "LOADED" + + # Removing the file source should not spoil the loaded dictionary. + instance.exec_in_container("rm /etc/clickhouse-server/config.d/dictionary_preset_no_file_2.txt") + time.sleep(6); + query("SELECT dictGetInt32('no_file_2', 'a', toUInt64(9))") == "10\n" + assert get_status("no_file_2") == "LOADED"