Welcome to mirror list, hosted at ThFree Co, Russian Federation.

migrate_tests.cpp « storage_integration_tests « storage - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d9b3d195bddf94b0d9fc4626b3218eeef1e0b121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "testing/testing.hpp"

#include "storage/storage_integration_tests/test_defines.hpp"

#include "map/framework.hpp"

#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"
#include "platform/platform_tests_support/scoped_dir.hpp"
#include "platform/platform_tests_support/writable_dir_changer.hpp"

#include "base/file_name_utils.hpp"
#include "base/scope_guard.hpp"
#include "base/string_utils.hpp"
#include "base/thread.hpp"

#include <cstdint>

using namespace platform;
using namespace storage;

static FrameworkParams const kFrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */);

UNIT_TEST(StorageFastMigrationTests)
{
  WritableDirChanger writableDirChanger(kMapTestDir);

  Framework f(kFrameworkParams);
  auto & s = f.GetStorage();

  uint32_t version;
  TEST(settings::Get("LastMigration", version), ("LastMigration didn't set"));

  TEST_GREATER_OR_EQUAL(s.GetCurrentDataVersion(), version, ());
}

// This test on migration from big square and two component mwms to smaller square and one component
// ones. According to |kMinRequiredVersion| constant at local_country_file_utils.cpp this migration
// took place at 02.03.2016. For the time being this migration is not supported and is not tested.
// The test bellow fails because when a prefeched storage, to download map or maps according to
// current position, is created with code
// |m_prefetchStorage.reset(new Storage(COUNTRIES_FILE, "migrate"));| does not create
// the directory ./migrate/ now. And late in this test creation a directory
// ./migrate/YYMMDD/ with Platform::MkDirChecked() fails because there's no ./migrate/
// directory.
// @TODO The code on the migration mentioned above should be removed. When this code is removed
// test below should be removed as well. Until code on the code is not removed from the project
// this test should be kept in case we decide to recover this feature.

// UNIT_TEST(StorageMigrationTests)
//{
//  CountriesVec const kOldCountries = {"Estonia"};
//  CountriesVec const kNewCountries = {"Estonia_East", "Estonia_West"};
//  CountriesVec const kPrefetchCountries = {"Russia_Moscow"};
//
//  WritableDirChanger writableDirChanger(kMapTestDir);
//
//  settings::Set("DisableFastMigrate", true);
//
//  Framework f(kFrameworkParams);
//  auto & s = f.GetStorage();
//
//  auto statePrefetchChanged = [&](CountryId const & id)
//  {
//    Status const nextStatus = f.GetStorage().GetPrefetchStorage()->CountryStatusEx(id);
//    LOG_SHORT(LINFO, (id, "status :", nextStatus));
//    if (!f.GetStorage().GetPrefetchStorage()->IsDownloadInProgress())
//    {
//      LOG_SHORT(LINFO, ("All prefetched. Ready to migrate."));
//      testing::StopEventLoop();
//    }
//  };
//
//  auto stateChanged = [&](CountryId const & id)
//  {
//    if (!f.GetStorage().IsDownloadInProgress())
//    {
//      LOG_SHORT(LINFO, ("All downloaded. Check consistency."));
//      testing::StopEventLoop();
//    }
//  };
//
//  auto progressChanged = [](CountryId const & id, LocalAndRemoteSize const & sz)
//  {
//    LOG_SHORT(LINFO, (id, "downloading progress:", sz));
//  };
//
//  // Somewhere in Moscow, Russia
//  ms::LatLon curPos(55.7, 37.7);
//
//  s.SetDownloadingServersForTesting({"http://direct.mapswithme.com/"});
//  s.Subscribe(stateChanged, progressChanged);
//  for (auto const & countryId : kOldCountries)
//    s.DownloadNode(countryId);
//
//  // Wait for downloading complete.
//  testing::RunEventLoop();
//
//  TEST_EQUAL(s.GetDownloadedFilesCount(), kOldCountries.size(), ());
//  for (auto const & countryId : kOldCountries)
//    TEST(s.IsNodeDownloaded(countryId), (countryId));
//
//  TEST_NOT_EQUAL(f.PreMigrate(curPos, statePrefetchChanged, progressChanged), kInvalidCountryId,
//  ()); TEST(f.GetStorage().GetPrefetchStorage()->IsDownloadInProgress(), ("Empty queue"));
//  // Wait for downloading complete.
//  testing::RunEventLoop();
//
//  TEST_EQUAL(s.GetDownloadedFilesCount(), kPrefetchCountries.size(), ());
//  for (auto const & countryId : kPrefetchCountries)
//    TEST(s.GetPrefetchStorage()->IsNodeDownloaded(countryId), (countryId));
//
//  f.Migrate();
//  // Wait for downloading complete.
//  testing::RunEventLoop();
//
//  TEST_EQUAL(s.GetDownloadedFilesCount(), kPrefetchCountries.size() + kNewCountries.size(), ());
//  for (auto const & countryId : kNewCountries)
//    TEST(s.IsNodeDownloaded(countryId), (countryId));
//  for (auto const & countryId : kPrefetchCountries)
//    TEST(s.IsNodeDownloaded(countryId), (countryId));
//
//  s.DeleteAllLocalMaps();
//}