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

zyxxoo pushed a commit to branch refactor/rust-rewrite-design
in repository https://gitbox.apache.org/repos/asf/hugegraph.git


The following commit(s) were added to refs/heads/refactor/rust-rewrite-design 
by this push:
     new bda9e0d32 test(poc): add cache invalidation oracle
bda9e0d32 is described below

commit bda9e0d32e3838c21331b7af151b2e0df4131576
Author: vaughn <[email protected]>
AuthorDate: Thu Sep 10 02:19:16 2026 +0800

    test(poc): add cache invalidation oracle
---
 tools/rust-partition-poc/src/lib.rs | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/rust-partition-poc/src/lib.rs 
b/tools/rust-partition-poc/src/lib.rs
index 0d64740e6..e2f760914 100644
--- a/tools/rust-partition-poc/src/lib.rs
+++ b/tools/rust-partition-poc/src/lib.rs
@@ -145,6 +145,13 @@ pub fn replay(
     Ok(state)
 }
 
+pub fn cache_read(cache: Option<Partition>, source: &Partition) -> 
Result<Partition, &'static str> {
+    match cache {
+        Some(value) if value.version >= source.version => Ok(value),
+        _ => Err("cache-stale"),
+    }
+}
+
 #[cfg(test)]
 mod recovery_tests {
     use super::*;
@@ -201,3 +208,22 @@ mod recovery_tests {
         assert_eq!(replay(base(), &events, 20), Err("stale-heartbeat"));
     }
 }
+
+#[cfg(test)]
+mod cache_tests {
+    use super::*;
+
+    #[test]
+    fn invalidation_requires_latest_value() {
+        let source = Partition { start: 0, end: 10, version: 2 };
+        let cached = Partition { start: 0, end: 10, version: 1 };
+        assert_eq!(cache_read(Some(cached), &source), Err("cache-stale"));
+        assert_eq!(cache_read(None, &source), Err("cache-stale"));
+    }
+
+    #[test]
+    fn latest_cache_value_is_equivalent_to_source() {
+        let source = Partition { start: 0, end: 10, version: 2 };
+        assert_eq!(cache_read(Some(source.clone()), &source), Ok(source));
+    }
+}

Reply via email to