ASSERT_GE(cache->GetPinnedUsage(), 1024 * 1024);
ASSERT_LT(cache->GetPinnedUsage(), 1024 * 1024 + 10000);
}
+
+TEST_F(WriteBufferManagerTest, CacheFull) {
+ // 15MB cache size with strict capacity
+ LRUCacheOptions lo;
+ lo.capacity = 12 * 1024 * 1024;
+ lo.num_shard_bits = 0;
+ lo.strict_capacity_limit = true;
+ std::shared_ptr<Cache> cache = NewLRUCache(lo);
+ std::unique_ptr<WriteBufferManager> wbf(new WriteBufferManager(0, cache));
+ wbf->ReserveMem(10 * 1024 * 1024);
+ size_t prev_pinned = cache->GetPinnedUsage();
+ ASSERT_GE(prev_pinned, 10 * 1024 * 1024);
+ // Some insert will fail
+ wbf->ReserveMem(10 * 1024 * 1024);
+ ASSERT_LE(cache->GetPinnedUsage(), 12 * 1024 * 1024);
+
+ // Increase capacity so next insert will succeed
+ cache->SetCapacity(30 * 1024 * 1024);
+ wbf->ReserveMem(10 * 1024 * 1024);
+ ASSERT_GT(cache->GetPinnedUsage(), 20 * 1024 * 1024);
+
+ // Gradually release 20 MB
+ for (int i = 0; i < 40; i++) {
+ wbf->FreeMem(512 * 1024);
+ }
+ ASSERT_GE(cache->GetPinnedUsage(), 10 * 1024 * 1024);
+ ASSERT_LT(cache->GetPinnedUsage(), 20 * 1024 * 1024);
+}
+
#endif // ROCKSDB_LITE
} // namespace ROCKSDB_NAMESPACE