29 using namespace folly;
36 using MutexTypes = ::testing::Types<std::mutex, folly::SharedMutex>;
40 static shared_ptr<LRUPersistentCache<string, string, T>>
createCache(
43 std::unique_ptr<TestPersistenceLayer> persistence =
nullptr) {
45 return std::make_shared<TestCache>(
47 std::chrono::milliseconds(syncMillis),
53 static shared_ptr<LRUPersistentCache<string, string, T>>
55 std::shared_ptr<folly::Executor>
executor,
56 std::unique_ptr<TestPersistenceLayer> persistence,
57 std::chrono::milliseconds syncInterval,
59 return std::make_shared<LRUPersistentCache<string, string, T>>(
91 template<
typename MutexT>
95 persistence = make_unique<MockPersistenceLayer>();
96 ON_CALL(*persistence, getLastPersistedVersion())
100 ON_CALL(*persistence, setPersistedVersion(
_))
104 manualExecutor = std::make_shared<folly::ManualExecutor>();
105 inlineExecutor = std::make_shared<folly::InlineExecutor>();
115 auto cache = createCache<TypeParam>(10, 1,
nullptr);
116 cache->put(
"k0",
"v0");
117 makeFuture().delayed(std::chrono::milliseconds(20)).thenValue(
119 auto val = cache->get(
"k0");
127 return size_t(n) == arg.size();
131 auto cache = createCache<TypeParam>(10, 10,
nullptr);
132 cache->put(
"k0",
"v0");
138 EXPECT_CALL(*this->persistence, persist_(DynSize(2)))
141 cache->setPersistence(
std::move(this->persistence));
145 auto cache = createCache<TypeParam>(10, 10000,
nullptr);
146 cache->setSyncOnDestroy(
true);
147 auto persistence = this->persistence.get();
148 cache->setPersistence(
std::move(this->persistence));
149 cache->put(
"k0",
"v0");
162 auto cache = createCache<TypeParam>(10, 10,
nullptr);
163 cache->put(
"k0",
"v0");
164 cache->put(
"k1",
"v1");
172 auto p2 = make_unique<MockPersistenceLayer>();
173 ON_CALL(*p2, getLastPersistedVersion())
188 EXPECT_CALL(*this->persistence, persist_(DynSize(2)))
192 cache->setPersistence(
std::move(this->persistence));
193 makeFuture().delayed(std::chrono::milliseconds(100)).get();
204 auto cache = createCache<TypeParam>(10, 10,
std::move(this->persistence));
209 EXPECT_CALL(*this->persistence, getLastPersistedVersion())
213 this->persistence.get(),
215 auto cache = createCache<TypeParam>(10, 10,
std::move(this->persistence));
220 auto cache = createCache<TypeParam>(10, 10,
std::move(this->persistence));
226 auto cache = createCache<TypeParam>(10, 10,
std::move(this->persistence));
231 auto cache = createCacheWithExecutor<TypeParam>(
232 this->manualExecutor,
234 std::chrono::milliseconds::zero(),
238 this->manualExecutor->drain();
246 auto rawPersistence = this->persistence.get();
247 auto cache = createCacheWithExecutor<TypeParam>(
248 this->manualExecutor,
250 std::chrono::milliseconds::zero(),
252 cache->put(
"k0",
"v0");
253 EXPECT_CALL(*rawPersistence, getLastPersistedVersion())
261 this->manualExecutor->run();
270 auto rawPersistence = this->persistence.get();
271 auto cache = createCacheWithExecutor<TypeParam>(
272 this->inlineExecutor,
274 std::chrono::milliseconds::zero(),
276 EXPECT_CALL(*rawPersistence, getLastPersistedVersion())
284 cache->put(
"k0",
"v0");
286 EXPECT_CALL(*rawPersistence, getLastPersistedVersion())
294 cache->put(
"k2",
"v2");
302 auto rawPersistence = this->persistence.get();
303 auto cache = createCacheWithExecutor<TypeParam>(
304 this->manualExecutor,
306 std::chrono::milliseconds::zero(),
308 EXPECT_CALL(*rawPersistence, getLastPersistedVersion())
313 cache->put(
"k0",
"v0");
317 this->manualExecutor->run();
319 cache->put(
"k1",
"v1");
328 this->manualExecutor->run();
338 auto cache = createCacheWithExecutor<TypeParam>(
339 this->manualExecutor,
341 std::chrono::milliseconds::zero(),
343 cache->put(
"k0",
"v0");
344 cache->put(
"k2",
"v2");
349 this->manualExecutor->drain();
356 auto rawPersistence = this->persistence.get();
357 auto cache = createCacheWithExecutor<TypeParam>(
358 this->manualExecutor,
360 std::chrono::milliseconds(60 * 60 * 1000),
362 EXPECT_CALL(*rawPersistence, getLastPersistedVersion())
367 cache->put(
"k0",
"v0");
371 this->manualExecutor->run();
374 EXPECT_CALL(*rawPersistence, persist_(DynSize(2))).Times(0);
375 EXPECT_CALL(*rawPersistence, setPersistedVersion(
_)).Times(0);
376 cache->put(
"k1",
"v1");
377 this->manualExecutor->run();
379 this->manualExecutor->drain();
static shared_ptr< LRUPersistentCache< string, string, T > > createCacheWithExecutor(std::shared_ptr< folly::Executor > executor, std::unique_ptr< TestPersistenceLayer > persistence, std::chrono::milliseconds syncInterval, int retryLimit)
static shared_ptr< LRUPersistentCache< string, string, T > > createCache(size_t capacity, uint32_t syncMillis, std::unique_ptr< TestPersistenceLayer > persistence=nullptr)
#define GMOCK_METHOD1_(tn, constness, ct, Method,...)
GTEST_API_ Cardinality AtLeast(int n)
CacheDataVersion getLastPersistedVersionConcrete() const
uint64_t CacheDataVersion
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
void setPersistedVersionConcrete(CacheDataVersion version)
Gen seq(Value first, Value last)
Optional< dynamic > load() noexceptoverride
unique_ptr< MockPersistenceLayer > persistence
TYPED_TEST_CASE(SynchronizedTest, SynchronizedTestTypes)
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
~MockPersistenceLayer() override
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
virtual void setPersistedVersion(CacheDataVersion version) noexcept
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
TYPED_TEST(SynchronizedTest, Basic)
constexpr auto data(C &c) -> decltype(c.data())
std::shared_ptr< folly::ManualExecutor > manualExecutor
::testing::Types< std::mutex, folly::SharedMutex > MutexTypes
#define EXPECT_TRUE(condition)
#define ON_CALL(obj, call)
#define MOCK_METHOD1(m,...)
static void array(EmptyArrayTag)
#define MOCK_CONST_METHOD0(m,...)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
virtual CacheDataVersion getLastPersistedVersion() const
bool persist(const dynamic &obj) noexceptoverride
Future< typename std::decay< T >::type > makeFuture(T &&t)
internal::ReturnAction< R > Return(R value)
std::shared_ptr< folly::InlineExecutor > inlineExecutor
#define MOCK_METHOD0(m,...)