MCPcopy Create free account
hub / github.com/elastic/devfiler / test_cache_basic_usage

Function test_cache_basic_usage

src/storage/table.rs:660–695  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

658
659 #[test]
660 fn test_cache_basic_usage() {
661 let temp_dir = tempfile::tempdir().unwrap();
662 let table = open_or_create::<TestTable>(temp_dir.path()).unwrap();
663
664 // Insert test data
665 let key1 = TestKey(100);
666 let key2 = TestKey(200);
667 let key3 = TestKey(300); // This key won't exist
668
669 let value1 = TestValue {
670 data: "value1".to_string(),
671 };
672 let value2 = TestValue {
673 data: "value2".to_string(),
674 };
675
676 table.insert(key1, value1);
677 table.insert(key2, value2);
678
679 // Clear cache to start fresh
680 table.clear_cache();
681
682 // First access - should load from RocksDB and cache
683 let _ = table.get(key1).unwrap();
684 let _ = table.get(key2).unwrap();
685 let _ = table.get(key3); // Should return None
686
687 // Second access - should come from cache
688 let _ = table.get(key1).unwrap();
689 let _ = table.get(key2).unwrap();
690
691 // Check that cache contains our items
692 let cache = table.cache().lock().unwrap();
693 assert_eq!(cache.len(), 2); // key1 and key2 should be cached
694 drop(cache);
695 }
696}

Callers

nothing calls this directly

Calls 4

TestKeyClass · 0.85
clear_cacheMethod · 0.80
insertMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected