Skip to content

Commit

Permalink
Add test for snapshot clear
Browse files Browse the repository at this point in the history
  • Loading branch information
lzydmxy committed Jun 21, 2024
1 parent c5e5442 commit 6344037
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
4 changes: 4 additions & 0 deletions tests/integration/helpers/cluster_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,10 @@ def file_exists(self, path):
return self.exec_in_container(
["bash", "-c", "echo $(if [ -e '{}' ]; then echo 'yes'; else echo 'no'; fi)".format(path)]) == 'yes\n'

def list_path(self, path):
return self.exec_in_container(
["bash", "-c", "ls {}".format(path)])

def copy_file_to_container(self, local_path, dest_path):
container_id = self.get_docker_handle().id
return self.cluster.copy_file_to_container(container_id, local_path, dest_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<keeper>
<my_id>1</my_id>
<host>node</host>
<log_dir>./raft_log</log_dir>
<snapshot_dir>./snapshot_log</snapshot_dir>
<log_dir>/raft_log</log_dir>
<snapshot_dir>/snapshot</snapshot_dir>
<snapshot_create_interval>86400</snapshot_create_interval>
<forwarding_port>8102</forwarding_port>
<port>8101</port>
Expand All @@ -15,6 +15,7 @@
<max_session_timeout_ms>80000</max_session_timeout_ms>
<operation_timeout_ms>1000</operation_timeout_ms>
<snapshot_distance>10</snapshot_distance>
<max_stored_snapshots>1</max_stored_snapshots>
<election_timeout_lower_bound_ms>1000</election_timeout_lower_bound_ms>
<election_timeout_upper_bound_ms>2000</election_timeout_upper_bound_ms>
<min_session_timeout_ms>1000</min_session_timeout_ms>
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/test_snapshots/configs/enable_keeper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<keeper>
<my_id>1</my_id>
<host>node</host>
<log_dir>./raft_log</log_dir>
<snapshot_dir>./snapshot_log</snapshot_dir>
<log_dir>/raft_log</log_dir>
<snapshot_dir>/snapshot</snapshot_dir>
<snapshot_create_interval>86400</snapshot_create_interval>
<forwarding_port>8102</forwarding_port>
<port>8101</port>
Expand All @@ -15,6 +15,7 @@
<max_session_timeout_ms>80000</max_session_timeout_ms>
<operation_timeout_ms>1000</operation_timeout_ms>
<snapshot_distance>10</snapshot_distance>
<max_stored_snapshots>1</max_stored_snapshots>
<election_timeout_lower_bound_ms>1000</election_timeout_lower_bound_ms>
<election_timeout_upper_bound_ms>2000</election_timeout_upper_bound_ms>
<min_session_timeout_ms>1000</min_session_timeout_ms>
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/test_snapshots/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,41 @@ def test_restart_with_no_log(started_cluster, node):
assert node_zk2.exists("/test_restart_with_no_log")
finally:
close_zk_clients([node_zk, node_zk2])


def get_snapshots(node):
files = node.list_path('/snapshot').split()

snapshots = dict()
for file_name in files:
print(file_name)
file_name_splits = file_name.split('_')
assert(len(file_name_splits) == 5)
key = '_'.join(file_name_splits[:4])
value = snapshots.get(key, [])
value.append(file_name_splits[4])
snapshots[key] = value
return snapshots


@pytest.mark.parametrize(
'node',
[
cluster.add_instance('node7', main_configs=['configs/enable_keeper.xml'], with_zookeeper=True, stay_alive=True),
cluster.add_instance('node8', main_configs=['configs/enable_async_snapshot_keeper.xml'], with_zookeeper=True, stay_alive=True)
]
)
def test_snapshot_clear(started_cluster, node):
node_zk = node_zk2 = None
try:
node_zk = node.get_fake_zk()

for i in range(5):
node_zk.create(f"/test_node_clear_{i}", b"test")
node.send_4lw_cmd(cmd="csnp")
# wait for snapshot to be taken
time.sleep(1)
snapshots = get_snapshots(node)
assert (len(snapshots) == 1)
finally:
close_zk_clients([node_zk, node_zk2])

0 comments on commit 6344037

Please sign in to comment.