diff --git a/src/cache/cache.rs b/src/cache/cache.rs index 0fd91d291..883ee7832 100644 --- a/src/cache/cache.rs +++ b/src/cache/cache.rs @@ -373,6 +373,12 @@ pub trait Storage: Send + Sync { /// Get the storage location. fn location(&self) -> String; + /// Get the cache backend type name (e.g., "disk", "redis", "s3"). + /// Used for statistics and display purposes. + fn cache_type_name(&self) -> &'static str { + "unknown" + } + /// Get the current storage usage, if applicable. async fn current_size(&self) -> Result>; @@ -470,6 +476,7 @@ impl PreprocessorCacheModeConfig { feature = "s3", feature = "webdav", feature = "oss", + feature = "cos" ))] pub struct RemoteStorage { operator: opendal::Operator, @@ -485,6 +492,7 @@ pub struct RemoteStorage { feature = "s3", feature = "webdav", feature = "oss", + feature = "cos" ))] impl RemoteStorage { pub fn new(operator: opendal::Operator, basedirs: Vec>) -> Self { @@ -502,6 +510,7 @@ impl RemoteStorage { feature = "s3", feature = "webdav", feature = "oss", + feature = "cos" ))] #[async_trait] impl Storage for RemoteStorage { @@ -585,6 +594,12 @@ impl Storage for RemoteStorage { ) } + fn cache_type_name(&self) -> &'static str { + // Use opendal's scheme as the cache type name + // This returns "s3", "redis", "azure", "gcs", etc. + self.operator.info().scheme() + } + async fn current_size(&self) -> Result> { Ok(None) } diff --git a/src/cache/disk.rs b/src/cache/disk.rs index 9f5167901..5f0b7a1ad 100644 --- a/src/cache/disk.rs +++ b/src/cache/disk.rs @@ -137,6 +137,10 @@ impl Storage for DiskCache { format!("Local disk: {:?}", self.lru.lock().unwrap().path()) } + fn cache_type_name(&self) -> &'static str { + "disk" + } + async fn current_size(&self) -> Result> { Ok(self.lru.lock().unwrap().get().map(|l| l.size())) } @@ -185,3 +189,27 @@ impl Storage for DiskCache { .commit(f)?) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_disk_cache_type_name() { + let tempdir = tempfile::tempdir().unwrap(); + let runtime = tokio::runtime::Builder::new_current_thread() + .build() + .unwrap(); + + let disk = DiskCache::new( + tempdir.path(), + 1024 * 1024, + runtime.handle(), + PreprocessorCacheModeConfig::default(), + CacheMode::ReadWrite, + vec![], + ); + + assert_eq!(disk.cache_type_name(), "disk"); + } +} diff --git a/src/cache/readonly.rs b/src/cache/readonly.rs index 715e664f6..68eb71108 100644 --- a/src/cache/readonly.rs +++ b/src/cache/readonly.rs @@ -49,6 +49,11 @@ impl Storage for ReadOnlyStorage { self.0.location() } + /// Get the cache backend type name. + fn cache_type_name(&self) -> &'static str { + self.0.cache_type_name() + } + /// Get the current storage usage, if applicable. async fn current_size(&self) -> Result> { self.0.current_size().await @@ -188,4 +193,33 @@ mod test { ); }); } + + #[test] + fn readonly_storage_forwards_cache_type_name() { + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .worker_threads(1) + .build() + .unwrap(); + + let tempdir = tempfile::Builder::new() + .prefix("readonly_cache_type_name") + .tempdir() + .expect("Failed to create tempdir"); + let cache_dir = tempdir.path().join("cache"); + std::fs::create_dir(&cache_dir).unwrap(); + + let disk_cache = crate::cache::disk::DiskCache::new( + &cache_dir, + 1024 * 1024, + runtime.handle(), + super::PreprocessorCacheModeConfig::default(), + super::CacheMode::ReadWrite, + vec![], + ); + + let readonly_storage = ReadOnlyStorage(std::sync::Arc::new(disk_cache)); + + assert_eq!(readonly_storage.cache_type_name(), "disk"); + } } diff --git a/tests/integration/Makefile b/tests/integration/Makefile index 079def9a1..51459cae7 100644 --- a/tests/integration/Makefile +++ b/tests/integration/Makefile @@ -10,20 +10,20 @@ BACKENDS := redis redis-deprecated memcached memcached-deprecated s3 azblob webd TOOLS := gcc clang cmake autotools coverage zstd # Map backends to their compose profiles -PROFILE_autotools := autotools -PROFILE_azblob := azblob -PROFILE_basedirs := basedirs -PROFILE_clang := clang -PROFILE_cmake := cmake -PROFILE_coverage := coverage -PROFILE_gcc := gcc -PROFILE_memcached := memcached -PROFILE_memcached-deprecated := memcached -PROFILE_redis := redis -PROFILE_redis-deprecated := redis -PROFILE_s3 := s3 -PROFILE_webdav := webdav -PROFILE_zstd := zstd +PROFILES_autotools := autotools +PROFILES_azblob := azblob +PROFILES_basedirs := basedirs redis memcached s3 azblob webdav +PROFILES_clang := clang +PROFILES_cmake := cmake +PROFILES_coverage := coverage +PROFILES_gcc := gcc +PROFILES_memcached := memcached +PROFILES_memcached-deprecated := memcached +PROFILES_redis := redis +PROFILES_redis-deprecated := redis +PROFILES_s3 := s3 +PROFILES_webdav := webdav +PROFILES_zstd := zstd # Map backends to their services SERVICES_autotools := @@ -93,16 +93,20 @@ $(SCCACHE_BIN): $(PROJECT_ROOT)/Cargo.toml $(PROJECT_ROOT)/Cargo.lock @echo "Binary built: $(SCCACHE_BIN)" @ls -lh $(SCCACHE_BIN) +define profiles +$(foreach profile,$(PROFILES_$(1)),--profile $(profile)) +endef + # Pattern rule for cleaning backends clean-%: - @docker compose --profile $(PROFILE_$*) down -v + docker compose $(call profiles,$*) down -v # Pattern rule for testing backends test-%: build clean-% @echo "Testing $* backend..." - @docker compose --profile $(PROFILE_$*) up --quiet-pull -d $(SERVICES_$*) - @docker compose --profile $(PROFILE_$*) run --quiet-pull --rm test-$* - @docker compose --profile $(PROFILE_$*) down + @docker compose $(call profiles,$*) up --quiet-pull -d $(SERVICES_$*) + @docker compose $(call profiles,$*) run --quiet-pull --rm test-$* + @docker compose $(call profiles,$*) down @echo "$* test completed" test-backends: $(addprefix test-,$(BACKENDS)) diff --git a/tests/integration/docker-compose.yml b/tests/integration/docker-compose.yml index 68b9172af..12cb7e668 100644 --- a/tests/integration/docker-compose.yml +++ b/tests/integration/docker-compose.yml @@ -31,7 +31,6 @@ services: profiles: - test - redis - - basedirs memcached: image: memcached:latest @@ -45,7 +44,6 @@ services: profiles: - test - memcached - - basedirs minio: image: minio/minio:latest @@ -62,7 +60,6 @@ services: profiles: - test - s3 - - basedirs minio-setup: image: minio/mc:latest @@ -78,7 +75,6 @@ services: profiles: - test - s3 - - basedirs azurite: image: mcr.microsoft.com/azure-storage/azurite:latest @@ -91,7 +87,6 @@ services: profiles: - test - azblob - - basedirs azurite-setup: image: mcr.microsoft.com/azure-cli:latest @@ -106,7 +101,6 @@ services: profiles: - test - azblob - - basedirs webdav: image: hacdias/webdav:latest @@ -119,7 +113,6 @@ services: profiles: - test - webdav - - basedirs test-redis-deprecated: <<: *test-runner