MCPcopy Create free account
hub / github.com/apache/datafusion / test_cache_with_ttl

Function test_cache_with_ttl

datafusion/execution/src/cache/list_files_cache.rs:828–883  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

826
827 #[test]
828 fn test_cache_with_ttl() {
829 let ttl = Duration::from_millis(100);
830
831 let mock_time = Arc::new(MockTimeProvider::new());
832 let cache = DefaultListFilesCache::new(10000, Some(ttl))
833 .with_time_provider(Arc::clone(&mock_time) as Arc<dyn TimeProvider>);
834
835 let (path1, value1, size1) = create_test_list_files_entry("path1", 2, 50);
836 let (path2, value2, size2) = create_test_list_files_entry("path2", 2, 50);
837
838 let table_ref = Some(TableReference::from("table"));
839 let key1 = TableScopedPath {
840 table: table_ref.clone(),
841 path: path1,
842 };
843 let key2 = TableScopedPath {
844 table: table_ref,
845 path: path2,
846 };
847 cache.put(&key1, value1.clone());
848 cache.put(&key2, value2.clone());
849
850 // Entries should be accessible immediately
851 assert!(cache.get(&key1).is_some());
852 assert!(cache.get(&key2).is_some());
853 // List cache entries
854 assert_eq!(
855 cache.list_entries(),
856 HashMap::from([
857 (
858 key1.clone(),
859 ListFilesEntry {
860 metas: value1,
861 size_bytes: size1,
862 expires: mock_time.now().checked_add(ttl),
863 }
864 ),
865 (
866 key2.clone(),
867 ListFilesEntry {
868 metas: value2,
869 size_bytes: size2,
870 expires: mock_time.now().checked_add(ttl),
871 }
872 )
873 ])
874 );
875 // Wait for TTL to expire
876 mock_time.inc(Duration::from_millis(150));
877
878 // Entries should now return None when observed through contains_key
879 assert!(!cache.contains_key(&key1));
880 assert_eq!(cache.len(), 1); // key1 was removed by contains_key()
881 assert!(!cache.contains_key(&key2));
882 assert_eq!(cache.len(), 0); // key2 was removed by contains_key()
883 }
884
885 #[test]

Callers

nothing calls this directly

Calls 6

newFunction · 0.85
with_time_providerMethod · 0.80
incMethod · 0.80
cloneMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…