diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 42420483f..69241d91f 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -34,6 +34,7 @@ keywords = ["rocketmq", "api", "client", "sdk", "grpc"] [dependencies] tokio = { version = "1", features = ["full"] } tokio-rustls = {version = "0.24.0", features = ["default", "dangerous_configuration"] } +tokio-stream="0.1.12" async-trait = "0.1.68" lazy_static = "1.4" tonic = {version = "0.9.0", features = ["tls", "default", "channel", "tls-roots"]} @@ -60,7 +61,6 @@ mac_address = "1.1.4" hex = "0.4.3" time = "0.3" once_cell = "1.9.0" -tokio-stream="0.1.12" mockall = "0.11.4" mockall_double= "0.3.0" diff --git a/rust/src/model/message_id.rs b/rust/src/model/message_id.rs index 1357a6008..cd718b773 100644 --- a/rust/src/model/message_id.rs +++ b/rust/src/model/message_id.rs @@ -83,8 +83,8 @@ pub(crate) static UNIQ_ID_GENERATOR: Lazy> = Lazy::new( Mutex::new(generator) }); -pub struct UniqueIdGenerator { - counter: i16, +pub(crate) struct UniqueIdGenerator { + counter: i32, prefix: String, start_timestamp: i64, next_timestamp: i64, @@ -122,19 +122,21 @@ impl UniqueIdGenerator { ((OffsetDateTime::now_utc().unix_timestamp() - self.start_timestamp) * 1000) as i32, ) .unwrap(); - buf.write_i16::(self.counter).unwrap(); + buf.write_i32::(self.counter).unwrap(); self.prefix.clone() + &hex::encode(buf) } } #[cfg(test)] mod test { + #[ignore] #[test] - fn text_generate_uniq_id() { + fn generate_uniq_id() { use super::UNIQ_ID_GENERATOR; - for i in 0..10 { + for i in 1..17 { let uid = UNIQ_ID_GENERATOR.lock().next_id(); - println!("i: {}, uid: {}", i, uid); + assert_eq!(uid.len(), 34); + assert_eq!(uid.get(26..).unwrap(), hex::encode(vec![0, 0, 0, i as u8])); } } }