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

ut: add test for Snapshot #39

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Changes from 2 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
93 changes: 93 additions & 0 deletions crates/paimon/src/spec/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,96 @@ impl Snapshot {
self.statistics.as_deref()
}
}

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

#[test]
fn test_snapshot_creation() {
let snapshot = Snapshot::builder()
.version(1)
.id(1001)
.schema_id(2002)
.base_manifest_list("base_manifest_list".to_string())
.delta_manifest_list("delta_manifest_list".to_string())
.commit_user("user1".to_string())
.build();

assert_eq!(snapshot.version(), 1);
assert_eq!(snapshot.id(), 1001);
assert_eq!(snapshot.schema_id(), 2002);
assert_eq!(snapshot.base_manifest_list(), "base_manifest_list");
assert_eq!(snapshot.delta_manifest_list(), "delta_manifest_list");
assert_eq!(snapshot.commit_user(), "user1");
assert!(snapshot.changelog_manifest_list().is_none());
assert!(snapshot.index_manifest().is_none());
assert!(snapshot.total_record_count().is_none());
assert!(snapshot.delta_record_count().is_none());
assert!(snapshot.changelog_record_count().is_none());
assert!(snapshot.watermark().is_none());
assert!(snapshot.statistics().is_none());
}

#[test]
fn test_snapshot_with_optional_fields() {
let snapshot = Snapshot::builder()
.version(2)
.id(1002)
.schema_id(2003)
.base_manifest_list("base_manifest_list_v2".to_string())
.delta_manifest_list("delta_manifest_list_v2".to_string())
.changelog_manifest_list(Some("changelog_manifest_list_v2".to_string()))
.index_manifest(Some("index_manifest_list_v2".to_string()))
.commit_user("user2".to_string())
.total_record_count(Some(500))
.delta_record_count(Some(200))
.changelog_record_count(Some(50))
.watermark(Some(123456789))
.statistics(Some("statistics_v2".to_string()))
.build();

assert_eq!(snapshot.version(), 2);
assert_eq!(snapshot.id(), 1002);
assert_eq!(snapshot.schema_id(), 2003);
assert_eq!(snapshot.base_manifest_list(), "base_manifest_list_v2");
assert_eq!(snapshot.delta_manifest_list(), "delta_manifest_list_v2");
assert_eq!(
snapshot.changelog_manifest_list(),
Some("changelog_manifest_list_v2")
);
assert_eq!(snapshot.index_manifest(), Some("index_manifest_list_v2"));
assert_eq!(snapshot.commit_user(), "user2");
assert_eq!(snapshot.total_record_count(), Some(500));
assert_eq!(snapshot.delta_record_count(), Some(200));
assert_eq!(snapshot.changelog_record_count(), Some(50));
assert_eq!(snapshot.watermark(), Some(123456789));
Copy link
Contributor

Choose a reason for hiding this comment

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

Add an option for ut with a value of None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add an option for ut with a value of None?

OK, I will do it later.

assert_eq!(snapshot.statistics(), Some("statistics_v2"));
}

#[test]
fn test_snapshot_default_values() {
let snapshot = Snapshot::builder()
.version(3)
.id(1003)
.schema_id(2004)
.base_manifest_list("base_manifest_list_v3".to_string())
.delta_manifest_list("delta_manifest_list_v3".to_string())
.commit_user("user3".to_string())
.build();

assert_eq!(snapshot.version(), 3);
assert_eq!(snapshot.id(), 1003);
assert_eq!(snapshot.schema_id(), 2004);
assert_eq!(snapshot.base_manifest_list(), "base_manifest_list_v3");
assert_eq!(snapshot.delta_manifest_list(), "delta_manifest_list_v3");
assert_eq!(snapshot.commit_user(), "user3");
assert!(snapshot.changelog_manifest_list().is_none());
assert!(snapshot.index_manifest().is_none());
assert!(snapshot.total_record_count().is_none());
assert!(snapshot.delta_record_count().is_none());
assert!(snapshot.changelog_record_count().is_none());
assert!(snapshot.watermark().is_none());
assert!(snapshot.statistics().is_none());
}
}
Loading