diff --git a/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_0.db3.zstd b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_0.db3.zstd new file mode 100644 index 0000000000..47efd7e928 Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_0.db3.zstd differ diff --git a/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_1.db3.zstd b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_1.db3.zstd new file mode 100644 index 0000000000..46a9604a27 Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_1.db3.zstd differ diff --git a/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_2.db3.zstd b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_2.db3.zstd new file mode 100644 index 0000000000..f901849587 Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_2.db3.zstd differ diff --git a/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_3.db3.zstd b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_3.db3.zstd new file mode 100644 index 0000000000..53c962965d Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_3.db3.zstd differ diff --git a/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_target.yaml b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_target.yaml new file mode 100644 index 0000000000..764e22a4c1 --- /dev/null +++ b/ros2bag/test/resources/reindex_test_bags/file_compression/file_compression_target.yaml @@ -0,0 +1,34 @@ +rosbag2_bagfile_information: + version: 4 + storage_identifier: sqlite3 + relative_file_paths: + - file_compression/file_compression_0.db3.zstd + - file_compression/file_compression_1.db3.zstd + - file_compression/file_compression_2.db3.zstd + - file_compression/file_compression_3.db3.zstd + duration: + nanoseconds: 59997866716 + starting_time: + nanoseconds_since_epoch: 1604357089919704830 + message_count: 775 + topics_with_message_count: + - topic_metadata: + name: /topic + type: std_msgs/msg/String + serialization_format: cdr + offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 2\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 2147483647\n nsec: 4294967295\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false" + message_count: 383 + - topic_metadata: + name: /parameter_events + type: rcl_interfaces/msg/ParameterEvent + serialization_format: cdr + offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 2\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 2147483647\n nsec: 4294967295\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false" + message_count: 0 + - topic_metadata: + name: /rosout + type: rcl_interfaces/msg/Log + serialization_format: cdr + offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 1\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 10\n nsec: 0\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false" + message_count: 392 + compression_format: zstd + compression_mode: FILE \ No newline at end of file diff --git a/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_0.db3 b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_0.db3 new file mode 100644 index 0000000000..cb496d68a3 Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_0.db3 differ diff --git a/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_1.db3 b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_1.db3 new file mode 100644 index 0000000000..fe3aba22e7 Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_1.db3 differ diff --git a/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_2.db3 b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_2.db3 new file mode 100644 index 0000000000..11a87eb30c Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_2.db3 differ diff --git a/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_3.db3 b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_3.db3 new file mode 100644 index 0000000000..9b189dfa13 Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_3.db3 differ diff --git a/ros2bag/test/resources/reindexing/metadata.yaml b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_target.yaml similarity index 73% rename from ros2bag/test/resources/reindexing/metadata.yaml rename to ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_target.yaml index fd38103bf6..147265e2c7 100644 --- a/ros2bag/test/resources/reindexing/metadata.yaml +++ b/ros2bag/test/resources/reindex_test_bags/message_compression/message_compression_target.yaml @@ -2,15 +2,15 @@ rosbag2_bagfile_information: version: 4 storage_identifier: sqlite3 relative_file_paths: - - reindex_test_0.db3 - - reindex_test_1.db3 - - reindex_test_2.db3 - - reindex_test_3.db3 + - message_compression/message_compression_0.db3 + - message_compression/message_compression_1.db3 + - message_compression/message_compression_2.db3 + - message_compression/message_compression_3.db3 duration: - nanoseconds: 19999827972 + nanoseconds: 59872587605 starting_time: - nanoseconds_since_epoch: 1609956791035931613 - message_count: 448 + nanoseconds_since_epoch: 1604581538133709023 + message_count: 1127 topics_with_message_count: - topic_metadata: name: /parameter_events @@ -23,12 +23,12 @@ rosbag2_bagfile_information: type: rcl_interfaces/msg/Log serialization_format: cdr offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 1\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 10\n nsec: 0\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false\n- history: 3\n depth: 0\n reliability: 1\n durability: 1\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 10\n nsec: 0\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false" - message_count: 305 + message_count: 758 - topic_metadata: name: /topic type: std_msgs/msg/String serialization_format: cdr - offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 2\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 2147483647\n nsec: 4294967295\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false" - message_count: 143 - compression_format: "" - compression_mode: "" \ No newline at end of file + offered_qos_profiles: "" + message_count: 369 + compression_format: zstd + compression_mode: MESSAGE \ No newline at end of file diff --git a/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_0.db3 b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_0.db3 new file mode 100644 index 0000000000..ffcf41d90b Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_0.db3 differ diff --git a/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_1.db3 b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_1.db3 new file mode 100644 index 0000000000..d742510b96 Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_1.db3 differ diff --git a/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_2.db3 b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_2.db3 new file mode 100644 index 0000000000..ced88a9cb7 Binary files /dev/null and b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_2.db3 differ diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_3.db3-shm b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_3.db3 similarity index 53% rename from ros2bag/test/resources/reindexing/reindex_test/reindex_test_3.db3-shm rename to ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_3.db3 index fe9ac2845e..6137336d10 100644 Binary files a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_3.db3-shm and b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_3.db3 differ diff --git a/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_target.yaml b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_target.yaml new file mode 100644 index 0000000000..a251989f7d --- /dev/null +++ b/ros2bag/test/resources/reindex_test_bags/multiple_files/multiple_files_target.yaml @@ -0,0 +1,34 @@ +rosbag2_bagfile_information: + version: 4 + storage_identifier: sqlite3 + relative_file_paths: + - multiple_files_0.db3 + - multiple_files_1.db3 + - multiple_files_2.db3 + - multiple_files_3.db3 + duration: + nanoseconds: 59997863418 + starting_time: + nanoseconds_since_epoch: 1604356847420232242 + message_count: 766 + topics_with_message_count: + - topic_metadata: + name: /topic + type: std_msgs/msg/String + serialization_format: cdr + offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 2\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 2147483647\n nsec: 4294967295\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false" + message_count: 378 + - topic_metadata: + name: /parameter_events + type: rcl_interfaces/msg/ParameterEvent + serialization_format: cdr + offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 2\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 2147483647\n nsec: 4294967295\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false" + message_count: 0 + - topic_metadata: + name: /rosout + type: rcl_interfaces/msg/Log + serialization_format: cdr + offered_qos_profiles: "- history: 3\n depth: 0\n reliability: 1\n durability: 1\n deadline:\n sec: 2147483647\n nsec: 4294967295\n lifespan:\n sec: 10\n nsec: 0\n liveliness: 1\n liveliness_lease_duration:\n sec: 2147483647\n nsec: 4294967295\n avoid_ros_namespace_conventions: false" + message_count: 388 + compression_format: "" + compression_mode: "" \ No newline at end of file diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_0.db3 b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_0.db3 deleted file mode 100644 index d2ab63702d..0000000000 Binary files a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_0.db3 and /dev/null differ diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_0.db3-shm b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_0.db3-shm deleted file mode 100644 index fe9ac2845e..0000000000 Binary files a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_0.db3-shm and /dev/null differ diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_0.db3-wal b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_0.db3-wal deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_1.db3 b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_1.db3 deleted file mode 100644 index 98977bbc33..0000000000 Binary files a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_1.db3 and /dev/null differ diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_1.db3-shm b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_1.db3-shm deleted file mode 100644 index fe9ac2845e..0000000000 Binary files a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_1.db3-shm and /dev/null differ diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_1.db3-wal b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_1.db3-wal deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_2.db3 b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_2.db3 deleted file mode 100644 index b4177fcee4..0000000000 Binary files a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_2.db3 and /dev/null differ diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_2.db3-shm b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_2.db3-shm deleted file mode 100644 index fe9ac2845e..0000000000 Binary files a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_2.db3-shm and /dev/null differ diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_2.db3-wal b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_2.db3-wal deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_3.db3 b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_3.db3 deleted file mode 100644 index 5172666fd4..0000000000 Binary files a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_3.db3 and /dev/null differ diff --git a/ros2bag/test/resources/reindexing/reindex_test/reindex_test_3.db3-wal b/ros2bag/test/resources/reindexing/reindex_test/reindex_test_3.db3-wal deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ros2bag/test/test_reindex.py b/ros2bag/test/test_reindex.py new file mode 100644 index 0000000000..6a25122a5e --- /dev/null +++ b/ros2bag/test/test_reindex.py @@ -0,0 +1,322 @@ +# Copyright 2020 DCS Corporation, All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# DISTRIBUTION A. Approved for public release; distribution unlimited. +# OPSEC #4584. +# +# Delivered to the U.S. Government with Unlimited Rights, as defined in DFARS +# Part 252.227-7013 or 7014 (Feb 2014). +# +# This notice must appear in all copies of this file and its derivatives. + +import contextlib +from pathlib import Path +from typing import Any +import unittest + +from launch import LaunchDescription +from launch.actions import ExecuteProcess +import launch_testing +import launch_testing.actions +import launch_testing.asserts +import launch_testing.markers +import launch_testing.tools + +import pytest +import yaml + + +RESOURCES_PATH = Path(__file__).parent / 'resources' / 'reindexing' +# TEST_NODE = 'ros2bag_record_qos_profile_test_node' +# TEST_NAMESPACE = 'ros2bag_record_qos_profile' +TEST_NODE = 'ros2bag_reindex_node' +TEST_NAMESPACE = 'ros2bag_reindex' +ERROR_STRING = r'\[ERROR] \[ros2bag]:' + + +@pytest.mark.rostest +@launch_testing.markers.keep_alive +def generate_test_description(): + return LaunchDescription([launch_testing.actions.ReadyToTest()]) + + +def check_version(target_base_node: Any, test_base_node: Any) -> None: + target_version = target_base_node.get('version') + test_version = test_base_node.get('version') + assert target_base_node.get('version') == test_base_node.get('version'), \ + print('Reindex generated wrong version. Expected "{}"; got "{}"'.format( + target_version, test_version + )) + + +def check_storage_identifier(target_base_node: Any, test_base_node: Any) -> None: + target_si = target_base_node.get('storage_identifier') + test_si = test_base_node.get('storage_identifier') + assert target_si == test_si, \ + print('Reindex generated wrong storage identifier. ' + 'Expected "{}"; got "{}"'.format( + target_si, test_si + )) + + +def check_relative_filepaths(target_base_node: Any, test_base_node: Any) -> None: + target_fp = target_base_node.get('relative_file_paths') + test_fp = test_base_node.get('relative_file_paths') + assert target_fp == test_fp, \ + print('Reindex generated wrong relative file paths. ' + 'Expected "{}"; got "{}"'.format( + target_fp, test_fp + )) + + +def check_duration(target_base_node: Any, test_base_node: Any) -> None: + target_duration = target_base_node.get('duration') + test_duration = test_base_node.get('duration') + assert target_duration == test_duration, \ + print('Reindex generated wrong duration. ' + 'Expected "{}"; got "{}"'.format( + target_duration, test_duration + )) + + +def check_starting_time(target_base_node: Any, test_base_node: Any) -> None: + target_start = target_base_node.get('starting_time') + test_start = test_base_node.get('starting_time') + assert target_start == test_start, \ + print('Reindex generated wrong starting time. ' + 'Expected "{}"; got "{}"'.format( + target_start, test_start + )) + + +def check_message_count(target_base_node: Any, test_base_node: Any) -> None: + target_mc = target_base_node.get('message_count') + test_mc = test_base_node.get('message_count') + assert target_mc == test_mc, \ + print('Reindex generated wrong message count. ' + 'Expected "{}"; got "{}'.format( + target_mc, test_mc + )) + + +def check_topic_type(target_topic_metadata: Any, test_topic_metadata: Any) -> None: + target_name = target_topic_metadata.get('topic_metadata').get('name') + test_type = test_topic_metadata.get('topic_metadata').get('type') + target_type = target_topic_metadata.get('topic_metadata').get('type') + assert test_type == target_type, \ + print('Reindex generated incorrect target type for "{}". ' + 'Expected "{}", got "{}'.format(target_name, target_type, test_type)) + + +def check_topic_ser_fmt(target_topic_metadata: Any, test_topic_metadata: Any) -> None: + target_name = target_topic_metadata.get('topic_metadata').get('name') + test_ser_fmt = test_topic_metadata.get('topic_metadata').get('serialization_format') + target_ser_fmt = target_topic_metadata.get('topic_metadata').get('serialization_format') + assert test_ser_fmt == target_ser_fmt, \ + print('Reindex generated incorrect serialization format for "{}". ' + 'Expected "{}", got "{}"'.format(target_name, target_ser_fmt, test_ser_fmt)) + + +def check_topic_qos(target_topic_metadata: Any, test_topic_metadata: Any) -> None: + target_name = target_topic_metadata.get('topic_metadata').get('name') + test_qos = test_topic_metadata.get('topic_metadata').get('offered_qos_profiles') + target_qos = test_topic_metadata.get('topic_metadata').get('offered_qos_profiles') + assert test_qos == target_qos, \ + print('Reindex generated incorrect QOS profiles for "{}". ' + 'Expected "{}", got "{}"'.format(target_name, target_qos, test_qos)) + + +def check_topic_message_count(target_topic_metadata: Any, test_topic_metadata: Any) -> None: + target_name = target_topic_metadata.get('topic_metadata').get('name') + test_count = test_topic_metadata.get('message_count') + target_count = target_topic_metadata.get('message_count') + assert test_count == target_count, \ + print('Reindex generated incorrect message count for "{}". ' + 'Expected "{}", got "{}"'.format(target_name, target_count, test_count)) + + +def check_topics(target_base_node: Any, test_base_node: Any) -> None: + target_topics = target_base_node.get('topics_with_message_count') + test_topics = test_base_node.get('topics_with_message_count') + assert test_topics, print('Reindex generated no topics block') + + if test_topics: + for test_topic in test_topics: + test_name = test_topic.get('topic_metadata').get('name') + target_topic = next((x for x in target_topics + if x.get('topic_metadata').get('name') == test_name)) + + assert target_topic, print('Reindex generated extra topic: "{}"'.format(test_name)) + if target_topic: + check_topic_type(target_topic, test_topic) + check_topic_ser_fmt(target_topic, test_topic) + check_topic_qos(target_topic, test_topic) + check_topic_message_count(target_topic, test_topic) + + +def check_compression_fmt(target_base_node: Any, test_base_node: Any) -> None: + target_c_fmt = target_base_node.get('compression_format') + test_c_fmt = test_base_node.get('compression_format') + assert target_c_fmt == test_c_fmt, \ + print('Reindex generated incorrect compression format. ' + 'Expected "{}", got "{}"'.format(target_c_fmt, test_c_fmt)) + + +def check_compression_mode(target_base_node: Any, test_base_node: Any) -> None: + target_mode = target_base_node.get('compression_mode') + test_mode = test_base_node.get('compression_mode') + assert target_mode == test_mode, \ + print('Reindex generated incorrect compression mode. ' + 'Expected "{}", got "{}"'.format(target_mode, test_mode)) + + +def compare_metadata_files(target_file: Path, test_file: Path): + target_yaml = yaml.safe_load(target_file.open()) + generated_yaml = yaml.safe_load(test_file.open()) + + # Check that base node exists + target_base_node = target_yaml.get('rosbag2_bagfile_information') + test_base_node = generated_yaml.get('rosbag2_bagfile_information') + assert test_base_node, print('Reindex was unable to generate base node') + + check_version(target_base_node, test_base_node) + check_storage_identifier(target_base_node, test_base_node) + + # INCONSISTENT BETWEEN COMPRESSED / NON COMPRESSED BAGS + # Disabling for now + # check_relative_filepaths(target_base_node, test_base_node) + + # MAY NOT BE ABLE TO GUARANTEE THIS # + # check_duration(target_base_node, test_base_node) + # check_starting_time(target_base_node, test_base_node) + + check_message_count(target_base_node, test_base_node) + check_topics(target_base_node, test_base_node) + check_compression_fmt(target_base_node, test_base_node) + check_compression_mode(target_base_node, test_base_node) + + +class TestRos2BagReindexMultiFile(unittest.TestCase): + + @classmethod + def setUpClass(cls, launch_service, proc_info, proc_output): + @contextlib.contextmanager + def launch_bag_command(self, arguments, **kwargs): + pkg_command_action = ExecuteProcess( + cmd=['ros2', 'bag', *arguments], + additional_env={'PYTHONUNBUFFERED': '1'}, + name='ros2bag-cli', + output='screen', + **kwargs + ) + with launch_testing.tools.launch_process( + launch_service, pkg_command_action, proc_info, proc_output + ) as pkg_command: + yield pkg_command + cls.launch_bag_command = launch_bag_command + + @classmethod + def tearDown(cls) -> None: + metadata_file = RESOURCES_PATH / 'multiple_files' / 'metadata.yaml' + metadata_file.unlink(True) + + def test_multiple_files(self): + bag_path = RESOURCES_PATH / 'multiple_files' + metadata_file = bag_path / 'metadata.yaml' + target_file = bag_path / 'multiple_files_target.yaml' + + arguments = ['reindex', bag_path.as_posix()] + with self.launch_bag_command(arguments=arguments) as bag_command: + bag_command.wait_for_shutdown(timeout=5) + + # Metadata.yaml file should be created at this point + compare_metadata_files(target_file, metadata_file) + + +class TestRos2BagReindexMessageCompression(unittest.TestCase): + + @classmethod + def setUpClass(cls, launch_service, proc_info, proc_output): + @contextlib.contextmanager + def launch_bag_command(self, arguments, **kwargs): + pkg_command_action = ExecuteProcess( + cmd=['ros2', 'bag', *arguments], + additional_env={'PYTHONUNBUFFERED': '1'}, + name='ros2bag-cli', + output='screen', + **kwargs + ) + with launch_testing.tools.launch_process( + launch_service, pkg_command_action, proc_info, proc_output + ) as pkg_command: + yield pkg_command + cls.launch_bag_command = launch_bag_command + + @classmethod + def tearDown(cls) -> None: + metadata_file = RESOURCES_PATH / 'message_compression' / 'metadata.yaml' + metadata_file.unlink(True) + + def test_compressed(self): + bag_path = RESOURCES_PATH / 'message_compression' + metadata_file = bag_path / 'metadata.yaml' + target_file = bag_path / 'message_compression_target.yaml' + + arguments = ['reindex', bag_path.as_posix(), + '--compression-format', 'zstd', + '--compression-mode', 'message'] + with self.launch_bag_command(arguments=arguments) as bag_command: + bag_command.wait_for_shutdown(timeout=5) + + # Metadata.yaml file should be created at this point + compare_metadata_files(target_file, metadata_file) + + +class TestRos2BagReindexFileCompression(unittest.TestCase): + + @classmethod + def setUpClass(cls, launch_service, proc_info, proc_output): + @contextlib.contextmanager + def launch_bag_command(self, arguments, **kwargs): + pkg_command_action = ExecuteProcess( + cmd=['ros2', 'bag', *arguments], + additional_env={'PYTHONUNBUFFERED': '1'}, + name='ros2bag-cli', + output='screen', + **kwargs + ) + with launch_testing.tools.launch_process( + launch_service, pkg_command_action, proc_info, proc_output + ) as pkg_command: + yield pkg_command + cls.launch_bag_command = launch_bag_command + + @classmethod + def tearDown(cls) -> None: + metadata_file = RESOURCES_PATH / 'file_compression' / 'metadata.yaml' + metadata_file.unlink(True) + + def test_compressed(self): + bag_path = RESOURCES_PATH / 'file_compression' + metadata_file = bag_path / 'metadata.yaml' + target_file = bag_path / 'file_compression_target.yaml' + + arguments = ['reindex', bag_path.as_posix(), + '--compression-format', 'zstd', + '--compression-mode', 'file'] + with self.launch_bag_command(arguments=arguments) as bag_command: + bag_command.wait_for_shutdown(timeout=5) + + # Metadata.yaml file should be created at this point + compare_metadata_files(target_file, metadata_file) \ No newline at end of file