diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-03-15 15:23:25 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-03-17 14:17:59 -0700 |
commit | 5130ca8843a342a1b708bb63263fd44c6c908120 (patch) | |
tree | 125ce7af31e47b603459977ddea0e8aaf9146bf1 /test | |
parent | aa60d295346871bad0884238d13dcd9995d97151 (diff) | |
download | qtlocation-mapboxgl-5130ca8843a342a1b708bb63263fd44c6c908120.tar.gz |
[core] Implement a vacuum strategy for the offline database
Enable `PRAGMA auto_vacuum = INCREMENTAL`, and perform a `PRAGMA incremental_vacuum` when deleting an offline region.
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/offline/v2.db | bin | 0 -> 43008 bytes | |||
-rw-r--r-- | test/storage/offline_database.cpp | 28 |
2 files changed, 28 insertions, 0 deletions
diff --git a/test/fixtures/offline/v2.db b/test/fixtures/offline/v2.db Binary files differnew file mode 100644 index 0000000000..8fadec4abe --- /dev/null +++ b/test/fixtures/offline/v2.db diff --git a/test/storage/offline_database.cpp b/test/storage/offline_database.cpp index 23269a98ed..11d56c237b 100644 --- a/test/storage/offline_database.cpp +++ b/test/storage/offline_database.cpp @@ -7,6 +7,7 @@ #include <mbgl/util/string.hpp> #include <gtest/gtest.h> +#include <sqlite3.hpp> #include <sqlite3.h> #include <thread> #include <random> @@ -660,3 +661,30 @@ TEST(OfflineDatabase, OfflineMapboxTileCount) { db.deleteRegion(std::move(region1)); EXPECT_EQ(0, db.getOfflineMapboxTileCount()); } + +static int databasePageCount(const std::string& path) { + mapbox::sqlite::Database db(path, mapbox::sqlite::ReadOnly); + mapbox::sqlite::Statement stmt = db.prepare("pragma page_count"); + stmt.run(); + return stmt.get<int>(0); +} + +TEST(OfflineDatabase, MigrateFromV2Schema) { + using namespace mbgl; + + // v2.db is a v2 database containing a single offline region with a small number of resources. + + deleteFile("test/fixtures/offline/v3.db"); + writeFile("test/fixtures/offline/v3.db", util::read_file("test/fixtures/offline/v2.db")); + + { + OfflineDatabase db("test/fixtures/offline/v3.db", 0); + auto regions = db.listRegions(); + for (auto& region : regions) { + db.deleteRegion(std::move(region)); + } + } + + EXPECT_LT(databasePageCount("test/fixtures/offline/v3.db"), + databasePageCount("test/fixtures/offline/v2.db")); +} |