Skip to content

[ISSUE #4575]🚀Implement BoundaryType enum with serialization, deserialization, and parsing methods; add SearchOffsetRequestHeader struct with tests - #4576

Merged
rocketmq-rust-bot merged 1 commit into
mainfrom
feature-4575
Dec 12, 2025
Merged

rocketmq-rust-bot merged 1 commit into
mainfrom
feature-4575

Conversation

@mxsm

@mxsm mxsm commented Dec 12, 2025 •

Copy link
Copy Markdown
Owner

Which Issue(s) This PR Fixes(Closes)

Fixes #4575

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced search offset request functionality with configurable boundary types (upper/lower).
    • Enhanced serialization and deserialization handling with case-insensitive parsing.
  • Tests

    • Expanded test coverage for boundary type defaults, serialization round-trips, and edge cases including empty topics and maximum values.

✏️ Tip: You can customize this high-level summary in your review settings.

…lization, and parsing methods; add SearchOffsetRequestHeader struct with tests
Copilot AI review requested due to automatic review settings December 12, 2025 09:26
@rocketmq-rust-bot

Copy link
Copy Markdown
Collaborator

🔊@mxsm 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

@coderabbitai

coderabbitai Bot commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR enhances the BoundaryType enum with serialization, deserialization, and parsing capabilities, adding trait implementations for Serialize, Deserialize, Display, and FromStr. It introduces the SearchOffsetRequestHeader struct that incorporates BoundaryType as a field, with comprehensive test coverage for both components.

Changes

Cohort / File(s) Summary
BoundaryType Enum Enhancements
rocketmq-common/src/common/boundary_type.rs
Added derives (Default, Clone, Copy) with Lower as default. Introduced get_name() method returning lowercase strings. Modified get_type() to return BoundaryType directly with case-insensitive parsing and Lower fallback. Implemented Serialize, Deserialize, Display, and FromStr traits for full serialization/deserialization support with uppercase string formatting. Expanded test suite covering new behavior including round-trip integrity.
SearchOffsetRequestHeader Struct
rocketmq-remoting/src/protocol/header/search_offset_request_header.rs
Added new SearchOffsetRequestHeader struct with fields: topic (CheetahString), queue_id (i32), timestamp (i64), and boundary_type (BoundaryType). Derives Default, Debug, Serialize, Deserialize, and RequestHeaderCodecV2. Includes comprehensive tests validating serialization, deserialization with camelCase naming, edge cases, and round-trip integrity.
Module Export
rocketmq-remoting/src/protocol/header.rs
Added public module export for search_offset_request_header.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • BoundaryType case-insensitive parsing logic: Verify the defaulting behavior to Lower for unrecognized values aligns with system expectations
  • Serialization format consistency: Confirm uppercase string formatting ("LOWER"/"UPPER") matches protocol requirements and Java compatibility
  • SearchOffsetRequestHeader field types: Validate that CheetahString, i32, i64, and BoundaryType serialization align with the protocol specification
  • Test coverage for edge cases: Review handling of empty topics, negative queue_id, i64::MAX values, and invalid boundaryType inputs

Poem

🐰 Boundaries now bounded with care,
Serialized strings floating through air,
Upper and lower, defaults so bright,
SearchOffsets ready to take flight!
✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: implementing BoundaryType enum with serialization, deserialization, and parsing methods, plus adding SearchOffsetRequestHeader struct with tests.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from #4575: BoundaryType enum with serialization, deserialization, parsing methods, and SearchOffsetRequestHeader struct with comprehensive tests.
Out of Scope Changes check ✅ Passed All changes are directly related to #4575 requirements: BoundaryType enhancements, SearchOffsetRequestHeader struct, public module export, and comprehensive test coverage. No extraneous changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature-4575

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rocketmq-rust-robot rocketmq-rust-robot added the feature🚀 Suggest an idea for this project. label Dec 12, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the BoundaryType enum with comprehensive serialization, deserialization, and parsing capabilities, along with the SearchOffsetRequestHeader struct, both matching Java RocketMQ behavior for cross-language compatibility.

  • Adds BoundaryType enum with serialization/deserialization support, case-insensitive parsing, and default fallback behavior
  • Implements SearchOffsetRequestHeader struct for search offset requests with proper field mappings
  • Includes extensive test coverage for both components covering serialization, deserialization, edge cases, and roundtrip scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
rocketmq-common/src/common/boundary_type.rs Implements BoundaryType enum with Default, Clone, Copy traits, custom Serialize/Deserialize implementations matching Java format (uppercase), Display and FromStr traits, plus comprehensive test suite
rocketmq-remoting/src/protocol/header/search_offset_request_header.rs Adds SearchOffsetRequestHeader struct with topic, queue_id, timestamp, and boundary_type fields, includes extensive tests for serialization, deserialization, edge cases, and boundary conditions
rocketmq-remoting/src/protocol/header.rs Registers the new search_offset_request_header module in the header module hierarchy

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +101 to +108
impl FromStr for BoundaryType {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// Always succeeds, returns Lower as default (matches Java behavior)
Ok(BoundaryType::get_type(s))
}
}

