Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #455] ✨Add CallSnapshot struct #456

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rocketmq-common/src/common/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pub mod call_snapshot;
pub mod moment_stats_item;
pub mod stats_snapshot;

Expand Down
61 changes: 61 additions & 0 deletions rocketmq-common/src/common/stats/call_snapshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#[derive(Debug, PartialEq, Copy, Clone)]

Check warning on line 18 in rocketmq-common/src/common/stats/call_snapshot.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-common/src/common/stats/call_snapshot.rs#L18

Added line #L18 was not covered by tests
pub struct CallSnapshot {
timestamp: u64,
times: u64,
value: u64,

Check warning on line 22 in rocketmq-common/src/common/stats/call_snapshot.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-common/src/common/stats/call_snapshot.rs#L20-L22

Added lines #L20 - L22 were not covered by tests
}

impl CallSnapshot {
pub fn new(timestamp: u64, times: u64, value: u64) -> Self {
CallSnapshot {
timestamp,
times,
value,
}
}

// Getter for timestamp
pub fn get_timestamp(&self) -> u64 {
self.timestamp
}

// Getter for times
pub fn get_times(&self) -> u64 {
self.times
}

// Getter for value
pub fn get_value(&self) -> u64 {
self.value
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn call_snapshot_initializes_correctly() {
let snapshot = CallSnapshot::new(100, 200, 300);
assert_eq!(snapshot.get_timestamp(), 100);
assert_eq!(snapshot.get_times(), 200);
assert_eq!(snapshot.get_value(), 300);
}
}
Loading