2020
2121
2222class BinlogReplicatorRunner (ProcessRunner ):
23- def __init__ (self ):
24- super ().__init__ (f'./main.py --config { CONFIG_FILE } binlog_replicator' )
23+ def __init__ (self , cfg_file = CONFIG_FILE ):
24+ super ().__init__ (f'./main.py --config { cfg_file } binlog_replicator' )
2525
2626
2727class DbReplicatorRunner (ProcessRunner ):
28- def __init__ (self , db_name , additional_arguments = None ):
28+ def __init__ (self , db_name , additional_arguments = None , cfg_file = CONFIG_FILE ):
2929 additional_arguments = additional_arguments or ''
3030 if not additional_arguments .startswith (' ' ):
3131 additional_arguments = ' ' + additional_arguments
32- super ().__init__ (f'./main.py --config { CONFIG_FILE } --db { db_name } db_replicator{ additional_arguments } ' )
32+ super ().__init__ (f'./main.py --config { cfg_file } --db { db_name } db_replicator{ additional_arguments } ' )
3333
3434
3535class RunAllRunner (ProcessRunner ):
36- def __init__ (self , db_name ):
37- super ().__init__ (f'./main.py --config { CONFIG_FILE } run_all --db { db_name } ' )
36+ def __init__ (self , cfg_file = CONFIG_FILE ):
37+ super ().__init__ (f'./main.py --config { cfg_file } run_all' )
3838
3939
4040def kill_process (pid , force = False ):
@@ -57,15 +57,16 @@ def prepare_env(
5757 cfg : config .Settings ,
5858 mysql : mysql_api .MySQLApi ,
5959 ch : clickhouse_api .ClickhouseApi ,
60+ db_name : str = TEST_DB_NAME
6061):
6162 if os .path .exists (cfg .binlog_replicator .data_dir ):
6263 shutil .rmtree (cfg .binlog_replicator .data_dir )
6364 os .mkdir (cfg .binlog_replicator .data_dir )
64- mysql .drop_database (TEST_DB_NAME )
65- mysql .create_database (TEST_DB_NAME )
66- mysql .set_database (TEST_DB_NAME )
67- ch .drop_database (TEST_DB_NAME )
68- assert_wait (lambda : TEST_DB_NAME not in ch .get_databases ())
65+ mysql .drop_database (db_name )
66+ mysql .create_database (db_name )
67+ mysql .set_database (db_name )
68+ ch .drop_database (db_name )
69+ assert_wait (lambda : db_name not in ch .get_databases ())
6970
7071
7172def test_e2e_regular ():
@@ -299,7 +300,7 @@ def test_runner():
299300 mysql .execute (f"INSERT INTO { TEST_TABLE_NAME } (name, age) VALUES ('Ivan', 42);" , commit = True )
300301 mysql .execute (f"INSERT INTO { TEST_TABLE_NAME } (name, age) VALUES ('Peter', 33);" , commit = True )
301302
302- run_all_runner = RunAllRunner (TEST_DB_NAME )
303+ run_all_runner = RunAllRunner ()
303304 run_all_runner .run ()
304305
305306 assert_wait (lambda : TEST_DB_NAME in ch .get_databases ())
@@ -371,4 +372,59 @@ def test_initial_only():
371372 ch .execute_command (f'USE { TEST_DB_NAME } ' )
372373
373374 assert TEST_TABLE_NAME in ch .get_tables ()
374- assert len (ch .select (TEST_TABLE_NAME )) == 2
375+ assert len (ch .select (TEST_TABLE_NAME )) == 2
376+
377+
378+ def test_database_tables_filtering ():
379+ cfg = config .Settings ()
380+ cfg .load ('tests_config_databases_tables.yaml' )
381+
382+ mysql = mysql_api .MySQLApi (
383+ database = None ,
384+ mysql_settings = cfg .mysql ,
385+ )
386+
387+ ch = clickhouse_api .ClickhouseApi (
388+ database = 'test_db_2' ,
389+ clickhouse_settings = cfg .clickhouse ,
390+ )
391+
392+ mysql .drop_database ('test_db_3' )
393+ mysql .create_database ('test_db_3' )
394+ ch .drop_database ('test_db_3' )
395+
396+ prepare_env (cfg , mysql , ch , db_name = 'test_db_2' )
397+
398+ mysql .execute (f'''
399+ CREATE TABLE test_table_3 (
400+ id int NOT NULL AUTO_INCREMENT,
401+ name varchar(255),
402+ age int,
403+ PRIMARY KEY (id)
404+ );
405+ ''' )
406+
407+ mysql .execute (f'''
408+ CREATE TABLE test_table_2 (
409+ id int NOT NULL AUTO_INCREMENT,
410+ name varchar(255),
411+ age int,
412+ PRIMARY KEY (id)
413+ );
414+ ''' )
415+
416+ mysql .execute (f"INSERT INTO test_table_3 (name, age) VALUES ('Ivan', 42);" , commit = True )
417+ mysql .execute (f"INSERT INTO test_table_2 (name, age) VALUES ('Ivan', 42);" , commit = True )
418+
419+ run_all_runner = RunAllRunner (cfg_file = 'tests_config_databases_tables.yaml' )
420+ run_all_runner .run ()
421+
422+ assert_wait (lambda : 'test_db_2' in ch .get_databases ())
423+ assert 'test_db_3' not in ch .get_databases ()
424+
425+ ch .execute_command ('USE test_db_2' )
426+
427+ assert_wait (lambda : 'test_table_2' in ch .get_tables ())
428+ assert_wait (lambda : len (ch .select ('test_table_2' )) == 1 )
429+
430+ assert 'test_table_3' not in ch .get_tables ()
0 commit comments