Skip to content

Commit

Permalink
tests: fs: add basic test for metadata log bootstrapping
Browse files Browse the repository at this point in the history
Checks if there is access to the newly created directories after bootstrapping.

Signed-off-by: Aleksander Sorokin <[email protected]>
  • Loading branch information
rokinsky authored and tropuq committed Apr 20, 2020
1 parent 7b96070 commit 47620f0
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ if (Seastar_EXPERIMENTAL_FS)
seastar_add_test (fs_cluster_allocator
KIND BOOST
SOURCES fs_cluster_allocator_test.cc)
seastar_add_test (fs_log_bootstrap
SOURCES
fs_log_bootstrap_test.cc
fs_mock_block_device.cc)
seastar_add_test (fs_metadata_to_disk_buffer
SOURCES
fs_metadata_to_disk_buffer_test.cc
Expand Down
86 changes: 86 additions & 0 deletions tests/unit/fs_log_bootstrap_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* This file is open source software, licensed to you under the terms
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. 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.
*/
/*
* Copyright (C) 2020 ScyllaDB
*/

#include "fs/bootstrap_record.hh"
#include "fs/inode.hh"
#include "fs/metadata_log.hh"
#include "fs/units.hh"
#include "fs_mock_block_device.hh"

#include "seastar/core/units.hh"
#include "seastar/fs/block_device.hh"
#include "seastar/testing/thread_test_case.hh"
#include "seastar/util/defer.hh"

using namespace seastar;
using namespace fs;

constexpr unit_size_t cluster_size = 1 * MB;
constexpr unit_size_t alignment = 4 * KB;
constexpr inode_t root_directory = 0;

future<std::set<std::string>> get_entries_from_directory(metadata_log& log, std::string dir_path) {
return async([&log, dir_path = std::move(dir_path)] {
std::set<std::string> entries;
log.iterate_directory(dir_path, [&entries] (const std::string& entry) -> future<stop_iteration> {
entries.insert(entry);
return make_ready_future<stop_iteration>(stop_iteration::no);
}).wait();
return entries;
});
}

BOOST_TEST_DONT_PRINT_LOG_VALUE(std::set<std::string>)

SEASTAR_THREAD_TEST_CASE(create_dirs_and_bootstrap_test) {
BOOST_TEST_MESSAGE("\nTest name: " << get_name());
const bootstrap_record::shard_info shard_info({1, {1, 16}});
const std::set<std::string> control_directories = {{"dir1", "dir2", "dir3"}};
auto dev_impl = make_shared<mock_block_device_impl>();

{
block_device device(dev_impl);
auto log = metadata_log(std::move(device), cluster_size, alignment);
const auto close_log = defer([&log]() mutable { log.shutdown().wait(); });
log.bootstrap(root_directory, shard_info.metadata_cluster, shard_info.available_clusters, 1, 0).wait();

int flush_after = 1;
for (auto directory: control_directories) {
log.create_directory("/" + std::move(directory), file_permissions::default_file_permissions).wait();
if (--flush_after == 0) {
log.flush_log().wait();
}
}

const auto entries = get_entries_from_directory(log, "/").get0();
BOOST_REQUIRE_EQUAL(entries, control_directories);
}

{
block_device device(dev_impl);
auto log = metadata_log(std::move(device), cluster_size, alignment);
const auto close_log = defer([&log]() mutable { log.shutdown().wait(); });
log.bootstrap(root_directory, shard_info.metadata_cluster, shard_info.available_clusters, 1, 0).wait();

const auto entries = get_entries_from_directory(log, "/").get0();
BOOST_REQUIRE_EQUAL(entries, control_directories);
}
}

0 comments on commit 47620f0

Please sign in to comment.