[core] Moving caching logic to DefaultFileSource
This results in OnlineFileSource containing precisely the logic we want for reuse by OfflineFileSource, and no more.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "storage.hpp"
|
||||
|
||||
#include <mbgl/storage/online_file_source.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/storage/sqlite_cache.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
@@ -11,8 +11,7 @@ TEST_F(Storage, CacheResponse) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache(":memory:");
|
||||
OnlineFileSource fs(&cache);
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/cache" };
|
||||
Response response;
|
||||
@@ -56,15 +55,14 @@ TEST_F(Storage, CacheNotFound) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache(":memory:");
|
||||
OnlineFileSource fs(&cache);
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource resource{ Resource::Unknown, "http://127.0.0.1:3000/not-found" };
|
||||
|
||||
// Insert existing data into the cache that will be marked as stale.
|
||||
Response response;
|
||||
response.data = std::make_shared<const std::string>("existing data");
|
||||
cache.put(resource, response);
|
||||
fs.getCache().put(resource, response);
|
||||
|
||||
std::unique_ptr<FileRequest> req1;
|
||||
std::unique_ptr<WorkRequest> req2;
|
||||
@@ -89,7 +87,7 @@ TEST_F(Storage, CacheNotFound) {
|
||||
req1.reset();
|
||||
|
||||
// Finally, check the cache to make sure we cached the 404 response.
|
||||
req2 = cache.get(resource, [&](std::unique_ptr<Response> res2) {
|
||||
req2 = fs.getCache().get(resource, [&](std::unique_ptr<Response> res2) {
|
||||
EXPECT_NE(nullptr, res2->error);
|
||||
EXPECT_EQ(Response::Error::Reason::NotFound, res2->error->reason);
|
||||
ASSERT_TRUE(res2->data.get());
|
||||
@@ -113,15 +111,14 @@ TEST_F(Storage, DontCacheConnectionErrors) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache(":memory:");
|
||||
OnlineFileSource fs(&cache);
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource resource{ Resource::Unknown, "http://127.0.0.1:3001" };
|
||||
|
||||
// Insert existing data into the cache that will be marked as stale.
|
||||
Response response;
|
||||
response.data = std::make_shared<const std::string>("existing data");
|
||||
cache.put(resource, response);
|
||||
fs.getCache().put(resource, response);
|
||||
|
||||
std::unique_ptr<FileRequest> req1;
|
||||
std::unique_ptr<WorkRequest> req2;
|
||||
@@ -145,7 +142,7 @@ TEST_F(Storage, DontCacheConnectionErrors) {
|
||||
|
||||
// Finally, check the cache to make sure we still have our original data in there rather
|
||||
// than the failed connection attempt.
|
||||
req2 = cache.get(resource, [&](std::unique_ptr<Response> res2) {
|
||||
req2 = fs.getCache().get(resource, [&](std::unique_ptr<Response> res2) {
|
||||
EXPECT_EQ(nullptr, res2->error);
|
||||
ASSERT_TRUE(res2->data.get());
|
||||
EXPECT_EQ("existing data", *res2->data);
|
||||
@@ -168,15 +165,14 @@ TEST_F(Storage, DontCacheServerErrors) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache(":memory:");
|
||||
OnlineFileSource fs(&cache);
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource resource{ Resource::Unknown, "http://127.0.0.1:3000/permanent-error" };
|
||||
|
||||
// Insert existing data into the cache that will be marked as stale.
|
||||
Response response;
|
||||
response.data = std::make_shared<const std::string>("existing data");
|
||||
cache.put(resource, response);
|
||||
fs.getCache().put(resource, response);
|
||||
|
||||
std::unique_ptr<FileRequest> req1;
|
||||
std::unique_ptr<WorkRequest> req2;
|
||||
@@ -202,7 +198,7 @@ TEST_F(Storage, DontCacheServerErrors) {
|
||||
|
||||
// Finally, check the cache to make sure we still have our original data in there rather
|
||||
// than the failed connection attempt.
|
||||
req2 = cache.get(resource, [&](std::unique_ptr<Response> res2) {
|
||||
req2 = fs.getCache().get(resource, [&](std::unique_ptr<Response> res2) {
|
||||
EXPECT_EQ(nullptr, res2->error);
|
||||
ASSERT_TRUE(res2->data.get());
|
||||
EXPECT_EQ("existing data", *res2->data);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "storage.hpp"
|
||||
|
||||
#include <mbgl/storage/online_file_source.hpp>
|
||||
#include <mbgl/storage/sqlite_cache.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
@@ -11,8 +10,7 @@ TEST_F(Storage, CacheRevalidateSame) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache(":memory:");
|
||||
OnlineFileSource fs(&cache);
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource revalidateSame { Resource::Unknown, "http://127.0.0.1:3000/revalidate-same" };
|
||||
std::unique_ptr<FileRequest> req1;
|
||||
@@ -61,8 +59,7 @@ TEST_F(Storage, CacheRevalidateModified) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache(":memory:");
|
||||
OnlineFileSource fs(&cache);
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource revalidateModified{ Resource::Unknown,
|
||||
"http://127.0.0.1:3000/revalidate-modified" };
|
||||
@@ -111,8 +108,7 @@ TEST_F(Storage, CacheRevalidateEtag) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache(":memory:");
|
||||
OnlineFileSource fs(&cache);
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource revalidateEtag { Resource::Unknown, "http://127.0.0.1:3000/revalidate-etag" };
|
||||
std::unique_ptr<FileRequest> req1;
|
||||
|
||||
@@ -13,7 +13,7 @@ TEST_F(Storage, HTTPCancel) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
auto req =
|
||||
fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
|
||||
@@ -31,7 +31,7 @@ TEST_F(Storage, HTTPCancelMultiple) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" };
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ TEST_F(Storage, HTTPTemporaryError) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
const auto start = Clock::now();
|
||||
|
||||
@@ -58,7 +58,7 @@ TEST_F(Storage, HTTPConnectionError) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
const auto start = Clock::now();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ TEST_F(Storage, HTTPExpiresParsing) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
std::unique_ptr<FileRequest> req1 = fs.request({ Resource::Unknown,
|
||||
"http://127.0.0.1:3000/test?modified=1420794326&expires=1420797926&etag=foo" },
|
||||
@@ -37,7 +37,7 @@ TEST_F(Storage, HTTPCacheControlParsing) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
std::unique_ptr<FileRequest> req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test?cachecontrol=max-age=120" },
|
||||
[&](Response res) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "storage.hpp"
|
||||
|
||||
#include <mbgl/storage/online_file_source.hpp>
|
||||
#include <mbgl/storage/sqlite_cache.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
// Test for https://github.com/mapbox/mapbox-gl-native/issue/1369
|
||||
@@ -22,8 +20,7 @@ TEST_F(Storage, HTTPIssue1369) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
SQLiteCache cache;
|
||||
OnlineFileSource fs(&cache);
|
||||
DefaultFileSource fs(":memory:", ".");
|
||||
|
||||
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" };
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ TEST_F(Storage, HTTPLoad) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
const int concurrency = 50;
|
||||
const int max = 10000;
|
||||
|
||||
@@ -11,7 +11,7 @@ TEST_F(Storage, HTTPOtherLoop) {
|
||||
|
||||
// This file source launches a separate thread to do the processing.
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
|
||||
[&](Response res) {
|
||||
|
||||
@@ -14,7 +14,7 @@ TEST_F(Storage, HTTPTest) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
std::unique_ptr<FileRequest> req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
|
||||
[&](Response res) {
|
||||
@@ -39,7 +39,7 @@ TEST_F(Storage, HTTP404) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
std::unique_ptr<FileRequest> req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/doesnotexist" },
|
||||
[&](Response res) {
|
||||
@@ -66,7 +66,7 @@ TEST_F(Storage, HTTP500) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
std::unique_ptr<FileRequest> req3 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/permanent-error" },
|
||||
[&](Response res) {
|
||||
@@ -93,7 +93,7 @@ TEST_F(Storage, HTTPNoCallback) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
try {
|
||||
fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" },
|
||||
|
||||
@@ -18,7 +18,7 @@ TEST_F(Storage, HTTPNetworkStatusChange) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/delayed" };
|
||||
|
||||
@@ -57,7 +57,7 @@ TEST_F(Storage, HTTPNetworkStatusChangePreempt) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
const auto start = Clock::now();
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ TEST_F(Storage, HTTPTimeout) {
|
||||
using namespace mbgl;
|
||||
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
OnlineFileSource fs;
|
||||
|
||||
int counter = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user