This is an automated email from the ASF dual-hosted git repository.

yukon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new f4f198b6 fix(rust): change sequence number type of message id from i16 
to i32 (#566)
f4f198b6 is described below

commit f4f198b69364d83f6cfe16a492bbc90465ff3f97
Author: SSpirits <[email protected]>
AuthorDate: Tue Jul 11 14:09:22 2023 +0800

    fix(rust): change sequence number type of message id from i16 to i32 (#566)
    
    * fix(rust): change sequence number type of message id from i16 to i32
    
    Signed-off-by: SSpirits <[email protected]>
    
    * fix(rust): optimize unit test
    
    Signed-off-by: SSpirits <[email protected]>
    
    * fix(rust): ignore message id test
    
    Signed-off-by: SSpirits <[email protected]>
    
    ---------
    
    Signed-off-by: SSpirits <[email protected]>
---
 rust/Cargo.toml              |  2 +-
 rust/src/model/message_id.rs | 14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 42420483..69241d91 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 1357a600..cd718b77 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<Mutex<UniqueIdGenerator>> = 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::<BigEndian>(self.counter).unwrap();
+        buf.write_i32::<BigEndian>(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]));
         }
     }
 }

Reply via email to