@@ -286,4 +286,108 @@ TEST_F(StoragePageCacheTest, mixed_pages) {
286286 }
287287}
288288
289+ TEST_F (StoragePageCacheTest, zero_index_cache_percentage) {
290+ StoragePageCache cache (kNumShards * 2048 , 0 , 0 , kNumShards );
291+
292+ StoragePageCache::CacheKey data_key (" data" , 0 , 0 );
293+ StoragePageCache::CacheKey index_key (" index" , 0 , 0 );
294+
295+ segment_v2::PageTypePB page_type_data = segment_v2::DATA_PAGE;
296+ segment_v2::PageTypePB page_type_index = segment_v2::INDEX_PAGE;
297+
298+ {
299+ PageCacheHandle handle;
300+ auto * data = new DataPage (1024 , true , page_type_data);
301+ cache.insert (data_key, data, &handle, page_type_data, false );
302+ auto found = cache.lookup (data_key, &handle, page_type_data);
303+ EXPECT_TRUE (found);
304+ }
305+
306+ {
307+ PageCacheHandle handle;
308+ auto * index = new DataPage (1024 , true , page_type_index);
309+ cache.insert (index_key, index, &handle, page_type_index, false );
310+ auto found = cache.lookup (index_key, &handle, page_type_index);
311+ EXPECT_FALSE (found);
312+ }
313+ }
314+
315+ TEST_F (StoragePageCacheTest, full_index_cache_percentage) {
316+ StoragePageCache cache (kNumShards * 2048 , 100 , 0 , kNumShards );
317+
318+ StoragePageCache::CacheKey data_key (" data" , 0 , 0 );
319+ StoragePageCache::CacheKey index_key (" index" , 0 , 0 );
320+
321+ segment_v2::PageTypePB page_type_data = segment_v2::DATA_PAGE;
322+ segment_v2::PageTypePB page_type_index = segment_v2::INDEX_PAGE;
323+
324+ {
325+ PageCacheHandle handle;
326+ auto * data = new DataPage (1024 , true , page_type_data);
327+ cache.insert (data_key, data, &handle, page_type_data, false );
328+ auto found = cache.lookup (data_key, &handle, page_type_data);
329+ EXPECT_FALSE (found);
330+ }
331+
332+ {
333+ PageCacheHandle handle;
334+ auto * index = new DataPage (1024 , true , page_type_index);
335+ cache.insert (index_key, index, &handle, page_type_index, false );
336+ auto found = cache.lookup (index_key, &handle, page_type_index);
337+ EXPECT_TRUE (found);
338+ }
339+ }
340+
341+ TEST_F (StoragePageCacheTest, zero_total_capacity) {
342+ StoragePageCache cache (0 , 50 , 0 , kNumShards );
343+
344+ StoragePageCache::CacheKey data_key (" data" , 0 , 0 );
345+ StoragePageCache::CacheKey index_key (" index" , 0 , 0 );
346+
347+ segment_v2::PageTypePB page_type_data = segment_v2::DATA_PAGE;
348+ segment_v2::PageTypePB page_type_index = segment_v2::INDEX_PAGE;
349+
350+ {
351+ PageCacheHandle handle;
352+ auto * data = new DataPage (1024 , true , page_type_data);
353+ cache.insert (data_key, data, &handle, page_type_data, false );
354+ auto found = cache.lookup (data_key, &handle, page_type_data);
355+ EXPECT_FALSE (found);
356+ }
357+
358+ {
359+ PageCacheHandle handle;
360+ auto * index = new DataPage (1024 , true , page_type_index);
361+ cache.insert (index_key, index, &handle, page_type_index, false );
362+ auto found = cache.lookup (index_key, &handle, page_type_index);
363+ EXPECT_FALSE (found);
364+ }
365+ }
366+
367+ TEST_F (StoragePageCacheTest, capacity_less_than_num_shards) {
368+ StoragePageCache cache (10 , 50 , 0 , kNumShards );
369+
370+ StoragePageCache::CacheKey data_key (" data" , 0 , 0 );
371+ StoragePageCache::CacheKey index_key (" index" , 0 , 0 );
372+
373+ segment_v2::PageTypePB page_type_data = segment_v2::DATA_PAGE;
374+ segment_v2::PageTypePB page_type_index = segment_v2::INDEX_PAGE;
375+
376+ {
377+ PageCacheHandle handle;
378+ auto * data = new DataPage (1024 , true , page_type_data);
379+ cache.insert (data_key, data, &handle, page_type_data, false );
380+ auto found = cache.lookup (data_key, &handle, page_type_data);
381+ EXPECT_FALSE (found);
382+ }
383+
384+ {
385+ PageCacheHandle handle;
386+ auto * index = new DataPage (1024 , true , page_type_index);
387+ cache.insert (index_key, index, &handle, page_type_index, false );
388+ auto found = cache.lookup (index_key, &handle, page_type_index);
389+ EXPECT_FALSE (found);
390+ }
391+ }
392+
289393} // namespace doris
0 commit comments