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:
@@ -50,6 +50,14 @@ target_sources(
|
||||
Main.cpp
|
||||
Playground.cpp
|
||||
ProfilerTests.cpp
|
||||
# Migration
|
||||
migration/cassandra/FullTableScannerTests.cpp
|
||||
migration/cassandra/SpecTests.cpp
|
||||
migration/MigratorRegisterTests.cpp
|
||||
migration/MigratorStatusTests.cpp
|
||||
migration/MigrationManagerBaseTests.cpp
|
||||
migration/MigrationManagerFactoryTests.cpp
|
||||
migration/SpecTests.cpp
|
||||
# RPC
|
||||
rpc/APIVersionTests.cpp
|
||||
rpc/BaseTests.cpp
|
||||
@@ -112,6 +120,7 @@ target_sources(
|
||||
util/async/AnyStrandTests.cpp
|
||||
util/async/AsyncExecutionContextTests.cpp
|
||||
util/BatchingTests.cpp
|
||||
util/ConceptsTests.cpp
|
||||
util/CoroutineGroupTests.cpp
|
||||
util/LedgerUtilsTests.cpp
|
||||
# Prometheus support
|
||||
|
||||
@@ -31,6 +31,7 @@ using namespace app;
|
||||
struct CliArgsTests : testing::Test {
|
||||
testing::StrictMock<testing::MockFunction<int(CliArgs::Action::Run)>> onRunMock;
|
||||
testing::StrictMock<testing::MockFunction<int(CliArgs::Action::Exit)>> onExitMock;
|
||||
testing::StrictMock<testing::MockFunction<int(CliArgs::Action::Migrate)>> onMigrateMock;
|
||||
};
|
||||
|
||||
TEST_F(CliArgsTests, Parse_NoArgs)
|
||||
@@ -44,7 +45,9 @@ TEST_F(CliArgsTests, Parse_NoArgs)
|
||||
EXPECT_FALSE(run.useNgWebServer);
|
||||
return returnCode;
|
||||
});
|
||||
EXPECT_EQ(action.apply(onRunMock.AsStdFunction(), onExitMock.AsStdFunction()), returnCode);
|
||||
EXPECT_EQ(
|
||||
action.apply(onRunMock.AsStdFunction(), onExitMock.AsStdFunction(), onMigrateMock.AsStdFunction()), returnCode
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(CliArgsTests, Parse_NgWebServer)
|
||||
@@ -58,7 +61,10 @@ TEST_F(CliArgsTests, Parse_NgWebServer)
|
||||
EXPECT_TRUE(run.useNgWebServer);
|
||||
return returnCode;
|
||||
});
|
||||
EXPECT_EQ(action.apply(onRunMock.AsStdFunction(), onExitMock.AsStdFunction()), returnCode);
|
||||
EXPECT_EQ(
|
||||
action.apply(onRunMock.AsStdFunction(), onExitMock.AsStdFunction(), onMigrateMock.AsStdFunction()),
|
||||
returnCode
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +78,10 @@ TEST_F(CliArgsTests, Parse_VersionHelp)
|
||||
auto const action = CliArgs::parse(argv.size(), const_cast<char const**>(argv.data()));
|
||||
|
||||
EXPECT_CALL(onExitMock, Call).WillOnce([](CliArgs::Action::Exit const& exit) { return exit.exitCode; });
|
||||
EXPECT_EQ(action.apply(onRunMock.AsStdFunction(), onExitMock.AsStdFunction()), EXIT_SUCCESS);
|
||||
EXPECT_EQ(
|
||||
action.apply(onRunMock.AsStdFunction(), onExitMock.AsStdFunction(), onMigrateMock.AsStdFunction()),
|
||||
EXIT_SUCCESS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,5 +96,7 @@ TEST_F(CliArgsTests, Parse_Config)
|
||||
EXPECT_EQ(run.configPath, configPath);
|
||||
return returnCode;
|
||||
});
|
||||
EXPECT_EQ(action.apply(onRunMock.AsStdFunction(), onExitMock.AsStdFunction()), returnCode);
|
||||
EXPECT_EQ(
|
||||
action.apply(onRunMock.AsStdFunction(), onExitMock.AsStdFunction(), onMigrateMock.AsStdFunction()), returnCode
|
||||
);
|
||||
}
|
||||
|
||||
110
tests/unit/migration/MigrationManagerBaseTests.cpp
Normal file
110
tests/unit/migration/MigrationManagerBaseTests.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 "migration/MigratiorStatus.hpp"
|
||||
#include "migration/TestMigrators.hpp"
|
||||
#include "migration/impl/MigrationManagerBase.hpp"
|
||||
#include "migration/impl/MigratorsRegister.hpp"
|
||||
#include "util/MockMigrationBackend.hpp"
|
||||
#include "util/MockMigrationBackendFixture.hpp"
|
||||
#include "util/MockPrometheus.hpp"
|
||||
#include "util/newconfig/ConfigConstraints.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
#include "util/newconfig/ConfigValue.hpp"
|
||||
#include "util/newconfig/Types.hpp"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using TestMigratorRegister =
|
||||
migration::impl::MigratorsRegister<MockMigrationBackend, SimpleTestMigrator, SimpleTestMigrator2>;
|
||||
|
||||
using TestCassandraMigrationManager = migration::impl::MigrationManagerBase<TestMigratorRegister>;
|
||||
|
||||
struct MigrationManagerBaseTest : public util::prometheus::WithMockPrometheus, public MockMigrationBackendTestStrict {
|
||||
util::config::ClioConfigDefinition cfg{
|
||||
{"migration.full_scan_threads",
|
||||
util::config::ConfigValue{util::config::ConfigType::Integer}.defaultValue(2).withConstraint(
|
||||
util::config::validateUint32
|
||||
)}
|
||||
};
|
||||
std::shared_ptr<TestCassandraMigrationManager> migrationManager;
|
||||
|
||||
MigrationManagerBaseTest()
|
||||
{
|
||||
auto mockBackendPtr = backend_.operator std::shared_ptr<MockMigrationBackend>();
|
||||
TestMigratorRegister migratorRegister(mockBackendPtr);
|
||||
migrationManager = std::make_shared<TestCassandraMigrationManager>(mockBackendPtr, cfg.getObject("migration"));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(MigrationManagerBaseTest, AllStatus)
|
||||
{
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus("SimpleTestMigrator", testing::_)).WillOnce(testing::Return("Migrated"));
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus("SimpleTestMigrator2", testing::_))
|
||||
.WillOnce(testing::Return("NotMigrated"));
|
||||
auto const status = migrationManager->allMigratorsStatusPairs();
|
||||
EXPECT_EQ(status.size(), 2);
|
||||
EXPECT_TRUE(
|
||||
std::find(
|
||||
status.begin(), status.end(), std::make_tuple("SimpleTestMigrator", migration::MigratorStatus::Migrated)
|
||||
) != status.end()
|
||||
);
|
||||
EXPECT_TRUE(
|
||||
std::find(
|
||||
status.begin(), status.end(), std::make_tuple("SimpleTestMigrator2", migration::MigratorStatus::NotMigrated)
|
||||
) != status.end()
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(MigrationManagerBaseTest, AllNames)
|
||||
{
|
||||
auto const names = migrationManager->allMigratorsNames();
|
||||
EXPECT_EQ(names.size(), 2);
|
||||
EXPECT_EQ(names[0], "SimpleTestMigrator");
|
||||
EXPECT_EQ(names[1], "SimpleTestMigrator2");
|
||||
}
|
||||
|
||||
TEST_F(MigrationManagerBaseTest, Description)
|
||||
{
|
||||
EXPECT_EQ(migrationManager->getMigratorDescriptionByName("unknown"), "No Description");
|
||||
EXPECT_EQ(migrationManager->getMigratorDescriptionByName("SimpleTestMigrator"), "The migrator for version 0 -> 1");
|
||||
EXPECT_EQ(migrationManager->getMigratorDescriptionByName("SimpleTestMigrator2"), "The migrator for version 1 -> 2");
|
||||
}
|
||||
|
||||
TEST_F(MigrationManagerBaseTest, RunMigration)
|
||||
{
|
||||
EXPECT_CALL(*backend_, writeMigratorStatus("SimpleTestMigrator", "Migrated"));
|
||||
migrationManager->runMigration("SimpleTestMigrator");
|
||||
}
|
||||
|
||||
TEST_F(MigrationManagerBaseTest, getMigratorStatusByName)
|
||||
{
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus("SimpleTestMigrator", testing::_)).WillOnce(testing::Return("Migrated"));
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus("SimpleTestMigrator2", testing::_))
|
||||
.WillOnce(testing::Return("NotMigrated"));
|
||||
|
||||
EXPECT_EQ(migrationManager->getMigratorStatusByName("SimpleTestMigrator"), migration::MigratorStatus::Migrated);
|
||||
EXPECT_EQ(migrationManager->getMigratorStatusByName("SimpleTestMigrator2"), migration::MigratorStatus::NotMigrated);
|
||||
}
|
||||
39
tests/unit/migration/MigrationManagerFactoryTests.cpp
Normal file
39
tests/unit/migration/MigrationManagerFactoryTests.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 "migration/impl/MigrationManagerFactory.hpp"
|
||||
#include "util/LoggerFixtures.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
#include "util/newconfig/ConfigValue.hpp"
|
||||
#include "util/newconfig/Types.hpp"
|
||||
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
struct MigrationManagerFactoryTests : public NoLoggerFixture {};
|
||||
|
||||
TEST_F(MigrationManagerFactoryTests, InvalidDBType)
|
||||
{
|
||||
util::config::ClioConfigDefinition const configDef{
|
||||
{"database.type", util::config::ConfigValue{util::config::ConfigType::String}.defaultValue("invalid")}
|
||||
};
|
||||
auto const ret = migration::impl::makeMigrationManager(configDef);
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(ret.error(), "Invalid database type");
|
||||
}
|
||||
189
tests/unit/migration/MigratorRegisterTests.cpp
Normal file
189
tests/unit/migration/MigratorRegisterTests.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 "migration/MigratiorStatus.hpp"
|
||||
#include "migration/TestMigrators.hpp"
|
||||
#include "migration/impl/MigratorsRegister.hpp"
|
||||
#include "util/MockMigrationBackend.hpp"
|
||||
#include "util/MockMigrationBackendFixture.hpp"
|
||||
#include "util/MockPrometheus.hpp"
|
||||
#include "util/newconfig/ConfigConstraints.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
#include "util/newconfig/ConfigValue.hpp"
|
||||
#include "util/newconfig/Types.hpp"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using EmptyMigratorRegister = migration::impl::MigratorsRegister<MockMigrationBackend>;
|
||||
|
||||
namespace {
|
||||
util::config::ClioConfigDefinition cfg{
|
||||
{{"migration.full_scan_threads",
|
||||
util::config::ConfigValue{util::config::ConfigType::Integer}.defaultValue(2).withConstraint(
|
||||
util::config::validateUint32
|
||||
)},
|
||||
{"migration.full_scan_jobs",
|
||||
util::config::ConfigValue{util::config::ConfigType::Integer}.defaultValue(4).withConstraint(
|
||||
util::config::validateUint32
|
||||
)},
|
||||
{"migration.cursors_per_job",
|
||||
util::config::ConfigValue{util::config::ConfigType::Integer}.defaultValue(100).withConstraint(
|
||||
util::config::validateUint32
|
||||
)}}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
struct MigratorRegisterTests : public util::prometheus::WithMockPrometheus, public MockMigrationBackendTest {};
|
||||
|
||||
TEST_F(MigratorRegisterTests, EmptyMigratorRegister)
|
||||
{
|
||||
EmptyMigratorRegister migratorRegister(backend_);
|
||||
EXPECT_EQ(migratorRegister.getMigratorsStatus().size(), 0);
|
||||
EXPECT_EQ(migratorRegister.getMigratorNames().size(), 0);
|
||||
EXPECT_EQ(migratorRegister.getMigratorStatus("unknown"), migration::MigratorStatus::NotKnown);
|
||||
EXPECT_NO_THROW(migratorRegister.runMigrator("unknown", cfg.getObject("migration")));
|
||||
EXPECT_EQ(migratorRegister.getMigratorDescription("unknown"), "No Description");
|
||||
}
|
||||
|
||||
using MultipleMigratorRegister =
|
||||
migration::impl::MigratorsRegister<MockMigrationBackend, SimpleTestMigrator, SimpleTestMigrator2>;
|
||||
|
||||
struct MultipleMigratorRegisterTests : public util::prometheus::WithMockPrometheus, public MockMigrationBackendTest {
|
||||
std::optional<MultipleMigratorRegister> migratorRegister;
|
||||
|
||||
MultipleMigratorRegisterTests()
|
||||
{
|
||||
migratorRegister.emplace(backend_);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, GetMigratorsStatusWhenError)
|
||||
{
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus(testing::_, testing::_))
|
||||
.Times(2)
|
||||
.WillRepeatedly(testing::Return(std::nullopt));
|
||||
|
||||
auto const status = migratorRegister->getMigratorsStatus();
|
||||
EXPECT_EQ(status.size(), 2);
|
||||
EXPECT_TRUE(
|
||||
std::find(
|
||||
status.begin(), status.end(), std::make_tuple("SimpleTestMigrator", migration::MigratorStatus::NotMigrated)
|
||||
) != status.end()
|
||||
);
|
||||
EXPECT_TRUE(
|
||||
std::find(
|
||||
status.begin(), status.end(), std::make_tuple("SimpleTestMigrator2", migration::MigratorStatus::NotMigrated)
|
||||
) != status.end()
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, GetMigratorsStatusWhenReturnInvalidStatus)
|
||||
{
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus(testing::_, testing::_))
|
||||
.Times(2)
|
||||
.WillRepeatedly(testing::Return("Invalid"));
|
||||
|
||||
auto const status = migratorRegister->getMigratorsStatus();
|
||||
EXPECT_EQ(status.size(), 2);
|
||||
EXPECT_TRUE(
|
||||
std::find(
|
||||
status.begin(), status.end(), std::make_tuple("SimpleTestMigrator", migration::MigratorStatus::NotMigrated)
|
||||
) != status.end()
|
||||
);
|
||||
EXPECT_TRUE(
|
||||
std::find(
|
||||
status.begin(), status.end(), std::make_tuple("SimpleTestMigrator2", migration::MigratorStatus::NotMigrated)
|
||||
) != status.end()
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, GetMigratorsStatusWhenOneMigrated)
|
||||
{
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus("SimpleTestMigrator", testing::_)).WillOnce(testing::Return("Migrated"));
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus("SimpleTestMigrator2", testing::_))
|
||||
.WillOnce(testing::Return("NotMigrated"));
|
||||
|
||||
auto const status = migratorRegister->getMigratorsStatus();
|
||||
EXPECT_EQ(status.size(), 2);
|
||||
EXPECT_TRUE(
|
||||
std::find(
|
||||
status.begin(), status.end(), std::make_tuple("SimpleTestMigrator", migration::MigratorStatus::Migrated)
|
||||
) != status.end()
|
||||
);
|
||||
EXPECT_TRUE(
|
||||
std::find(
|
||||
status.begin(), status.end(), std::make_tuple("SimpleTestMigrator2", migration::MigratorStatus::NotMigrated)
|
||||
) != status.end()
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, GetMigratorStatus)
|
||||
{
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus("SimpleTestMigrator", testing::_)).WillOnce(testing::Return("Migrated"));
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus("SimpleTestMigrator2", testing::_))
|
||||
.WillOnce(testing::Return("NotMigrated"));
|
||||
|
||||
EXPECT_EQ(migratorRegister->getMigratorStatus("unknown"), migration::MigratorStatus::NotKnown);
|
||||
EXPECT_EQ(migratorRegister->getMigratorStatus("SimpleTestMigrator"), migration::MigratorStatus::Migrated);
|
||||
EXPECT_EQ(migratorRegister->getMigratorStatus("SimpleTestMigrator2"), migration::MigratorStatus::NotMigrated);
|
||||
}
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, GetMigratorStatusWhenError)
|
||||
{
|
||||
EXPECT_CALL(*backend_, fetchMigratorStatus(testing::_, testing::_))
|
||||
.Times(2)
|
||||
.WillRepeatedly(testing::Return(std::nullopt));
|
||||
|
||||
EXPECT_EQ(migratorRegister->getMigratorStatus("unknown"), migration::MigratorStatus::NotKnown);
|
||||
EXPECT_EQ(migratorRegister->getMigratorStatus("SimpleTestMigrator"), migration::MigratorStatus::NotMigrated);
|
||||
EXPECT_EQ(migratorRegister->getMigratorStatus("SimpleTestMigrator2"), migration::MigratorStatus::NotMigrated);
|
||||
}
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, Names)
|
||||
{
|
||||
auto names = migratorRegister->getMigratorNames();
|
||||
EXPECT_EQ(names.size(), 2);
|
||||
EXPECT_TRUE(std::find(names.begin(), names.end(), "SimpleTestMigrator") != names.end());
|
||||
EXPECT_TRUE(std::find(names.begin(), names.end(), "SimpleTestMigrator2") != names.end());
|
||||
}
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, Description)
|
||||
{
|
||||
EXPECT_EQ(migratorRegister->getMigratorDescription("unknown"), "No Description");
|
||||
EXPECT_EQ(migratorRegister->getMigratorDescription("SimpleTestMigrator"), "The migrator for version 0 -> 1");
|
||||
EXPECT_EQ(migratorRegister->getMigratorDescription("SimpleTestMigrator2"), "The migrator for version 1 -> 2");
|
||||
}
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, RunUnknownMigrator)
|
||||
{
|
||||
EXPECT_CALL(*backend_, writeMigratorStatus(testing::_, testing::_)).Times(0);
|
||||
EXPECT_NO_THROW(migratorRegister->runMigrator("unknown", cfg.getObject("migration")));
|
||||
}
|
||||
|
||||
TEST_F(MultipleMigratorRegisterTests, MigrateNormalMigrator)
|
||||
{
|
||||
EXPECT_CALL(*backend_, writeMigratorStatus("SimpleTestMigrator", "Migrated")).Times(1);
|
||||
EXPECT_NO_THROW(migratorRegister->runMigrator("SimpleTestMigrator", cfg.getObject("migration")));
|
||||
}
|
||||
51
tests/unit/migration/MigratorStatusTests.cpp
Normal file
51
tests/unit/migration/MigratorStatusTests.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 "migration/MigratiorStatus.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(MigratiorStatus, ToString)
|
||||
{
|
||||
migration::MigratorStatus status(migration::MigratorStatus::Migrated);
|
||||
EXPECT_EQ(status.toString(), "Migrated");
|
||||
status = migration::MigratorStatus(migration::MigratorStatus::NotMigrated);
|
||||
EXPECT_EQ(status.toString(), "NotMigrated");
|
||||
status = migration::MigratorStatus(migration::MigratorStatus::NotKnown);
|
||||
EXPECT_EQ(status.toString(), "NotKnown");
|
||||
}
|
||||
|
||||
TEST(MigratiorStatus, FromString)
|
||||
{
|
||||
EXPECT_EQ(migration::MigratorStatus::fromString("Migrated"), migration::MigratorStatus::Migrated);
|
||||
EXPECT_EQ(migration::MigratorStatus::fromString("NotMigrated"), migration::MigratorStatus::NotMigrated);
|
||||
EXPECT_EQ(migration::MigratorStatus::fromString("NotKnown"), migration::MigratorStatus::NotKnown);
|
||||
EXPECT_EQ(migration::MigratorStatus::fromString("Unknown"), migration::MigratorStatus::NotMigrated);
|
||||
}
|
||||
|
||||
TEST(MigratiorStatus, Compare)
|
||||
{
|
||||
migration::MigratorStatus status1(migration::MigratorStatus::Migrated);
|
||||
migration::MigratorStatus status2(migration::MigratorStatus::Migrated);
|
||||
EXPECT_TRUE(status1 == status2);
|
||||
status2 = migration::MigratorStatus(migration::MigratorStatus::NotMigrated);
|
||||
EXPECT_FALSE(status1 == status2);
|
||||
EXPECT_FALSE(status1 == migration::MigratorStatus::NotMigrated);
|
||||
EXPECT_TRUE(status1 == migration::MigratorStatus::Migrated);
|
||||
}
|
||||
41
tests/unit/migration/SpecTests.cpp
Normal file
41
tests/unit/migration/SpecTests.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 "migration/TestMigrators.hpp"
|
||||
#include "migration/impl/Spec.hpp"
|
||||
#include "util/MockMigrationBackend.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace {
|
||||
class Fake {};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(MigrationSpec, MigratorSpec)
|
||||
{
|
||||
static_assert(!migration::impl::MigratorSpec<Fake, MockMigrationBackend>);
|
||||
static_assert(migration::impl::MigratorSpec<SimpleTestMigrator, MockMigrationBackend>);
|
||||
}
|
||||
|
||||
TEST(MigrationSpec, AllMigratorSpec)
|
||||
{
|
||||
static_assert(!migration::impl::AllMigratorSpec<SimpleTestMigrator, SimpleTestMigrator2, Fake>);
|
||||
static_assert(migration::impl::AllMigratorSpec<SimpleTestMigrator2, SimpleTestMigrator>);
|
||||
}
|
||||
111
tests/unit/migration/cassandra/FullTableScannerTests.cpp
Normal file
111
tests/unit/migration/cassandra/FullTableScannerTests.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 "migration/cassandra/impl/FullTableScanner.hpp"
|
||||
#include "util/LoggerFixtures.hpp"
|
||||
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace {
|
||||
|
||||
struct TestScannerAdaper {
|
||||
TestScannerAdaper(
|
||||
testing::MockFunction<void(migration::cassandra::impl::TokenRange const&, boost::asio::yield_context)>& func
|
||||
)
|
||||
: callback(func) {};
|
||||
|
||||
TestScannerAdaper(TestScannerAdaper const&) = default;
|
||||
TestScannerAdaper(TestScannerAdaper&&) = default;
|
||||
|
||||
std::reference_wrapper<
|
||||
testing::MockFunction<void(migration::cassandra::impl::TokenRange const&, boost::asio::yield_context)>>
|
||||
callback;
|
||||
|
||||
void
|
||||
readByTokenRange(migration::cassandra::impl::TokenRange const& range, boost::asio::yield_context yield) const
|
||||
{
|
||||
callback.get().Call(range, yield);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
struct FullTableScannerTests : public NoLoggerFixture {};
|
||||
|
||||
TEST_F(FullTableScannerTests, workerNumZero)
|
||||
{
|
||||
testing::MockFunction<void(migration::cassandra::impl::TokenRange const&, boost::asio::yield_context)> mockCallback;
|
||||
EXPECT_DEATH(
|
||||
migration::cassandra::impl::FullTableScanner<TestScannerAdaper>(
|
||||
{.ctxThreadsNum = 1, .jobsNum = 0, .cursorsPerJob = 100}, TestScannerAdaper(mockCallback)
|
||||
),
|
||||
"jobsNum for full table scanner must be greater than 0"
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(FullTableScannerTests, cursorsPerWorkerZero)
|
||||
{
|
||||
testing::MockFunction<void(migration::cassandra::impl::TokenRange const&, boost::asio::yield_context)> mockCallback;
|
||||
EXPECT_DEATH(
|
||||
migration::cassandra::impl::FullTableScanner<TestScannerAdaper>(
|
||||
{.ctxThreadsNum = 1, .jobsNum = 1, .cursorsPerJob = 0}, TestScannerAdaper(mockCallback)
|
||||
),
|
||||
"cursorsPerJob for full table scanner must be greater than 0"
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(FullTableScannerTests, SingleThreadCtx)
|
||||
{
|
||||
testing::MockFunction<void(migration::cassandra::impl::TokenRange const&, boost::asio::yield_context)> mockCallback;
|
||||
EXPECT_CALL(mockCallback, Call(testing::_, testing::_)).Times(100);
|
||||
auto scanner = migration::cassandra::impl::FullTableScanner<TestScannerAdaper>(
|
||||
{.ctxThreadsNum = 1, .jobsNum = 1, .cursorsPerJob = 100}, TestScannerAdaper(mockCallback)
|
||||
);
|
||||
scanner.wait();
|
||||
}
|
||||
|
||||
TEST_F(FullTableScannerTests, MultipleThreadCtx)
|
||||
{
|
||||
testing::MockFunction<void(migration::cassandra::impl::TokenRange const&, boost::asio::yield_context)> mockCallback;
|
||||
EXPECT_CALL(mockCallback, Call(testing::_, testing::_)).Times(200);
|
||||
auto scanner = migration::cassandra::impl::FullTableScanner<TestScannerAdaper>(
|
||||
{.ctxThreadsNum = 2, .jobsNum = 2, .cursorsPerJob = 100}, TestScannerAdaper(mockCallback)
|
||||
);
|
||||
scanner.wait();
|
||||
}
|
||||
|
||||
MATCHER(RangeMinMax, "Matches the range with min and max")
|
||||
{
|
||||
return (arg.start == std::numeric_limits<std::int64_t>::min()) &&
|
||||
(arg.end == std::numeric_limits<std::int64_t>::max());
|
||||
}
|
||||
TEST_F(FullTableScannerTests, RangeSizeIsOne)
|
||||
{
|
||||
testing::MockFunction<void(migration::cassandra::impl::TokenRange const&, boost::asio::yield_context)> mockCallback;
|
||||
EXPECT_CALL(mockCallback, Call(RangeMinMax(), testing::_)).Times(1);
|
||||
auto scanner = migration::cassandra::impl::FullTableScanner<TestScannerAdaper>(
|
||||
{.ctxThreadsNum = 2, .jobsNum = 1, .cursorsPerJob = 1}, TestScannerAdaper(mockCallback)
|
||||
);
|
||||
scanner.wait();
|
||||
}
|
||||
40
tests/unit/migration/cassandra/SpecTests.cpp
Normal file
40
tests/unit/migration/cassandra/SpecTests.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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 "migration/cassandra/impl/Spec.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <tuple>
|
||||
|
||||
namespace {
|
||||
class Empty {};
|
||||
|
||||
struct SimpleTestTable {
|
||||
using Row = std::tuple<std::uint32_t, std::uint32_t>;
|
||||
static constexpr char const* PARTITION_KEY = "key";
|
||||
static constexpr char const* TABLE_NAME = "test";
|
||||
};
|
||||
} // namespace
|
||||
TEST(MigrationSpec, TableSpec)
|
||||
{
|
||||
static_assert(!migration::cassandra::impl::TableSpec<Empty>);
|
||||
static_assert(migration::cassandra::impl::TableSpec<SimpleTestTable>);
|
||||
}
|
||||
55
tests/unit/util/ConceptsTests.cpp
Normal file
55
tests/unit/util/ConceptsTests.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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/Concepts.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(ConceptTests, SomeNumberType)
|
||||
{
|
||||
static_assert(util::SomeNumberType<int>);
|
||||
static_assert(!util::SomeNumberType<bool>);
|
||||
static_assert(util::SomeNumberType<char>);
|
||||
static_assert(!util::SomeNumberType<int const>);
|
||||
}
|
||||
|
||||
TEST(ConceptTests, hasNoDuplicates)
|
||||
{
|
||||
static_assert(util::hasNoDuplicates(1, 2, 3, 4, 5));
|
||||
static_assert(!util::hasNoDuplicates(1, 2, 3, 4, 5, 5));
|
||||
}
|
||||
|
||||
struct TestA {
|
||||
static constexpr auto name = "TestA";
|
||||
};
|
||||
|
||||
struct AnotherA {
|
||||
static constexpr auto name = "TestA";
|
||||
};
|
||||
|
||||
struct TestB {
|
||||
static constexpr auto name = "TestB";
|
||||
};
|
||||
|
||||
TEST(ConceptTests, hasNoDuplicateNames)
|
||||
{
|
||||
static_assert(util::hasNoDuplicateNames<TestA, TestB>());
|
||||
static_assert(!util::hasNoDuplicateNames<TestA, AnotherA, TestB>());
|
||||
static_assert(!util::hasNoDuplicateNames<TestA, TestB, AnotherA>());
|
||||
}
|
||||
Reference in New Issue
Block a user