-
Notifications
You must be signed in to change notification settings - Fork 318
Add filter for reading selective topics #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
bf71f78
fa96e5c
7d16787
585dddf
80e06be
5e09b58
59d4cb1
2923abf
071612b
f29c609
7724188
b62736a
f0b3f49
48ed8a7
c0fbd0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright 2020 Open Source Robotics Foundation, Inc. | ||
| // | ||
| // 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. | ||
|
|
||
| #ifndef ROSBAG2_STORAGE__STORAGE_FILTER_HPP_ | ||
| #define ROSBAG2_STORAGE__STORAGE_FILTER_HPP_ | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace rosbag2_storage | ||
| { | ||
|
|
||
| struct StorageFilter | ||
| { | ||
| std::vector<std::string> topics; | ||
|
mabelzhang marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| } // namespace rosbag2_storage | ||
|
|
||
| #endif // ROSBAG2_STORAGE__STORAGE_FILTER_HPP_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
|
|
||
| #include <gmock/gmock.h> | ||
|
|
||
| #include <rosbag2_storage/storage_filter.hpp> | ||
|
|
||
|
mabelzhang marked this conversation as resolved.
Outdated
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <tuple> | ||
|
|
@@ -111,6 +113,33 @@ TEST_F(StorageTestFixture, get_next_returns_messages_in_timestamp_order) { | |
| EXPECT_FALSE(readable_storage->has_next()); | ||
| } | ||
|
|
||
| TEST_F(StorageTestFixture, read_next_returns_filtered_messages) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would appreciate having this test actually happening in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had trouble creating the test. Can you suggest a test file in The other problem is since the actual filtering is only implemented in What I have done locally is I added a new class to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you have two options here. Either you modify the mock functions in a way to take the filter logic into account or you shift the test over to Do you think it makes sense to apply the filter to each individual reader instance? Then we should add the two functions (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spent some time putting the tests in In the So with The tests in The tests in So my question is what we want to go into this PR - I have a mess of both routes on my local computer, with new tests in all 3 packages, and I haven't pushed anything. I think both the If we also want to add end-to-end tests and implement a new flag on
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with basically everything you said here. I would still appreciate some basic tests in The functionality can be tested in the sqlite3 implementation of it (I think that's what you meant with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. I added basic tests in I tried making a new test in In fact, I cannot even open But |
||
| std::vector<std::tuple<std::string, int64_t, std::string, std::string, std::string>> | ||
| string_messages = | ||
| {std::make_tuple("topic1 message", 1, "topic1", "", ""), | ||
| std::make_tuple("topic2 message", 2, "topic2", "", ""), | ||
| std::make_tuple("topic3 message", 3, "topic3", "", "")}; | ||
|
|
||
| write_messages_to_sqlite(string_messages); | ||
| std::unique_ptr<rosbag2_storage::storage_interfaces::ReadOnlyInterface> readable_storage = | ||
| std::make_unique<rosbag2_storage_plugins::SqliteStorage>(); | ||
|
|
||
| auto db_filename = (rcpputils::fs::path(temporary_dir_path_) / "rosbag.db3").string(); | ||
| readable_storage->open(db_filename); | ||
|
|
||
| rosbag2_storage::StorageFilter storage_filter; | ||
| storage_filter.topics.push_back("topic2"); | ||
| storage_filter.topics.push_back("topic3"); | ||
| readable_storage->set_filter(storage_filter); | ||
|
|
||
| EXPECT_TRUE(readable_storage->has_next()); | ||
| auto first_message = readable_storage->read_next(); | ||
| EXPECT_THAT(first_message->topic_name, Eq("topic2")); | ||
| EXPECT_TRUE(readable_storage->has_next()); | ||
| auto second_message = readable_storage->read_next(); | ||
| EXPECT_THAT(second_message->topic_name, Eq("topic3")); | ||
|
mabelzhang marked this conversation as resolved.
|
||
| } | ||
|
|
||
| TEST_F(StorageTestFixture, get_all_topics_and_types_returns_the_correct_vector) { | ||
| std::unique_ptr<rosbag2_storage::storage_interfaces::ReadWriteInterface> writable_storage = | ||
| std::make_unique<rosbag2_storage_plugins::SqliteStorage>(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.