#![allow(deprecated)]
use oxcache::backend::l2::L2Backend;
use oxcache::config::L2Config;
use std::sync::Arc;
use crate::common;
#[tokio::test]
async fn test_version_control() {
common::setup_logging();
if !common::is_redis_available().await {
println!("Skipping test_version_control because Redis is not available");
return;
}
let redis_url =
std::env::var("REDIS_URL").unwrap_or_else(|_| "redis://127.0.0.1:6379".to_string());
let l2_config = L2Config {
connection_string: redis_url.into(),
..Default::default()
};
let l2 = Arc::new(
L2Backend::new(&l2_config)
.await
.expect("Failed to create L2"),
);
let _ = l2.delete("version_key").await;
l2.set_with_version("version_key", b"v1".to_vec(), None)
.await
.expect("Set failed");
let (val1, ver1) = l2
.get_with_version("version_key")
.await
.expect("Get failed")
.expect("Value missing");
assert_eq!(val1, b"v1");
l2.set_with_version("version_key", b"v2".to_vec(), None)
.await
.expect("Set failed");
let (val2, ver2) = l2
.get_with_version("version_key")
.await
.expect("Get failed")
.expect("Value missing");
assert_eq!(val2, b"v2");
assert!(ver2 > ver1, "Version should increment: {} > {}", ver2, ver1);
let _ = l2.delete("version_key").await;
}