Moved ugc migration files option to ugc_tests CMakeList.

This commit is contained in:
VladiMihaylenko 2018-06-21 19:43:24 +03:00 committed by mpimenov
parent b8c9a8a020
commit 262b15bd42
10 changed files with 45 additions and 15 deletions

View file

@ -64,7 +64,6 @@ option(USE_TSAN "Enable Thread Sanitizer" OFF)
option(PYBINDINGS "Create makefiles for building python bindings" OFF)
option(SKIP_DESKTOP "Skip building of desktop application" OFF)
option(BUILD_MAPSHOT "Build mapshot tool" OFF)
option(UGC_MIGRATION "Build migration file for ugc" OFF)
option(USE_PCH "Use precompiled headers" OFF)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -81,6 +81,10 @@ namespace migration
{
Result Migrate(UpdateIndexes & source)
{
CHECK(!source.empty(), ());
if (source.front().m_version == IndexVersion::Latest)
return Result::UpToDate;
auto const result = MigrateFromV0ToV1(source);
return result ? Result::Success : Result::Failure;
}

View file

@ -8,8 +8,9 @@ namespace migration
{
enum class Result
{
UpToDate,
Failure,
Success,
Success
};
Result Migrate(UpdateIndexes & source);

View file

@ -214,8 +214,8 @@ public:
template <typename T, EnableIfEnum<T> * = nullptr>
void operator()(T & t, char const * name = nullptr)
{
using UndelyingType = std::underlying_type_t<T>;
UndelyingType res;
using UnderlyingType = std::underlying_type_t<T>;
UnderlyingType res;
FromJSONObject(m_json, name, res);
t = static_cast<T>(res);
}

View file

@ -24,6 +24,8 @@
#include "3party/jansson/myjansson.hpp"
#include <boost/optional/optional.hpp>
using namespace std;
namespace
@ -215,8 +217,14 @@ void Storage::Load()
if (m_indexes.empty())
return;
boost::optional<IndexVersion> version;
for (auto const & i : m_indexes)
{
if (!version)
version = i.m_version;
else
CHECK_EQUAL(static_cast<uint8_t>(*version), static_cast<uint8_t>(i.m_version), ("Inconsistent index"));
if (i.m_deleted)
++m_numberOfDeleted;
}
@ -226,12 +234,13 @@ void Storage::Load()
void Storage::Migrate(string const & indexFilePath)
{
// We assume there is no situation when indexes from different versions are stored in the vector.
if (m_indexes.front().m_version == IndexVersion::Latest)
if (m_indexes.empty())
return;
switch (migration::Migrate(m_indexes))
{
case migration::Result::UpToDate:
break;
case migration::Result::Failure:
LOG(LWARNING, ("Index migration failed"));
break;

View file

@ -16,7 +16,7 @@ namespace ugc
class Storage
{
public:
explicit Storage(Index const & index) : m_index(index) {}
explicit Storage(DataSourceBase const & index) : m_index(index) {}
UGCUpdate GetUGCUpdate(FeatureID const & id) const;
@ -46,7 +46,7 @@ private:
std::unique_ptr<FeatureType> GetFeature(FeatureID const & id) const;
void Migrate(std::string const & indexFilePath);
Index const & m_index;
DataSourceBase const & m_index;
UpdateIndexes m_indexes;
size_t m_numberOfDeleted = 0;
};

View file

@ -2,6 +2,8 @@ project(ugc_tests)
include_directories(${OMIM_ROOT}/3party/jansson/src)
option(UGC_MIGRATION "Build migration file for ugc" OFF)
set(
SRC
serdes_binary_tests.cpp
@ -17,6 +19,8 @@ if (UGC_MIGRATION)
${SRC}
migration/generate_migration_files.cpp
)
message("Generating files for UGC index migration")
endif()
omim_add_test(${PROJECT_NAME} ${SRC})

View file

@ -20,6 +20,7 @@
#include "coding/file_name_utils.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/writer.hpp"
#include "coding/zlib.hpp"
#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"
@ -441,14 +442,27 @@ UNIT_CLASS_TEST(StorageTest, GetNumberOfUnsentSeparately)
UNIT_TEST(UGC_IndexMigrationFromV0ToV1Smoke)
{
auto & p = GetPlatform();
auto const version = "v0";
auto const indexFileName = "index.json";
auto const folder = my::JoinPath(p.WritableDir(), "ugc_migration", "test_index", version);
auto const indexFilePath = my::JoinPath(folder, indexFileName);
{
using Inflate = coding::ZLib::Inflate;
auto const r = p.GetReader(my::JoinPath(folder, "index.gz"));
string data;
r->ReadAsString(data);
Inflate inflate(Inflate::Format::GZip);
string index;
inflate(data.data(), data.size(), back_inserter(index));
FileWriter w(indexFilePath);
w.Write(index.data(), index.size());
}
auto & builder = MwmBuilder::Builder();
builder.Build({});
auto const versionString = "v0";
auto const indexFileName = "index.json";
auto const indexFilePath = my::JoinPath(GetPlatform().WritableDir(), "ugc_migration", "test_index", versionString,
indexFileName);
auto const v0IndexFilePath = indexFilePath + "." + versionString;
auto const v0IndexFilePath = indexFilePath + "." + version;
Storage s(builder.GetIndex());
s.LoadForTesting(indexFilePath);
uint64_t migratedIndexFileSize = 0;
@ -465,5 +479,5 @@ UNIT_TEST(UGC_IndexMigrationFromV0ToV1Smoke)
}
my::DeleteFileX(indexFilePath);
my::RenameFileX(v0IndexFilePath, indexFilePath);
my::DeleteFileX(v0IndexFilePath);
}