mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
feat: Migration framework (#1768)
This PR implemented the migration framework, which contains the command line interface to execute migration and helps to migrate data easily. Please read README.md for more information about this framework.
This commit is contained in:
53
tests/common/migration/TestMigrators.hpp
Normal file
53
tests/common/migration/TestMigrators.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of clio: https://github.com/XRPLF/clio
|
||||
Copyright (c) 2024, the clio developers.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include "util/MockMigrationBackend.hpp"
|
||||
#include "util/newconfig/ObjectView.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct SimpleTestMigrator {
|
||||
using Backend = MockMigrationBackend;
|
||||
static constexpr auto name = "SimpleTestMigrator";
|
||||
static constexpr auto description = "The migrator for version 0 -> 1";
|
||||
static void
|
||||
runMigration(std::shared_ptr<MockMigrationBackend>, util::config::ObjectView const&)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
reset()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct SimpleTestMigrator2 {
|
||||
using Backend = MockMigrationBackend;
|
||||
static constexpr auto name = "SimpleTestMigrator2";
|
||||
static constexpr auto description = "The migrator for version 1 -> 2";
|
||||
static void
|
||||
runMigration(std::shared_ptr<MockMigrationBackend>, util::config::ObjectView const&)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
reset()
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -175,6 +175,13 @@ struct MockBackend : public BackendInterface {
|
||||
(const, override)
|
||||
);
|
||||
|
||||
MOCK_METHOD(
|
||||
std::optional<std::string>,
|
||||
fetchMigratorStatus,
|
||||
(std::string const&, boost::asio::yield_context),
|
||||
(const, override)
|
||||
);
|
||||
|
||||
MOCK_METHOD(std::optional<LedgerRange>, hardFetchLedgerRange, (boost::asio::yield_context), (const, override));
|
||||
|
||||
MOCK_METHOD(void, writeLedger, (ripple::LedgerHeader const&, std::string&&), (override));
|
||||
@@ -206,7 +213,7 @@ struct MockBackend : public BackendInterface {
|
||||
|
||||
MOCK_METHOD(bool, doFinishWrites, (), (override));
|
||||
|
||||
MOCK_METHOD(void, writeMPTHolders, ((std::vector<MPTHolderData> const&)), (override));
|
||||
MOCK_METHOD(void, writeMPTHolders, (std::vector<MPTHolderData> const&), (override));
|
||||
|
||||
MOCK_METHOD(
|
||||
MPTHoldersAndCursor,
|
||||
@@ -218,4 +225,6 @@ struct MockBackend : public BackendInterface {
|
||||
boost::asio::yield_context),
|
||||
(const, override)
|
||||
);
|
||||
|
||||
MOCK_METHOD(void, writeMigratorStatus, (std::string const&, std::string const&), (override));
|
||||
};
|
||||
|
||||
26
tests/common/util/MockMigrationBackend.hpp
Normal file
26
tests/common/util/MockMigrationBackend.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of clio: https://github.com/XRPLF/clio
|
||||
Copyright (c) 2024, the clio developers.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/MockBackend.hpp"
|
||||
|
||||
struct MockMigrationBackend : public MockBackend {
|
||||
using MockBackend::MockBackend;
|
||||
};
|
||||
86
tests/common/util/MockMigrationBackendFixture.hpp
Normal file
86
tests/common/util/MockMigrationBackendFixture.hpp
Normal file
@@ -0,0 +1,86 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of clio: https://github.com/XRPLF/clio
|
||||
Copyright (c) 2024, the clio developers.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/LoggerFixtures.hpp"
|
||||
#include "util/MockMigrationBackend.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
template <template <typename> typename MockType = ::testing::NiceMock>
|
||||
struct MockMigrationBackendTestBase : virtual public NoLoggerFixture {
|
||||
class BackendProxy {
|
||||
std::shared_ptr<MockType<MockMigrationBackend>> backend =
|
||||
std::make_shared<MockType<MockMigrationBackend>>(util::config::ClioConfigDefinition{});
|
||||
|
||||
public:
|
||||
auto
|
||||
operator->()
|
||||
{
|
||||
return backend.get();
|
||||
}
|
||||
|
||||
operator std::shared_ptr<MockMigrationBackend>()
|
||||
{
|
||||
return backend;
|
||||
}
|
||||
|
||||
operator std::shared_ptr<MockMigrationBackend const>() const
|
||||
{
|
||||
return backend;
|
||||
}
|
||||
|
||||
MockType<MockMigrationBackend>&
|
||||
operator*()
|
||||
{
|
||||
return *backend;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
BackendProxy backend_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Fixture with a "nice" mock backend.
|
||||
*
|
||||
* Use @see MockBackendTestNaggy during development to get unset call expectation warnings.
|
||||
* Once the test is ready and you are happy you can switch to this fixture to mute the warnings.
|
||||
*
|
||||
* A fixture that is based off of this MockBackendTest or MockBackendTestNaggy get a `backend` member
|
||||
* that is a `BackendProxy` that can be used to access the mock backend. It can be used wherever a
|
||||
* `std::shared_ptr<BackendInterface>` is expected as well as `*backend` can be used with EXPECT_CALL and ON_CALL.
|
||||
*/
|
||||
using MockMigrationBackendTest = MockMigrationBackendTestBase<::testing::NiceMock>;
|
||||
|
||||
/**
|
||||
* @brief Fixture with a "naggy" mock backend.
|
||||
*
|
||||
* Use this during development to get unset call expectation warnings.
|
||||
*/
|
||||
using MockMigrationBackendTestNaggy = MockMigrationBackendTestBase<::testing::NaggyMock>;
|
||||
|
||||
/**
|
||||
* @brief Fixture with a "strict" mock backend.
|
||||
*/
|
||||
using MockMigrationBackendTestStrict = MockMigrationBackendTestBase<::testing::StrictMock>;
|
||||
Reference in New Issue
Block a user