@@ -223,6 +223,7 @@ mod tests {
223
223
use crate :: { storage:: page_cache:: DumbLruPageCache , Page } ;
224
224
225
225
use super :: PageCacheKey ;
226
+ use super :: PageRef ;
226
227
227
228
#[ test]
228
229
fn test_page_cache_evict ( ) {
@@ -335,6 +336,40 @@ mod tests {
335
336
key
336
337
}
337
338
339
+ #[ test]
340
+ fn test_page_cache_insert_existing ( ) {
341
+ let mut cache = DumbLruPageCache :: new ( 1 ) ;
342
+ #[ allow( clippy:: arc_with_non_send_sync) ]
343
+ let page1 = Arc :: new ( Page :: new ( 1 ) ) ;
344
+ assert_eq ! ( Arc :: strong_count( & page1) , 1 ) ;
345
+ let _ = insert_page_provided ( & mut cache, 1 , page1. clone ( ) ) ;
346
+ assert_eq ! ( Arc :: strong_count( & page1) , 2 ) ; // Should be another ref at page cache
347
+ }
348
+
349
+ #[ test]
350
+ fn test_page_cache_insert_duplicate_key ( ) {
351
+ let mut cache = DumbLruPageCache :: new ( 1 ) ;
352
+ #[ allow( clippy:: arc_with_non_send_sync) ]
353
+ let page1 = Arc :: new ( Page :: new ( 1 ) ) ;
354
+ assert_eq ! ( Arc :: strong_count( & page1) , 1 ) ;
355
+ let _ = insert_page_provided ( & mut cache, 1 , page1. clone ( ) ) ;
356
+ #[ allow( clippy:: arc_with_non_send_sync) ]
357
+ let page2 = Arc :: new ( Page :: new ( 1 ) ) ;
358
+ let _ = insert_page_provided ( & mut cache, 1 , page2. clone ( ) ) ; // This should fail
359
+ assert_eq ! ( Arc :: strong_count( & page1) , 2 ) ; // first page should stay (referenced) in cache
360
+ assert_eq ! ( Arc :: strong_count( & page2) , 1 ) ;
361
+ }
362
+
363
+ fn insert_page_provided (
364
+ cache : & mut DumbLruPageCache ,
365
+ id : usize ,
366
+ page : PageRef ,
367
+ ) -> PageCacheKey {
368
+ let key = PageCacheKey :: new ( id, None ) ;
369
+ cache. insert ( key. clone ( ) , page. clone ( ) ) ;
370
+ key
371
+ }
372
+
338
373
#[ test]
339
374
fn test_page_cache_insert_sequential ( ) {
340
375
let mut cache = DumbLruPageCache :: new ( 2 ) ;
0 commit comments