|
| 1 | +use core::pin::Pin; |
| 2 | +use std::sync::Arc; |
| 3 | + |
| 4 | +use nativelink_error::Error; |
| 5 | +use nativelink_macro::nativelink_test; |
| 6 | +use nativelink_metric::MetricsComponent; |
| 7 | +use nativelink_util::buf_channel::{DropCloserReadHalf, DropCloserWriteHalf}; |
| 8 | +use nativelink_util::default_health_status_indicator; |
| 9 | +use nativelink_util::health_utils::HealthStatusIndicator; |
| 10 | +use nativelink_util::store_trait::{ |
| 11 | + RemoveItemCallback, Store, StoreDriver, StoreKey, StoreLike, UploadSizeInfo, |
| 12 | +}; |
| 13 | +use tonic::async_trait; |
| 14 | + |
| 15 | +#[derive(Debug, MetricsComponent)] |
| 16 | +struct FakeStore {} |
| 17 | + |
| 18 | +#[async_trait] |
| 19 | +#[allow(clippy::todo)] |
| 20 | +impl StoreDriver for FakeStore { |
| 21 | + async fn has_with_results( |
| 22 | + self: Pin<&Self>, |
| 23 | + _keys: &[StoreKey<'_>], |
| 24 | + _results: &mut [Option<u64>], |
| 25 | + ) -> Result<(), Error> { |
| 26 | + todo!(); |
| 27 | + } |
| 28 | + |
| 29 | + async fn update( |
| 30 | + self: Pin<&Self>, |
| 31 | + _key: StoreKey<'_>, |
| 32 | + _reader: DropCloserReadHalf, |
| 33 | + _size_info: UploadSizeInfo, |
| 34 | + ) -> Result<(), Error> { |
| 35 | + todo!(); |
| 36 | + } |
| 37 | + |
| 38 | + async fn get_part( |
| 39 | + self: Pin<&Self>, |
| 40 | + _key: StoreKey<'_>, |
| 41 | + _writer: &mut DropCloserWriteHalf, |
| 42 | + _offset: u64, |
| 43 | + _length: Option<u64>, |
| 44 | + ) -> Result<(), Error> { |
| 45 | + todo!(); |
| 46 | + } |
| 47 | + |
| 48 | + fn inner_store(&self, _digest: Option<StoreKey>) -> &dyn StoreDriver { |
| 49 | + self |
| 50 | + } |
| 51 | + |
| 52 | + fn as_any(&self) -> &(dyn core::any::Any + Sync + Send + 'static) { |
| 53 | + self |
| 54 | + } |
| 55 | + |
| 56 | + fn as_any_arc(self: Arc<Self>) -> Arc<dyn core::any::Any + Sync + Send + 'static> { |
| 57 | + self |
| 58 | + } |
| 59 | + |
| 60 | + fn register_remove_callback( |
| 61 | + self: Arc<Self>, |
| 62 | + _callback: Arc<dyn RemoveItemCallback>, |
| 63 | + ) -> Result<(), Error> { |
| 64 | + todo!(); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +default_health_status_indicator!(FakeStore); |
| 69 | + |
| 70 | +#[nativelink_test] |
| 71 | +async fn fast_has_with_results() -> Result<(), Error> { |
| 72 | + let store = Store::new(Arc::new(FakeStore {})); |
| 73 | + let mut results: [Option<u64>; 0] = []; |
| 74 | + store.has_with_results(&[], &mut results).await?; |
| 75 | + |
| 76 | + Ok(()) |
| 77 | +} |
| 78 | + |
| 79 | +#[nativelink_test] |
| 80 | +async fn fast_has_many() -> Result<(), Error> { |
| 81 | + let store = Store::new(Arc::new(FakeStore {})); |
| 82 | + let res = store.has_many(&[]).await?; |
| 83 | + assert!(res.is_empty()); |
| 84 | + |
| 85 | + Ok(()) |
| 86 | +} |
0 commit comments