-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: refactor(storage-manager):
overriding_wild_update
without get
- [ ] Unit test: changes in #1499 will simplify adding Wildcard Updates The previous implementation was always performing a `get` on the Storage when checking if a received publication could be overridden by a Wildcard Update. This commit changes that behaviour and removes the call to the Storage. In addition to potentially creating more network exchanges, this was also generating "warning" logs during the alignment process when Wildcard Updates are involved. * plugins/zenoh-plugin-storage-manager/src/storages_mgt/mod.rs * plugins/zenoh-plugin-storage-manager/src/storages_mgt/service.rs * plugins/zenoh-plugin-storage-manager/src/storages_mgt/tests/service.tests.rs Signed-off-by: Julien Loudet <[email protected]>
- Loading branch information
Showing
3 changed files
with
127 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
plugins/zenoh-plugin-storage-manager/src/storages_mgt/tests/service.tests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// Copyright (c) 2024 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use std::sync::Arc; | ||
|
||
use tokio::sync::{Mutex, RwLock}; | ||
use zenoh::{ | ||
internal::Value, | ||
key_expr::{ | ||
keyexpr_tree::{KeBoxTree, KeyedSetProvider, NonWild, UnknownWildness}, | ||
OwnedKeyExpr, | ||
}, | ||
time::Timestamp, | ||
Result as ZResult, | ||
}; | ||
use zenoh_backend_traits::{ | ||
config::{GarbageCollectionConfig, StorageConfig}, | ||
Capability, Storage, StorageInsertionResult, StoredData, | ||
}; | ||
|
||
use super::{StorageService, Update}; | ||
use crate::storages_mgt::CacheLatest; | ||
|
||
struct DummyStorage; | ||
|
||
#[async_trait::async_trait] | ||
impl Storage for DummyStorage { | ||
fn get_admin_status(&self) -> serde_json::Value { | ||
todo!() | ||
} | ||
|
||
async fn put( | ||
&mut self, | ||
_key: Option<OwnedKeyExpr>, | ||
_value: Value, | ||
_timestamp: Timestamp, | ||
) -> ZResult<StorageInsertionResult> { | ||
todo!() | ||
} | ||
|
||
async fn delete( | ||
&mut self, | ||
_key: Option<OwnedKeyExpr>, | ||
_timestamp: Timestamp, | ||
) -> ZResult<StorageInsertionResult> { | ||
todo!() | ||
} | ||
|
||
async fn get( | ||
&mut self, | ||
_key: Option<OwnedKeyExpr>, | ||
_parameters: &str, | ||
) -> ZResult<Vec<StoredData>> { | ||
todo!() | ||
} | ||
|
||
async fn get_all_entries(&self) -> ZResult<Vec<(Option<OwnedKeyExpr>, Timestamp)>> { | ||
todo!() | ||
} | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn test_overriding_wild_update() { | ||
let _storage_service = StorageService { | ||
session: Arc::new(zenoh::open(zenoh::Config::default()).await.unwrap()), | ||
configuration: StorageConfig { | ||
name: "test".to_string(), | ||
key_expr: OwnedKeyExpr::new("test/**").unwrap(), | ||
complete: true, | ||
strip_prefix: Some(OwnedKeyExpr::new("test").unwrap()), | ||
volume_id: "test-volume".to_string(), | ||
volume_cfg: serde_json::json!({}), | ||
garbage_collection_config: GarbageCollectionConfig::default(), | ||
replication: None, | ||
}, | ||
name: "test-storage".to_string(), | ||
storage: Arc::new(Mutex::new(Box::new(DummyStorage {}) as Box<dyn Storage>)), | ||
capability: Capability { | ||
persistence: zenoh_backend_traits::Persistence::Volatile, | ||
history: zenoh_backend_traits::History::Latest, | ||
}, | ||
tombstones: Arc::new(RwLock::new( | ||
KeBoxTree::<Timestamp, NonWild, KeyedSetProvider>::default(), | ||
)), | ||
wildcard_updates: Arc::new(RwLock::new(KeBoxTree::< | ||
Update, | ||
UnknownWildness, | ||
KeyedSetProvider, | ||
>::default())), | ||
cache_latest: CacheLatest::default(), | ||
}; | ||
} |