Copilot AI Dec 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FromStr implementation's error type is defined as String, but the implementation always returns Ok. This creates an inconsistency where the error type suggests failure is possible but it never actually occurs. Consider using std::convert::Infallible as the error type to correctly represent that parsing never fails, matching the documented behavior that it "always succeeds, returns Lower as default".

Copilot uses AI. Check for mistakes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
rocketmq-remoting/src/protocol/header/search_offset_request_header.rs (2)

23-30: Consider #[serde(default)] to allow missing fields (esp. boundaryType) without failing deserialization.
Right now, deserializing JSON that omits boundaryType errors instead of defaulting to BoundaryType::Lower (and similarly for other fields). If you want “Java-like defaulting” for absent fields too, add struct-level defaulting.

 #[derive(Default, Debug, Serialize, Deserialize, RequestHeaderCodecV2)]
+#[serde(default)]
 #[serde(rename_all = "camelCase")]
 pub struct SearchOffsetRequestHeader {
     pub topic: CheetahString,
     pub queue_id: i32,
     pub timestamp: i64,
     pub boundary_type: BoundaryType,
 }

60-76: Prefer asserting on serde_json::Value instead of json.contains(...) for stability.
This avoids coupling the test to serialization formatting/details and makes failures more actionable.

     #[test]
     fn search_offset_request_header_serializes_to_json() {
         let header = SearchOffsetRequestHeader {
             topic: CheetahString::from("my_topic"),
             queue_id: 2,
             timestamp: 1702345678999,
             boundary_type: BoundaryType::Upper,
         };

-        let json = serde_json::to_string(&header).unwrap();
-
-        // Verify camelCase field names and uppercase enum
-        assert!(json.contains(r#""topic":"my_topic""#));
-        assert!(json.contains(r#""queueId":2"#));
-        assert!(json.contains(r#""timestamp":1702345678999"#));
-        assert!(json.contains(r#""boundaryType":"UPPER""#));
+        let v = serde_json::to_value(&header).unwrap();
+        assert_eq!(v["topic"], "my_topic");
+        assert_eq!(v["queueId"], 2);
+        assert_eq!(v["timestamp"], 1702345678999_i64);
+        assert_eq!(v["boundaryType"], "UPPER");
     }
rocketmq-common/src/common/boundary_type.rs (2)

101-108: FromStr should be infallible (Err = Infallible) since it never returns Err.
Current signature implies parsing can fail, but it can’t.

 use std::fmt;
 use std::str::FromStr;
+use std::convert::Infallible;

 impl FromStr for BoundaryType {
-    type Err = String;
+    type Err = Infallible;

     fn from_str(s: &str) -> Result<Self, Self::Err> {
         // Always succeeds, returns Lower as default (matches Java behavior)
         Ok(BoundaryType::get_type(s))
     }
 }

21-25: Verify serde dependency/feature policy + consider non-allocating deserialize path.
If rocketmq-common keeps serde behind a feature flag, these unconditional serde imports/impls should be cfg(feature = "serde"). Also, you can avoid allocating a String by deserializing into Cow<'de, str>.

Also applies to: 80-89

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27f90bf and cad0613.

📒 Files selected for processing (3)
  • rocketmq-common/src/common/boundary_type.rs (1 hunks)
  • rocketmq-remoting/src/protocol/header.rs (1 hunks)
  • rocketmq-remoting/src/protocol/header/search_offset_request_header.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Upload results
  • GitHub Check: Build & Test (macos-latest)
  • GitHub Check: Build & Test (windows-latest)
  • GitHub Check: Build & Test (ubuntu-latest)
  • GitHub Check: Code Coverage
  • GitHub Check: auto-approve
🔇 Additional comments (1)
rocketmq-remoting/src/protocol/header.rs (1)

72-73: Public module export looks right; just ensure module path/name matches the file.
Given this is a new public surface, a quick compile check will catch any mod/filename mismatch (and accidental shadowing with similarly named headers).

@codecov

codecov Bot commented Dec 12, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 31.07%. Comparing base (27f90bf) to head (cad0613).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4576      +/-   ##
==========================================
+ Coverage   30.91%   31.07%   +0.16%     
==========================================
  Files         675      676       +1     
  Lines       98814    99028     +214     
==========================================
+ Hits        30551    30776     +225     
+ Misses      68263    68252      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - All CI checks passed ✅

@rocketmq-rust-bot
rocketmq-rust-bot merged commit f287443 into main Dec 12, 2025
28 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Dec 12, 2025
@mxsm
mxsm deleted the feature-4575 branch December 14, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI review first Ai review pr first approved PR has approved auto merge feature🚀 Suggest an idea for this project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature🚀] Implement BoundaryType enum with serialization, deserialization, and parsing methods; add SearchOffsetRequestHeader struct with tests

4 participants