From 54d12e1b57b1aee2f65c92d43408e930f76e4690 Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Fri, 5 Jul 2024 09:49:04 +0200 Subject: [PATCH] Bump uhlc to 0.8.0 - changing formatting of Timestamps as Strings (#1218) * Bump uhlc to 0.8.0 * Remove irrelevant tests in storages replication * Convert Timestamps in some unit tests * Make cargo fmt happy --- Cargo.lock | 4 +- Cargo.toml | 2 +- plugins/zenoh-plugin-rest/src/lib.rs | 6 +- .../src/replica/digest.rs | 381 ------------------ .../tests/operations.rs | 9 +- .../tests/wildcard.rs | 15 +- 6 files changed, 14 insertions(+), 403 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5344e0135c..3438a2d2c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4715,9 +4715,9 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "uhlc" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99b6df3f3e948b40e20c38a6d1fd6d8f91b3573922fc164e068ad3331560487e" +checksum = "79ac3c37bd9506595768f0387bd39d644525728b4a1d783218acabfb56356db7" dependencies = [ "humantime", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index a1820cb495..ce8ae1643d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -171,7 +171,7 @@ tokio-rustls = { version = "0.26.0", default-features = false } # tokio-vsock = see: io/zenoh-links/zenoh-link-vsock/Cargo.toml (workspaces does not support platform dependent dependencies) thread-priority = "1.1.0" typenum = "1.16.0" -uhlc = { version = "0.7.0", default-features = false } # Default features are disabled due to usage in no_std crates +uhlc = { version = "0.8.0", default-features = false } # Default features are disabled due to usage in no_std crates unwrap-infallible = "0.1.5" unzip-n = "0.1.2" url = "2.3.1" diff --git a/plugins/zenoh-plugin-rest/src/lib.rs b/plugins/zenoh-plugin-rest/src/lib.rs index e3dcc0130e..d6db7c74cb 100644 --- a/plugins/zenoh-plugin-rest/src/lib.rs +++ b/plugins/zenoh-plugin-rest/src/lib.rs @@ -56,7 +56,7 @@ struct JSONSample { key: String, value: serde_json::Value, encoding: String, - time: Option, + timestamp: Option, } pub fn base64_encode(data: &[u8]) -> String { @@ -100,7 +100,7 @@ fn sample_to_json(sample: &Sample) -> JSONSample { key: sample.key_expr().as_str().to_string(), value: payload_to_json(sample.payload(), sample.encoding()), encoding: sample.encoding().to_string(), - time: sample.timestamp().map(|ts| ts.to_string()), + timestamp: sample.timestamp().map(|ts| ts.to_string()), } } @@ -111,7 +111,7 @@ fn result_to_json(sample: Result<&Sample, &ReplyError>) -> JSONSample { key: "ERROR".into(), value: payload_to_json(err.payload(), err.encoding()), encoding: err.encoding().to_string(), - time: None, + timestamp: None, }, } } diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/digest.rs b/plugins/zenoh-plugin-storage-manager/src/replica/digest.rs index bf06c61f25..07ba7e9ea3 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/digest.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/digest.rs @@ -833,384 +833,3 @@ impl Digest { } } } - -#[test] -fn test_create_digest_empty_initial() { - async_std::task::block_on(async { - zenoh::internal::zasync_executor_init!(); - }); - let created = Digest::create_digest( - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - Vec::new(), - 1671612730, - ); - let expected = Digest { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - config: DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - checksum: 0, - eras: HashMap::new(), - intervals: HashMap::new(), - subintervals: HashMap::new(), - }; - assert_eq!(created, expected); -} - -#[test] -fn test_create_digest_with_initial_hot() { - async_std::task::block_on(async { - zenoh::internal::zasync_executor_init!(); - }); - let created = Digest::create_digest( - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - vec![LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }], - 1671634800, - ); - let expected = Digest { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - config: DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - checksum: 6001159706341373391, - eras: HashMap::from([( - EraType::Hot, - Interval { - checksum: 4598971083408074426, - content: BTreeSet::from([1671634800]), - }, - )]), - intervals: HashMap::from([( - 1671634800, - Interval { - checksum: 8436018757196527319, - content: BTreeSet::from([16716348000]), - }, - )]), - subintervals: HashMap::from([( - 16716348000, - SubInterval { - checksum: 10827088509365589085, - content: BTreeSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }]), - }, - )]), - }; - assert_eq!(created, expected); -} - -#[test] -fn test_create_digest_with_initial_warm() { - async_std::task::block_on(async { - zenoh::internal::zasync_executor_init!(); - }); - let created = Digest::create_digest( - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - vec![LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }], - 1671634810, - ); - let expected = Digest { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - config: DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - checksum: 6001159706341373391, - eras: HashMap::from([( - EraType::Warm, - Interval { - checksum: 4598971083408074426, - content: BTreeSet::from([1671634800]), - }, - )]), - intervals: HashMap::from([( - 1671634800, - Interval { - checksum: 8436018757196527319, - content: BTreeSet::from([16716348000]), - }, - )]), - subintervals: HashMap::from([( - 16716348000, - SubInterval { - checksum: 10827088509365589085, - content: BTreeSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }]), - }, - )]), - }; - assert_eq!(created, expected); -} - -#[test] -fn test_create_digest_with_initial_cold() { - async_std::task::block_on(async { - zenoh::internal::zasync_executor_init!(); - }); - let created = Digest::create_digest( - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - vec![LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }], - 1671634910, - ); - let expected = Digest { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - config: DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - checksum: 6001159706341373391, - eras: HashMap::from([( - EraType::Cold, - Interval { - checksum: 4598971083408074426, - content: BTreeSet::from([1671634800]), - }, - )]), - intervals: HashMap::from([( - 1671634800, - Interval { - checksum: 8436018757196527319, - content: BTreeSet::from([16716348000]), - }, - )]), - subintervals: HashMap::from([( - 16716348000, - SubInterval { - checksum: 10827088509365589085, - content: BTreeSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }]), - }, - )]), - }; - assert_eq!(created, expected); -} - -#[test] -fn test_update_digest_add_content() { - async_std::task::block_on(async { - zenoh::internal::zasync_executor_init!(); - }); - let created = Digest::update_digest( - Digest { - timestamp: Timestamp::from_str("2022-12-21T13:00:00.000000000Z/1").unwrap(), - config: DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - checksum: 0, - eras: HashMap::new(), - intervals: HashMap::new(), - subintervals: HashMap::new(), - }, - 1671634910, - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - HashSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }]), - HashSet::new(), - ); - let expected = Digest { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - config: DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - checksum: 6001159706341373391, - eras: HashMap::from([( - EraType::Cold, - Interval { - checksum: 4598971083408074426, - content: BTreeSet::from([1671634800]), - }, - )]), - intervals: HashMap::from([( - 1671634800, - Interval { - checksum: 8436018757196527319, - content: BTreeSet::from([16716348000]), - }, - )]), - subintervals: HashMap::from([( - 16716348000, - SubInterval { - checksum: 10827088509365589085, - content: BTreeSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }]), - }, - )]), - }; - assert_eq!(created, expected); -} - -#[test] -fn test_update_digest_remove_content() { - async_std::task::block_on(async { - zenoh::internal::zasync_executor_init!(); - }); - let created = Digest::update_digest( - Digest { - timestamp: Timestamp::from_str("2022-12-21T13:00:00.000000000Z/1").unwrap(), - config: DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - checksum: 3304302629246049840, - eras: HashMap::from([( - EraType::Cold, - Interval { - checksum: 8238986480495191270, - content: BTreeSet::from([1671634800]), - }, - )]), - intervals: HashMap::from([( - 1671634800, - Interval { - checksum: 12344398372324783476, - content: BTreeSet::from([16716348000]), - }, - )]), - subintervals: HashMap::from([( - 16716348000, - SubInterval { - checksum: 10007212639402189432, - content: BTreeSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }]), - }, - )]), - }, - 1671634910, - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - HashSet::new(), - HashSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("demo/example/a").unwrap(), - }]), - ); - let expected = Digest { - timestamp: Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - config: DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - checksum: 0, - eras: HashMap::new(), - intervals: HashMap::new(), - subintervals: HashMap::new(), - }; - assert_eq!(created, expected); -} - -#[test] -fn test_update_remove_digest() { - async_std::task::block_on(async { - zenoh::internal::zasync_executor_init!(); - }); - let created = Digest::create_digest( - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - DigestConfig { - delta: Duration::from_millis(1000), - sub_intervals: 10, - hot: 6, - warm: 30, - }, - Vec::new(), - 1671612730, - ); - let added = Digest::update_digest( - created.clone(), - 1671612730, - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - HashSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T12:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("a/b/c").unwrap(), - }]), - HashSet::new(), - ); - assert_ne!(created, added); - - let removed = Digest::update_digest( - added.clone(), - 1671612730, - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - HashSet::new(), - HashSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T12:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("a/b/c").unwrap(), - }]), - ); - assert_eq!(created, removed); - - let added_again = Digest::update_digest( - removed, - 1671612730, - Timestamp::from_str("2022-12-21T15:00:00.000000000Z/1").unwrap(), - HashSet::from([LogEntry { - timestamp: Timestamp::from_str("2022-12-21T12:00:00.000000000Z/1").unwrap(), - key: OwnedKeyExpr::from_str("a/b/c").unwrap(), - }]), - HashSet::new(), - ); - assert_eq!(added, added_again); -} diff --git a/plugins/zenoh-plugin-storage-manager/tests/operations.rs b/plugins/zenoh-plugin-storage-manager/tests/operations.rs index 505634e6fb..c1ed09b1a7 100644 --- a/plugins/zenoh-plugin-storage-manager/tests/operations.rs +++ b/plugins/zenoh-plugin-storage-manager/tests/operations.rs @@ -86,8 +86,7 @@ async fn test_updates_in_order() { &session, "operation/test/a", "1", - Timestamp::from_str("2022-01-17T10:42:10.418555997Z/BC779A06D7E049BD88C3FF3DB0C17FCC") - .unwrap(), + Timestamp::from_str("7054123566570568799/BC779A06D7E049BD88C3FF3DB0C17FCC").unwrap(), ) .await; @@ -102,8 +101,7 @@ async fn test_updates_in_order() { &session, "operation/test/b", "2", - Timestamp::from_str("2022-01-17T10:43:10.418555997Z/BC779A06D7E049BD88C3FF3DB0C17FCC") - .unwrap(), + Timestamp::from_str("7054123824268606559/BC779A06D7E049BD88C3FF3DB0C17FCC").unwrap(), ) .await; @@ -117,8 +115,7 @@ async fn test_updates_in_order() { delete_data( &session, "operation/test/a", - Timestamp::from_str("2022-01-17T10:43:10.418555997Z/BC779A06D7E049BD88C3FF3DB0C17FCC") - .unwrap(), + Timestamp::from_str("7054123824268606559/BC779A06D7E049BD88C3FF3DB0C17FCC").unwrap(), ) .await; diff --git a/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs b/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs index 04e4549508..d6e94ecb1f 100644 --- a/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs +++ b/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs @@ -87,8 +87,7 @@ async fn test_wild_card_in_order() { &session, "wild/test/*", "1", - Timestamp::from_str("2022-01-17T10:42:10.418555997Z/BC779A06D7E049BD88C3FF3DB0C17FCC") - .unwrap(), + Timestamp::from_str("7054123566570568799/BC779A06D7E049BD88C3FF3DB0C17FCC").unwrap(), ) .await; @@ -102,8 +101,7 @@ async fn test_wild_card_in_order() { &session, "wild/test/a", "2", - Timestamp::from_str("2022-01-17T10:42:11.418555997Z/BC779A06D7E049BD88C3FF3DB0C17FCC") - .unwrap(), + Timestamp::from_str("7054123570865536095/BC779A06D7E049BD88C3FF3DB0C17FCC").unwrap(), ) .await; @@ -119,8 +117,7 @@ async fn test_wild_card_in_order() { &session, "wild/test/b", "3", - Timestamp::from_str("2022-01-17T10:42:11.418555997Z/BC779A06D7E049BD88C3FF3DB0C17FCC") - .unwrap(), + Timestamp::from_str("7054123570865536095/BC779A06D7E049BD88C3FF3DB0C17FCC").unwrap(), ) .await; @@ -150,8 +147,7 @@ async fn test_wild_card_in_order() { &session, "wild/test/*", "4", - Timestamp::from_str("2022-01-17T10:43:12.418555997Z/BC779A06D7E049BD88C3FF3DB0C17FCC") - .unwrap(), + Timestamp::from_str("7054123832858541151/BC779A06D7E049BD88C3FF3DB0C17FCC").unwrap(), ) .await; @@ -168,8 +164,7 @@ async fn test_wild_card_in_order() { delete_data( &session, "wild/test/*", - Timestamp::from_str("2022-01-17T13:43:10.418555997Z/BC779A06D7E049BD88C3FF3DB0C17FCC") - .unwrap(), + Timestamp::from_str("7054170209915403359/BC779A06D7E049BD88C3FF3DB0C17FCC").unwrap(), ) .await;